Hello, i am still coding my EA but there are some questions that i wanna ask to you all because I am an amateur in this MQL5 language. Sorry for my bad english xD
The questions are:
1) How to give a certain time interval for EA to execute buy or sell?
Example: I activate the autotrading on Metatrader. And then, I want my EA to detect opportunities to buy or sell at certain intervals, such as detect for 2 hours and pause for 2 hours after detect and then detect again automatically. So, I do not click the autotrading manually every 2 hours to start detetct opportunites to buy or sell.
2) Is it possible for the EA use several indicator on different timeframes as conditions for buying or selling? How to code it?
Example: Detect buy conditions on H4 timeframe with MA and buy conditions on M15 with ADX. If both are met, it will execute buy.
3) Is it possible for the EA to execute a buy when the price on the current bar is now above the moving average as far as 20 pips? How to code it?
Thanks for your care!
All 3 things you ask are possible. I'm not going to program it for you, only give some pointers:
1) you can use the OnTimer() block. If you have this block run once per 60 seconds you have to create a counter. The counter starts when you want and then counts up to 120, which is 2 hours.
2) you can use a fixed timeframe in the indicators. For example in the moving average you can use iMA(Symbol(),PERIOD_H4,...). Similar for the ADX indicator.
3) you can compare the current price to any reference you want. So (current price) > (movav + 20*pip) is possible.
Then how to get the current price on my code?
You can get current price by:
MqlTick latestPrice; SymbolInfoTick(Symbol(), latestPrice);
There are 2 prices: ask and bid
double askPrice = latestPrice.ask; double bidPrice = latestPrice.bid;

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello, i am still coding my EA but there are some questions that i wanna ask to you all because I am an amateur in this MQL5 language. Sorry for my bad english xD
The questions are:
1) How to give a certain time interval for EA to execute buy or sell?
Example: I activate the autotrading on Metatrader. And then, I want my EA to detect opportunities to buy or sell at certain intervals, such as detect for 2 hours and pause for 2 hours after detect and then detect again automatically. So, I do not click the autotrading manually every 2 hours to start detetct opportunites to buy or sell.
2) Is it possible for the EA use several indicator on different timeframes as conditions for buying or selling? How to code it?
Example: Detect buy conditions on H4 timeframe with MA and buy conditions on M15 with ADX. If both are met, it will execute buy.
3) Is it possible for the EA to execute a buy when the price on the current bar is now above the moving average as far as 20 pips? How to code it?
Thanks for your care!