Download MetaTrader 5
To add comments, please log in or register
Code Base will help you in mastering your theoretical skills. Come and learn!
brettosm8
241
brettosm8 2016.03.04 22:53 

Hi there,

I have this indicator which draws SR lines from fractal levels.

I appears as below and looks like it is working.

 

 Then, I go in to Strategy Tester and start testing a system using the indicator.

It starts off as expected as below.

 

 The lines are being drawn at the same levels in Strategy Test as in the regular view. 

Then I press F12 for the next bar to appear and the red line has changed its position as below.

 

 The code for the indicator is below:

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue

int      i;
int      DeadPeriod=20;
int      HigherTF;
double   UpperFractal;
double   LowerFractal;
double   UpperLine;
double   LowerLine;
int      NewHighStartBar;
int      NewLowStartBar;
double   HighLevel;
double   LowLevel=99999;
double   Hv[];
double   Lv[];

string   text;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,Red);
   SetIndexDrawBegin(0,i);
   SetIndexBuffer(0,Hv);
   SetIndexLabel(0,"Resistance");

   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1,Blue);
   SetIndexDrawBegin(1,i);
   SetIndexBuffer(1,Lv);
   SetIndexLabel(1,"Support");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
//---

   i=Bars;

   while(i>=0)
     {

      UpperLine=NormalizeDouble(iCustom(NULL,HigherTF,"AG Keltner Channel",0,i+2),8);
      LowerLine=NormalizeDouble(iCustom(NULL,HigherTF,"AG Keltner Channel",2,i+2),8);

      UpperFractal=NormalizeDouble(iFractals(Symbol(),HigherTF,MODE_UPPER,i+1),8);
      LowerFractal=NormalizeDouble(iFractals(Symbol(),HigherTF,MODE_LOWER,i+1),8);

      //Find new highs
      if(UpperFractal>UpperLine && 
         UpperFractal>HighLevel)
        {
         NewHighStartBar=i;
         HighLevel=UpperFractal;
        }
      if(UpperFractal>UpperLine && 
         NewHighStartBar-i>=DeadPeriod)
        {
         NewHighStartBar=i;
         HighLevel=UpperFractal;
        }

      if(HighLevel>0) Hv[i+1]=HighLevel;


      //Find new lows
      if(LowerFractal<LowerLine && 
         LowerFractal<LowLevel &&
         LowerFractal>0)
        {
         NewLowStartBar=i;
         LowLevel=LowerFractal;
        }
      if(LowerFractal<LowerLine && 
         NewLowStartBar-i>=DeadPeriod &&
         LowerFractal>0)
        {
         NewLowStartBar=i;
         LowLevel=LowerFractal;
        }

      if(LowLevel<99999) Lv[i+1]=LowLevel;

      i--;
     }//End While i>=0

   Comment(text);

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

 Can someone please advise how to deal with this?

Thanks. 

Vasyl Nosal
18222
Vasyl Nosal 2016.03.05 09:24  

So?

UpperFractal=NormalizeDouble(iFractals(Symbol(),HigherTF,MODE_UPPER,i+1),8);

fractals can appeirs with pause 2-5 bars.+from higher tf is 2-5bars*(HigherTF/CurrentTF)= bars can be redraw.

 

You can't do anything with this. 

/
To add comments, please log in or register