Test Custom Indicator using iCustom() in Strategy Tester via EA

 

I would like to test the Custom indicator using Strategy Tester. Hence I create a simple EA to call the Custom Indicator using iCustom()

Problem: Custom indicator global variable seem do not record the previous assigned value when testing in Strategy Tester but this is not the case when manually attach to chart window.

EA Code:

#property link      ""
double ind1[6], ind2[6], ind3[6];
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   GetSubIndicatorValue();
//----
   return(0);
  }
//+------------------------------------------------------------------+

//Fetch all subindicator value into the system
void GetSubIndicatorValue()
{
   //string indicator1 = "TradingRange";
   string indicator2 = "FlagV2";
   //string indicator3 = "Pennant";
   
   
   //get value from indicator1
   //total : 5
   //ind1[0]= iCustom(NULL,0,indicator1,0,0);
   //ind1[1]= iCustom(NULL,0,indicator1,1,0);
   //ind1[2]= iCustom(NULL,0,indicator1,2,0);
   //ind1[3]= iCustom(NULL,0,indicator1,3,0);
   //ind1[4]= iCustom(NULL,0,indicator1,4,0);
   
   //get value from indicator2
   //total : 5
   
   ind2[0]= iCustom(NULL,0,indicator2,0,true,0);
   ind2[1]= iCustom(NULL,0,indicator2,1,true,0);
   ind2[2]= iCustom(NULL,0,indicator2,2,true,0);
   ind2[3]= iCustom(NULL,0,indicator2,3,true,0);
   ind2[4]= iCustom(NULL,0,indicator2,4,true,0);
   
   //get value from indicator3
   //total : 4
   /*
   ind3[0]= iCustom(NULL,0,indicator3,0,true, 0);
   ind3[1]= iCustom(NULL,0,indicator3,1,true, 0);
   ind3[2]= iCustom(NULL,0,indicator3,2,true, 0);
   ind3[3]= iCustom(NULL,0,indicator3,3,true, 0);
   */
}

The on test Custom Indicator Code:

#property link      ""

#property indicator_chart_window

#property indicator_buffers 6 
//create an indicator to store the data used for public, retrieve them from top.
//store at bottom
//convert store value to int, string or double.
#property indicator_color1 Tomato      
#property indicator_color2 Tomato      
#property indicator_color3 Tomato      
#property indicator_color4 Tomato      
#property indicator_color5 Tomato      
#property indicator_color6 Tomato  
// ----- indicator_buffers
//share buffer
double   IndicatorBuffer1[5000];
double   IndicatorBuffer2[];
double   IndicatorBuffer3[];
double   IndicatorBuffer4[];
double   IndicatorBuffer5[];
double   IndicatorBuffer6[];

bool BreakOutCheckingNeeded;

//AveragedMedian = AccumulatedMedian/MedianPeriod
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
  Comment("init() Entered");

     //RangeEffect
   SetIndexStyle(0,DRAW_ARROW);     
   SetIndexBuffer(0,IndicatorBuffer1); 
   
   SetIndexStyle(1,DRAW_NONE);          
   SetIndexBuffer(1,IndicatorBuffer2); 
   
   SetIndexStyle(2,DRAW_NONE);          
   SetIndexBuffer(2,IndicatorBuffer3);
   
   SetIndexStyle(3,DRAW_NONE);          
   SetIndexBuffer(3,IndicatorBuffer4);
   
   SetIndexStyle(4,DRAW_NONE);          
   SetIndexBuffer(4,IndicatorBuffer5);
   
   SetIndexStyle(5,DRAW_NONE);          
   SetIndexBuffer(5,IndicatorBuffer6);
     //clear buffer value 
   SetIndexEmptyValue(0,0.0); 
   SetIndexEmptyValue(1,0.0);
   SetIndexEmptyValue(2,0.0); 
   SetIndexEmptyValue(3,0.0);
   SetIndexEmptyValue(4,0.0); 
   SetIndexEmptyValue(5,0.0);

   BreakOutCheckingNeeded = false;

   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   DeleteObjectStartWithName(ObjName);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
  
  DebugMsg2 = BreakOutCheckingNeeded;
  BreakOutCheckingNeeded = true;

   GUIPainter_Label(ObjName+"labeldebug2",DebugMsg2,Red,0,5,25);

   return(0);
  }
//+------------------------------------------------------------------+


//Create a label
void GUIPainter_Label(string labelName, string msg,color clr,int refCorner, int xpos,int ypos)//---------------- 1 --
{
---
}


-----------

test result

-----------


Custom Indicator shot from Strategy Tester

Custom indicator label showing "0" on Strategy Tester Chart window (when testing on progress).


Custom Indicator shot from Strategy Tester 2

Custom indicator label showing "1" on Strategy Tester Chart window (when Stop pressed).



Manual attach Custom Indicator to Chart Window

Custom Indicator showing "1" on live Chart window when custom indicator manually attached.

Suspect for problem:

