[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);
}
//+------------------------------------------------------------------+

Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account log in.