//+------------------------------------------------------------------+
//| 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);
}
//+------------------------------------------------------------------+
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme
List of users who liked
11