//+------------------------------------------------------------------+ //| Manage Open Positions: Breakeven and Trailing Stop | //+------------------------------------------------------------------+ void ManageOpenPositions() { for(int i = 0; i < PositionsTotal(); i++) { if(PositionGetSymbol(i)==_Symbol) // Select and check if the position is on the current symbol { ulong ticket = (ulong)PositionGetInteger(POSITION_TICKET); // Get the position ticket double entryPrice = PositionGetDouble(POSITION_PRICE_OPEN); // Get the position open price double SL_Price = PositionGetDouble(POSITION_SL); // Get the position StopLoss price double TP_Price = PositionGetDouble(POSITION_TP); // Get the position TakeProfit price double currentPrice = SymbolInfoDouble(_Symbol, SYMBOL_BID); // Get the current price double newStopLoss=0.0; // For Buy Positions if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY) { // Immediate Trailing Stop Logic newStopLoss = currentPrice - TrailingStep * _Point; if(newStopLoss > SL_Price) { trade.PositionModify(ticket, newStopLoss, TP_Price); } // Breakeven logic if((currentPrice - entryPrice) >= BreakevenTrigger * _Point) { newStopLoss = entryPrice + BreakevenOffset * _Point; trade.PositionModify(ticket, newStopLoss, TP_Price); } } // For Sell Positions else { if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL) { // Immediate Trailing Stop Logic newStopLoss = currentPrice + TrailingStep * _Point; if(newStopLoss < SL_Price) { trade.PositionModify(ticket, newStopLoss, TP_Price); } // Breakeven logic if((entryPrice - currentPrice) >= BreakevenTrigger * _Point) { newStopLoss = entryPrice - BreakevenOffset * _Point; trade.PositionModify(ticket, newStopLoss, TP_Price); } } } } } }
возможно при селл такая строка актуальна вместо предложенной:
if(newStopLoss < SL_Price || SL_Price == 0)
добавил трал в ф-ии по символ и магику с профита (не проверял):
//+------------------------------------------------------------------+ //| Manage Open Positions: Trailing Stop | //+------------------------------------------------------------------+ void ManageOpenPositions(string Sym, int mn) { if(TrailingStop > 0) for(int i = 0; i < PositionsTotal(); i++) { if(PositionGetSymbol(i)==Sym) // Select and check if the position is on the current symbol if(PositionGetString(POSITION_SYMBOL) == Sym) if(PositionGetInteger(POSITION_MAGIC)==mn || mn == -1) { ulong ticket = (ulong)PositionGetInteger(POSITION_TICKET); // Get the position ticket double entryPrice = PositionGetDouble(POSITION_PRICE_OPEN); // Get the position open price double SL_Price = PositionGetDouble(POSITION_SL); // Get the position StopLoss price double TP_Price = PositionGetDouble(POSITION_TP); // Get the position TakeProfit price double currentPrice = SymbolInfoDouble(_Symbol, SYMBOL_BID); // Get the current price double currentPrice_sell = SymbolInfoDouble(_Symbol, SYMBOL_ASK); // Get the current price double newStopLoss=0.0; // For Buy Positions if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY) { // Immediate Trailing Stop Logic newStopLoss = currentPrice - TrailingStop * _Point; if(newStopLoss > SL_Price && entryPrice < newStopLoss) { trade.PositionModify(ticket, newStopLoss, TP_Price); } // Breakeven logic //if((currentPrice - entryPrice) >= BreakevenTrigger * _Point) // { // newStopLoss = entryPrice + BreakevenOffset * _Point; // trade.PositionModify(ticket, newStopLoss, TP_Price); // } } // For Sell Positions else { if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL) { // Immediate Trailing Stop Logic newStopLoss = SymbolInfoDouble(_Symbol, SYMBOL_ASK) + TrailingStop * _Point; if(newStopLoss < SL_Price || SL_Price == 0) if(entryPrice > newStopLoss) { trade.PositionModify(ticket, newStopLoss, TP_Price); } // Breakeven logic // if((entryPrice - currentPrice) >= BreakevenTrigger * _Point) // { // newStopLoss = entryPrice - BreakevenOffset * _Point; // trade.PositionModify(ticket, newStopLoss, TP_Price); // } } } } } }
Вы упускаете торговые возможности:
- Бесплатные приложения для трейдинга
- 8 000+ сигналов для копирования
- Экономические новости для анализа финансовых рынков
Регистрация
Вход
Вы принимаете политику сайта и условия использования
Если у вас нет учетной записи, зарегистрируйтесь
Я уже всю голову поломал, почему Trailing Stop и Breakeven вообще не тригерятся. Ладно бы делали это с ошибками, но нет ни ошибок, ни исполнения. Может есть кто-то с опытным глазом, кто сможет заметить очевидную ошибку, которую я в упор не замечаю.