iCustom() function working on live account, but not in back testing

 

Iam  facing same problem with iCustom indicators. Iam using super trend indicator and Iam calling using ST2=iCustom(Symbol(),0,"SuperTrend",24,3.0,1,1). It works well in live and demo account when i call them, but does not work well on back testing. Can Anyone help me on this pls. Iam clueless.


I have attached a sample EA which calls the super trend using iCustom(Symbol(),0,"SuperTrend",24,3.0,1,1) or iCustom(Symbol(),0,STnewformat,1440,10,3.0,1,1). I have attached both versions of Super Trend as below. Pls help me.  Thank you.


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

//|                                              SuperTrend_03.mq4 |

//|                        Copyright 2014, MetaQuotes Software Corp. |

//|                                              http://www.mql5.com |

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

// Different TimeFrame between chart & Super Trend Lines

// Begin 17 Nov 2014

#property copyright "Jay Ngui"

#property version   "1.1"

#property strict



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

//| Custom indicator initialization function                         |

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





#property indicator_chart_window

#property indicator_color1 Green

#property indicator_color2 Red

#property indicator_buffers 2



double TrendUp[], TrendDown[];

//int changeOfTrend;

extern int TimeFrame = 1440;

extern int NumPeriod = 10; //number of period

extern double Multiplier = 3;



//global variables

double UppBand[], LowBand[], SupTrPrice[];

datetime SupTrTime[];

datetime Time_0_Old = 0, Time_0_New;

int OnInit()

  {

//---- indicators

   SetIndexBuffer(0, TrendUp);

   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID);

   SetIndexLabel(0, "Trend Up");

   SetIndexBuffer(1, TrendDown);

   SetIndexStyle(1, DRAW_LINE, STYLE_SOLID);

   SetIndexLabel(1, "Trend Down");

   

//----

   return(INIT_SUCCEEDED);

  }

  

int deinit()

  {

   

         

   return(0);

}

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

//| 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[])

//  {

//---

int start()

{



   int i, j, k;

   int wBarLeft, wBarRight, wBarSupTr;

   int wTimeFrame, wTimeFrame_Trend;

   string wSym;

   double wClose_0, wClose_1, wHigh_0, wLow_0;

   datetime wTime;

   

   wBarSupTr=0;

   wSym=Symbol();

   wTimeFrame=Period();

   wBarLeft = Bars;

   wBarRight = 0;

   ArrayResize(UppBand,wBarLeft+2);

   ArrayResize(LowBand,wBarLeft+2);

   ArrayResize(TrendDown,wBarLeft+2);

   ArrayResize(TrendUp,wBarLeft+2);

   ArrayResize(SupTrPrice,wBarLeft+2);

   ArrayResize(SupTrTime,wBarLeft+2);

   

   wTimeFrame_Trend = TimeFrame;

   //if (Trend_Same_As_Chart) wTimeFrame_Trend = wTimeFrame;

   

   Time_0_New = iTime(wSym, wTimeFrame, 0);

   if (Time_0_New != Time_0_Old)

   {

//super trend array    

      fnSuperTrend_Array(wSym, wTimeFrame_Trend, wBarLeft, wBarRight, NumPeriod, Multiplier, SupTrPrice, SupTrTime,

         UppBand, LowBand);



//draw super trend line

      for (i=wBarLeft-1; i>=wBarRight; i--) // i refer chart

      {

         TrendUp[i] = EMPTY_VALUE;

         TrendDown[i] = EMPTY_VALUE;    

         wTime = iTime(wSym, wTimeFrame, i);// time (bar) on chart

         for (j=0; j<2000; j++) //j refer Super Trend data

         { 

            if (wTime > SupTrTime[0]) 

            {

              wBarSupTr = 0;//

              break;//exit j

            }//end if (wTime > SupTrTime[0])

            if ((wTime >= SupTrTime[j+1]) && (wTime < SupTrTime[j]))

            {

               wBarSupTr = j + 1;

               break; //exit j

            }//end if ((wTime < SupTrTime[j]) && (wTime >= SupTrTime[j+1]))

         }//end for (j=0; j<2000; j++)

            

         k = wBarSupTr;//reference Super Trend

         wClose_0 = iClose(wSym,wTimeFrame_Trend,k);//reference Super Trend

         wClose_1 = iClose(wSym,wTimeFrame_Trend,k+1);//reference Super Trend

         wHigh_0 = iHigh(wSym,wTimeFrame_Trend,k);//reference Super Trend

         wLow_0 = iLow(wSym,wTimeFrame_Trend,k);//reference Super Trend

         if (wClose_0 >= SupTrPrice[k]) TrendUp[i] = SupTrPrice[k];

         if (wClose_0 < SupTrPrice[k]) TrendDown[i] = SupTrPrice[k];

//change trend

         if ((wTime == SupTrTime[k]))//first point of Super Trend Bar

         {

            if ((wClose_1 > SupTrPrice[k+1]) && (wClose_0 < SupTrPrice[k])) TrendDown[i+1] = SupTrPrice[k+1];

            if ((wClose_1 < SupTrPrice[k+1]) && (wClose_0 > SupTrPrice[k])) TrendUp[i+1] = SupTrPrice[k+1];

         }//emd if ((wTime % TimeFrame) == 0)

      }//end for (i=wBarLeft; i>=wBarRight; i--)[i-1];



      WindowRedraw();

   }//end if (Time_0_New != Time_0_Old)  

   Time_0_Old = Time_0_New;

   return(0);

//   return(rates_total);

  }

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

