Problem in Strategy Tester with indicator (code attached)

 

Can any body tell me why this indicator does not work in the strategy Tester although it works fine on a chart?

The problem is that in the Strategy Tester (ST) it is stuck stuck on only one of the two possible values (50.0000) of the two index buffers. The image below shows that in the ST the value is stuck on 50.000 for the second buffer (window 3) while it should actually be 50.0000 in the first buffer as shown in window 4. It never changes values in the ST - it stay 50.0000 in the one buffer although the trend changes all the time.

Here is the code for the indicator:

//+------------------------------------------------------------------+
//|                                                          SSL.mq4 |
//|ssl bar fast mtf                                          Kalenzo |
//|                                      bartlomiej.gorski@gmail.com |
//+------------------------------------------------------------------+
//mod2008fxtsd   ml ki   
#property copyright "Kalenzo"
#property link      "bartlomiej.gorski@gmail.com"
//----
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1  DodgerBlue
#property indicator_color2  OrangeRed
#property indicator_width1  2
#property indicator_width2  2
#property indicator_minimum 10
#property indicator_maximum 90
//----
extern int     Lb          =3;
extern int     SSL_BarLevel=50;    //BarLevel 10-90
extern int     TimeFrame=1440;
extern string  TimeFrames="M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN|0-CurrentTF";
//----
double sslHup[];
double sslHdn[];
double hlv[];
string IndicatorFileName;
datetime TimeArray[];
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {
   string TimeFrameStr;
   if(TimeFrame<Period()) TimeFrame=Period();
   switch(TimeFrame)
     {
      case PERIOD_M1:  TimeFrameStr="M1";break;
      case PERIOD_M5:  TimeFrameStr="M5";break;
      case PERIOD_M15: TimeFrameStr="M15";break;
      case PERIOD_M30: TimeFrameStr="M30";break;
      case PERIOD_H1:  TimeFrameStr="H1";break;
      case PERIOD_H4:  TimeFrameStr="H4";break;
      case PERIOD_D1:  TimeFrameStr="D1";break;
      case PERIOD_W1:  TimeFrameStr="W1";break;
      case PERIOD_MN1: TimeFrameStr="MN1";break;
      default :        TimeFrameStr="TF0";
     }
//----
   IndicatorBuffers(3);
   SetIndexBuffer(0,sslHup); SetIndexStyle(0,DRAW_ARROW); SetIndexArrow(0,167); SetIndexLabel(0,"SSLup "+Lb+" ["+TimeFrame+"]");
   SetIndexBuffer(1,sslHdn); SetIndexStyle(1,DRAW_ARROW); SetIndexArrow(1,167); SetIndexLabel(1,"SSLdn "+Lb+" ["+TimeFrame+"]");
   SetIndexBuffer(2,hlv);
//----
   IndicatorShortName("SSL "+Lb+"["+TimeFrameStr+"]");
   IndicatorFileName=WindowExpertName();
//----
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   int  i,y=0,limit;
//----
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   if(counted_bars==0) limit-=1+1+TimeFrame/Period();
//----
   if(TimeFrame!=Period())
     {
      //limit=MathMax(limit,TimeFrame/Period());
      ArrayCopySeries(TimeArray,MODE_TIME,NULL,TimeFrame);
      //----
      for(i=0,y=0; i<limit; i++)
        {
         if(y<ArraySize(TimeArray)){ if(Time[i]<TimeArray[y]) y++;}
         sslHup[i]=iCustom(NULL,TimeFrame,IndicatorFileName,Lb,SSL_BarLevel,0,y);
         sslHdn[i]=iCustom(NULL,TimeFrame,IndicatorFileName,Lb,SSL_BarLevel,1,y);
        }
      return(0);
     }
//----
   for(i=limit-1;i>=0;i--)
     {
      hlv[i]=hlv[i+1];
      if(Close[i]>iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_HIGH,i+1)) hlv[i]= 1;
      if(Close[i]<iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_LOW,i+1))  hlv[i]=-1;
      if(hlv[i]==-1) { sslHdn[i]=SSL_BarLevel; sslHup[i]=EMPTY_VALUE;  }
      else
        { sslHdn[i]=EMPTY_VALUE;  sslHup[i]=SSL_BarLevel; }
     }
   return(0);
  }
//+------------------------------------------------------------------+
 
Can nobody help me with this problem?
 

Very probably there are some errors on the code that do not refresh indicator on each new tick/bar.

First of all, you need to use #property strict and OnCalculate instead of start.

 

I have added "#property strict" but it still compiles successfully.

When I change "int start()" to "int OnCalculate()" I get an error.

I was hoping somebody could have a look at the code to see if there is in fact something causing the problem since i have never coded an indicator.

 
Ernest Klokow:

I have added "#property strict" but it still compiles successfully.

When I change "int start()" to "int OnCalculate()" I get an error.

I was hoping somebody could have a look at the code to see if there is in fact something causing the problem since i have never coded an indicator.

What chart period and indicator settings are you using ?
 

In the ST, if you leave the mouse cursor static, the data window does not always update values.

Make sure that this is not the problem.

 
Keith Watford:

In the ST, if you leave the mouse cursor static, the data window does not always update values.

Make sure that this is not the problem.

This is interesting!

Do I understand correctly that I have to move the mouse cursor all the time while the ST is running - or am I understanding this wrongly?

 
Alain Verleyen:
What chart period and indicator settings are you using ?

Why would it matter which chart period and indicator settings I am using?

I am using it on the Daily timeframe (this is a multi-timeframe indicator) but running the test on the H4 or H1 time frames.

 

I think the problem lies with the fact that this is a mtf indicator and I use a higher time frame for the indicator than the tf for the chart it is run on.

I am also experiencing difficulties with running this indicator in a simulator. If I use a different tf in the indicator than the chart tf I am doing the simulation on no values for the indicator appears on the chart.

Is there a way one can overcome this? I find this indicator of great value and really would like to make use of it in the ST and/or simulator.

 
Ernest Klokow:

I think the problem lies with the fact that this is a mtf indicator and I use a higher time frame for the indicator than the tf for the chart it is run on.

I am also experiencing difficulties with running this indicator in a simulator. If I use a different tf in the indicator than the chart tf I am doing the simulation on no values for the indicator appears on the chart.

Is there a way one can overcome this? I find this indicator of great value and really would like to make use of it in the ST and/or simulator.

8
 

I discovered another problem with this indicator.

Since it is a mtf indicator you can set the timeframe parameter either as 0 (which means it defaults to the current timeframe which it is loaded on) or you can set the timeframe in hours like e.g. 240 for the H4.

If you use the different methods on an H4 chart you get differences in the results as shown in the image below with the red vertical lines. That is incorrect - they should be exactly the same!

The top one is set to 240 as in the image and the bottom one is set to 0 on a H4 chart. They both show H4 as the timeframe.

Reason: