В коде спред учитывается в пипсах, на вероятности не влияет. В этом примере в идеале должно быть по 50%. В строке profit/loss показано соотношение вероятностей и пипсов.
Без спреда соотношения profit/loss должны в идеале быть по 1.
Чтоб сгенерировать новую серию, достаточно переключитьТФ.
Код для МТ5
#property indicator_separate_window #property indicator_buffers 1 #property indicator_plots 1 //--- plot Label1 #property indicator_label1 "Label1" #property indicator_type1 DRAW_LINE #property indicator_color1 clrGreen #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- input parameters input int win=100000;//Window input int TP=10; input int SL=10; input int Spread=1; //--- indicator buffers double Price[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,Price,INDICATOR_DATA); PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,Bars(NULL,0)-win-1); IndicatorSetInteger(INDICATOR_DIGITS,0); srand(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);//1 запуск //---random walk Price[rates_total-win-1]=0.; for(int i=rates_total-win;i<rates_total;i++) {int rn=rand()%2*2-1;//+-1 Price[i]=Price[i-1]+rn; } //---statistics double tp=TP; double sl=-SL; double ask=Spread; double bid=0.; int ntp=0; int nsl=0; for(int i=rates_total-win;i<rates_total;i++) {if(Price[i]+0.1>=tp) {ntp++; bid=Price[i]; ask=bid+Spread; tp=bid+TP; sl=bid-SL; } if(Price[i]-0.1<=sl) {nsl++; bid=Price[i]; ask=bid+Spread; tp=bid+TP; sl=bid-SL; } } //---printout int n=ntp+nsl; double psl=nsl*100./(ntp+nsl); double ptp=ntp*100./(ntp+nsl); double profit=TP-Spread; double loss=SL+Spread; Alert("profit/loss: ",DoubleToString(1.*ntp/nsl,2)," ",DoubleToString(profit/loss,2)); Alert(" loss: ",nsl," (",DoubleToString(psl,2)," %), ",loss," pips"); Alert(" profit: ",ntp," (",DoubleToString(ptp,2)," %), ",profit," pips"); Alert("trades: ",n); //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+