Good afternoon. Can you help me solve a problem. on an M15 candlestick, several trades open in a row.
I want no more than one trade to open. The logic behind the EA is that until the previous order is closed, the next one will not open, but sometimes a series of deals opens on such a long candlestick. Please advise what to add in the code to prevent this situation?
code snippet :
In bCheckOrders(), not only open orders but also pending orders (MODE_TRADES) are enumerated.
Good afternoon. Can you help me solve a problem. on an M15 candle, several trades open in a row.
I want no more than one trade to open. The logic behind the EA is that until the previous order is closed, the next one will not open, but sometimes a series of deals opens on such a long candlestick. Please advise what to add in the code to prevent this situation?
voidOnTick()
{
// Получим значение индикатора
dMA = iMA(Symbol(), 0,PeriodMA, MovingShift, MODE_SMA, PRICE_CLOSE, 0); // MODE_SMA - простое усреднение , значение 0. PRICE_CLOSE- цена закрытия, значение 0.// Если нет открытых ордеров, то входим в условиеif(bCheckOrders() == true)
{
// Если появился сигнал на покупку, то откроем ордер на покупкуif(bSignalBuy() == true)
vOrderOpenBuy();
// Если появился сигнал на продажу, то откроем ордер на продажуif(bSignalSell() == true)
vOrderOpenSell();
}
// Проверяем, вышел ли текущий баланс по открытому ордеру за вилку из внешних переменных CountLoss и CountProfitif(GetProfitFromStart()>CountProfit || GetProfitFromStart()<CountLoss*-1)
{
// Если да, то закроем ордер по текущей цене, не дожидаясь стопа или тейка
CloseOrder();
}
DrawLABEL("lab_Take",1,5,0,Color(GetProfitFromStart()>0,Lime,Red),StringConcatenate("Profit: ",DoubleToStr(GetProfitFromStart(),2),AC));
}
Try this, remove bCheckOrders() from OnTick() and put it as highlighted.
voidOnTick()
{
// Получим значение индикатора
dMA = iMA(Symbol(), 0,PeriodMA, MovingShift, MODE_SMA, PRICE_CLOSE, 0); // MODE_SMA - простое усреднение , значение 0. PRICE_CLOSE- цена закрытия, значение 0.// Если появился сигнал на покупку, то откроем ордер на покупкуif(bSignalBuy() == true)
vOrderOpenBuy();
// Если появился сигнал на продажу, то откроем ордер на продажуif(bSignalSell() == true)
vOrderOpenSell();
// Проверяем, вышел ли текущий баланс по открытому ордеру за вилку из внешних переменных CountLoss и CountProfitif(GetProfitFromStart()>CountProfit || GetProfitFromStart()<CountLoss*-1)
{
// Если да, то закроем ордер по текущей цене, не дожидаясь стопа или тейка
CloseOrder();
}
DrawLABEL("lab_Take",1,5,0,Color(GetProfitFromStart()>0,Lime,Red),StringConcatenate("Profit: ",DoubleToStr(GetProfitFromStart(),2),AC));
}
//+-----------------------------------------------------------------------------------------------+//| Функция открытия ордера на покупку |//+-----------------------------------------------------------------------------------------------+void vOrderOpenBuy()
{
// Если нет открытых ордеров, то входим в условиеif(bCheckOrders() == true)
{
// Тикет ордераint iOTi = 0;
iOTi = OrderSend(Symbol(), OP_BUY, LOT(), Ask, Slippage, 0, 0, "", Magic, 0, clrNONE);
// Проверим открылся ли ордерif(iOTi > 0)
// Есди да, то выставим уровни убытка и прибыли
vOrderModify(iOTi);
else// Если нет, то получим ошибку
vError(GetLastError());
}
}
//+-----------------------------------------------------------------------------------------------+//| Функция открытия ордера на продажу |//+-----------------------------------------------------------------------------------------------+void vOrderOpenSell()
{
// Если нет открытых ордеров, то входим в условиеif(bCheckOrders() == true)
{
// Тикет ордера int iOTi = 0;
iOTi = OrderSend(Symbol(), OP_SELL, LOT(), Bid, Slippage, 0, 0, "", Magic, 0, clrNONE);
// Проверим открылся ли ордерif(iOTi > 0)
// Есди да, то выставим уровни убытка и прибыли
vOrderModify(iOTi);
else// Если нет, то получим ошибку
vError(GetLastError());
}
}
Removed unnecessary code.
What does it mean?
To be able to calculate this data on different TFs.
I wonder if anyone has an implementation through a class.
I'm trying to understand the logic of classes, it would be a great help for learning.
Good afternoon. Can you help me solve a problem. on an M15 candlestick, several trades open in a row.
I want no more than one trade to open. The logic behind the EA is that until the previous order is closed, the next one will not open, but sometimes a series of deals opens on such a long candlestick. Please advise what to add in the code to prevent this situation?
code snippet :
Um... in iOTi in vOrderModify() always = 1, it's not a ticket but a positive result of OrderSend() operation i.e. value "1".
Thanks. The original code is not mine, so I don't change anything unnecessarily. It works and it works.
Will this help solve my problem?
Good afternoon. Can you help me solve a problem. on an M15 candle, several trades open in a row.
I want no more than one trade to open. The logic behind the EA is that until the previous order is closed, the next one will not open, but sometimes a series of deals opens on such a long candlestick. Please advise what to add in the code to prevent this situation?
code snippet :
I'm just looking for someone who is able to share experience in implementing indicator integration in Expert Advisor
To be able to calculate this data on different TFs.
I wonder if anyone has an implementation through a class.
I'm trying to understand the logic of classes, it would be a great help for learning.
rates_total = Bars time[] = Time[] open[] = Open[] high[] = High[] low[] = Low[] close[] = Close[]Show OnTick()
Thank you. The original code is not mine, so I don't change anything unnecessarily. It works and it works.
Does this solve my problem in any way?
Try this, remove bCheckOrders() from OnTick() and put it as highlighted.
Nah, I was wrong, OrderSend() returns a ticket or -1, so there's nothing wrong with that.
Okay.
I'll keep that in mind for the future.