Ordermodify error - compare double?
Can't move the open price closer to market than MarketInfo(Symbol(), MODE_STOPLEVEL)*Point
I couldn't get pending orders to work with TP/SL (Use zero and set TP/SL once order opens)
always test return codes, allow EA to run on multiple pairs.
for (int pos = OrdersTotal()-1; pos >= 0; pos--) if( OrderSelect(pos, SELECT_BY_POS) && OrderSymbol() == Symbol()){
Can't move the open price closer to market than MarketInfo(Symbol(), MODE_STOPLEVEL)*Point
I couldn't get pending orders to work with TP/SL (Use zero and set TP/SL once order opens)
always test return codes, allow EA to run on multiple pairs.
sorry, dont really understand what you're saying. i just found this for OrderModify: "Notes: Open price and expiration time can be changed only for pending orders." So i should only change Openprice for the pending order(s) and fill TP/SL with 0, then modify the 0 when trade opens, right?
OK i changed my code to this, it that right?:
void CheckOrders() { int total = OrdersTotal(); for (int cnt = 0 ; cnt < total ; cnt++) { OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); //ORDER ACTIONS if(OrderType()==OP_SELL&& OrderMagicNumber()==111) { ready111=0; if (OrderStopLoss()!=TopLine) OrderModify(OrderTicket(),0,TopLine,TopGoldLine,0,Red); } if(OrderType()==OP_BUY&& OrderMagicNumber()==222) { ready222=0; if (OrderStopLoss()!=BottomLine) OrderModify(OrderTicket(),0,BottomLine,BottomGoldLine,0,Blue); } if(OrderType()==OP_BUY&& OrderMagicNumber()==333) { ready333=0; if (OrderStopLoss()!=MiddleWhiteLine) OrderModify(OrderTicket(),0,MiddleWhiteLine,TopGoldLine,0,Blue); } if(OrderType()==OP_SELL&& OrderMagicNumber()==444) { ready444=0; if (OrderStopLoss()!=MiddleWhiteLine) OrderModify(OrderTicket(),0,MiddleWhiteLine,BottomGoldLine,0,Red); } //PENDING ORDER ACTIONS if(OrderType()==OP_BUYSTOP&& OrderMagicNumber()==333) { ready333=0; if (OrderOpenPrice()!=TopGreenLine) OrderModify(OrderTicket(),TopGreenLine,0,0,0,Blue); } if(OrderType()==OP_SELLSTOP&& OrderMagicNumber()==444) { ready444=0; if (OrderOpenPrice()!=BottomGreenLine) OrderModify(OrderTicket(),BottomGreenLine,0,0,0,Red); } } }
but first few times, i does ordermodify correctly, but then suddenly it keeps opening pending buystops? what's wrong with this code?
//CENTERLINE ORDER
if (Ask>=MiddleWhiteLine && Bid<=MiddleWhiteLine&& ready333==1&& ready444==1) {
entryw1 = TopGreenLine;
TPw1 = TopGoldLine;
SLw1 = MiddleWhiteLine;
entryw2 = BottomGreenLine;
TPw2 = BottomGoldLine;
SLw2 = MiddleWhiteLine;
Print("Pending GSPE Orders placed");
OrderSend(Symbol(),OP_BUYSTOP,lots,entryw1,100,SLw1,TPw1,NULL,333,0,Blue);
OrderSend(Symbol(),OP_SELLSTOP,lots,entryw2,100,SLw2,TPw2,NULL,444,0,Red);
}
//END CENTERLINE ORDER
if(!OrdersTotal()){ if (Ask>=MiddleWhiteLine && Bid<=MiddleWhiteLine&& ready333==1&& ready444==1) { entryw1 = TopGreenLine; TPw1 = TopGoldLine; SLw1 = MiddleWhiteLine; entryw2 = BottomGreenLine; TPw2 = BottomGoldLine; SLw2 = MiddleWhiteLine; Print("Pending GSPE Orders placed"); OrderSend(Symbol(),OP_BUYSTOP,lots,entryw1,100,SLw1,TPw1,NULL,333,0,Blue); OrderSend(Symbol(),OP_SELLSTOP,lots,entryw2,100,SLw2,TPw2,NULL,444,0,Red); } }
You need to stop the EA from opening orders on each new tick. The above example is one way of doing it. It simply checks if orders are = 0 and if so then it is ok to open orders. If any orders exist, it will by-pass the order opening.
This is a crude way of doing it since it assumes yours is the only EA running. A better way would be to set up a function that counts your open orders taking magic number and symbols into account and returns that count. Anyway, I am sure you get the idea.......
it should not matter if it checks every tick for existing orders like i had, but just to test, i changed it with the orderstotal - but same stuff happens. 2 pendings are created, then a few times the pendings are modified, then many modifyerror 1 (but its no problem...), and then it continues to open new BUYSTOPS (no SELLSTOPS....), so somewhere the must be something wrong with the ready333 variable i suppose..
can someone show me what needs to be changed to get the following code working? I'm having 2 pending orders, which need to be modified (with magicnumber 222 and 333). When a green line on the chart is moving, it needs to adjust the openprice, TP and SL on the pending orders. Here is what i have done, but is giving me many error 130, and sometimes error 1: