//+------------------------------------------------------------------+
//| Levels.mq4 |
//| Copyright 2023, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#property indicator_chart_window
input int step=222;
input int count=5;
input int width=1;
input color clr=Red;
input bool uplev=1;
input bool dnlev=1;
input bool right=1;
datetime t=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutTrendLine(string name,datetime time1,double price1,datetime time2,double price2)
{
ObjectDelete(0,name);
ObjectCreate(0,name,OBJ_TREND,0,time1,price1,time2,price2);
//--- установим цвет линии
ObjectSetInteger(0,name,OBJPROP_COLOR,clr);
//--- установим стиль отображения линии
ObjectSetInteger(0,name,OBJPROP_STYLE,0);
//--- установим толщину линии
ObjectSetInteger(0,name,OBJPROP_WIDTH,width);
//--- включим (true) или отключим (false) режим продолжения отображения линии вправо
ObjectSetInteger(0,name,OBJPROP_RAY_RIGHT,false);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutRLabel(string name,datetime time,double price)
{
//--- создадим текстовую метку
ObjectDelete(0,name);
ObjectCreate(0,name,OBJ_ARROW_RIGHT_PRICE,0,time,price);
//--- установим размер метки
ObjectSetInteger(0,name,OBJPROP_WIDTH,width);
//--- установим цвет
ObjectSetInteger(0,name,OBJPROP_COLOR,clr);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//---
if(t!=Time[0])
{
for(int i=0; i<ObjectsTotal(); i++)
{
if(ObjectType(ObjectName(0,i,0,OBJ_ARROW_RIGHT_PRICE)))
{
ObjectSetInteger(0,ObjectName(0,i,0,OBJ_ARROW_RIGHT_PRICE),OBJPROP_TIME1,Time[0]+11*PeriodSeconds());
}
if(ObjectType(ObjectName(0,i,0,OBJ_TREND)))
{
ObjectSetInteger(0,ObjectName(0,i,0,OBJ_TREND),OBJPROP_TIME1,Time[0]);
ObjectSetInteger(0,ObjectName(0,i,0,OBJ_TREND),OBJPROP_TIME2,Time[0]+11*PeriodSeconds());
}
}
t=Time[0];
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnChartEvent(const int id, // идентификатор события
const long& lparam, // параметр события типа long
const double& dparam, // параметр события типа double
const string& sparam // параметр события типа string
)
{
if(id==CHARTEVENT_CLICK)
{
//--- подготовим переменные
int x =(int)lparam;
int y =(int)dparam;
datetime dt =0;
double price =0;
int window=0;
//--- преобразуем координаты X и Y в терминах дата/время
ChartXYToTimePrice(0,x,y,window,dt,price);
PutTrendLine("null",Time[0],price,Time[0]+11*PeriodSeconds(),price);
if(right)
PutRLabel("lab",Time[0]+11*PeriodSeconds(),price);
for(int i=1; i<=count; i++)
{
if(uplev)
{
PutTrendLine("up"+string(i),Time[0],price+step*_Point*i,Time[0]+11*PeriodSeconds(),price+step*_Point*i);
if(right)
PutRLabel("ulab"+string(i),Time[0]+11*PeriodSeconds(),price+step*_Point*i);
}
if(dnlev)
{
PutTrendLine("dn"+string(i),Time[0],price-step*_Point*i,Time[0]+11*PeriodSeconds(),price-step*_Point*i);
if(right)
PutRLabel("dlab"+string(i),Time[0]+11*PeriodSeconds(),price-step*_Point*i);
}
}
}
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
Сов простой
AM2