Оригинал был доработан по моему ТЗ.
Называется «Виртуальный день», поскольку имеющиеся дни меня не совсем устраивают.
//+------------------------------------------------------------------+
//| IndVirtualDay.mq4 |
//| Copyright 2013, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_chart_window
//----
#import "user32.dll"
//----
bool GetWindowRect(int h, int& pos[4]);
//----
extern int NumDays =100; //количество дней отображения
extern int StartHour =0; //старт виртуального дня в часах
extern int StartMin =0; //старт виртуального дня в минутах
extern int StopHour =0; //окончание виртуального дня в часах
extern int StopMin =0; //окончание виртуального дня в минутах
extern int UseHigh =0; //разрешение отрисовки надписи линии максимальной цены дня
extern int UseLow =0; //разрешение отрисовки надписи линии минимальной цены дня
extern int UseOpen =0; //разрешение отрисовки надписи линии цены открытия дня
extern int UseClose =0; //разрешение отрисовки надписи линии цены закрытия дня
extern color ColorHigh =DarkViolet; //цвет линии максимальной цены дня
extern color ColorLow =DarkViolet; //цвет линии минимальной цены дня
extern color ColorOpen =FireBrick; //цвет линии цены открытия дня
extern color ColorClose =OrangeRed; //цвет линии цены закрытия дня
extern int LineWidth =2; //толщина линий
extern int FontSize =6; //размер шрифта
extern int FontSize1 =6; //размер шрифта котировок
extern string ExtTFShow = "M1,M5,M15,M30,H1"; //На каких таймфреймах показывать
//----
int indent1[6][6]={6400,3200,1600,800,400,200,
16000,8000,4000,2200,1500,1000,
45000,25000,14000,8000,4000,2000,
90000,50000,28000,16000,8000,4000,
160000,85000,45000,28000,15000,8000,
704000,352000,176000,88000,44000,22000};
//----
int time_frame;
int scale_prev;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
if(Period()>240)
return(0);
//----
switch(Period())
{
case 1: time_frame=0;
if(StringFind(ExtTFShow, "M1", 0) == -1) return(INIT_FAILED);
break;
//----
case 5: time_frame=1;
if(StringFind(ExtTFShow, "M5", 0) == -1) return(INIT_FAILED);
break;
//----
case 15: time_frame=2;
if(StringFind(ExtTFShow, "M15", 0) == -1) return(INIT_FAILED);
break;
//----
case 30: time_frame=3;
if(StringFind(ExtTFShow, "M30", 0) == -1) return(INIT_FAILED);
break;
//----
case 60: time_frame=4;
if(StringFind(ExtTFShow, "H1", 0) == -1) return(INIT_FAILED);
break;
//----
case 240: time_frame=5;
if(StringFind(ExtTFShow, "H4", 0) == -1) return(INIT_FAILED);
break;
//----
default: time_frame=0;
}
//----
scale_prev=MathRound(MathLog(GetTimeScalePx())/MathLog(2.0));
//----
for(int pos=NumDays-1;pos>=0;pos--)
DayCreate(pos,scale_prev);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
for(int pos=ObjectsTotal()-1;pos>=0;pos--)
{
if(StringSubstr(ObjectName(pos),0,StringLen("START_DAY_"))=="START_DAY_")
ObjectDelete(ObjectName(pos));
//----
if(StringSubstr(ObjectName(pos),0,StringLen("STOP_DAY_"))=="STOP_DAY_")
ObjectDelete(ObjectName(pos));
//----
if(StringSubstr(ObjectName(pos),0,StringLen("OPEN_DAY_"))=="OPEN_DAY_")
ObjectDelete(ObjectName(pos));
//----
if(StringSubstr(ObjectName(pos),0,StringLen("CLOSE_DAY_"))=="CLOSE_DAY_")
ObjectDelete(ObjectName(pos));
//----
if(StringSubstr(ObjectName(pos),0,StringLen("HIGH_DAY_"))=="HIGH_DAY_")
ObjectDelete(ObjectName(pos));
//----
if(StringSubstr(ObjectName(pos),0,StringLen("LOW_DAY_"))=="LOW_DAY_")
ObjectDelete(ObjectName(pos));
//----
if(StringSubstr(ObjectName(pos),0,StringLen("TEXT_OPEN_DAY"))=="TEXT_OPEN_DAY")
ObjectDelete(ObjectName(pos));
//----
if(StringSubstr(ObjectName(pos),0,StringLen("TEXT_CLOSE_DAY"))=="TEXT_CLOSE_DAY")
ObjectDelete(ObjectName(pos));
//----
if(StringSubstr(ObjectName(pos),0,StringLen("TEXT_HIGH_DAY"))=="TEXT_HIGH_DAY")
ObjectDelete(ObjectName(pos));
//----
if(StringSubstr(ObjectName(pos),0,StringLen("TEXT_LOW_DAY"))=="TEXT_LOW_DAY")
ObjectDelete(ObjectName(pos));
//----
if(StringSubstr(ObjectName(pos),0,StringLen("TEXT_DATE_DAY"))=="TEXT_DATE_DAY")
ObjectDelete(ObjectName(pos));
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//----
if(Period()>240)
return(0);
//----
int scale=MathRound(MathLog(GetTimeScalePx())/MathLog(2.0));
//----
if(scale==scale_prev)
DayCreate(0,scale);
else
for(int pos=NumDays-1;pos>=0;pos--)
{
DayCreate(pos,scale);
scale_prev=scale;
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int GetTimeScalePx()
{
int h=WindowHandle(Symbol(),Period());
int rect[4];
//----
if(h==0)
return(-1);
//----
GetWindowRect(h,rect);
int wW=rect[2]-rect[0]; // ширина окна
int bpc=WindowBarsPerChart();
//----
if(bpc==0)
return(-1);
//----
return(MathFloor((wW-48)/bpc));
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DayCreate(int num_day,int scale)
{
color color_day;
//----
datetime start_real_day;
datetime start_virtual_day;
datetime stop_virtual_day;
datetime time1;
datetime time2;
datetime time3;
datetime time4;
datetime time;
datetime weekend = 0;
//----
string name_day;
string date;
//----
double price1;
double price2;
double price;
double open_day;
double close_day;
double high_day;
double low_day;
//----
int shift_bar;
int ind1;
int ind2;
int ind3=100;
//--- в выходные ничего не рисуем:
//----
ind1=indent1[time_frame][scale];
start_real_day=iTime(Symbol(),PERIOD_D1,num_day);
//----отрисовка вертикальных линий начала дня
start_virtual_day=StartHour*3600+StartMin*60;
if(TimeDayOfWeek(start_real_day) == 1 && start_virtual_day < 0)
weekend = -2*PERIOD_D1*60;
time1=start_real_day+start_virtual_day+weekend;
time2=start_real_day+start_virtual_day+weekend;
//----
ObjectCreate("START_DAY_"+start_real_day,OBJ_TREND,0,0,0.0,0,0.0);
ObjectSet("START_DAY_"+start_real_day,OBJPROP_TIME1,time1);
ObjectSet("START_DAY_"+start_real_day,OBJPROP_PRICE1,0.01);
ObjectSet("START_DAY_"+start_real_day,OBJPROP_TIME2,time2);
ObjectSet("START_DAY_"+start_real_day,OBJPROP_PRICE2,1.0);
ObjectSet("START_DAY_"+start_real_day,OBJPROP_COLOR,DimGray);
ObjectSet("START_DAY_"+start_real_day,OBJPROP_STYLE,STYLE_DOT);
ObjectSet("START_DAY_"+start_real_day,OBJPROP_WIDTH,1);
ObjectSet("START_DAY_"+start_real_day,OBJPROP_RAY,true);
ObjectSet("START_DAY_"+start_real_day,OBJPROP_BACK,true);
//----отрисовка вертикальных линий конца дня
if(StopHour>0)
{
stop_virtual_day=StopHour*3600+StopMin*60;
time3=start_real_day+stop_virtual_day;
time4=start_real_day+stop_virtual_day;
}
else
{
weekend = 0;
if(TimeDayOfWeek(start_real_day) == 5 && start_virtual_day >=0)
weekend = 3*PERIOD_D1*60;
time3=start_real_day+start_virtual_day+PERIOD_D1*60+weekend;
time4=start_real_day+start_virtual_day+PERIOD_D1*60+weekend;
}
//----
ObjectCreate("STOP_DAY_"+start_real_day,OBJ_TREND,0,0,0.0,0,0.0);
ObjectSet("STOP_DAY_"+start_real_day,OBJPROP_TIME1,time3);
ObjectSet("STOP_DAY_"+start_real_day,OBJPROP_PRICE1,0.01);
ObjectSet("STOP_DAY_"+start_real_day,OBJPROP_TIME2,time4);
ObjectSet("STOP_DAY_"+start_real_day,OBJPROP_PRICE2,1.0);
ObjectSet("STOP_DAY_"+start_real_day,OBJPROP_COLOR,DimGray);
ObjectSet("STOP_DAY_"+start_real_day,OBJPROP_STYLE,STYLE_DOT);
ObjectSet("STOP_DAY_"+start_real_day,OBJPROP_WIDTH,1);
ObjectSet("STOP_DAY_"+start_real_day,OBJPROP_RAY,true);
ObjectSet("STOP_DAY_"+start_real_day,OBJPROP_BACK,true);
//----отрисовка горизонтальной линии цены открытия дня
if(StopHour>0)
{
time2=start_real_day+stop_virtual_day;
}
else
{
if(TimeDayOfWeek(start_real_day)==5 && start_virtual_day >=0)
time2=start_real_day+start_virtual_day+PERIOD_D1*180;
else
time2=start_real_day+start_virtual_day+PERIOD_D1*60;
}
//----
if(StopHour==0)
if(num_day==0)
time2=start_real_day+start_virtual_day+PERIOD_D1*60;
//----
shift_bar=iBarShift(Symbol(),Period(),start_real_day+start_virtual_day,false);
open_day=Open[shift_bar];
ObjectCreate("OPEN_DAY_"+start_real_day,OBJ_TREND,0,0,0.0,0,0.0);
ObjectSet("OPEN_DAY_"+start_real_day,OBJPROP_TIME1,time1);
ObjectSet("OPEN_DAY_"+start_real_day,OBJPROP_PRICE1,Open[shift_bar]);
ObjectSet("OPEN_DAY_"+start_real_day,OBJPROP_TIME2,time2);
ObjectSet("OPEN_DAY_"+start_real_day,OBJPROP_PRICE2,Open[shift_bar]);
ObjectSet("OPEN_DAY_"+start_real_day,OBJPROP_COLOR,ColorOpen);
ObjectSet("OPEN_DAY_"+start_real_day,OBJPROP_STYLE,DRAW_LINE);
ObjectSet("OPEN_DAY_"+start_real_day,OBJPROP_WIDTH,LineWidth);
ObjectSet("OPEN_DAY_"+start_real_day,OBJPROP_RAY,false);
ObjectSet("OPEN_DAY_"+start_real_day,OBJPROP_BACK,true);
//----отрисовка надписи цены открытия дня
if(UseOpen==1)
{
ObjectCreate("TEXT_OPEN_DAY"+start_real_day,OBJ_TEXT,0,0,0.0,0,0.0);
ObjectSet("TEXT_OPEN_DAY"+start_real_day,OBJPROP_TIME1,time1+ind1);
ObjectSet("TEXT_OPEN_DAY"+start_real_day,OBJPROP_PRICE1,Open[shift_bar]+ind2*Point);
ObjectSet("TEXT_OPEN_DAY"+start_real_day,OBJPROP_BACK,false);
ObjectSetText("TEXT_OPEN_DAY"+start_real_day,"Open: "+DoubleToStr(Open[shift_bar],Digits),
FontSize1,"Times New Roman",White);
}
//----отрисовка горизонтальной линии цены закрытия дня
if(StopHour>0)
{
time2=start_real_day+stop_virtual_day;
shift_bar=iBarShift(Symbol(),Period(),time2-1,false);
price1=Close[shift_bar];
price2=Close[shift_bar];
}
else
{
if(TimeDayOfWeek(start_real_day)==5 && start_virtual_day >=0)
{
time2=start_real_day+start_virtual_day+PERIOD_D1*180;
shift_bar=iBarShift(Symbol(),Period(),time2-1,false);
price1=Close[shift_bar];
price2=Close[shift_bar];
}
else
{
time2=start_real_day+start_virtual_day+PERIOD_D1*60;
shift_bar=iBarShift(Symbol(),Period(),time2-1,false);
price1=Close[shift_bar];
price2=Close[shift_bar];
}
}
//----
if(StopHour==0)
if(num_day==0)
time2=start_real_day+start_virtual_day+PERIOD_D1*60;
//----
close_day=Close[shift_bar];
ObjectCreate("CLOSE_DAY_"+start_real_day,OBJ_TREND,0,0,0.0,0,0.0);
ObjectSet("CLOSE_DAY_"+start_real_day,OBJPROP_TIME1,time1);
ObjectSet("CLOSE_DAY_"+start_real_day,OBJPROP_PRICE1,price1);
ObjectSet("CLOSE_DAY_"+start_real_day,OBJPROP_TIME2,time2);
ObjectSet("CLOSE_DAY_"+start_real_day,OBJPROP_PRICE2,price2);
ObjectSet("CLOSE_DAY_"+start_real_day,OBJPROP_COLOR,ColorClose);
ObjectSet("CLOSE_DAY_"+start_real_day,OBJPROP_STYLE,DRAW_LINE);
ObjectSet("CLOSE_DAY_"+start_real_day,OBJPROP_WIDTH,LineWidth);
ObjectSet("CLOSE_DAY_"+start_real_day,OBJPROP_RAY,false);
ObjectSet("CLOSE_DAY_"+start_real_day,OBJPROP_BACK,true);
//----отрисовка надписи цены закрытия дня
if(UseClose==1)
{
ObjectCreate("TEXT_CLOSE_DAY"+start_real_day,OBJ_TEXT,0,0,0.0,0,0.0);
ObjectSet("TEXT_CLOSE_DAY"+start_real_day,OBJPROP_TIME1,time1+ind1);
ObjectSet("TEXT_CLOSE_DAY"+start_real_day,OBJPROP_PRICE1,Close[shift_bar]+ind2*Point);
ObjectSet("TEXT_CLOSE_DAY"+start_real_day,OBJPROP_BACK,false);
ObjectSetText("TEXT_CLOSE_DAY"+start_real_day,"Close: "+DoubleToStr(Close[shift_bar],Digits),
FontSize1,"Times New Roman",White);
}
//----отрисовка горизонтальной линии максимальной цены дня
price=0.0;
//----
if(StopHour>0)
{
time2=start_real_day+stop_virtual_day;
time=time2-1;
//----
while(true)
{
shift_bar=iBarShift(Symbol(),Period(),time,false);
//----
if(High[shift_bar]>price)
price=High[shift_bar];
//----
time=time-Period()*60;
//----
if(time<time1)
break;
}
}
else
{
if(TimeDayOfWeek(start_real_day)==5 && start_virtual_day >=0)
{
time2=start_real_day+start_virtual_day+PERIOD_D1*180;
time=time2-1;
//----
while(true)
{
shift_bar=iBarShift(Symbol(),Period(),time,false);
//----
if(High[shift_bar]>price)
price=High[shift_bar];
//----
time=time-Period()*60;
//----
if(time<time1)
break;
}
}
else
{
time2=start_real_day+start_virtual_day+PERIOD_D1*60;
time=time2-1;
//----
while(true)
{
shift_bar=iBarShift(Symbol(),Period(),time,false);
//----
if(High[shift_bar]>price)
price=High[shift_bar];
//----
time=time-Period()*60;
//----
if(time<time1)
break;
}
}
}
//----
if(StopHour==0)
if(num_day==0)
time2=start_real_day+start_virtual_day+PERIOD_D1*60;
//----
high_day=price;
ObjectCreate("HIGH_DAY_"+start_real_day,OBJ_TREND,0,0,0.0,0,0.0);
ObjectSet("HIGH_DAY_"+start_real_day,OBJPROP_TIME1,time1);
ObjectSet("HIGH_DAY_"+start_real_day,OBJPROP_PRICE1,price);
ObjectSet("HIGH_DAY_"+start_real_day,OBJPROP_TIME2,time2);
ObjectSet("HIGH_DAY_"+start_real_day,OBJPROP_PRICE2,price);
ObjectSet("HIGH_DAY_"+start_real_day,OBJPROP_COLOR,ColorHigh);
ObjectSet("HIGH_DAY_"+start_real_day,OBJPROP_STYLE,DRAW_LINE);
ObjectSet("HIGH_DAY_"+start_real_day,OBJPROP_WIDTH,LineWidth);
ObjectSet("HIGH_DAY_"+start_real_day,OBJPROP_RAY,false);
ObjectSet("HIGH_DAY_"+start_real_day,OBJPROP_BACK,true);
//----отрисовка надписи максимальной цены дня
if(UseHigh==1)
{
ObjectCreate("TEXT_HIGH_DAY"+start_real_day,OBJ_TEXT,0,0,0.0,0,0.0);
ObjectSet("TEXT_HIGH_DAY"+start_real_day,OBJPROP_TIME1,time1+ind1);
ObjectSet("TEXT_HIGH_DAY"+start_real_day,OBJPROP_PRICE1,price+ind2*Point);
ObjectSet("TEXT_HIGH_DAY"+start_real_day,OBJPROP_BACK,false);
ObjectSetText("TEXT_HIGH_DAY"+start_real_day,"High: "+DoubleToStr(price,Digits),
FontSize1,"Times New Roman",White);
}
//----отрисовка горизонтальной линии минимальной цены дня
price=0.0;
//----
if(StopHour>0)
{
time2=start_real_day+stop_virtual_day;
time=time2-1;
//----
while(true)
{
shift_bar=iBarShift(Symbol(),Period(),time,false);
//----
if(price==0.0)
price=Low[shift_bar];
//----
if(Low[shift_bar]<price)
price=Low[shift_bar];
//----
time=time-Period()*60;
//----
if(time<time1)
break;
}
}
else
{
if(TimeDayOfWeek(start_real_day)==5 && start_virtual_day >=0)
{
time2=start_real_day+start_virtual_day+PERIOD_D1*180;
time=time2-1;
//----
while(true)
{
shift_bar=iBarShift(Symbol(),Period(),time,false);
//----
if(price==0.0)
price=Low[shift_bar];
//----
if(Low[shift_bar]<price)
price=Low[shift_bar];
//----
time=time-Period()*60;
//----
if(time<time1)
break;
}
}
else
{
time2=start_real_day+start_virtual_day+PERIOD_D1*60;
time=time2-1;
//----
while(true)
{
shift_bar=iBarShift(Symbol(),Period(),time,false);
//----
if(price==0.0)
price=Low[shift_bar];
//----
if(Low[shift_bar]<price)
price=Low[shift_bar];
//----
time=time-Period()*60;
//----
if(time<time1)
break;
}
}
}
//----
if(StopHour==0)
if(num_day==0)
time2=start_real_day+start_virtual_day+PERIOD_D1*60;
//----
low_day=price;
ObjectCreate("LOW_DAY_"+start_real_day,OBJ_TREND,0,0,0.0,0,0.0);
ObjectSet("LOW_DAY_"+start_real_day,OBJPROP_TIME1,time1);
ObjectSet("LOW_DAY_"+start_real_day,OBJPROP_PRICE1,price);
ObjectSet("LOW_DAY_"+start_real_day,OBJPROP_TIME2,time2);
ObjectSet("LOW_DAY_"+start_real_day,OBJPROP_PRICE2,price);
ObjectSet("LOW_DAY_"+start_real_day,OBJPROP_COLOR,ColorLow);
ObjectSet("LOW_DAY_"+start_real_day,OBJPROP_STYLE,DRAW_LINE);
ObjectSet("LOW_DAY_"+start_real_day,OBJPROP_WIDTH,LineWidth);
ObjectSet("LOW_DAY_"+start_real_day,OBJPROP_RAY,false);
ObjectSet("LOW_DAY_"+start_real_day,OBJPROP_BACK,true);
//----отрисовка надписи минимальной цены дня
if(UseLow==1)
{
ObjectCreate("TEXT_LOW_DAY"+start_real_day,OBJ_TEXT,0,0,0.0,0,0.0);
ObjectSet("TEXT_LOW_DAY"+start_real_day,OBJPROP_TIME1,time1+ind1);
ObjectSet("TEXT_LOW_DAY"+start_real_day,OBJPROP_PRICE1,price+ind2*Point);
ObjectSet("TEXT_LOW_DAY"+start_real_day,OBJPROP_BACK,false);
ObjectSetText("TEXT_LOW_DAY"+start_real_day,"Low: "+DoubleToStr(price,Digits),
FontSize1,"Times New Roman",White);
}
//----
//----определение дня недели
if(TimeDayOfWeek(start_real_day)==1)
name_day="Пон";
//----
if(TimeDayOfWeek(start_real_day)==2)
name_day="Вт";
//----
if(TimeDayOfWeek(start_real_day)==3)
name_day="Ср";
//----
if(TimeDayOfWeek(start_real_day)==4)
name_day="Чет";
//----
if(TimeDayOfWeek(start_real_day)==5)
name_day="Пят";
//----установка цвета дня
if(open_day<close_day)
color_day=Green;
//----установка цвета дня
if(open_day>close_day)
color_day=Red;
//----установка цвета дня
if(open_day==close_day)
color_day=Blue;
//----отрисовка наименования дней
date=StringSubstr(TimeToStr(start_real_day,TIME_DATE),5,0);
//----
ObjectCreate("TEXT_DATE_DAY"+start_real_day,OBJ_TEXT,0,0,0.0,0,0.0);
ObjectSet("TEXT_DATE_DAY"+start_real_day,OBJPROP_TIME1,time1+ind1);
ObjectSet("TEXT_DATE_DAY"+start_real_day,OBJPROP_PRICE1,high_day+ind3*Point);
ObjectSet("TEXT_DATE_DAY"+start_real_day,OBJPROP_BACK,false);
ObjectSetText("TEXT_DATE_DAY"+start_real_day,name_day+" "+date,FontSize,"Times New Roman",color_day);
//----
WindowRedraw();
}
//+------------------------------------------------------------------+
Комментарии (7)
расскажи в двух словах что к чему
13 Enot-pipsun Сообщений: 301
Чёрточки, цифИрЬКИ
20 Anatoly74 Автор Сообщений: 3710 - Анатолий
да шучу я
уже прикрутил. люблю линии красивые посмотреть
13 Enot-pipsun Сообщений: 301
27 Oxy Сообщений: 3430 - ..ιllιlι.lι.ιllι.ιlι..
Ещё со времён ящика Пандоры.
20 Anatoly74 Автор Сообщений: 3710 - Анатолий
имеем опен хай лоу клоуз дня.
в настройках можно менять время открытия дня
13 Enot-pipsun Сообщений: 301
20 Anatoly74 Автор Сообщений: 3710 - Анатолий
Зарегистрируйтесь или авторизуйтесь, чтобы оставить комментарий