Download MetaTrader 5
To add comments, please log in or register
What are the latest MQL5.community news? The Wall section will tell you!
Stephen Reynolds
483
Stephen Reynolds 2015.08.21 17:00 

I am trying to run a test on the MT4 strategy tester on the 5m chart. I want conditions to be met on both the 5m and 30m charts.

It appears to ignore the 30m chart condition so the condition is never true?

// Input variables
input int KPeriod = 14;
input int DPeriod = 3;
input int Slowing = 3;
input ENUM_MA_METHOD StochMethod = MODE_SMA;
input ENUM_STO_PRICE StochPrice = STO_LOWHIGH;

input int BandsPeriod= 20;  
input int BandsShift = 0;   
input double BandsDeviations = 2.0; 
input ENUM_APPLIED_PRICE BollPrice = PRICE_CLOSE;

// OnTick() event handler                
void OnTick()    
{
   double close = Close[1];  
   datetime time = iTime(NULL,0,1);   
            
   double stochasticBigMain = iStochastic(_Symbol,PERIOD_M30,KPeriod,DPeriod,Slowing,StochMethod,StochPrice,MODE_MAIN,1); 
   double stochasticBigSignal = iStochastic(_Symbol,PERIOD_M30,KPeriod,DPeriod,Slowing,StochMethod,StochPrice,MODE_SIGNAL,1);   
   
   bool timeframeBigBuyCondition = (stochasticBigMain > stochasticBigSignal && stochasticBigMain < 80);
   
   double stochasticSmallMain = iStochastic(_Symbol,PERIOD_M5,KPeriod,DPeriod,Slowing,StochMethod,StochPrice,MODE_MAIN,1); 
   double stochasticSmallSignal = iStochastic(_Symbol,PERIOD_M5,KPeriod,DPeriod,Slowing,StochMethod,StochPrice,MODE_SIGNAL,1);    
   
   bool timeframeSmallBuyCondition = (stochasticSmallMain > stochasticSmallSignal && stochasticSmallMain < 80);   
   
   if(timeframeBigBuyCondition == true && timeframeSmallBuyCondition == true) 
   {                      
      ObjectCreate("Buy",OBJ_ARROW_THUMB_UP,0,time,close);                 
   }  
}  

 

I basically dont know how to make a condition true on a bigger timeframe apply to a smaller timeframe?

Keith Watford
Moderator
7875
Keith Watford 2015.08.21 22:48  

How do you know the conditions are never true?

Once the object "Buy" has been created, another object with the same name cannot be created again

Either check that the object exists already and if so, move it.

Or give each object a unique name, such as

 

  double close = Close[1];         //The price from earlier in your code 
  datetime time = iTime(NULL,0,1); //The time from earlier in your code
  
  string ob_name="Buy "+TimeToStr(time);
  if(ObjectFind(0,ob_name)<0)
     ObjectCreate(ob_name,OBJ_ARROW_THUMB_UP,0,time,close);

 

 

Unrelated to your question. When comparing values from any indicator from different timeframes, you need to be sure that you are comparing the bars that you want to.

with your code, say the current time is 05:12

At that time Bar[1] on the M5 chart is the bar that opened at 05:05 

on M15, Bar[1] opened at 04:45.

Stephen Reynolds
483
Stephen Reynolds 2015.08.22 16:14  
GumRai:

How do you know the conditions are never true?

Once the object "Buy" has been created, another object with the same name cannot be created again

Either check that the object exists already and if so, move it.

Or give each object a unique name, such as

 

 

 

Unrelated to your question. When comparing values from any indicator from different timeframes, you need to be sure that you are comparing the bars that you want to.

with your code, say the current time is 05:12

At that time Bar[1] on the M5 chart is the bar that opened at 05:05 

on M15, Bar[1] opened at 04:45.

 

 Thanks for the code GumRai that will be useful  

/
To add comments, please log in or register