Error Strategy Tester

 

Hi everyone!

Can anyone tell me why this indicator that estimates the average price doesn't work in the Strategy Tester?  Is there an error in the code?

Muchas gracias!!!

#property strict

#property indicator_chart_window

#property indicator_buffers 1

//Input parámetros

input color    Color=clrRed; 

input int      periodos=100;

double recta_media[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer( 0, recta_media );

   SetIndexStyle( 0, DRAW_LINE, DRAW_LINE, STYLE_SOLID, Color );   

//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

int start() {

   int i,j,n,Counted_bars,anteriores=1;

   double media_precio;

   double precio[];

   ArrayResize(precio, Bars); ArrayInitialize(precio, 0.0); ArraySetAsSeries(precio, true);  

   Counted_bars = IndicatorCounted();

   i = Bars - Counted_bars -1;     

   j = i - periodos;

   while (i>=0){

   precio[i]=Close[i];

      if (i<=(j+1)) {   

      media_precio=0;       

      //Calculo la media del precio

      for (n=(i+periodos-1);n>=i;n--) {

          media_precio += (precio[n]/periodos);

      }

      recta_media[i]=media_precio;

      //dibujar una recta lineal de la media

      if (anteriores==1) {

         for (n=(Bars - Counted_bars -1);n>=(j+2);n--) {     

            recta_media[n]=media_precio;      

         }

      }

      anteriores=0;

      }    

      i--;   

      RefreshRates();

   }

    return (0);

} 
 

Forum on trading, automated trading systems and testing trading strategies


Hello,

Please use the SRC button when you post code. Thank you.


This time, I edited it for you.


Reason: