BuyTicketOrder1 = OrderSend(Symbol(),OP_BUY,LotSize_Buy,Ask + Point,3, 0,0,NULL,MagicNumber1,0,Green); BuyTicketOrder2 = OrderSend(Symbol(),OP_BUY,LotSize_Buy2,Ask + Point,3, 0,0,NULL,MagicNumber1,0,Green); BuyTicketOrder3 = OrderSend(Symbol(),OP_BUY,LotSize_Buy3,Ask + Point,3, 0,0,NULL,MagicNumber1,0,Green); BuyTicketOrder4 = OrderSend(Symbol(),OP_BUY,LotSize_Buy4,Ask + Point,3, 0,0,NULL,MagicNumber1,0,Green);
- Check your return codes (OrderSelect)
What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
- Server call takes time, you must refreshRates() between them.
- How do you expect to open an order other than market price?
- What is MarketInfo(market_pair, MODE_STOPLEVEL)? You can't put pending orders closer than that and you're using 1.
Yeah I've deleted the prints to make it easier to read. Thanks for your advice. I've changed that mistake above.
I'm not using pending orders...? I thought I am using a market order...
The errors seem to be coming from the ordermodify's error "0".
I've got it sorted. As usual, thanks for your help WHRoeder! :) (I was being a bit - no surprise - of a dingbat)
This is what I now use for the for loop part - slapping continue; when one of the ordermodify was successful meant that ALL the orders will then being properly selected and modified:
for(int b=OrdersTotal()-1; b>=0; b--) { if( !OrderSelect(b,SELECT_BY_POS,MODE_TRADES))continue; { if( OrderMagicNumber()== MagicNumber1 ) if(OrderSymbol() == Symbol()) if( OrderType() == OP_BUY ) if( OrderStopLoss() == 0 || OrderTakeProfit() == 0 ) { if( OrderTicket() == BuyTicketOrder1 ){ bool ModifyBuy1 = OrderModify(BuyTicketOrder1,OrderOpenPrice(),BuyStopPrice,btp1,0,clrNONE); if(ModifyBuy1 == False )Print(" ModifyBuy1 failed: ", GetLastError() ); if(ModifyBuy1 == True )Print(" ModifyBuy1 Success: ", OrderSymbol() );continue;} if( OrderTicket() == BuyTicketOrder2 ){ bool ModifyBuy2 = OrderModify(BuyTicketOrder2,OrderOpenPrice(),BuyStopPrice,btp2,0,clrNONE); if(ModifyBuy2 == False )Print(" ModifyBuy2 failed: ", GetLastError() ); if(ModifyBuy2 == True )Print(" ModifyBuy2 Success: ", OrderSymbol() );continue;} if( OrderTicket() == BuyTicketOrder3 ){ bool ModifyBuy3 = OrderModify(BuyTicketOrder3,OrderOpenPrice(),BuyStopPrice,btp3,0,clrNONE); if(ModifyBuy3 == False )Print(" ModifyBuy3 failed: ", GetLastError() ); if(ModifyBuy3 == True )Print(" ModifyBuy3 Success: ", OrderSymbol() );continue;} if( OrderTicket() == BuyTicketOrder4 ){ bool ModifyBuy4 = OrderModify(BuyTicketOrder4,OrderOpenPrice(),BuyStopPrice,btp4,0,clrNONE); if(ModifyBuy4 == False )Print(" ModifyBuy4 failed: ", GetLastError() ); if(ModifyBuy4 == True )Print(" ModifyBuy4 Success: ", OrderSymbol() );continue;} } } break; }
... if( OpenOrdersThisPair(Symbol()) == 0 && LotSize_Buy - minlot > Point / 2. )//&& D1_ATR > Todays_Range - Point) { BuyTicketOrder1 = OrderSend(Symbol(),OP_BUY,LotSize_Buy,Ask ,3, 0,0,NULL,MagicNumber1,0,Green);RefreshRates(); BuyTicketOrder2 = OrderSend(Symbol(),OP_BUY,LotSize_Buy2,Ask ,3, 0,0,NULL,MagicNumber1,0,Green);RefreshRates(); BuyTicketOrder3 = OrderSend(Symbol(),OP_BUY,LotSize_Buy3,Ask ,3, 0,0,NULL,MagicNumber1,0,Green);RefreshRates(); BuyTicketOrder4 = OrderSend(Symbol(),OP_BUY,LotSize_Buy4,Ask ,3, 0,0,NULL,MagicNumber1,0,Green);RefreshRates(); if(BuyTicketOrder1 == -1)Print("First Buy Order Last Error = ",GetLastError(), " On: ", Symbol());//return; //if(BuyTicketOrder1 > 0)Print("First Buy Order Placed: ", Symbol(), " LotSize_Buy is: ", LotSize_Buy ); if(BuyTicketOrder2 == -1)Print("Second Buy Order Last Error = ",GetLastError(), " On: ", Symbol());//return; //if(BuyTicketOrder2 > 0)Print("Second Buy Order Placed: ", Symbol(), " LotSize_Buy is: ", LotSize_Buy2 ); if(BuyTicketOrder3 == -1)Print("Third Buy Order Last Error = ",GetLastError(), " On: ", Symbol());//return; //if(BuyTicketOrder3 > 0)Print("Third Buy Order Placed: ", Symbol(), " LotSize_Buy is: ", LotSize_Buy3 ); if(BuyTicketOrder4 == -1)Print("Fourth Buy Order Last Error = ",GetLastError(), " On: ", Symbol());//return; //if(BuyTicketOrder4 > 0)Print("Fourth Buy Order Placed: ", Symbol(), " LotSize_Buy is: ", LotSize_Buy4 ); } for(int b=OrdersTotal()-1; b>=0; b--) { if( !OrderSelect(b,SELECT_BY_TICKET))continue; { if( OrderMagicNumber()== MagicNumber1 ) if(OrderSymbol() == Symbol()) if( OrderType() == OP_BUY ) { if( OrderTicket() == BuyTicketOrder1 ){ bool ModifyBuy1 = OrderModify(BuyTicketOrder1,OrderOpenPrice(),BuyStopPrice,btp1,0,clrNONE); if(ModifyBuy1 == False )Print(" ModifyBuy1 failed: ", GetLastError() ); if(ModifyBuy1 == True )Print(" ModifyBuy1 Success: ", OrderSymbol() );continue;} if( OrderTicket() == BuyTicketOrder2 ){ bool ModifyBuy2 = OrderModify(BuyTicketOrder2,OrderOpenPrice(),BuyStopPrice,btp2,0,clrNONE); if(ModifyBuy2 == False )Print(" ModifyBuy2 failed: ", GetLastError() ); if(ModifyBuy2 == True )Print(" ModifyBuy2 Success: ", OrderSymbol() );continue;} if( OrderTicket() == BuyTicketOrder3 ){ bool ModifyBuy3 = OrderModify(BuyTicketOrder3,OrderOpenPrice(),BuyStopPrice,btp3,0,clrNONE); if(ModifyBuy3 == False )Print(" ModifyBuy3 failed: ", GetLastError() ); if(ModifyBuy3 == True )Print(" ModifyBuy3 Success: ", OrderSymbol() );continue;} if( OrderTicket() == BuyTicketOrder4 ){ bool ModifyBuy4 = OrderModify(BuyTicketOrder4,OrderOpenPrice(),BuyStopPrice,btp4,0,clrNONE); if(ModifyBuy4 == False )Print(" ModifyBuy4 failed: ", GetLastError() ); if(ModifyBuy4 == True )Print(" ModifyBuy4 Success: ", OrderSymbol() );continue;} } } //break; } ...
Ok, I got rid of the for loop. That was unnecessary. I do it like this now...
if( OpenOrdersThisPair(Symbol()) == 0 && LotSize_Buy >= minlot )//&& D1_ATR > Todays_Range - Point) { BuyTicketOrder1 = OrderSend(Symbol(),OP_BUY,LotSize_Buy,Ask ,3, 0,0,NULL,MagicNumber1,0,Green);RefreshRates(); if( OrderSelect(BuyTicketOrder1,SELECT_BY_TICKET)){ if(OrderSymbol() == Symbol() && OrderType() == OP_BUY ) bool ModifyBuy1 = OrderModify(BuyTicketOrder1,OrderOpenPrice(),BuyStopPrice,btp1,0,clrNONE);} BuyTicketOrder2 = OrderSend(Symbol(),OP_BUY,LotSize_Buy2,Ask ,3, 0,0,NULL,MagicNumber1,0,Green);RefreshRates(); if( OrderSelect(BuyTicketOrder2,SELECT_BY_TICKET)){ if(OrderSymbol() == Symbol() && OrderType() == OP_BUY ) bool ModifyBuy2 = OrderModify(BuyTicketOrder2,OrderOpenPrice(),BuyStopPrice,btp2,0,clrNONE);} BuyTicketOrder3 = OrderSend(Symbol(),OP_BUY,LotSize_Buy3,Ask ,3, 0,0,NULL,MagicNumber1,0,Green);RefreshRates(); if( OrderSelect(BuyTicketOrder3,SELECT_BY_TICKET)){ if(OrderSymbol() == Symbol() && OrderType() == OP_BUY ) bool ModifyBuy3 = OrderModify(BuyTicketOrder3,OrderOpenPrice(),BuyStopPrice,btp3,0,clrNONE);} BuyTicketOrder4 = OrderSend(Symbol(),OP_BUY,LotSize_Buy4,Ask ,3, 0,0,NULL,MagicNumber1,0,Green);RefreshRates(); if( OrderSelect(BuyTicketOrder4,SELECT_BY_TICKET)){ if(OrderSymbol() == Symbol() && OrderType() == OP_BUY ) bool ModifyBuy4 = OrderModify(BuyTicketOrder4,OrderOpenPrice(),BuyStopPrice,btp4,0,clrNONE);}
if(BuyTicketOrder1 == -1)Print("First Buy Order Last Error = ",GetLastError(),Does GetLastError refer to the error on order1 or order2 or order3 or order4? Of course you have no idea. If the open fails you must capture the error right there and then. What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
Yea I see what I am doing wrong with regards to print.
With regards to above, sometimes on a rare occasion the OrderSend does not actually successfully modify, well, at least 1 OP_BUY || OP_SELL is not modified. How do I make sure that the trade is modified?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Anyway, OrderEntry(0); is the buy side and gets called... I am getting the error in the for loop below (i'I've deleted prints to make it easier to read but kept the OrderModify prints):