Trying to implement a simple reversal. When a stop position is reached --> open the opposite position. I can't get it to open opposite position once and not open anything else. Please advise.
I have it implemented in the following way - this is a condition - if the previous position closed with a loss, then opening the opposite one... If you need to open the opposite position exactly when the stop loss of the previous position is reached, then Kim Igor Vladimirovich has a function at http://www.kimiv.ru/ that determines exactly how to close the order at the stop loss. So, when you connect this function, you should prescribe the condition if the pose was closed when the stop loss was reached. If it was, you should open another one.
PS: Just remembered, this closing fi code for a pose at stop loss was posted on this thread a few pages before... Have a look.
//---Поиск последнего отработавшего ордера для открытия очередной позиции ---for (orderIndex = (OrdersHistoryTotal() - 1); orderIndex >= 0; orderIndex--)
{
if (!OrderSelect(orderIndex, SELECT_BY_POS, MODE_HISTORY))
{
Print("Ошибка при доступе к исторической базе (",GetLastError(),")");
continue;
}
if ((OrderSymbol() != Symbol()) || (OrderMagicNumber() != MagicNumber))
{
continue;
}
//-------------------------Принимаем в расчет только ордер, закрытый недавно-----------------------if (OrderCloseTime() >= iTime(NULL, 0, 1))
{
int lastType = OrderType();
double lastLots = OrderLots();
double lastProfit = OrderProfit() + OrderSwap();
// Print ("lastProfit = ", NormalizeDouble(lastProfit, 1));// Анализ только что закрывшегося ордераif (lastProfit < 0.0)
{
//---Ордер закрылся с убытком открываемся в ОБРАТНОМ направлении// ---------НОРМАЛИЗУЕМ НОВЫЕ РАСЧЕТНЫЕ ЛОТЫ И ОТКРЫВАЕМ ОЧЕРЕДНУЮ ПОЗИЦИЮ... // -----если предыдущий ордер был бай, то открываем очередной ордер
lots = NormalizeLots(lots);
if (lastType == OP_SELL) OrderSend(Symbol(), OP_BUY, lots,...);
if (lastType == OP_BUY) OrderSend(Symbol(), OP_SELL, lots, ...);
}
return (0);
}
// Найден закрытый ордер, но он старыйbreak;
}
Trying to implement a simple reversal. When a stop position is reached --> open the opposite position. I can't get it to open opposite position once and not open anything else. Please advise.
What if on level of stop simply put the pending order? Would it not work that way?
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.
https://www.mql5.com/ru/forum/105952
Thanks, but can't figure out where the error is...
Good people, please advise me, I need a CODE to implement TrailingStop!?
The ones I found online don't work (crawling backwards and forwards)
Good people, please advise me, I need a CODE to implement TrailingStop!?
The ones I found online don't work (crawling backwards and forwards)
Thank you, but I can't figure out where the error is...
need a full indicator
Need a full indicator
thanks
On first run, the ArrayMaximum and ArrayMinimum functions were out of scope
On first run, the ArrayMaximum and ArrayMinimum functions were out of scope
Trying to implement a simple reversal. When a stop position is reached --> open the opposite position. I can't get it to open opposite position once and not open anything else. Please advise.
I have it implemented in the following way - this is a condition - if the previous position closed with a loss, then opening the opposite one... If you need to open the opposite position exactly when the stop loss of the previous position is reached, then Kim Igor Vladimirovich has a function at http://www.kimiv.ru/ that determines exactly how to close the order at the stop loss. So, when you connect this function, you should prescribe the condition if the pose was closed when the stop loss was reached. If it was, you should open another one.
PS: Just remembered, this closing fi code for a pose at stop loss was posted on this thread a few pages before... Have a look.
Trying to implement a simple reversal. When a stop position is reached --> open the opposite position. I can't get it to open opposite position once and not open anything else. Please advise.