PeriodSeconds() only reports the number of seconds in one bar of the current char. On M1 chart, it will return 60, on M5 chart, it will return 300.
You have to look documentation for TimeCurrent(), iTime() or Time[] array and properties of the datetime type.
To get the number of seconds you should subtract current server time from the beginning time of the current bar. Something like this:
int secs = TimeCurrent() - Time[0];
acecard:
the elapsed number of seconds in the current bar is above a certain number PeriodSeconds must be used on ENUM_TIMEFRAMES. However, if period is set to "current" then would it still be able to operate on the M10 chart? |
|
Ok, I see. Having read these, this makes a bit more sense. So, putting this into my current code:
This didn't seem to work. Do I have the time format written correctly? Thanks AC
RefreshRates(); if(Cross(0, Bid > iMA(NULL, PERIOD_CURRENT, 14, 0, MODE_SMA, PRICE_CLOSE, 0)) //Price crosses above Moving Average && TimeCurrent() - Time[0] < 30 // Bar timer //Custom Code )
This didn't seem to work. Do I have the time format written correctly? Thanks AC
The section starting with "//" is a comment so you are basically just adding more comments.
This might be what you are looking for:
RefreshRates(); if( Cross(0, Bid > iMA(NULL, PERIOD_CURRENT, 14, 0, MODE_SMA, PRICE_CLOSE, 0)) && ((TimeCurrent() - Time[0]) < 30) ) // Price crosses above Moving Average and Custom Bar Timer Code
However, that original code is somewhat too "Stringy". Clean it up a bit and give it more readable structure.
acecard: This didn't seem to work. |
|

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 all,
I am new here, but have been reading for a few weeks. I am attempting to get into MQL coding in order to write my own EA for my trade ideas. I paid for someone to write one previously but wish to understand how to do this myself, and therefore would much appreciate some guidance relating to the following issue.
I wish for an order to be placed when 2 conditions are met at the same time: the first is that the bar crosses above the the MA line, and the second is that the elapsed number of seconds in the current bar is above a certain number.
As mentioned, I am extremely new to this, however I have been searching through various example EAs and looking at the very helpful documentation. It seems that I am looking for a PeriodSeconds function, as detailed below:
https://docs.mql4.com/common/periodseconds
From this, I gather that I could specify that the PeriodSeconds function must be above the number of seconds that I specify. Is this correct?
My next question is this: I am using an offline M10 chart, and according to the documentation, PeriodSeconds must be used on ENUM_TIMEFRAMES. However, if period is set to "current" then would it still be able to operate on the M10 chart?
I hope I have made sense! Any responses much appreciated.
AC