Download MetaTrader 5

Pivot Point Formula : from an indicator to an EA

To add comments, please log in or register
Make profit on MQL5 services. It's easy!
Icham Aidibe
10044
Icham Aidibe 2014.11.28 10:38 

Hi,

Because of a fatal error in a custom indicator I use on an EA, I'd like to rewrite directly the algorithms of pivot point inside the EA. It may save some memory. So here's a piece of code from the indicator :

      for(int i=start;i<rates_total;i++){
         BufHigh[i]=BufHigh[i-1];
         BufLow[i]=BufLow[i-1];   
         PivotBuffer[i]=PivotBuffer[i-1];         
         datetime NowTime=time[i]-TimeShift;
         datetime PreTime=time[i-1]-TimeShift;         
            if(NewDay(NowTime,PreTime)){
                  if(BufHigh[i]!=0){
                     P=(BufHigh[i]+BufLow[i]+close[i-1])/3;
                        if(PivotsBufers){
                           PivotBuffer[i]=P;
                       
                        }
                  }
               BufHigh[i]=high[i];
               BufLow[i]=low[i];
            }
            else{
               BufHigh[i]=MathMax(BufHigh[i],high[i]);
               BufLow[i]=MathMin(BufLow[i],low[i]);

And here's the code in the indicator, that provide QUITE similar results, I'd like exactly the same results since the indicator is very good :

MqlRates price[2];
double PivotP,S1,R1,S2,R2,S3,R3;
if(CopyRates(Symbol(),PERIOD_D1,1,2,price)<0)
   {
Alert("Error copying rates buffer - error: ",GetLastError());
return;
   }   
PivotP=(price[1].high + price[1].low + price[0].close) / 3 ;
printf("Pivot (indicator) : %g // Pivot (EA): %g", Pivot[0], PivotP);

As you can see the results are quite similar, but not exactly the same :

2014.11.28 09:31:47     Core 1  2014.08.25 04:19:30   Pivot (indicator) : 3.89067 // Pivot (EA): 3.905
2014.11.28 09:31:47     Core 1  2014.08.22 22:46:30   Pivot (indicator) : 3.91033 // Pivot (EA): 3.89433
2014.11.28 09:31:45     Core 1  2014.08.12 16:58:00   Pivot (indicator) : 3.972 // Pivot (EA): 3.96533

Even if the formula is the same one :

EA : 
PivotP=(price[1].high + price[1].low + price[0].close) / 3 ; <--- current high, current low, previous close

Indicator : 
P=(BufHigh[i]+BufLow[i]+close[i-1])/3; <--- current high, current low, previous close
with ... 
BufHigh[i]=high[i];
BufLow[i]=low[i];

Anyone may help please ?

To add comments, please log in or register