How to count bars after order open?

 

Hello there

My EA requires counting the bars after an order has opened (measure MACD values against a 'sloping' (changing) value (not the signal)).

This is what i thought (my problem):

  • get the Order Open Time - OOT - (in seconds),
  • datetime OOT=OrderOpenTime();
  • get the current time - Bar 0,
       int MM=TimeMinute(Time[0]);
       int SS=Seconds();
  • Subtract the next bar time value (say it is 15 min chart and next candle value is the 45 minute candle) form the current TimeMinute value. Let say it is 2 minutes and 25 seconds before the next Bar starts, thus the value will be 145 (seconds).
  • get the Timecurrent() value and add the 145 seconds to it = Bar_check_value.
  • do math calc and see how many 900 seconds (15 x 60 = 900) intervals the current time is away from the OOT.
  • that's how many bars away from the OOT.

Isn't there an easier way?

Any other ideas?

 

Yep, much easier

https://docs.mql4.com/series/iBarShift

Hope that helps

V

 

thanks, will give it a try!!!
 

53056:

get the Order Open Time - OOT - (in seconds),

  • get the current time - Bar 0,
  • Subtract the next bar time value (say it is 15 min chart and next candle value is the 45 minute candle) form the current TimeMinute value. Let say it is 2 minutes and 25 seconds before the next Bar starts, thus the value will be 145 (seconds).
  • get the Timecurrent() value and add the 145 seconds to it = Bar_check_value.
  • do math calc and see how many 900 seconds (15 x 60 = 900) intervals the current time is away from the OOT.
  • that's how many bars away from the OOT.

Isn't there an easier way?

Any other ideas?

I made a sessions Indy which coincidentally fits your need. It's simplifies datetime operations greatly. Perhaps you can use the solution for your EA, I commented it with lots of explanation in case needed. 

HTH

 
awesome!
 

Hi everyone,

I have a question that can we open opposite position on the same pair. If not, what would happened if we run two different ea bots on the same pair and they triggered opposite positions?

 
Dang Thanh: I have a question that can we open opposite position on the same pair.
Not with a US broker. Since 2009, hedging is not permitted for US traders.

          NFA Enforces FIFO Rule, Bans Forex Hedging in US Forex Accounts - Trading Heroes
          FAQ: FIFO in the Forex Market - BabyPips.com

 
Dang Thanh:

Hi everyone,

I have a question that can we open opposite position on the same pair. If not, what would happened if we run two different ea bots on the same pair and they triggered opposite positions?

You have asked your question in a non related and an old topic, you could better create a new topic in MT5 forum, here is MT4 forum.
Reason: