DomGilberto: I am getting the error 4108 and market order cannot be deleted... I know OrderClose is for open trades and OrderDelete is for pending, but I cannot see why I am getting this error?
Your code | for(int o=OrdersTotal()-1; o>=0; o--) { if(!OrderSelect(o,SELECT_BY_POS,MODE_TRADES))continue; if(OrderType()==OP_SELLSTOP) if(OrderMagicNumber()==MagicNumber) if(OrderSymbol() != Symbol())continue; { if(OrderStopLoss() - BuyStopPrice > Point / 2.) : } } |
Your code properly formatted | for(int o=OrdersTotal()-1; o>=0; o--){ if(!OrderSelect(o,SELECT_BY_POS,MODE_TRADES))continue; if(OrderType()==OP_SELLSTOP) if(OrderMagicNumber()==MagicNumber) if(OrderSymbol() != Symbol())continue; { // OrderType, MN and symbol could be anything here except a sellStop from another chart from this EA. if(OrderStopLoss() - BuyStopPrice > Point / 2.) : } } |
DomGilberto:
This gets called and checked every hour with regards to the bias. For example "H1_Bias" will be checked every hour and can change to "None", Down, or Up based upon MA's. It works in conjunction with "IsNewCandle()" function.
I am getting the error 4108 and market order cannot be deleted... I know OrderClose is for open trades and OrderDelete is for pending, but I cannot see why I am getting this error?
This gets called and checked every hour with regards to the bias. For example "H1_Bias" will be checked every hour and can change to "None", Down, or Up based upon MA's. It works in conjunction with "IsNewCandle()" function.
I am getting the error 4108 and market order cannot be deleted... I know OrderClose is for open trades and OrderDelete is for pending, but I cannot see why I am getting this error?
I told you about this yesterday ( https://www.mql5.com/en/forum/146416 ) . . . you will continue ( pardon the pun ) to get issues like this and not see them unless you either change your coding style or learn to check your code more carefully . . .
if(!OrderSelect(o,SELECT_BY_POS,MODE_TRADES))continue; if(OrderType()==OP_SELLSTOP) if(OrderMagicNumber()==MagicNumber) if(OrderSymbol() != Symbol())continue; { // the contents of this brace will be executed regardless of any of the checks above if(OrderStopLoss() - BuyStopPrice > Point / 2.) { Stored_SellPrice = OrderOpenPrice(); DeleteOrder=OrderDelete(OrderTicket()); if(DeleteOrder!=TRUE)Print("Sell Delete Order Failed = ",GetLastError()); } // this is what your code does . . . if(!OrderSelect(o,SELECT_BY_POS,MODE_TRADES))continue; if(OrderType()==OP_SELLSTOP) if(OrderMagicNumber()==MagicNumber) if(OrderSymbol() != Symbol()) continue; if(OrderStopLoss() - BuyStopPrice > Point / 2.) { Stored_SellPrice = OrderOpenPrice(); DeleteOrder=OrderDelete(OrderTicket()); if(DeleteOrder!=TRUE) Print("Sell Delete Order Failed = ",GetLastError()); }
Man, I am so confused. I swear I saw you brace it in a previous post you recommended to me... (I just tried to find it?)
The brace above where you have written "// the contents of this brace...", are you saying that brace pair does not need to be there, and if it remains, every single check I do above that, is irrelevant ?
I think what you meant was this . . . // (Your post) for(int b=OrdersTotal()-1; b>=0; b--) { if(!OrderSelect(b, SELECT_BY_POS, MODE_TRADES)) continue; if( OrderType() == OP_BUYSTOP && OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol() ) <<<<< I guess because you have not written OrderSymbol() != Symbol())continue; the brace immediately below it, is appropriate? { if(OrderStopLoss() < iMA(NULL, 60, MA_Period, 0, 1, 0, 0) - ATR) { Stored_BuyPrice = OrderOpenPrice(); DeleteOrder = OrderDelete(OrderTicket()); } if(OpenOrdersThisPair(Symbol()) == 0 && DeleteOrder) // If there are no open orders = place a new order. { int NewBuyOrder = OrderSend(Symbol(), OP_BUYSTOP, LotSize, Stored_BuyPrice, 3, BuyStopPrice, btp, NULL, MagicNumber, 0, Green); if(NewBuyOrder == -1) Print("New Buy Order Last Error = ", GetLastError()); } } }
Yea forget this thread. I'm being a complete idiot!
Appreciate all your help for pointing out my amnesia...
Appreciate all your help for pointing out my amnesia...
DomGilberto:
xxx sake - yea forget this thread. I'm being a complete idiot!
Appreciate all your help for pointing out my amnesia...
xxx sake - yea forget this thread. I'm being a complete idiot!
Appreciate all your help for pointing out my amnesia...
Please edit your post . . . and please keep in mind all the Forum rules
4. Any use of obscene expressions is forbidden.
Yea - sorry!
DomGilberto:
Yea - sorry!
Thank you
Yea - sorry!
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
I am getting the error 4108 and market order cannot be deleted... I know OrderClose is for open trades and OrderDelete is for pending, but I cannot see why I am getting this error?
THIS IS CALLED NEXT IF THE TOP CODE SENDS IT THROUGH "OrderEntry(1)" if(direction==1) {//--Sell--// double stp=sell_takeprofit_price; double MinLot = MarketInfo(Symbol(),MODE_MINLOT); //Print("The minimum lots are: ",DoubleToStr(Min_Lot,Digits)); double LotStep = MarketInfo(Symbol(),MODE_LOTSTEP); //Print("The Lotstep is: ",DoubleToStr(Lot_Step,Digits)); double SellLotSize =(RiskedAmount/(pips_to_ssl/pips))/10; double lots = NormalizeDouble(SellLotSize,2); LotSize = MathFloor(lots/LotStep)*LotStep; //Print("The Lots to close is: ",DoubleToStr(LotSize,Digits)); static double Stored_SellPrice; if(OpenOrdersThisPair(Symbol())==0) { int SellTicketOrder=OrderSend(Symbol(),OP_SELLSTOP,LotSize,sellPrice,3,SellStopPrice,stp,NULL,MagicNumber,0,Red); } for(int o=OrdersTotal()-1; o>=0; o--) { if(!OrderSelect(o,SELECT_BY_POS,MODE_TRADES))continue; if(OrderType()==OP_SELLSTOP) if(OrderMagicNumber()==MagicNumber) if(OrderSymbol() != Symbol())continue; { if(OrderStopLoss() - BuyStopPrice > Point / 2.) { Stored_SellPrice = OrderOpenPrice(); DeleteOrder=OrderDelete(OrderTicket()); if(DeleteOrder!=TRUE)Print("Sell Delete Order Failed = ",GetLastError()); } if(OpenOrdersThisPair(Symbol())==0 && DeleteOrder) { int NewSellOrder = OrderSend(Symbol(),OP_SELLSTOP,LotSize,Stored_SellPrice,3,SellStopPrice,stp,NULL,MagicNumber,0,Green); } } } } }