How to detect candle open/close inside an Expert Advisor

Back to topics list To post a new topic, please log in or register
avatar
127
wemersonrv 2015.06.10 03:04
 

Hi folks!

I'm start to learn basics to construction an Expert, and it's going well so far. Eevery day some options become clearer and easy to understand, but others, not so much.

Need to know how to detect the exact moment when a candle is closed... and otherwise, also when a new candle starts.

Need this because my strategy works on the closing event of a candle, and open trade on starting next candle!

 

I do a previous search here on the forum and found a lot of information, but not cleared or inserted on much code... and don't understand !

  .

 

 

avatar
120
DeanDeV 2015.06.10 11:16 #
 
wemersonrv:


Need to know how to detect the exact moment when a candle is closed... and otherwise, also when a new candle starts.

Need this because my strategy works on the closing event of a candle, and open trade on starting next candle!


Use this when checking if the candle has opened before you send your orders:

bool IsNewCandle()                 
 {
  static int BarsOnChart=0;          
   if(Bars==BarsOnChart)
   return(false);
   BarsOnChart=Bars;
   return(true);
 }

 

avatar
127
wemersonrv 2015.06.10 14:59 #
 
DeanDeV:

Use this when checking if the candle has opened before you send your orders:

 

Great my friend. Thanks.

 

Now i need to know how to detect the end of the candle... or in the detection of new candle check the confluences of my strategy on previous candle.

 

avatar
12985
WHRoeder 2015.06.10 15:38 #
 
wemersonrv: Need to know how to detect the exact moment when a candle is closed... and otherwise, also when a new candle starts
  1. The candle closes when the new candle starts. A new candle starts when a tick comes in at or beyond the last candle time+period.
  2. DeanDeV posted his IsNewCandle() but I recommend that it not be placed into a function. Calling the function a second time, in the same tick, returns false. I just use
    start(){
       static datetime time0; bool isNewBar = time0 != Time[0]; time0 = Time[0];
    
      if(isNewBar) ...

  3. If both cases, the above codes do not properly handle, first tick or deinit/init cycles. See https://forum.mql4.com/57074/page3#825991
avatar
127
wemersonrv 2015.06.10 16:00 #
 
WHRoeder:
  1. The candle closes when the new candle starts. A new candle starts when a tick comes in at or beyond the last candle time+period.
  2. DeanDeV posted his IsNewCandle() but I recommend that it not be placed into a function. Calling the function a second time, in the same tick, returns false. I just use
  3. If both cases, the above codes do not properly handle, first tick or deinit/init cycles. See https://forum.mql4.com/57074/page3#825991
Ok, understand!
Back to topics list  

To add comments, please log in or register