I won't even study your code as you do not use descriptive variable names.
You can use TimeToStruct() to break down a number of seconds into hours and days. To get the candle time of another timeframe use iTime().
And you seem to be mixing long and char.
string TimeTillNextBar(ENUM_TIMEFRAMES tf=PERIOD_CURRENT) { datetime now=TimeCurrent(); datetime bartime=iTime(NULL,tf,0); datetime remainingTime=bartime+PeriodSeconds(tf)-now; MqlDateTime mdt; TimeToStruct(remainingTime,mdt); if(mdt.day_of_year>0) return StringFormat("%d d %d h %d m %d s",mdt.day_of_year,mdt.hour,mdt.min,mdt.sec); if(mdt.hour>0) return StringFormat("%d h %d m %d s",mdt.hour,mdt.min,mdt.sec); if(mdt.min>0) return StringFormat("%d m %d s",mdt.min,mdt.sec); return StringFormat("%d s",mdt.sec); }
And call it with PERIOD_M1, PERIOD_M5 like so:
Comment("M1: "+TimeTillNextBar(PERIOD_M1)+"\n"+"M5: "+TimeTillNextBar(PERIOD_M5));
Documentation on MQL5: Date and Time / TimeToStruct
- www.mql5.com
Date and Time / TimeToStruct - Reference on algorithmic/automated trading language for MetaTrader 5
lippmaje:
You can use TimeToStruct() to break down a number of seconds into hours and days. To get the candle time of another timeframe use iTime().
And you seem to be mixing long and char.
And call it with PERIOD_M1, PERIOD_M5 like so:
hi
Thanks alot
that works correctly
Hello
How to adding in the chart
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
hi every one
I write below code in expert to show current candle time in chart and it works in all time frame M1,M3,M15,....
now I run this expert in time frame: M1 it will show current candle time in M1 now if I want to see current candle time in M5 I should change time frame but I want without changing time frame I can see current candle time in M1 and M5 all together
can anyone help me?
Best regards
Neda