Download MetaTrader 5

Little bug... please help

To add comments, please log in or register
Baptiste George
528
Baptiste George  

Hi all,

I have a global close function called when total open orders (equity) is > $100

This function is called on EURUSD chart.


The function below isn't closing orders like USDJPY... in fact JPY's pair.


Please help how to avoid the error message 4107 (Invalid price param):


/*
   Global Equity reached
*/
void Global_closeTrades(string motif) {
      int total = OrdersTotal();
    for(int i = total-1; i >= 0; i--){
      if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
         logData("Error : "+GetLastError());
      }
      if( OrderType() == OP_BUY || OrderType() == OP_SELL ) {
                  bool res = false;
         if(OrderType() == OP_BUY){
            res = OrderCloseReliable(OrderTicket(),OrderLots(),Bid,slippage,Green);
         }else if(OrderType() == OP_SELL){
            res = OrderCloseReliable(OrderTicket(),OrderLots(),Ask,slippage,Red);
         }
         
         if(res){
            logData(OrderType()+" Order closed : "+motif);
         } else if(GetLastError() != 0){
            logData("Order delete error : "+GetLastError());
         }
      }
   }
}

// I tried this:
res = ( OrderCloseReliable(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),slippage,Green);

// I tried this:
res = ( OrderCloseReliable(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),slippage,Green) || OrderCloseReliable(OrderTicket(),OrderLots(),NormalizeDouble(Bid,3),slippage,Green) );


Regards

whroeder1
16099
whroeder1  
  1. OrderSelect loop does not filter by magic numberr - incompatible with every other EA including itself on other charts and manual trading. Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 forum
  2. OrderSelect loop does not filter by pair - You can't use any predefines if it's not the current chart. Shouldn't the EA on the other chart be closing it's orders?
  3. Do not use NormalizeDouble EVER Trailing Bar Entry EA - MQL4 forum
Alain Verleyen
Moderator
33491
Alain Verleyen  

No need for Ask/Bid, you can use OrderClosePrice()

            res = OrderCloseReliable(OrderTicket(),OrderLots(),OrderClosePrice(),slippage,Red);
Baptiste George
528
Baptiste George  
angevoyageur:

No need for Ask/Bid, you can use OrderClosePrice()


That wasn't working : (It only closed any orders except JPY's pair.)


"
15:08:23 EA_Index_Points_V4 EURNZD,M5: failed close: Ticket #36101780, Price: 1.61975, Slippage: 30
15:08:23 EA_Index_Points_V4 EURNZD,M5: last error: 4107:invalid price parameter for trade function (price = 1.61975, Ask = 1.61975, and Bid = 1.61943)
"

Baptiste George
528
Baptiste George  
WHRoeder:
  1. OrderSelect loop does not filter by magic numberr - incompatible with every other EA including itself on other charts and manual trading. Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 forum
  2. OrderSelect loop does not filter by pair - You can't use any predefines if it's not the current chart. Shouldn't the EA on the other chart be closing it's orders?
  3. Do not use NormalizeDouble EVER Trailing Bar Entry EA - MQL4 forum

2. => So I have to create a global VAR. Global_Equity = 1 (when equity is above $100)


So Any EA will refer to it and will launch the Close function from any chart... so when it will be done from any JPY's chart it will close properly.

Baptiste George
528
Baptiste George  
Global var = > Done.
Keith Watford
Moderator
10615
Keith Watford  
FrenchyTrader:

That wasn't working : (It only closed any orders except JPY's pair.)


"
15:08:23 EA_Index_Points_V4 EURNZD,M5: failed close: Ticket #36101780, Price: 1.61975, Slippage: 30
15:08:23 EA_Index_Points_V4 EURNZD,M5: last error: 4107:invalid price parameter for trade function (price = 1.61975, Ask = 1.61975, and Bid = 1.61943)
"


Then you obviously weren't using OrderClosePrice()
To add comments, please log in or register