1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

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

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?