The script close all open orders - page 2

 
Roger:

You have wrong place to refresh Bids and Asks, If prices change, it'll never been refresh.

You are right. It should be:


bool CloseOrder(int ticket, double lots, int slippage, int tries, int pause)
{
   bool result=false;
   double ask , bid;
   
   if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
   {
      RefreshRates();
      ask = NormalizeDouble(MarketInfo(OrderSymbol(),MODE_ASK),MarketInfo(OrderSymbol(),MODE_DIGITS));
      bid = NormalizeDouble(MarketInfo(OrderSymbol(),MODE_BID),MarketInfo(OrderSymbol(),MODE_DIGITS));
      
      if(OrderType()==OP_BUY)
      {
         for(int c = 0 ; c < tries ; c++)
         {
            if(lots==0) result = OrderClose(OrderTicket(),OrderLots(),bid,slippage,Violet);
            else result = OrderClose(OrderTicket(),lots,bid,slippage,Violet);
            if(result==true) break; 
            else
            {
               Sleep(pause);
               RefreshRates();
               ask = NormalizeDouble(MarketInfo(OrderSymbol(),MODE_ASK),MarketInfo(OrderSymbol(),MODE_DIGITS));
               bid = NormalizeDouble(MarketInfo(OrderSymbol(),MODE_BID),MarketInfo(OrderSymbol(),MODE_DIGITS));      
               continue;
            }
         }
      }
      if(OrderType()==OP_SELL)
      {
         for(c = 0 ; c < tries ; c++)
         {
            if(lots==0) result = OrderClose(OrderTicket(),OrderLots(),ask,slippage,Violet);
            else result = OrderClose(OrderTicket(),lots,ask,slippage,Violet);
            if(result==true) break; 
            else
            {
               Sleep(pause);
               RefreshRates();
               ask = NormalizeDouble(MarketInfo(OrderSymbol(),MODE_ASK),MarketInfo(OrderSymbol(),MODE_DIGITS));
               bid = NormalizeDouble(MarketInfo(OrderSymbol(),MODE_BID),MarketInfo(OrderSymbol(),MODE_DIGITS));  
               continue;
            }
         }
      }
   }
   return(result);
}
 
Roger, You didn't tell me what do you think about the change. Or you are only criticizing?
 

Hi CG, I tried your "close all open positions" but did not do anything. Do you have an updated script that works? Also, a script that *closes all profit orders*

I am searching for either of these scripts!!!

 

codersguru:

You are right. It should be:

I believe you are both wrong. RefResh rates refreshes the Predefined variables . . . "Refreshing of data in pre-defined variables and series arrays." you are using MarketInfo not predefined variables and arrays so you do not need to use RefreshRates in this code snippet.

https://docs.mql4.com/windows/RefreshRates & https://docs.mql4.com/predefined/variables

 

I noticed several EA's, who are capable to close multiple entries from a certain pair in only one trade.

Here's an example

Time Order Symbol Type Volume Price S / L T / P Time State
2011.10.03 16:02 5984884 6726688 eurusd sell in 3.42 1.33339 0.00
2011.10.03 16:08 5985072 6726879 eurusd sell in 1.88 1.33345 0.00
2011.10.03 16:10 5985174 6727016 eurusd sell in 0.86 1.33446 0.00
2011.10.03 17:10 5987793 6729655 eurusd buy out 5.00 1.32666 3 448.85

AFAIK it's impossible to merge orders.

Is this simply a matter of placing a new order in the opposite direction?

 
RaptorUK:
Changing the position of RefreshRates makes no difference . . . Bid and Ask aren't used.

of course its used, acceptable slippage is determined by Bid or Ask so put it in the for loop
 
trevone:

of course its used, acceptable slippage is determined by Bid or Ask so put it in the for loop
Which Predefined variable needs to be refreshed ?
 
trevone: of course its used, acceptable slippage is determined by Bid or Ask so put it in the for loop
Acceptable slippage is determined (from the value sent) in the server. Server is always up to date. Answer the question.
 
Ahmed Soliman #:

I just tried to close 5 orders

2011.09.20 21:46:09 CloseAll GBPUSD,H1: delete #67127798 sell stop 0.01 GBPUSD at 1.5678 sl: 0.0000 tp: 0.0000 ok
2011.09.20 21:46:06 CloseAll GBPUSD,H1: close #67127783 buy 0.01 GBPUSD at 1.5727 at price 1.5726
2011.09.20 21:46:03 CloseAll GBPUSD,H1: close #67127764 sell 0.01 GBPUSD at 1.5726 at price 1.5729
2011.09.20 21:46:00 CloseAll GBPUSD,H1: delete #67127700 sell stop 0.01 EURUSD at 1.3650 sl: 0.0000 tp: 0.0000 ok
2011.09.20 21:46:00 CloseAll GBPUSD,H1: delete #67127700 sell stop 0.01 EURUSD at 1.3650 sl: 0.0000 tp: 0.0000 ok

and no SUCKS at all


whats the script pls and how to use the script? thanks bro
Reason: