The main mistake:
ENUM_ORDER_TYPE type NOT EQUAL PositionGetInteger (POSITION_TYPE).
Correct this gross error first. Then you can move on.
Please read the MQL5 documentation: an order is NOT a POSITION !!!
Vladimir Karputov:
The main mistake:
ENUM_ORDER_TYPE type NOT EQUAL PositionGetInteger (POSITION_TYPE).
Correct this gross error first. Then you can move on.
Please read the MQL5 documentation: an order is NOT a POSITION !!!
void TrailPendingOrders(double price,double step) //set Stop Loss to "TS" if price is going your way with "step" { int totalTrades=0; bool ordmdf; MqlTick last_tick; int total = OrdersTotal(); for(int i = total-1; i >= 0; i--) { if(OrderGetTicket(i) <= 0) continue; if(OrderGetInteger(ORDER_MAGIC) != MagicNumber || OrderGetString(ORDER_SYMBOL) != Symbol()) continue; SymbolInfoTick(Symbol(), last_tick); double SL = OrderGetDouble(ORDER_SL); double currentprice = OrderGetDouble(ORDER_PRICE_CURRENT); double openprice = OrderGetDouble(ORDER_PRICE_OPEN); double pb=NormalizeDouble(getAsk()+price,_Digits); double ps=NormalizeDouble(getBid()-price,_Digits); step = NormalizeDouble(step, Digits()); ulong ticket = OrderGetInteger(ORDER_TICKET); totalTrades++; switch ( (ENUM_ORDER_TYPE)OrderGetInteger(ORDER_TYPE) ) { case ORDER_TYPE_BUY_STOP: if(openprice < pb + step) break; ordmdf = m_trade.OrderModify(ticket,pb,0,0,ORDER_TIME_GTC,0); if(!ordmdf) break; Print("Order Modify Error", (GetLastError())); break; case ORDER_TYPE_SELL_STOP: if(ps < openprice + step) break; ordmdf = m_trade.OrderModify(ticket,ps,0,0,ORDER_TIME_GTC,0); if(!ordmdf) break; Print("Order Modify Error", (GetLastError())); } } } double getBid() { MqlTick last_tick; SymbolInfoTick(Symbol(), last_tick); return(last_tick.bid); } double getAsk() { MqlTick last_tick; SymbolInfoTick(Symbol(), last_tick); return(last_tick.ask); }
Okay Thanks a lot working now!!
Hi can you share the mt5 version for trailing pending orders
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi..
am trying to make a version of trailing pending order for mt5
always get order modify error
mql4 working pending trailing order
mql5 code
please what am i doing wrong!!