Download MetaTrader 5

Indicator Back testing problem

To add comments, please log in or register
Publish your article and thousands of people all over the world will read it!
Somsri Sarkar
2053
Somsri Sarkar 2016.11.18 13:00 

Hello Members,

This is the standard view of the indicator

 

Back Testing with Speed 32 shows something like this,

 

There is a big Gap, Trendline get drawn only for current few bars, not for previous one, is it normal with backtest? Or there is a problem with the coding?  

Regards

Alain Verleyen
Moderator
30731
Alain Verleyen 2016.11.18 16:24  
Somsri Sarkar:

Hello Members,

This is the standard view of the indicator

 

Back Testing with Speed 32 shows something like this,

 

There is a big Gap, Trendline get drawn only for current few bars, not for previous one, is it normal with backtest? Or there is a problem with the coding?  

Regards

Coding issue most probably.
Somsri Sarkar
2053
Somsri Sarkar 2016.11.19 03:49  

Hi Here is the code structure: Can you please help?

int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   if(counted_bars==0) limit-=1+1;
   //---------------------
  long CI = ChartID();
    
    counter = 0;
    counter2 = 0;
    
for(int i=0;  i<= limit; i++)
{
if(Condition)

{

  if(showdata == true && counter2 != 0 )
   {
      // calculation of data //
  
    
    Range = Calculation;
    Data = Calculation;
     Obj_Name=IntegerToString(i)+ "step1";            
     ObjectCreate(Obj_Name,OBJ_TEXT,0,Time[i],Low[i]);
    //Object Create properly got removed here on the post//

    
     ObjectMove(CI,Obj_Name,0,Time[i],Low[i]);
     ObjectMove(CI,Obj_Name,1,Time[i],Low[i]);
    
     }
    
     if(counter2 != 0)
     {
    
  
     Obj_Name=IntegerToString(i)+ "step2";            
     ObjectCreate(Obj_Name,OBJ_TREND,0,Time[i-counter2],iHigh(Symbol(),0,iHighest(Symbol(),0,MODE_HIGH,counter2,i)),Time[i-counter2],Low[i-counter2]);
     //Object Create properly got removed here on the post//

    }
   //---------------------
  
   counter2 = 0;
   counter++;
  
   WindowRedraw();
   ChartRedraw();
}




else if(Condition)
{
  
  
   if(showdata == true && counter != 0 )
   {
      // calculation of data //
      
    Range2 = Calculation;
    Data = Calculation;
      
     Obj_Name=IntegerToString(i)+ "step1";            
     ObjectCreate(Obj_Name,OBJ_TEXT,0,Time[i],Low[i]);
     ObjectSetString(CI,Obj_Name,OBJPROP_TEXT,Data);
     // Objectcreat properly got removed here in the post//

     ObjectMove(CI,Obj_Name,0,Time[i],Low[i]);
     ObjectMove(CI,Obj_Name,1,Time[i],Low[i]);
    
    }
    if(counter != 0 )
    {
    
    
     Obj_Name=IntegerToString(i)+ "step3";            
     ObjectCreate(Obj_Name,OBJ_TREND,0,Time[i-counter],High[i-counter],Time[i-counter],iLow(Symbol(),0,iLowest(Symbol(),0,MODE_LOW,counter,i)));
  
    // Objectcreat properly got removed here in the post//
    
    ObjectMove(CI,Obj_Name,0,Time[i-counter],High[i-counter]);
    ObjectMove(CI,Obj_Name,1,Time[i-counter],iLow(Symbol(),0,iLowest(Symbol(),0,MODE_LOW,counter,i)));
   }
   //---------------------
   counter = 0;
   counter2++;

   WindowRedraw();
   ChartRedraw();
   }

else { counter = 0; counter2 = 0;}
}

WindowRedraw();
ChartRedraw();
RefreshRates();


 

Somsri Sarkar
2053
Somsri Sarkar 2016.11.19 03:54  
During the backtest, chart is not refreshing, if I refresh or reinsert indicator, then it draws things properly.
Carl Schreiber
6590
Carl Schreiber 2016.11.19 11:16  
Code your indicator so that it does not need graphical objects but indicator buffers or (global) variables. The tester does not 'like' (your) objects as the slow down the calculation!
Somsri Sarkar
2053
Somsri Sarkar 2016.11.21 08:50  
Carl Schreiber:
Code your indicator so that it does not need graphical objects but indicator buffers or (global) variables. The tester does not 'like' (your) objects as the slow down the calculation!

I have tried that before with buffer.

//---------------------
   counter = 0;
   counter2++;
   bear_buffer[i] = iHigh(Symbol(),0,iHighest(Symbol(),0,MODE_HIGH,counter2,i));
   buffer[i] = iHigh(Symbol(),0,iHighest(Symbol(),0,MODE_HIGH,counter2,i));
   WindowRedraw();
   ChartRedraw();

 But that didn't worked.

This is original

 

This is with backtest 32 speed.

 

Hope you now see the difference.

In case buffer I use following loop:

for(int i=limit;  i> 0; i--)
Somsri Sarkar
2053
Somsri Sarkar 2016.11.22 05:48  

Is there any to auto refresh buffer setup & indicator reinsert codes available ? 

I tried refreshrates, chartredraw, windowredraw etc. 

whroeder1
14504
whroeder1 2016.11.22 15:47  

No because they are not needed.

Your code is broken.
   counter = 0;
   counter2++;
   bear_buffer[i] = iHigh(Symbol(),0,iHighest(Symbol(),0,MODE_HIGH,counter2,i));

First time you process all bars and it works. Second time you only reprocess bar zero, but counter2 has already been changed by the previous update of bar zero and now you change it again.

If you are going to use static variables, you must not update bar zero. Otherwise, put them in an extra buffer.

counter2[i] = counter2[i+1] + 1; // Not counter2++

See How to do your lookbacks correctly.

Somsri Sarkar
2053
Somsri Sarkar 2016.11.24 02:49  
whroeder1:

No because they are not needed.

Your code is broken.
   counter = 0;
   counter2++;
   bear_buffer[i] = iHigh(Symbol(),0,iHighest(Symbol(),0,MODE_HIGH,counter2,i));

First time you process all bars and it works. Second time you only reprocess bar zero, but counter2 has already been changed by the previous update of bar zero and now you change it again.

If you are going to use static variables, you must not update bar zero. Otherwise, put them in an extra buffer.

counter2[i] = counter2[i+1] + 1; // Not counter2++

See How to do your lookbacks correctly.

I used your coding suggestion, in following way,

C1[i] = C1[i+1] +1 ;
   bull_buffer[i] = iLow(Symbol(),0,iLowest(Symbol(),0,MODE_LOW,(int)C1[i],i));  

 That fetched me a chart like this: 

 

Not Working. 

Sergey Golubev
Moderator
93667
Sergey Golubev 2017.01.20 05:56  

Forum on trading, automated trading systems and testing trading strategies

How To Create RSI TL as Indicator and The EA about RSI-TL breakout on Sub Window

Fernando Carreiro, 2017.01.20 04:59

No problem at all and very easy to solve!

Just head on over to the Freelance section and place a new job request to the community! Remember to properly define all your requirements and the amount you have on budget!

I am sure you will get many applicants in no time at all! Then just pick one that satisfies your conditions!


To add comments, please log in or register