Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
1
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

@tani-shi

[MQL5]クリックした場所に横線を引くスクリプト

//+------------------------------------------------------------------+
//|                                                   LineRedraw.mq5 |
//|                                                Shintaro Tanikawa |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Shintaro Tanikawa"
#property link      "https://www.mql5.com"
#property version   "1.00"

static const string vLineName = "V-Line";
static const string hLineName = "H-Line";

void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{
  if (id == CHARTEVENT_CLICK)
  {
    const int x = (int)lparam;
    const int y = (int)dparam;
    datetime dt = 0;
    double price = 0;
    int window = 0;
    long chartId = ChartID();
    if (ChartXYToTimePrice(chartId, x, y, window, dt, price))
    {
      CreateHLine(chartId, window, dt, price);
      //CreateVLine(chartId, window, dt, price);

      ChartRedraw(chartId);
    }
  }
}

void CreateHLine(long chartId, int window, datetime dt, double price)
{
  if (ObjectFind(chartId, hLineName))
  {
    ObjectDelete(chartId, hLineName);
  }

  ObjectCreate(chartId, hLineName, OBJ_HLINE, 0, dt, price);
  ObjectSetInteger(chartId, hLineName, OBJPROP_COLOR, clrRed);
}

void CreateVLine(long chartId, int window, datetime dt, double price)
{
  if (ObjectFind(chartId, vLineName))
  {
    ObjectDelete(chartId, vLineName);
  }

  ObjectCreate(chartId, vLineName, OBJ_VLINE, 0, dt, price);
  ObjectSetInteger(chartId, vLineName, OBJPROP_COLOR, clrRed);
}
//+------------------------------------------------------------------+

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
1
Help us understand the problem. What are the problem?