Hey traders! Today, we’re diving into a handy tool that can really streamline your trading process: an Expert Advisor (EA) for MetaTrader 5 that opens and closes positions based on precise timing.
How It Works
This EA is designed to execute trades at specific times, but it also checks a couple of key conditions before making any moves:
- For Buy Orders: The EA will only initiate a buy if the fast iMA (Indicator Moving Average) on the first bar exceeds the slow iMA. Here’s the logic:
if(iMAGet(handle_iMAFast,1) > iMAGet(handle_iMASlow,1)) {
if(!RefreshRates())
return;
price = m_symbol.Ask();
if(Extm_sl > 0.0)
sl = m_symbol.Bid() - Extm_sl;
if(Extm_tp > 0.0)
tp = m_symbol.Bid() + Extm_tp;
m_trade.Buy(m_lots, InpSymbol, price, sl, tp);
}
- For Sell Orders: Conversely, the EA will execute a sell if the fast iMA on the first bar is less than the slow iMA:
if(iMAGet(handle_iMAFast,1) < iMAGet(handle_iMASlow,1)) {
if(!RefreshRates())
return;
price = m_symbol.Bid();
if(Extm_sl > 0.0)
sl = m_symbol.Ask() + Extm_sl;
if(Extm_tp > 0.0)
tp = m_symbol.Ask() - Extm_tp;
m_trade.Sell(m_lots, InpSymbol, price, sl, tp);
}
Only the time in HH:mm format is considered for the inputs, so be sure to set your trade times accurately!
Input Parameters
- Opening Time: The time you want your position to open (only HH:mm format).
- Closing Time: The time for your position to close (only HH:mm format).
- Symbol: The asset you’re trading.
- Volume Transaction: The size of your position.
- Sell Stop: The stop-loss level.
- Take Profit: The take-profit level.
- Order Type: Set to true for Buy orders or false for Sell orders.
- Magic Number: A unique identifier for your EA.
This EA can be a game-changer for your trading strategy, allowing you to manage your time effectively while you focus on other tasks. Give it a whirl and let me know how it goes!
Comments 0