I am new to programming in MQL and have had a good look on the site to try and answer this question but to no avail. I only want to enter one trade per candle but if, on the next candle, the signal still holds the EA should make another trade up to a maximum number of lots. I think I understand the first part of my problem but don't seem to be able to get the second part to work. Any help much appreciated or suggestion on where to look. Thanks Here is simple code:
externdouble lotsize = 0.01;
externdouble maxlots = 0.03;
externint MacdFastEma = 12;
externint MacdSlowEma = 26;
intOnInit()
{
//---return(INIT_SUCCEEDED);
}
//---//+------------------------------------------------------------------+//| Expert deinitialization function |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
//---
}
//+------------------------------------------------------------------+//| Expert tick function |//+------------------------------------------------------------------+voidOnTick()
{
staticdatetime candletime;
if(candletime != Time[0])
{
CheckForSignal();
candletime=Time[0];
}
}
void CheckForSignal()
{
double atrh = iATR(NULL,60,120,0);
double spread_broker = MarketInfo(Symbol(),MODE_SPREAD);
double spread = spread_broker/100000;
double stoploss = atrh;
double takeprofit = 2*atrh;
double EntryPrice = Close[2];
double CurrentMacd = iMACD(Symbol(),0,MacdFastEma,MacdSlowEma,9,PRICE_CLOSE,MODE_MAIN,1);
double PreviousMacd = iMACD(Symbol(),0,MacdFastEma,MacdSlowEma,9,PRICE_CLOSE,MODE_MAIN,2);
if(OrdersTotal()==0) //This line works as expected//if(OrdersTotal()<=maxlots) // This line works as if only 0.01 lot can ever be held?if(Low[1]<Close[2] && CurrentMacd<PreviousMacd)
OrderSend(Symbol(),OP_BUYLIMIT,lotsize,EntryPrice,2,EntryPrice-stoploss,EntryPrice+takeprofit,NULL,0,TimeCurrent()+3*60*60,Green);
elseif(High[1]>Close[2] && CurrentMacd>PreviousMacd)
OrderSend(Symbol(),OP_SELLLIMIT,lotsize,EntryPrice,2,EntryPrice+stoploss,EntryPrice-takeprofit,NULL,0,TimeCurrent()+3*60*60,Red);
elseMessageBox("NO SIGNAL","Info");
}
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.
Hi,
I am new to programming in MQL and have had a good look on the site to try and answer this question but to no avail. I only want to enter one trade per candle but if, on the next candle, the signal still holds the EA should make another trade up to a maximum number of lots. I think I understand the first part of my problem but don't seem to be able to get the second part to work. Any help much appreciated or suggestion on where to look. Thanks Here is simple code: