I need some help.
How to count days that the orders had been open including weekends and holidays.
for example:
buy/sell order had been open for 40 days, it should return 40
buy/sell order had been open for 20 days, it should return 20
Only full days or part days too ? or are you counting any contiguous 24 hour period as a day ? you need to be specific about what you are trying to code.
If you include full and part days, select the order using OrderSelect(), get the OrderOpenTime() . . . then . . .
datetime OOT = OrderOpenTime(); int OpenDay = OOT - (OOT%(PERIOD_D1*60)); int Midnight = TimeCurrent() - (TimeCurrent()%(PERIOD_D1*60)); int DaysOpen = (Midnight - OOT) / (PERIOD_D1*60);
. . . might do what you want, not compiled, not tested. Read, understand, if it doesn't do what you want change it.
i put it in orderselect and it worked. thank you very much
I know that the thread is old
This is what worked for me
for (int i=PositionsTotal()-1; i>=0; i--) if (m_position.SelectByIndex(i)) if (m_position.Magic()==mn1) { ulong DaysOpen = ulong((TimeCurrent()-m_position.Time())/(24*60*60)); // 24 hours 60 minutes 60 seconds since we first converted //our time difference to be value which comes in seconds ulong DaysOpen = ulong((TimeCurrent()-m_position.Time()); if (TimeToString(TimeCurrent(),TIME_MINUTES)== "12:00") { Print("DaysOpen ",DaysOpen); } }
I know that the thread is old
This is what worked for me
Please don't bring old topics to the top for no good reason.
This topic is in the MQL4 section and about MQL4 code, so what is the point of posting MQL5 code??
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I need some help.
How to count days that the orders had been open including weekends and holidays.
for example:
buy/sell order had been open for 40 days, it should return 40
buy/sell order had been open for 20 days, it should return 20