Download MetaTrader 5
To add comments, please log in or register
Unable to find the answer to your question? Use the search!
Stephen Reynolds
483
Stephen Reynolds 2016.06.13 13:37 

Record Session High  = A current candle closes higher than the previous candles up to 6 bars back.

The following code has been made to count the candlestick record session highs up to 8 and then start drawing objects on each candle to mark the overbought or oversold condition.

But this code only works on the open price test and not on tick test. Its because i don't know a way to count bars on tick test. I know iBarShift can be used  and i also got the idea of using with a static modifier object if(Volume[0]==1) barcount++;    

but i cant get these to count in this code.  


void OnTick()
{
   static int objectBuyCount = 0;  

   int lowest = iLowest(NULL,0,MODE_LOW,lowBars,1);   
   double lowestLow = Low[lowest];

   static int bullBarCount = 1;
  
   static bool enableBullCount = false;   

   static double bullBarClose = Close[1]; 

   static bool lowestCount = true;
      
   static int resetBullCount = 1; 


   // Bull Signal  (EG Price has been bearish, now possible reversal)   
   if(Low[1] > lowestLow)
   {                              
      enableBullCount = true;   
   }
   else
   {
      enableBullCount = false;
      lowestCount = true;
      bullBarCount = 1; // My way of resetting barCount and lowestCount if new lowestLow is found
   }     
     
   if(lowestCount == true && enableBullCount == true && Close[1] > Open[1] && Close[1] > lowestLow)
   {
      bullBarClose = Close[1];        
      lowestCount = false; // Switches of this if statement after one use 
   }                                   // until another lowest low
   
   if(Close[1] > Open[1] && Close[1] > bullBarClose)   
   {
      bullBarClose = Close[1];
      bullBarCount++;   
   }               
   
   // Counts each bar only if its close isnt higher than previous RSH barcount
   if(Close[1] < bullBarClose && Volume[1]==1) resetBullCount++; 
      else resetBullCount = 1;
      
   // Resets RSH count and lowest low object ready for new low search
   if(resetBullCount > 6) 
   {
      bullBarCount = 1;
      lowBars = 1;
   }

   // End Of Bulls RSH
   if(bullBarCount >= 8) 
   {
      double c = Close[0];
      datetime t = iTime(NULL,0,0);                
      string ob_Shorts = "Shorts"+TimeToStr(t);
      
      ObjectCreate(0,ob_Shorts,OBJ_ARROW,0,t,c);  // Makes position of arrow end of candle wick +/- 50pts
      ObjectSetInteger(0,ob_Shorts,OBJPROP_ARROWCODE,174);  
      ObjectSetInteger(0,ob_Shorts,OBJPROP_COLOR,clrBlue);
   } 
}
whroeder1
13590
whroeder1 2016.06.13 14:17  
renzbub: if(Volume[0]==1) barcount++;   
Bars is unreliable (a refresh/reconnect can change number of bars on chart) volume is unreliable (miss ticks) Always use time. New candle - MQL4 forum
Stephen Reynolds
483
Stephen Reynolds 2016.06.13 16:16  
WHRoeder:
Bars is unreliable (a refresh/reconnect can change number of bars on chart) volume is unreliable (miss ticks) Always use time. New candle - MQL4 forum
Thanks for that improvement. 
/
To add comments, please log in or register