What about . . .
int Bars_TM = iBarShift( Symbol(), Period(), OrderOpenTime()) ;
int Bars_TM = iBarShift(NULL,0, OrderOpenTime());
Which handles holidays and weeks ends.
- As you can see, this code is not working out.No mind readers here, we can't see anything unless you post it.
WHRoeder:
Which handles holidays and weeks ends.
- As you can see, this code is not working out.No mind readers here, we can't see anything unless you post it.
datetime Time_dif_TM = OrderOpenTime() - iTime(Symbol(),Period(),0); int Bars_TM = Time_dif_TM / 60 / Period();
WHRoeder:
Which handles holidays and weeks ends.
- As you can see, this code is not working out.No mind readers here, we can't see anything unless you post it.
datetime Time_dif_TM = OrderOpenTime() - iTime(Symbol(),Period(),0); int Bars_TM = Time_dif_TM / 60 / Period();
Two points, one has already been made by WHRoeder:
- your code won't work if the Time_dif_TM spans a weekend or holiday when the market is closed, there are no bars during closed periods
- your calculation is wrong
int Bars_TM = Time_dif_TM / 60 / Period(); Assume the trade was placed 2 hours ago, 7200 secs . . . 7200/60 = 120 but you calculation does this 7200/ (60/Period()) = 7200/1 = 7200 Code should be . . . int Bars_TM = Time_dif_TM / 60 * Period();
- JuergZimmermann:
datetime Time_dif_TM = OrderOpenTime() - iTime(Symbol(),Period(),0);
No mind readers here, we can't see anything unless you post it.Posting the same code AGAIN doesn't give any additional information. Next time print some results and you would have quickly determined: - Yesterday - today is a negative number. Itime - OOT (or more simply Time[0] - OOT()) would work except on the bar that opened you get a negative number so your calculation would always be off. TimeCurrent() - OOT works except for missing bars (weekends and holidays.)
- RaptorUK:
int Bars_TM = Time_dif_TM / 60 / Period(); same as int Bars_TM = Time_dif_TM /(60 * Period()); sec/ (sec/min) / (minutes/bar) = bar int Bars_TM = Time_dif_TM / 60 * Period(); same as int Bars_TM =(Time_dif_TM / 60)* Period(); sec / (sec/min) * min = minutes squared = meaningless
His calculation was correct.
Ah, OK . . . . assumption is a very bad thing . . . I assumed the multiplication would occur first, I guess not, I learn something new every day :-)
Precedence goes from left to right . . . . https://docs.mql4.com/basis/operations/rules
Thanks gentlemen, I think I got the message: My calculation is basically correct, exept for holidays and weekends.
Thanks for your help.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello,
I like to establish the amount of bars from placing an Order to the actual bar[0].
The following code was an intent to calculate the difference between OrderOpenTime and iTime and convert it back to bars based on the current Period().
The idea was, that OrderOpenTime delivers time in seconds. iTime as well. Subtract iTime from OrderOpenTime = Difference in Seconds.
Difference in Seconds convert to minutes and divide it with Period().
Current code:
datetime Time_dif_TM = OrderOpenTime() - iTime(Symbol(),Period(),0);int Bars_TM = Time_dif_TM / 60 / Period();
As you can see, this code is not working out.
Anybody has an idea how this proplem could be solved?
Your help is appreciated. Thanks.