how to solve it ?
//+------------------------------------------------------------------+
//+ For Position Sell Breakeven Trailing
for (int i = PositionsTotal() - 1; i >= 0; i--)
{
if (ForAllSymbol || PositionGetSymbol(i) == Symbols)
If ForAllSymbol is true your position is never selected.
yes, i use false.
but still the err.
why ?
If you get the server-error "Position doesn't exist" it mostly has been already closed by the server due to you SL or TP.
isnt the looping only counting the number of open positions.
so, it wont be already closed.
yes, i use false.
but still the err.
why ?
If you get the server-error "Position doesn't exist" it mostly has been already closed by the server due to you SL or TP.
isnt the looping only counting the number of open positions.
so, it wont be already closed.
im coding it and testing it now.
...but there is no error processing in your code.
Add error processing, print values to find why it happens.
EDIT: the code you posted only process SELL positions, and your screenshot show a BUY. You should provide complete and correct code and information if you want help.
Forum on trading, automated trading systems and testing trading strategies
why err = Position doesnt exist.
Alain Verleyen, 2016.12.10 14:58
Add error processing, print values to find why it happens.
EDIT: the code you posted only process SELL positions, and your screenshot show a BUY. You should provide complete and correct code and information if you want help.
Anyway. If you are using an hedging account, you have to specify the position id you want to change. Please check the documentation :
SL & TP Modification
Trade order to modify the StopLoss and/or TakeProfit price levels. It requires to specify the following 4 fields:
- action
- symbol
- sl
- tp
- position
Anyway. If you are using an hedging account, you have to specify the position id you want to change. Please check the documentation :
yes, i'm trying in MT5 hedge acc,
i added this
but still no working, still the error position doesnt exist.
maybe something wrong on here, but i dont where the mistake.
{
if (For_AllSymbol || PositionGetSymbol(i) == Symbol())
{
ulong Order_Ticket = OrderGetTicket(i);
ulong Position_Ticket = PositionGetTicket(i);
string Position_Symbol = PositionGetString(POSITION_SYMBOL);
int Position_Digits = (int)SymbolInfoInteger(Position_Symbol, SYMBOL_DIGITS);
ulong Position_Magic = PositionGetInteger(POSITION_MAGIC);
double Position_Volume = PositionGetDouble(POSITION_VOLUME);
double Position_SL = PositionGetDouble(POSITION_SL);
double Position_TP = PositionGetDouble(POSITION_TP);
ENUM_POSITION_TYPE Position_Type = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
if (Position_Type == POSITION_TYPE_BUY)
{
...function to do anything
}
}
}
yes, i'm trying in MT5 hedge acc,
i added this
but still no working, still the error position doesnt exist.
maybe something wrong on here, but i dont where the mistake.
{
if (For_AllSymbol || PositionGetSymbol(i) == Symbol())
{
ulong Order_Ticket = OrderGetTicket(i);
ulong Position_Ticket = PositionGetTicket(i);
string Position_Symbol = PositionGetString(POSITION_SYMBOL);
int Position_Digits = (int)SymbolInfoInteger(Position_Symbol, SYMBOL_DIGITS);
ulong Position_Magic = PositionGetInteger(POSITION_MAGIC);
double Position_Volume = PositionGetDouble(POSITION_VOLUME);
double Position_SL = PositionGetDouble(POSITION_SL);
double Position_TP = PositionGetDouble(POSITION_TP);
ENUM_POSITION_TYPE Position_Type = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
if (Position_Type == POSITION_TYPE_BUY)
{
...function to do anything
}
}
}
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
how to solve it ?
//+------------------------------------------------------------------+
//+ For Position Sell Breakeven Trailing
for (int i = PositionsTotal() - 1; i >= 0; i--)
{
if (ForAllSymbol || PositionGetSymbol(i) == Symbols)
{
MqlTradeRequest request = {0};
MqlTradeResult result = {0};
request.action = TRADE_ACTION_SLTP;
request.symbol = Symbol();
if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
{
if ((Enabled_Breakeven) && (Breakeven > 0))
{
if ((PositionGetDouble(POSITION_PROFIT) + PositionGetDouble(POSITION_SWAP) + PositionGetDouble(POSITION_COMMISSION)) > 0.0)
{
request.sl = PositionGetDouble(POSITION_PRICE_OPEN);
request.tp = TakeProfitLevel;
bool Send = OrderSend(request, result);
Print("ProceedBreakevenSell : ", result.price);
Print("ProceedBreakevenSell : ", PositionGetDouble(POSITION_SL));
}
}
if ((Enabled_Trailing) && (Trailing > 0))
{
if (((PositionGetDouble(POSITION_PROFIT) + PositionGetDouble(POSITION_SWAP) + PositionGetDouble(POSITION_COMMISSION)) > 0.0))
if ((PositionGetDouble(POSITION_PRICE_OPEN) - SymbolInfoDouble(Symbols, SYMBOL_ASK)) > (Trailing * _Point + PipsStep * _Point))
if ((PositionGetDouble(POSITION_SL) > (SymbolInfoDouble(Symbols, SYMBOL_ASK) + Trailing * _Point)))
if ((PositionGetDouble(POSITION_SL) - SymbolInfoDouble(Symbols, SYMBOL_ASK)) > MinStopLossLevel * _Point)
{
request.sl = SymbolInfoDouble(_Symbol, SYMBOL_ASK) + Trailing * _Point - PipsStep * _Point;
request.tp = TakeProfitLevel;
bool Send = OrderSend(request, result);
Print("ProceedTrailingSell : ", result.price);
Print("ProceedTrailingSell : ", PositionGetDouble(POSITION_SL));
}
}
}
}
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+