Download MetaTrader 5
To add comments, please log in or register
Publish your articles and improve your rating!
Frenchytrader
281
Frenchytrader 2014.04.29 11:57 

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
13609
whroeder1 2014.04.29 12:27  
  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
28550
Alain Verleyen 2014.04.29 12:29  

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

            res = OrderCloseReliable(OrderTicket(),OrderLots(),OrderClosePrice(),slippage,Red);
Frenchytrader
281
Frenchytrader 2014.04.29 13:11  
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)
"

Frenchytrader
281
Frenchytrader 2014.04.29 13:14  
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.

Frenchytrader
281
Frenchytrader 2014.04.29 14:21  
Global var = > Done.
Keith Watford
Moderator
7899
Keith Watford 2014.04.29 18:17  
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