MultiSymbolSignals/Include/MultiSymbol/Checks.mqh

486 lines
40 KiB
MQL5
Raw Permalink Normal View History

2025-05-30 16:10:44 +02:00
<EFBFBD><EFBFBD>//--- !2O7L A >A=>2=K< D09;>< 8=48:0B>@0
//#include "..\MultiSymbolPriceDivergence.mq5"
//--- >4:;NG05< A2>8 181;8>B5:8
#include "SettingChart.mqh"
#include "SetDeleteObjects.mqh"
//+------------------------------------------------------------------+
//| 03@C605B 8 D>@<8@C5< =5>1E>48<>5/8<5NI55AO :>;-2> 40==KE |
//+------------------------------------------------------------------+
void LoadFormationData()
{
int try =10; // >;8G5AB2> C40G=KE ?>?KB>:
int number_bars =100; // >;8G5AB2> ?>43@C605<KE 10@>2
//---
for(int s=0; s<SYMBOLS; s++)
{
int count_try =0; // !GQBG8: ?>?KB>: :>?8@>20=8O 40==KE
int array_size =0; // 07<5@ <0AA820
datetime server_firstdate =NULL; // @5<O ?5@2>3> 10@0 =0 A5@25@5
datetime series_firstdate =NULL; // @5<O ?5@2>3> 10@0 2 1075 B5@<8=0;0
//--- >;CG8< ?5@2CN 40BC A8<2>;0-?5@8>40 2 1075 B5@<8=0;0
for(int i=0; i<try; i++)
if(SeriesInfoInteger(symbols_names[s],Period(),SERIES_FIRSTDATE,series_firstdate))
break;
//--- >;CG8< ?5@2CN 40BC A8<2>;0-?5@8>40 =0 A5@25@5
for(int i=0; i<try; i++)
if(SeriesInfoInteger(symbols_names[s],Period(),SERIES_SERVER_FIRSTDATE,server_firstdate))
break;
//--- K2545< A>>1I5=85
message_last=message_formation_data="@>F5AA 703@C7:8 8 D>@<8@>20=8O 40==KE B5:CI53> B09<D@59<0: "+
symbols_names[s]+"("+IntegerToString(s+1)+"/"+IntegerToString(SYMBOLS)+") ... ";
ShowCanvasMessage(message_formation_data);
//--- 03@C78</AD>@<8@C5< 40==K5,
// 5A;8 @07<5@ <0AA820 <5=LH5, G5< <0:A8<0;L=>5 :>;8G5AB2> 10@>2 2 B5@<8=0;5, 0 B0:65
// <564C ?5@2>9 40B>9 A5@88 2 B5@<8=0;5 8 ?5@2>9 40B>9 A5@88 =0 A5@25@5 1>;LH5 C:070==>3> :>;8G5AB20 10@>2
while(array_size<on_calc_rates_total &&
series_firstdate-server_firstdate>PeriodSeconds()*number_bars)
{
datetime copied_time[];
//--- >;CG8< ?5@2CN 40BC A8<2>;0-?5@8>40 2 1075 B5@<8=0;0
for(int i=0; i<try; i++)
if(SeriesInfoInteger(symbols_names[s],Period(),SERIES_FIRSTDATE,series_firstdate))
break;
//--- 03@C78</A:>?8@C5< 5IQ C:070==>5 :>;8G5AB2> 10@>2
if(CopyTime(symbols_names[s],Period(),0,array_size+number_bars,copied_time))
{
//--- A;8 2@5<O ?5@2>3> 10@0 <0AA820 A 2KG5B>< :>;-20 ?>43@C605<KE 10@>2 @0=LH5,
// G5< 2@5<O ?5@2>3> 10@0 =0 3@0D8:5, >AB0=>28< F8:;
if(copied_time[0]-PeriodSeconds()*number_bars<on_calc_time[0])
break;
//--- A;8 @07<5@ <0AA820 =5 C25;8G8;AO,
// C25;8G8< AGQBG8:
if(ArraySize(copied_time)==array_size)
count_try++;
//--- =0G5 ?>;CG8< B5:CI89 @07<5@ <0AA820
else
array_size=ArraySize(copied_time);
//--- A;8 @07<5@ <0AA820 =5 C25;8G8205BAO 2 B5G5=88
// 100 ?>?KB>:, >AB0=>28< F8:; 8 >1=C;8< AGQBG8: 4;O A;54CNI53> A8<2>;0
if(count_try==100)
{
count_try=0;
break;
}
}
}
}
}
//+------------------------------------------------------------------+
//| 03@C605B 8 D>@<8@C5< =5>1E>48<>5/8<5NI55AO :>;-2> 40==KE |
//+------------------------------------------------------------------+
void LoadFormationDataHighTF()
{
//--- A;8 2 @568<5 25@B8:0;L=>9 ;8=88 4;O =0G0;L=>9 B>G:8 @0AE>645=8O F5=, 2KE>48<
if(StartPriceDivergence==VERT_LINE)
return;
//---
int try =50; // >;8G5AB2> C40G=KE ?>?KB>:
int number_bars =100; // >;8G5AB2> ?>43@C605<KE 10@>2
//---
int count_try =0; // !GQBG8: ?>?KB>: :>?8@>20=8O 40==KE
int array_size =0; // 07<5@ <0AA820
datetime server_firstdate =NULL; // @5<O ?5@2>3> 10@0 =0 A5@25@5
datetime series_firstdate =NULL; // @5<O ?5@2>3> 10@0 2 1075 B5@<8=0;0
//--- >;CG8< ?5@2CN 40BC A8<2>;0-?5@8>40 2 1075 B5@<8=0;0
for(int i=0; i<try; i++)
if(SeriesInfoInteger(Symbol(),timeframe_start_point,SERIES_FIRSTDATE,series_firstdate))
break;
//--- >;CG8< ?5@2CN 40BC A8<2>;0-?5@8>40 =0 A5@25@5
for(int i=0; i<try; i++)
if(SeriesInfoInteger(Symbol(),timeframe_start_point,SERIES_SERVER_FIRSTDATE,server_firstdate))
break;
//--- K2545< A>>1I5=85
message_last=message_formation_data="@>F5AA 703@C7:8 8 D>@<8@>20=8O 40==KE AB0@H53> B09<D@59<0 ... ";
ShowCanvasMessage(message_formation_data);
//--- 03@C78</AD>@<8@C5< 40==K5,
// <564C ?5@2>9 40B>9 A5@88 2 B5@<8=0;5 8 ?5@2>9 40B>9 A5@88 =0 A5@25@5 1>;LH5 C:070==>3> :>;8G5AB20 10@>2
while(series_firstdate>server_firstdate &&
series_firstdate-server_firstdate>PeriodSeconds(timeframe_start_point)*number_bars)
{
datetime copied_time[];
//--- >;CG8< ?5@2CN 40BC A8<2>;0-?5@8>40 2 1075 B5@<8=0;0
for(int i=0; i<try; i++)
if(SeriesInfoInteger(Symbol(),timeframe_start_point,SERIES_FIRSTDATE,series_firstdate))
break;
//--- 03@C78</A:>?8@C5< 5IQ C:070==>5 :>;8G5AB2> 10@>2
if(CopyTime(Symbol(),timeframe_start_point,0,array_size+number_bars,copied_time))
{
//--- A;8 2@5<O ?5@2>3> 10@0 <0AA820 A 2KG5B>< :>;-20 ?>43@C605<KE 10@>2 @0=LH5 <5=LH5,
// G5< 2@5<O ?5@2>3> 10@0 =0 3@0D8:5, >AB0=>28< F8:;
if(copied_time[0]-PeriodSeconds(timeframe_start_point)*number_bars<=on_calc_time[0])
break;
//--- A;8 @07<5@ <0AA820 =5 C25;8G8;AO,
// C25;8G8< AGQBG8:
if(ArraySize(copied_time)==array_size)
count_try++;
//--- =0G5 ?>;CG8< B5:CI89 @07<5@ <0AA820
else
array_size=ArraySize(copied_time);
//--- A;8 @07<5@ <0AA820 =5 C25;8G8205BAO 2 B5G5=88
// 100 ?>?KB>:, >AB0=>28< F8:; 8 >1=C;8< AGQBG8: 4;O A;54CNI53> A8<2>;0
if(count_try==100)
break;
}
}
}
//+------------------------------------------------------------------+
//| @>25@O5B :>;8G5AB2> 4>ABC?=KE 40==KE C 2A5E A8<2>;>2 |
//+------------------------------------------------------------------+
bool CheckAvailableData()
{
int try=100;
//---
for(int s=0; s<SYMBOLS; s++)
{
//--- A;8 B0:>9 A8<2>; 5ABL
if(symbols_names[s]!=empty_symbol)
{
datetime time[]; // 0AA82 4;O ?@>25@:8 :>;8G5AB20 10@>2
int total_period_bars =0; // >;8G5AB2> 10@>2 B5:CI53> ?5@8>40
datetime terminal_first_date =NULL; // 5@20O 40B0 8<5NI8EAO 40==KE B5:CI53> ?5@8>40 2 B5@<8=0;5
//--- >;CG8< ?5@2CN 40BC 40==KE B5:CI53> ?5@8>40 2 B5@<8=0;5
terminal_first_date=(datetime)SeriesInfoInteger(symbols_names[s],Period(),SERIES_TERMINAL_FIRSTDATE);
//--- >;CG8< :>;8G5AB2> 4>ABC?=KE 10@>2 >B C:070==>9 40BK
total_period_bars=Bars(symbols_names[s],Period(),terminal_first_date,TimeCurrent());
//--- @>25@8< 3>B>2=>ABL 40==KE 10@>2
for(int i=0; i<try; i++)
{
//--- !:>?8@C5< C:070==>5 :>;8G5AB2> 40==KE
if(CopyTime(symbols_names[s],Period(),0,total_period_bars,time))
{
//--- A;8 A:>?8@>20;>AL =C6=>5 :>;8G5AB2>, >AB0=>28< F8:;
if(ArraySize(time)>=total_period_bars)
break;
}
}
//--- A;8 A:>?8@>20=> <5=LH5 40==KE
// 7=0G8B =C6=> A>25@H8BL 5IQ >4=C ?>?KB:C
if(ArraySize(time)==0 || ArraySize(time)<total_period_bars)
{
message_last=message_data_available;
ShowCanvasMessage(message_data_available);
on_calc_prev_calculated=0;
return(false);
}
}
}
//--- A;8 2 @568<5 25@B8:0;L=>9 ;8=88 4;O =0G0;L=>9 B>G:8 @0AE>645=8O F5=, 2KE>48<
if(StartPriceDivergence==VERT_LINE)
return(true);
else
{
datetime time[]; // 0AA82 4;O ?@>25@:8 :>;8G5AB20 10@>2
int total_period_bars =0; // >;8G5AB2> 10@>2 B5:CI53> ?5@8>40
datetime terminal_firstdate =NULL; // 5@20O 40B0 8<5NI8EAO 40==KE B5:CI53> ?5@8>40 2 B5@<8=0;5
//--- >;CG8< ?5@2CN 40BC 40==KE B5:CI53> ?5@8>40 2 B5@<8=0;5
for(int i=0; i<try; i++)
if((terminal_firstdate=(datetime)SeriesInfoInteger(Symbol(),Period(),SERIES_FIRSTDATE))>0)
break;
//--- >;CG8< :>;8G5AB2> 4>ABC?=KE 10@>2 >B C:070==>9 40BK
for(int i=0; i<try; i++)
if((total_period_bars=(int)SeriesInfoInteger(Symbol(),timeframe_start_point,SERIES_BARS_COUNT))>0)
break;
//--- @>25@8< 3>B>2=>ABL 40==KE 10@>2
// !:>?8@C5< C:070==>5 :>;8G5AB2> 40==KE
for(int i=0; i<try; i++)
if(CopyTime(Symbol(),timeframe_start_point,
terminal_firstdate+PeriodSeconds(timeframe_start_point),TimeCurrent(),time)>0)
break;
//--- A;8 A:>?8@>20=> <5=LH5 40==KE
// 7=0G8B =C6=> A>25@H8BL 5IQ >4=C ?>?KB:C
if(ArraySize(time)<=0 || total_period_bars<=0)
{
message_last=message_data_available;
ShowCanvasMessage(message_data_available);
on_calc_prev_calculated=0;
return(false);
}
}
//---
return(true);
}
//+------------------------------------------------------------------+
//| @>25@:0 A>1KB8O 703@C7:8 1>;55 3;C1>:>9 8AB>@88 |
//+------------------------------------------------------------------+
bool CheckEventLoadHistory()
{
bool load=false;
//---
for(int s=0; s<SYMBOLS; s++)
{
//--- A;8 B0:>9 A8<2>; 5ABL
if(symbols_names[s]!=empty_symbol)
{
//--- A;8 =C6=> >1=>28BL A5@88
if(on_calc_prev_calculated==0)
{
ResetLastError();
//--- >;CG8< ?5@2CN 40BC A8<2>;0-?5@8>40
SeriesInfoInteger(symbols_names[s],Period(),SERIES_FIRSTDATE,series_first_date[s]);
if(GetLastError()!=0)
return(true);
//--- A;8 745AL 2 ?5@2K9 @07 (>BACBAB2C5B 7=0G5=85), B>
if(series_first_date_last[s]==NULL)
//--- 0?><=8< ?5@2CN 40BC A8<2>;0-?5@8>40 4;O ?>A;54CNI8E A@02=5=89
// A F5;LN >?@545;5=8O 703@C7:8 1>;55 3;C1>:>9 8AB>@88
series_first_date_last[s]=series_first_date[s];
}
else
{
ResetLastError();
//--- >;CG8< ?5@2CN 40BC A8<2>;0-?5@8>40
SeriesInfoInteger(symbols_names[s],Period(),SERIES_FIRSTDATE,series_first_date[s]);
if(GetLastError()!=0)
return(true);
//--- A;8 40BK >B;8G0NBAO, B> 5ABL 40B0 2 ?0<OB8 1>;55 ?>74=OO,
// G5< B0, :>B>@CN ?>;CG8;8 A59G0A, B>
// 7=0G8B 1K;0 703@C7:0 1>;55 3;C1>:>9 8AB>@88
if(series_first_date_last[s]>series_first_date[s])
{
//--- K2545< A>>1I5=85 2 6C@=0;
Print("(",symbols_names[s],",",TimeframeToString(Period()),
") > K;0 703@C65=0/AD>@<8@>20=0 1>;55 3;C1>:0O 8AB>@8O: ",
series_first_date_last[s]," > ",series_first_date[s]);
//--- 0?><=8< 40BC
series_first_date_last[s]=series_first_date[s];
load=true;
}
}
}
}
//--- A;8 1K;0 703@C65=0/AD>@<8@>20=0 1>;55 3;C1>:0O 8AB>@8O, B>
// >B?@028< :><0=4C =0 >1=>2;5=85 3@0D8G5A:8E A5@89 8=48:0B>@0
if(load)
return(false);
//---
return(true);
}
//+------------------------------------------------------------------+
//| @>25@O5B A8=E@>=878@>20==>ABL ?> A8<2>;C/?5@8>4C |
//+------------------------------------------------------------------+
bool CheckSymbolIsSynchronized()
{
//--- A;8 5ABL A>548=5=85 A A5@25@><, B>
// ?@>25@8< A8=E@>=878@>20==>ABL 40==KE
if(TerminalInfoInteger(TERMINAL_CONNECTED))
{
for(int s=0; s<SYMBOLS; s++)
{
//--- A;8 A8<2>; 5ABL
if(symbols_names[s]!=empty_symbol)
{
//--- A;8 40==K5 =5 A8=E@>=878@>20=K, B>
// A>>1I8< >1 MB>< 8 ?>?@>1C5< A=>20
if(!SeriesInfoInteger(symbols_names[s],Period(),SERIES_SYNCHRONIZED) ||
!SeriesInfoInteger(symbols_names[s],timeframe_start_point,SERIES_SYNCHRONIZED))
{
message_last=message_is_synchronized;
ShowCanvasMessage(message_is_synchronized);
return(false);
}
}
}
}
//---
return(true);
}
//+------------------------------------------------------------------+
//| ?@545;5=85 2@5<5=8 ?5@2>3> 8AB8==>3> 10@0 4;O >B@8A>2:8 |
//+------------------------------------------------------------------+
bool DetermineBeginForCalculate()
{
for(int s=0; s<SYMBOLS; s++)
{
datetime time[]; // 0AA82 2@5<5=8 10@>2
int total_period_bars=0; // >;8G5AB2> 10@>2
//--- A;8 B0:>3> A8<2>;0 =5B, ?5@59B8 : A;54CNI5<C
if(symbols_names[s]==empty_symbol)
continue;
//--- >;CG8< >1I55 :>;8G5AB2> 10@>2 A8<2>;0
total_period_bars=Bars(symbols_names[s],Period());
//--- !:>?8@C5< <0AA82 2@5<5=8 10@>2.
// A;8 =5 ?>;CG8;>AL, ?>?@>1C5< 5IQ @07
if(CopyTime(symbols_names[s],Period(),0,total_period_bars,time)<total_period_bars)
return(false);
//--- >;CG8< 2@5<O ?5@2>3> 8AB8==>3> 10@0,
// :>B>@K9 A>>B25BAB2C5B B5:CI5<C B09<D@59<C
limit_time[s]=GetFirstTruePeriodBarTime(time);
//--- #AB0=>28< 25@B8:0;L=CN ;8=8N =0 8AB8==>< 10@5
CreateVerticalLines(0,0,limit_time[s],prefix+symbols_names[s]+": begin time series",
2,STYLE_SOLID,line_color[s],false,false,true,TimeToString(limit_time[s]),"\n");
}
//---
return(true);
}
//+------------------------------------------------------------------+
//| >72@0I05B 2@5<O ?5@2>3> 8AB8==>3> 10@0 B5:CI53> ?5@8>40 |
//+------------------------------------------------------------------+
datetime GetFirstTruePeriodBarTime(datetime &time[])
{
datetime true_period =NULL; // @5<O ?5@2>3> 8AB8==>3> 10@0
int array_size =0; // 07<5@ <0AA820
//--- >;CG8< @07<5@ <0AA820
array_size=ArraySize(time);
ArraySetAsSeries(time,false);
//--- >>G5@Q4=> ?@>25@O5< :064K9 10@
for(int i=1; i<array_size; i++)
{
//--- A;8 10@ A>>B25BAB2C5B B5:CI5<C B09<D@59<C
if(time[i]-time[i-1]==PeriodSeconds())
{
//--- 0?><=8< 8 >AB0=>28< F8:;
true_period=time[i-1];
break;
}
}
//--- 5@=Q< 2@5<O ?5@2>3> 8AB8==>3> 10@0
return(true_period);
}
//+------------------------------------------------------------------+
//| >102;O5B C:070==K9 A8<2>; 2 >:=> >17>@ @K=:0 |
//+------------------------------------------------------------------+
string CheckGetSymbol(string symbol)
{
int symbol_total =0; // >;8G5AB2> A8<2>;>2
string nm_symbol =""; // <O A8<2>;0
//--- A;8 ?5@540;8 ?CABCN AB@>:C, B> 25@=CBL ?CABCN AB@>:C
if(symbol=="")
return(empty_symbol);
//--- A53> A8<2>;>2 =0 A5@25@5
symbol_total=SymbolsTotal(false);
//--- @>9B8AL ?> 2A5<C A?8A:C A8<2>;>2
for(int s=symbol_total-1; s>=0; s--)
{
//--- <O A8<2>;0 =0 A5@25@5
nm_symbol=SymbolName(s,false);
//--- A;8 5ABL B0:>9 A8<2>;, B>
if(nm_symbol==symbol)
{
//--- CAB0=>28< 53> 2 >:=> 17>@ K=:0 8
SymbolSelect(nm_symbol,true);
//--- 25@=Q< 53> 8<O
return(symbol);
}
}
//--- A;8 B0:>3> A8<2>;0 =5B, B>
// 25@=Q< AB@>:C A8<2>;878@CNICN >BACBAB285 A8<2>;0
return(empty_symbol);
}
//+------------------------------------------------------------------+
//| @>25@:0 =0 8A?>;L7>20=85 8=48:0B>@0 2 B5AB5@5 |
//+------------------------------------------------------------------+
bool CheckTesterMode()
{
//--- A;8 8=48:0B>@ 1K; 70?CI5= 2 B5AB5@5, B> A>>1I8<, GB>
// >= =5 ?@54=07=0G5= 4;O 8A?>;L7>20=8O 2 B5AB5@5
if(MQL5InfoInteger(MQL5_TESTER) ||
MQL5InfoInteger(MQL5_VISUAL_MODE) ||
MQL5InfoInteger(MQL5_OPTIMIZATION))
{
Comment("0 40==K9 <><5=B 8=48:0B>@ <- "+PROGRAM_NAME+" -> =5 ?@54=07=0G5= 4;O 8A?>;L7>20=8O 2 B5AB5@5!");
return(false);
}
//---
return(true);
}
//+------------------------------------------------------------------+
//| @>25@O5B 2E>4=K5 ?0@0<5B@K =0 :>@@5:B=>ABL |
//+------------------------------------------------------------------+
bool CheckInputParameters()
{
//--- A;8 A59G0A @568< =5 25@B8:0;L=>9 ;8=88
if(StartPriceDivergence!=VERT_LINE)
{
//--- A;8 B5:CI89 ?5@8>4 1>;LH5 ;81> @025=
// C:070==><C 4;O =0G0;L=>9 B>G:8 @0AE>645=8O F5=, A>>1I8< >1 MB>< 8 2K945<
if(PeriodSeconds()>=PeriodSeconds(timeframe_start_point))
{
Print(""5:CI89 B09<D@59< 4>;65= 1KBL <5=LH5, G5< 2 ?0@0<5B@5 Start Price Divergence!");
Comment(""5:CI89 B09<D@59< 4>;65= 1KBL <5=LH5, G5< 2 ?0@0<5B@5 Start Price Divergence!");
return(false);
}
}
//---
return(true);
}
//+------------------------------------------------------------------+
//| !;548B 70 @07<5@0<8 :0=2K |
//+------------------------------------------------------------------+
void EventChartChange()
{
//--- >;CG8< A2>9AB20 >:=0
SetSubwindowProperties();
//--- A;8 @07<5@K >:=0 =5 87<5=8;8AL, 2K945<
if(!CheckChartSize())
return;
//--- A;8 @07<5@ >:=0 <5=LH5 >4=>3> ?8:A5;O 8;8
// F5=B@ @0AAG8B0= =5:>@@5:B=>, 2K945<
if(chart_height<1 || chart_vcenter<1)
return;
//--- #AB0=>28< =>2K9 @07<5@ :0=25
ResizeCanvas();
//--- >:065< ?>A;54=55 A>>1I5=85
ShowCanvasMessage(message_last);
}
//+------------------------------------------------------------------+
//| @>25@8< @07<5@K 3@0D8:0 |
//+------------------------------------------------------------------+
bool CheckChartSize()
{
//--- A;8 @07<5@K 3@0D8:0 =5 87<5=8;8AL, 2K945<
if(last_chart_width==chart_width &&
last_chart_height==chart_height)
return(false);
//--- A;8 65 87<5=8;8AL, B> 70?><=8< 8E
else
{
last_chart_width=chart_width;
last_chart_height=chart_height;
}
//---
return(true);
}
//+------------------------------------------------------------------+
//| @>25@O5B ?CABK5 7=0G5=8O |
//+------------------------------------------------------------------+
bool CheckEmptyValues()
{
if(MQL5InfoInteger(MQL5_VISUAL_MODE))
return(true);
//---
for(int s=0; s<SYMBOLS; s++)
{
static int count_empty=0;
if(count_empty>1000)
{
count_empty=0;
on_calc_prev_calculated=0;
return(false);
}
//---
if(symbols_names[s]!=empty_symbol)
{
for(int i=on_calc_rates_total-500; i<on_calc_rates_total; i++)
{
if(on_calc_time[i]<limit_time[s])
continue;
//---
if(buffer_data[s].close[i]==EMPTY_VALUE)
count_empty++;
}
}
}
//---
return(true);
}
//+------------------------------------------------------------------+
//| K2>48B 2 6C@=0; C:070==>5 :>;8G5AB2> 7=0G5=89 87 ?>A;54=8E |
//+------------------------------------------------------------------+
void CheckLastEmptyValues(int amount)
{
for(int i=on_calc_rates_total-amount; i<on_calc_rates_total; i++)
Print(symbols_names[0],": ",DoubleToString(buffer_data[0].close[i],Digits()));
//---
Print("---");
}
//+------------------------------------------------------------------+