//***********************************************************************************





//******************************************************************

//------------------------------------------------------------------

//******************************************************************

//begin fnSuperTrend_Array()

void fnSuperTrend_Array(string wSym, int wTimeFrame, int wBarLeft, int wBarRight, int wNumPeriod, double wMultiplier, 

      double& wSupTrPrice[], datetime& wSupTrTime[], double& wUppBand[], double& wLowBand[])

{

   int i;      

   double wHigh_t, wLow_t, wClose_t, wClose_tp, wATR;

   double wTR, wUppBandB, wLowBandB;

   datetime wTime_t;

     

   for (i=wBarLeft; i>=wBarRight; i--)

   {

      wHigh_t=iHigh(wSym, wTimeFrame,i);

      wLow_t=iLow(wSym,wTimeFrame,i);

      wClose_t=iClose(wSym,wTimeFrame,i);

      wClose_tp=iClose(wSym,wTimeFrame,i+1);

      wTime_t=iTime(wSym,wTimeFrame,i);



//calculate True Range      

      wTR=(wHigh_t-wLow_t);

      if (wClose_tp>wHigh_t) wTR=wClose_tp-wLow_t;

      if (wClose_tp<wLow_t) wTR=wHigh_t-wClose_tp;     



//calculate Average True Range

      wATR = iATR(wSym, wTimeFrame,wNumPeriod,i);

//calculate Upper/Lower Band Basic

      wUppBandB = (wHigh_t+wLow_t)/2 + wMultiplier*wATR;//Upper Band Basic

      wLowBandB = (wHigh_t+wLow_t)/2 - wMultiplier*wATR;//Lowper Band Basic



//calculate Upper/Lower Band

      wUppBand[i]=wUppBand[i+1];

      if ((wUppBandB<wUppBand[i+1]) || (wUppBand[i+1]<wClose_tp))

         wUppBand[i]=wUppBandB;



      wLowBand[i]=wLowBand[i+1];

      if ((wLowBandB>wLowBand[i+1]) || (wLowBand[i+1]>wClose_tp))

         wLowBand[i]=wLowBandB;

//calculate SuperTrend

      if (wSupTrPrice[i+1]==wUppBand[i+1])//Upper Band

      {

         wSupTrPrice[i]=wLowBand[i];

         if (wClose_t<=wUppBand[i])

            wSupTrPrice[i]=wUppBand[i];

      }

      else //Lower Band

      {

         wSupTrPrice[i]=wUppBand[i];

         if (wClose_t>=wLowBand[i])

            wSupTrPrice[i]=wLowBand[i];

      }//end if (wSupTr[i+1]=wUppBand[i+1])                          

      wSupTrTime[i]=wTime_t;

   }//end for (i=wBarLeft; i>wBarRight; i--)

      

}//end fnSuperTrend_Array()

//end fnSuperTrend_Array()



Files:
 
There is no logging you should add a reset and print of the last error to the log, at every step, to find where it goes haywire.
Reason: