What I'm trying to do is modify an order after a partial close of the order. But the tester tells me it can't find the order. Come to find out that the tester increases the order number by 1. ie., if ticket=3, then after the partial close, ticket then becomes 4.
What I want to know is; does this happen in live trading? If so, how does one go about coding it?
Here's the code to find the order:
Here's my code after I've looped through and selected the order:
Any help is greatly appreciated.
Thanks.
What I want to know is; does this happen in live trading? If so, how does one go about coding it?
Here's the code to find the order:
Inserted Code
//====== work current open orders ================== bool varNoOrder=true; for (int i=0; i<OrdersTotal(); i++) {//1 +cycle by orders search if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; if (OrderMagicNumber()!=varOrderMagicNumber) continue; int varOrderType=OrderType(); procOrderWork(varOrderType); varNoOrder=false; } //====== done w/ work current open order ===========
Here's my code after I've looped through and selected the order:
Inserted Code
void procOrderWork(int varOT) { double varATR=iATR(NULL,0,14,1); double varSlope=iCustom(NULL,varTF,"LR - Least Squares - Slope",4," ",5,0,1); double varSL; RefreshRates(); double varAsk = NormalizeDouble( MarketInfo(Symbol(), MODE_ASK ), Digits ); double varBid = NormalizeDouble( MarketInfo(Symbol(), MODE_BID ), Digits ); bool varNewBar=funcIsNewBar(Period()); if (varOT==OP_BUY) { if (varSlope<=0) {CloseAll(Symbol(),varOrderMagicNumber,OP_BUY,5,varSlippage,"trend changed"); return(0);} if (!varHitBig) { if (varAsk>=varBigTP) { varHitBig=OrderClose(OrderTicket(),varLotBig,varAsk,varSlippage,Blue); OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Blue); } } if (varNewBar && varHitBig) { varSL=varAsk-varATR; if (varSL>OrderStopLoss()) {OrderModify(OrderTicket(),OrderOpenPrice(),varSL,OrderTakeProfit(),0,Red);} } } else if (varOT==OP_SELL) { if (varSlope>=0) {CloseAll(Symbol(),varOrderMagicNumber,OP_SELL,5,varSlippage,"trend changed"); return(0);} if (!varHitBig) { if (varBid<=varBigTP) { varHitBig=OrderClose(OrderTicket(),varLotBig,varAsk,varSlippage,Blue); OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Red); } } if (varNewBar && varHitBig) { varSL=varBid+varATR; if (varSL<OrderStopLoss()) {OrderModify(OrderTicket(),OrderOpenPrice(),varSL,OrderTakeProfit(),0,Red);} } } }
Thanks.