0
92
По этой статье сделал индикатор и интересно получается. При убытках больше прибыли нижняя линия (худшее значение за все итерации) раньше выходит в плюс.
Пример. Матожидание 0.5.
Случай с P/L=3. Выход в плюс за 210 сделок.
Случай с P/L=1/3. Выход в плюс за 137 сделок.
Код для МТ5
#property indicator_separate_window #property indicator_buffers 3 #property indicator_plots 3 //--- plot Label1 #property indicator_label1 "Матожидание" #property indicator_type1 DRAW_LINE #property indicator_color1 clrBlue #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- plot Label2 #property indicator_label2 "Макс" #property indicator_type2 DRAW_LINE #property indicator_color2 clrRed #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //--- plot Label3 #property indicator_label3 "Мин" #property indicator_type3 DRAW_LINE #property indicator_color3 clrRed #property indicator_style3 STYLE_SOLID #property indicator_width3 1 //--- input parameters input double TP=2;//Прибыль input double SL=1;//Убыток input double EP=0;//Матожидание input double Spread=0;//Спред input int Win=386;//Сделок input int Count=10000;//Итераций //--- indicator buffers double Label1[]; double Label2[]; double Label3[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,Label1,INDICATOR_DATA); SetIndexBuffer(1,Label2,INDICATOR_DATA); SetIndexBuffer(2,Label3,INDICATOR_DATA); MathSrand(GetTickCount()); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[]) { //--- if(prev_calculated!=0) return(rates_total); double A=32768.*(EP-Spread+SL)/(TP+SL); Comment("Win: ",DoubleToString(100*A/32768,2)," %"); for(int j=0;j<Count;j++) {double b=0; for(int i=0;i<Win;i++) {int r=rand(); if(r<A) b+=TP; else b-=SL; if(j==0) {Label1[rates_total-Win+i]=(EP-Spread)*(i+1); Label2[rates_total-Win+i]=Label1[rates_total-Win+i]; Label3[rates_total-Win+i]=Label1[rates_total-Win+i]; continue; } if(b>Label2[rates_total-Win+i]) Label2[rates_total-Win+i]=b; if(b<Label3[rates_total-Win+i]) Label3[rates_total-Win+i]=b; } } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+