OnCalculate Indicator

 
I wrote the following simple indicator:
 int OnCalculate ( const int rates_total,
                 const int prev_calculated,
                 const datetime &time[],
                 const double &open[],
                 const double &high[],
                 const double &low[],
                 const double &close[],
                 const long &tick_volume[],
                 const long &volume[],
                 const int &spread[])
  {
   if (rates_total< 2 )
       return ( 0 );
//--- starting point
   int start;
   if (prev_calculated< 2 )
      start=prev_calculated+ 2 ;
   else
      start=rates_total- 1 ;
//--- main cycle of calculations
   for ( int i=start; i<rates_total && ! IsStopped (); i++)
   {
       if (high[i- 1 ]>high[i- 2 ] && close[i- 1 ]>open[i- 1 ])
         ExtFRABuffer[i]= 1 ;
       else if (low[i- 1 ]<low[i- 2 ] && close[i- 1 ]<open[i- 1 ])
         ExtFRABuffer[i]=- 1 ;
       else
         ExtFRABuffer[i]= 0 ;      
   }
//--- OnCalculate done. Return new prev_calculated.
   return (rates_total);
  }

The "ExtFRABuffer" is correct when testing the indicator (on the opening price) on the strategy tester. However, when back-testing its value (on the opening price) within an EA, I only get the value 1 correctly, while -1 is assigned incorrectly (it is assigned when low[i-1]>low[ i-2] && close[i-1]<open[i-1] and not when low[i-1]<low[i-2] && close[i-1]<open[i-1] ). What am I doing wrong?

 

Il tuo argomento è stato spostato nella sezione: Indicatori tecnici
Considera quale sezione è più appropriata: https://www.mql5.com/en/forum/172166/page6#comment_49114893

Sul forum italiano scrivete in italiano. Utilizza lo strumento di traduzione automatica o pubblica in uno dei forum in altre lingue.

Motivazione: