MTF Stochastic Indicator and Strategy Tester

 

Hi All,

 

Working on a Multi Time frame stochastic oscillator tool that works well for me as a manual trading strategy ive integrated into part of my EA and it works fine forward testing it but I cant back test it using strategy tester.

 

Ive done a lot of modding of the code lately to really strip it down as had a lot of pointless stuff in there. Its fixed settings as this is what works and doesnt need to be tampered with but what im struggling with is it would be mega helpful if I could actually back test it but MT4 doesnt allow you to calc times or as it seems any other time frame indicators while using strategy tester. So the values and the display of my MTF indicator is useless and so the EA doesnt trade.

It only takes into account the variance of the H4 stochastic or rather the open time frame stochastic which in this case is H4.

 

Any ideas. I wondered if this could be achieved by amending the code to an OnCalculate() function or something so it would calculate all time frames stochastics on every tick which in theory should work with strategy tester as it apparently does have access to every available time frame it just doesnt work right unless it has a strict enough function call.

 

Code for the MTF Stoch is attached here:

//+------------------------------------------------------------------+
//|                                   BigBroking MTF Stochastics.mq4 |
//|                                              www.big-broking.com |
//|                                       http://www.big-broking.com |
//+------------------------------------------------------------------+
#property copyright "BigBroking - Multi Time Frame Stochastic Fixed settings. "
#property link      "http://www.big-broking.com"
#property link      "Multi Time Frame Stochastics"
//----
#property indicator_separate_window
#property indicator_buffers 10
//----
#property indicator_color1 Red
#property indicator_color2 Red
#property indicator_color3 DodgerBlue
#property indicator_color4 DodgerBlue
#property indicator_color5 Magenta
#property indicator_color6 Magenta
#property indicator_color7 Lime
#property indicator_color8 Lime
#property indicator_color9 Gold
#property indicator_color10 Gold
#property indicator_level1 80
#property indicator_level2 50
#property indicator_level3 20
#property indicator_levelcolor DimGray




/*******************************************************************
Price Options
PRICE_CLOSE = 0 Close price.
PRICE_OPEN = 1 Open price.
PRICE_HIGH = 2 High price.
PRICE_LOW = 3 Low price.
PRICE_MEDIAN = 4 Median price, (high+low)/2.
PRICE_TYPICAL = 5 Typical price, (high+low+close)/3.
PRICE_WEIGHTED = 6 Weighted close price, (high+low+close+close)/4.

Line Style Options
STYLE_SOLID = 0 The line is solid.
STYLE_DASH = 1 The line is dashed.
STYLE_DOT = 2 The line is dotted.
STYLE_DASHDOT = 3 The line has alternating dashes and dots.
STYLE_DASHDOTDOT = 4 The line has alternating dashes and double dots.

Ma Options
MODE_SMA = 0 Simple moving average,
MODE_EMA = 1 Exponential moving average,
MODE_SMMA = 2 Smoothed moving average,
MODE_LWMA = 3 Linear weighted moving average.
**********************************************************************/

//bool Show_StochLabels=true;
int Shift_Text=0;
//>>> Stoch #1 Settings >>>>>>>>>>>>>>>";
int TimeFrame1=5;
int K_period1=14;
int D_period1=2;
int S_period1=2;
//all Other Periods stochastic settings >>>>>>>>>>>>>
int K_period2=14;
int D_period2=3;
int S_period2=3;
int STOCH_MAIN_Line_Style=0;
int STOCH_SIGNAL_Line_Style=2;
int STOCH_MAIN_Price=4;
int STOCH_SIGNAL_Price=4;
int STOCH_MAIN_Ma=0;
int STOCH_SIGNAL_Ma=0;
//>>> Stoch #2 Settings >>>>>>>>>>>>>>>>>
int TimeFrame2=15;
//>>> Stoch #3 Settings >>>>>>>>>>>>>>>>>>>
int TimeFrame3=30;
//>>> Stoch #4 Settings >>>>>>>>>>>>>>>>>>>>>
int TimeFrame4=60;
//>>> Stoch #5 Settings >>>>>>>>>>>>>>>>>>>>>
int TimeFrame5=240;
//----
double MainBuffer1[];
double SignalBuffer1[];
double MainBuffer2[];
double SignalBuffer2[];
double MainBuffer3[];
double SignalBuffer3[];
double MainBuffer4[];
double SignalBuffer4[];
double MainBuffer5[];
double SignalBuffer5[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
  //----Draw this only on start------Should speed up indicator//
   ObjectCreate("StoRectangle",OBJ_RECTANGLE_LABEL,WindowFind("BigBroking MTF STOCH #1 "),OBJPROP_XDISTANCE,OBJPROP_XSIZE,OBJPROP_YDISTANCE,OBJPROP_YSIZE);
      //--- set the chart's corner, relative to which point coordinates are defined
      ObjectSet("StoRectangle",OBJPROP_CORNER,CORNER_LEFT_UPPER);
      //--- set label coordinates
      ObjectSet("StoRectangle",OBJPROP_XDISTANCE,15);
      ObjectSet("StoRectangle",OBJPROP_YDISTANCE,15);
      //--- set label size
      ObjectSet("StoRectangle",OBJPROP_XSIZE,150);
      ObjectSet("StoRectangle",OBJPROP_YSIZE,95);
      //--- set background color
      ObjectSet("StoRectangle",OBJPROP_FILL,clrBlack);
      //--- set rectangle color
      ObjectSet("StoRectangle",OBJPROP_BGCOLOR,clrBlack);
      //--- set border type
      ObjectSet("StoRectangle",OBJPROP_BORDER_TYPE,2);
      //--- set flat border color (in Flat mode)
      ObjectSet("StoRectangle",OBJPROP_COLOR,clrBlack);
      //--- set flat border line style
      ObjectSet("StoRectangle",OBJPROP_STYLE,1);
      //--- set flat border width
      ObjectSet("StoRectangle",OBJPROP_WIDTH,5);
      //--- display in the foreground (false) or background (true)
      ObjectSet("StoRectangle",OBJPROP_BACK,false);

      //----
      ObjectCreate("stoLABEL",OBJ_LABEL,WindowFind("BigBroking MTF STOCH #1 "),0,0);
      ObjectSetText("stoLABEL","STOCH #1 :   Period M5",9,"Tahoma Narrow",indicator_color1);
      ObjectSet("stoLABEL",OBJPROP_CORNER,CORNER_LEFT_UPPER);
      ObjectSet("stoLABEL",OBJPROP_XDISTANCE,20);
      ObjectSet("stoLABEL",OBJPROP_YDISTANCE,20);
      //----
      ObjectCreate("stoLABEL1",OBJ_LABEL,WindowFind("BigBroking MTF STOCH #1 "),0,0);
      ObjectSetText("stoLABEL1","STOCH #2 :   Period M15",9,"Tahoma Narrow",indicator_color3);
      ObjectSet("stoLABEL1",OBJPROP_CORNER,CORNER_LEFT_UPPER);
      ObjectSet("stoLABEL1",OBJPROP_XDISTANCE,20);
      ObjectSet("stoLABEL1",OBJPROP_YDISTANCE,35);
      //----
      ObjectCreate("stoLABEL2",OBJ_LABEL,WindowFind("BigBroking MTF STOCH #1 "),0,0);
      ObjectSetText("stoLABEL2","STOCH #3 :   Period M30",9,"Tahoma Narrow",indicator_color5);
      ObjectSet("stoLABEL2",OBJPROP_CORNER,CORNER_LEFT_UPPER);
      ObjectSet("stoLABEL2",OBJPROP_XDISTANCE,20);
      ObjectSet("stoLABEL2",OBJPROP_YDISTANCE,50);
      //----
      ObjectCreate("stoLABEL4",OBJ_LABEL,WindowFind("BigBroking MTF STOCH #1 "),0,0);
      ObjectSetText("stoLABEL4","STOCH #4 :   Period H1",9,"Tahoma Narrow",indicator_color7);
      ObjectSet("stoLABEL4",OBJPROP_CORNER,CORNER_LEFT_UPPER);
      ObjectSet("stoLABEL4",OBJPROP_XDISTANCE,20);
      ObjectSet("stoLABEL4",OBJPROP_YDISTANCE,65);
      //----
      ObjectCreate("stoLABEL5",OBJ_LABEL,WindowFind("BigBroking MTF STOCH #1 "),0,0);
      ObjectSetText("stoLABEL5","STOCH #5 :   Period H4",9,"Tahoma Narrow",indicator_color9);
      ObjectSet("stoLABEL5",OBJPROP_CORNER,CORNER_LEFT_UPPER);
      ObjectSet("stoLABEL5",OBJPROP_XDISTANCE,20);
      ObjectSet("stoLABEL5",OBJPROP_YDISTANCE,80);
//---- indicator line

   SetIndexBuffer(0,MainBuffer1);
   SetIndexStyle(0,DRAW_LINE,STOCH_MAIN_Line_Style);
   SetIndexLabel(0,"MAIN #1  ( 14 )( 2 )( 2 )");
   SetIndexBuffer(1,SignalBuffer1);
   SetIndexStyle(1,DRAW_LINE,STOCH_SIGNAL_Line_Style);
   SetIndexLabel(1,"SIGNAL #1 ( 14 )( 2 )( 2 )");
//----

   SetIndexBuffer(2,MainBuffer2);
   SetIndexStyle(2,DRAW_LINE,STOCH_MAIN_Line_Style);
   SetIndexLabel(2,"MAIN #2 ( "+(string)K_period2+" )( "+(string)D_period2+" )( "+(string)S_period2+" )");
   SetIndexBuffer(3,SignalBuffer2);
   SetIndexStyle(3,DRAW_LINE,STOCH_SIGNAL_Line_Style);
   SetIndexLabel(3,"SIGNAL #2 ( "+(string)K_period2+" )( "+(string)D_period2+" )( "+(string)S_period2+" )");
//----

   SetIndexBuffer(4,MainBuffer3);
   SetIndexStyle(4,DRAW_LINE,STOCH_MAIN_Line_Style);
   SetIndexLabel(4,"MAIN #3 ( "+(string)K_period2+" )( "+(string)D_period2+" )( "+(string)S_period2+" )");
   SetIndexBuffer(5,SignalBuffer3);
   SetIndexStyle(5,DRAW_LINE,STOCH_SIGNAL_Line_Style);
   SetIndexLabel(5,"SIGNAL #3 ( "+(string)K_period2+" )( "+(string)D_period2+" )( "+(string)S_period2+" )");
//----

   SetIndexBuffer(6,MainBuffer4);
   SetIndexStyle(6,DRAW_LINE,STOCH_MAIN_Line_Style);
   SetIndexLabel(6,"MAIN #4 ( "+(string)K_period2+" )( "+(string)D_period2+" )( "+(string)S_period2+" )");
   SetIndexBuffer(7,SignalBuffer4);
   SetIndexStyle(7,DRAW_LINE,STOCH_SIGNAL_Line_Style);
   SetIndexLabel(7,"SIGNAL #4 ( "+(string)K_period2+" )( "+(string)D_period2+" )( "+(string)S_period2+" )");
//----
  
   SetIndexBuffer(8,MainBuffer5);
   SetIndexStyle(8,DRAW_LINE,STOCH_MAIN_Line_Style);
   SetIndexLabel(8,"MAIN #5 ( "+(string)K_period2+" )( "+(string)D_period2+" )( "+(string)S_period2+" )");
   SetIndexBuffer(9,SignalBuffer5);
   SetIndexStyle(9,DRAW_LINE,STOCH_SIGNAL_Line_Style);
   SetIndexLabel(9,"SIGNAL #5 ( "+(string)K_period2+" )( "+(string)D_period2+" )( "+(string)S_period2+" )");
//---- name for DataWindow and indicator subwindow label  
   IndicatorShortName("BigBroking MTF STOCH #1 ");
   return(0);
  }
//----

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   ObjectsDeleteAll(0,OBJ_LABEL);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| MTF Stochastic                                                   |
//+------------------------------------------------------------------+
int start()
  {
   datetime TimeArray[];
   int    i,limit,y=0,counted_bars=IndicatorCounted();
// Plot defined timeframe on to current timeframe  
   ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),PERIOD_M5);
   ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),PERIOD_M15);
   ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),PERIOD_M30);
   ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),PERIOD_H1);
   ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),PERIOD_H4);
//----
   limit=Bars-counted_bars*5/Period(); //TimeFrame1
   limit=Bars-counted_bars*15/Period(); //TimeFrame2
   limit=Bars-counted_bars*30/Period(); //TimeFrame3
   limit=Bars-counted_bars*60/Period(); //TimeFrame4
   limit=Bars-counted_bars*240/Period(); //TimeFrame5
   for(i=0,y=0;i<limit;i++)
     {
      if(Time[i]<TimeArray[y]) y++;
      MainBuffer1[i]=iStochastic(NULL,PERIOD_M5,K_period1,D_period1,S_period1,STOCH_MAIN_Ma,STOCH_MAIN_Price,MODE_MAIN,y);
      SignalBuffer1[i]=iStochastic(NULL,PERIOD_M5,K_period1,D_period1,S_period1,STOCH_SIGNAL_Ma,STOCH_SIGNAL_Price,MODE_SIGNAL,y);
      //----
      MainBuffer2[i]=iStochastic(NULL,PERIOD_M15,K_period2,D_period2,S_period2,STOCH_MAIN_Ma,STOCH_MAIN_Price,MODE_MAIN,y);
      SignalBuffer2[i]=iStochastic(NULL,PERIOD_M15,K_period2,D_period2,S_period2,STOCH_SIGNAL_Ma,STOCH_SIGNAL_Price,MODE_SIGNAL,y);
      //----
      MainBuffer3[i]=iStochastic(NULL,PERIOD_M30,K_period2,D_period2,S_period2,STOCH_MAIN_Ma,STOCH_MAIN_Price,MODE_MAIN,y);
      SignalBuffer3[i]=iStochastic(NULL,PERIOD_M30,K_period2,D_period2,S_period2,STOCH_SIGNAL_Ma,STOCH_SIGNAL_Price,MODE_SIGNAL,y);
      //----
      MainBuffer4[i]=iStochastic(NULL,PERIOD_H1,K_period2,D_period2,S_period2,STOCH_MAIN_Ma,STOCH_MAIN_Price,MODE_MAIN,y);
      SignalBuffer4[i]=iStochastic(NULL,PERIOD_H1,K_period2,D_period2,S_period2,STOCH_SIGNAL_Ma,STOCH_SIGNAL_Price,MODE_SIGNAL,y);
      //----
      MainBuffer5[i]=iStochastic(NULL,PERIOD_H4,K_period2,D_period2,S_period2,STOCH_MAIN_Ma,STOCH_MAIN_Price,MODE_MAIN,y);
      SignalBuffer5[i]=iStochastic(NULL,PERIOD_H4,K_period2,D_period2,S_period2,STOCH_SIGNAL_Ma,STOCH_SIGNAL_Price,MODE_SIGNAL,y);
     }
    
//----
   return(0);
  }
//+------------------------------------------------------------------+


 

 

Sorry know this is an old thread but im having the same problem and im reading some countering information.

 

MTF cant be tested on MT4 but others say it can using defined time parameters. Can anyone help me with this? I have attached my MQ4 code to the post.

 

Ive tried all sorts to make it backtestable but not getting any joy right now it will only calculate and draw the stochastic for the H4 It shows a history trail of previous data but doesnt do anything going forward....

 

 

 
Thehallster:

Sorry know this is an old thread but im having the same problem and im reading some countering information.

 

MTF cant be tested on MT4 but others say it can using defined time parameters. Can anyone help me with this? I have attached my MQ4 code to the post.

 
If you are testing an EA and have MTF indicators attached to the testing chart, they will not display correctly. However, the iCustom calls in the EA will get the correct values (in my experience)
 
  1.    ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),PERIOD_M5);
       ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),PERIOD_M15);
       ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),PERIOD_M30);
       ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),PERIOD_H1);
       ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),PERIOD_H4);
    Bogus. Which series do you want TimeArray to be? can't be more than one.
  2.   limit=Bars-counted_bars+TimeFrame1/Period();
       limit=Bars-counted_bars+TimeFrame2/Period();
       limit=Bars-counted_bars+TimeFrame3/Period();
       limit=Bars-counted_bars+TimeFrame4/Period();
       limit=Bars-counted_bars+TimeFrame5/Period();
       for(i=0,y=0;i<limit;i++)
    Bogus. You want to paint all candles on the current TF - See How to do your lookbacks correctly.
  3. Don't double post Don't hijack old threads.
 

Hey Keith,

 

Thanks for the heads up on that it appears that strategy tester can indeed get the values but it cant get the values whilst using an indicator that gets them values.

 

So changed the EA to run the iCustom calls within itself and its solved the problem and the EA is now back testable. Just optimizing the code now to speed it up as its slow as hell! quicker to forward test it lol