1. what happen when EA called iCustom each time?
when tick arrive, iCustom() trigger, is the sequence of indicator evaluation start from Init()->Start() always?
or control go directly to Start() and the Init() only trigger once when the strategy tester started?

2. Is this problem caused only to UI Invalidate problem but the global variable value still take effect during run time on Strategy tester?

It seem like UI do not show correct result "1" but showing "0" instread during run time, but it shows the correct result "1" when Stop pressed.

Any one know why this happen?


Thanks for taking time to understand the problem. Please let me know if you need any further clarification.

Thanks.




 

Your expression

ind2[0]= iCustom(NULL,0,indicator2,0,true,0);
is wrong

real expression

double iCustom( string symbol, int timeframe, string name, ..., int mode, int shift)

 
Roger:

Your expression

ind2[0]= iCustom(NULL,0,indicator2,0,true,0);
is wrong

real expression

double iCustom(string symbol, int timeframe, string name, ..., int mode, int shift)

Hi Roger,

thanks for spotting the problem.

sorry for the wrong expression:

the real expression used are during posting this forum is 

ind2[0]= iCustom(NULL,0,indicator2,0,0); //withoud the "true" extern variable defined.

So the problem still persisit.

Any one have encounter this problem before? or use similar or better method to test the custom indicator in Strategy tester?

Is there any exisitng article on this method?

 

This Post solve the problem on invalidate of custom indicator in the stragety tester.

Add custom indicator to the Strategy Tester Chart after "Start"

Is this the best way?

My doubt on iCustom() is still not solved:

1. When EA use iCustom(), do the custom indicator Init() trigger everytime the "iCustom()" called or it trigger only once at the adding time of EA to the Chart?

2. Is iCustom() shows same behaviour as it is when manually added to Live chart window?

Thanks in advance for helping to clarify the doubt.

You can send me reference link to the mention problem. 



 

Did you ever get an answer as to why your EA was pulling up a zero everytime when you tried to call on the iCustom? I'm having the same exact issue when referencing iCustom in my EA or even a simple script with an alert...I keep gettting a zero! Even though my custom indicator plots fine on the chart itself.

 
patrick772goh wrote >>

I would like to test the Custom indicator using Strategy Tester. Hence I create a simple EA to call the Custom Indicator using iCustom()

Problem: Custom indicator global variable seem do not record the previous assigned value when testing in Strategy Tester but this is not the case when manually attach to chart window.

EA Code:

The on test Custom Indicator Code:


-----------

test result

-----------


Custom Indicator shot from Strategy Tester

Custom indicator label showing "0" on Strategy Tester Chart window (when testing on progress).


Custom Indicator shot from Strategy Tester 2

Custom indicator label showing "1" on Strategy Tester Chart window (when Stop pressed).



Manual attach Custom Indicator to Chart Window

Custom Indicator showing "1" on live Chart window when custom indicator manually attached.

Suspect for problem:

1. what happen when EA called iCustom each time?
when tick arrive, iCustom() trigger, is the sequence of indicator evaluation start from Init()->Start() always?
or control go directly to Start() and the Init() only trigger once when the strategy tester started?

2. Is this problem caused only to UI Invalidate problem but the global variable value still take effect during run time on Strategy tester?

It seem like UI do not show correct result "1" but showing "0" instread during run time, but it shows the correct result "1" when Stop pressed.

Any one know why this happen?


Thanks for taking time to understand the problem. Please let me know if you need any further clarification.

Thanks.


It can happen if you define Ind as an integer array
ForexWatchman


 
ForexWatchman:



I am having the same problem. I am calling iCustom from an Indicator and from an expert advisor and getting different results. I have inserted print statements and I know the parameters being passed are identical.

EA:

double haOpen = iCustom(NULL,prd,"Heiken_Ashi_Smoothed",MaMetod,MaPeriod,MaMetod2,MaPeriod2,2,yy);
double haClose = iCustom(NULL,prd,"Heiken_Ashi_Smoothed",MaMetod,MaPeriod,MaMetod2,MaPeriod2,3,yy);

Print(" Heiken EA tf=",tf," yy=",yy," prd=",prd," open=",haOpen," close=",haClose," ",MaMetod," ",MaPeriod," ",MaMetod2," ",MaPeriod2);

Indicator:

haOpen = iCustom(NULL,prd,"Heiken_Ashi_Smoothed",MaMetod,MaPeriod,MaMetod2,MaPeriod2,2,yy) ;
haClose = iCustom(NULL,prd,"Heiken_Ashi_Smoothed",MaMetod,MaPeriod,MaMetod2,MaPeriod2,3,yy) ;

Alert(" Heiken indicator tf=",tf," prd=",prd," open=",haOpen," close=",haClose," ",MaMetod," ",MaPeriod," ",MaMetod2," ",MaPeriod2," yy=",yy);

This is very frustrating.

Larene

 

I figured it out. Here is my EA. I can view the direction on 4 time frames.

Files:
Reason: