- Experts: 1 Click Button To Close All Open and Pending Orders V03
- Very high CPU usage (per-core) in MT4
- Strategy tester never completes
despite being exact to the point..
then..it shouldn't be infinite loops.
post some code if you need help.
My opening and closing loops, despite being exact to the point never work. Please help
then..it shouldn't be infinite loops.
post some code if you need help.
I uploaded the file
int Ans = 0; int Tip = -1; while(true) { if(Tip==0 && close_buy) { Alert("Attempt to close Buy ",Ticket,". Waiting for response.."); Comment("Attempt to close Buy ",Ticket,". Waiting for response.."); Print("Attempt to close Buy ",Ticket,". Waiting for response.."); RefreshRates(); Ans=OrderClose(Ticket,Lot,Bid,2); if(Ans==true) // Success :) { Alert("Closed order Buy ",Ticket); Comment("Closed order Buy ",Ticket); Print("Closed order Buy ",Ticket); break; // Exit closing loop } } if(Tip==1 && close_sell==true) { Alert("Attempt to close Sell ",Ticket,". Waiting for response.."); Comment("Attempt to close Sell ",Ticket,". Waiting for response.."); Print("Attempt to close Sell ",Ticket,". Waiting for response.."); RefreshRates(); Ans=OrderClose(Ticket,Lot,Ask,2); if(Ans==true) { Alert("Closed order Sell ",Ticket); Comment("Closed order Sell ",Ticket); Print("Closed order Sell ",Ticket); break; } } } while(true) { if(Total==0 && open_buy==true) { RefreshRates(); SL = Bid - Stop_Loss * Point; TP = Bid + Take_Profit * Point; Alert("Attempt to open Buy. Waiting for response.."); Comment("Attempt to open Buy. Waiting for response.."); Print("Attempt to open Buy. Waiting for response.."); Ticket=OrderSend(Symb,OP_BUY,0.01,Ask,2,SL,TP);//Opening Buy if(Ticket<0) // Success :) { Alert("Opened order Buy ",Ticket); Comment("Opened order Buy ",Ticket); Print("Opened order Buy ",Ticket); return(0); // Exit start() } } if(Total==0 && open_sell==true) { RefreshRates(); SL = Ask + Stop_Loss * Point; TP = Ask - Take_Profit * Point; Alert("Attempt to open Sell. Waiting for response.."); Comment("Attempt to open Sell. Waiting for response.."); Print("Attempt to open Sell. Waiting for response.."); Ticket=OrderSend(Symb,OP_SELL,0.01,Bid,2,SL,TP); if(Ticket<0) // Success :) { Alert("Opened order Sell ",Ticket); Comment("Opened order Sell ",Ticket); Print("Opened order Sell ",Ticket); return(0); // Exit start() } } }
Please format your source code with the tool provided by the editor.
You have a nice way to code a endless loop.
Just one word : A negative ticket is a failure, not a success.
Please format your source code with the tool provided by the editor.
You have a nice way to code a endless loop.
Just one word : A negative ticket is a failure, not a success.
I did click on the Style option, so, what do you mean to format it?
Ticket and Ans are the variables to return the value of OrderSend and OrderClose functions. Tip is -1 because i it was initialized to 0, it would then trigger the order type upon first use.
You have not fixed it. You just made it worse!
Because you still don't understand that the OrderSend function does not return a boolean (it is not true or false, it has a value). It returns a value of a valid ticket if it succeeds or WRONG_VALUE when it fails.
Read the documentation!
You have not fixed it. You just made it worse!
Because you still don't understand that the OrderSend function does not return a boolean (it is not true or false, it has a value). It returns a value of a valid ticket if it succeeds or WRONG_VALUE when it fails.
Read the documentation!
I did go ahead and read it and changed it
//+------------------------------------------------------------------+ // Order Opening //+------------------------------------------------------------------+ double Buy_Stoploss=Bid-Stop_Loss*Point, Buy_Take_Profit=Bid+Take_Profit*Point, Sell_Stoploss=Ask+Stop_Loss*Point, Sell_Take_Profit=Ask-Take_Profit*Point; int Mod_Order=0; if(OrdersTotal()<1 && open_buy==true) { RefreshRates(); Ticket=OrderSend(Symb,OP_BUY,Lot_Size,Ask,3,0,0,NULL, Magic_Number,0,clrGreen); if(Ticket>0) { Mod_Order=OrderModify(Ticket,OrderOpenPrice(),Buy_Stoploss, Buy_Take_Profit,0,clrGreen); } } if(OrdersTotal()<1 && open_sell==true) { RefreshRates(); Ticket=OrderSend(Symb,OP_SELL,Lot_Size,Bid,3,0,0,NULL, Magic_Number,clrRed); if(Ticket>0) { Mod_Order=OrderModify(Ticket,OrderOpenPrice(),Sell_Stoploss, Sell_Take_Profit,0,clrRed); } } //+------------------------------------------------------------------+ // Order Closing //+------------------------------------------------------------------+ if(OrdersTotal()>0) { if(close_buy==true) { for(int Counter=OrdersTotal()-1; Counter>=0; Counter--) { if(OrderSelect(Counter,SELECT_BY_POS,MODE_TRADES)==true) { if(OrderType()==OP_BUY) { RefreshRates(); Comment("Closing Buy Order!"); Print("Closing Buy Order!"); bool Ans=OrderClose(OrderTicket(),OrderLots(),Bid,3,clrYellow); } } } } if(close_sell==true) { for(int Counter=OrdersTotal()-1; Counter>=0; Counter--) { if(OrderSelect(Counter,SELECT_BY_POS,MODE_TRADES)==true) { if(OrderType()==OP_SELL) { RefreshRates(); Comment("Closing Sell Order!"); Print("Closing Sell Order!"); bool Ans=OrderClose(OrderTicket(),OrderLots(),Ask,3,clrYellow); } } } } }
Please use the insert code button when pasting code. I have edited it for you this time.
if(Ticket>0) { Mod_Order=OrderModify(Ticket,OrderOpenPrice(),Buy_Stoploss,Buy_Take_Profit,0,clrGreen); }
Where do you select the order?
Although it can be good to use empty lines to divide sections of code, in my opinion your over-use of empty lines just makes your code difficult to read
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use