I'm working with a builder ea, and to enter the market, buy or sell, you have to meet two conditions.
CONDITION 1 MA 10> 20
CONDITION 2 The MA 50> 300
The problem is that the order only enters if the two conditions are given at that moment. My idea is that if the (CONDITION 1) is fulfilled the order will not enter the market, until the (CONDITION 2) is fulfilled, and insert a reset, for candles.
Example: If it is fulfilled (CONDITION 1) we wait a maximum of, 20 candles, until the (CONDITION 2) is fulfilled. If this period is not fulfilled, the order will be reset and start again. If this period is fulfilled, the order enters the market.
Can anybody help me?
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
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
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);
}