![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
Here I leave the code:
//Open Buy Order
if(iMA(NULL, PERIOD_CURRENT, 10, 0, MODE_SMA, PRICE_CLOSE, 0) > iMA(NULL, PERIOD_CURRENT, 20, 0, MODE_SMA, PRICE_CLOSE, 0) + DISTANCIA_MA_ENTRADA * myPoint //Moving Average > Moving Average + fixed value
&& iMA(NULL, PERIOD_CURRENT, 50, 0, MODE_SMA, PRICE_CLOSE, 0) > iMA(NULL, PERIOD_CURRENT, 300, 0, MODE_SMA, PRICE_CLOSE, 0) //Moving Average > Moving Average
)
{
RefreshRates();
price = Ask;
SL = SL_PIPS * myPoint; //Stop Loss = value in points (relative to price)
if(TimeCurrent() - LastTradeTime < NextOpenTradeAfterBars * PeriodSeconds()) return; //next open trade after time
if(IsTradeAllowed())
{
ticket = myOrderSend(OP_BUY, price, MM_Size(), "");
if(ticket <= 0) return;
}
else //not autotrading => only send alert
myAlert("order", "");
LastTradeTime = TimeCurrent();
myOrderModifyRel(ticket, SL, 0);
}