Download MetaTrader 5

Error Strategy Tester

To add comments, please log in or register
All activity at is clearly visible. Have a look at the Wall!
Inaki Munarriz Herrador
Inaki Munarriz Herrador 2015.09.22 23:52 

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 );   





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){


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


      //Calculo la media del precio

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

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



      //dibujar una recta lineal de la media

      if (anteriores==1) {

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









    return (0);

Alain Verleyen
Alain Verleyen 2015.09.23 07:54  

Forum on trading, automated trading systems and testing trading strategies


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

This time, I edited it for you.

To add comments, please log in or register