Error invalid parameters - page 3

To add comments, please log in or register
18081961
687
18081961  
RaptorUK:

I'm not sure how you are getting 0 for the Spread,  are you multiplying the figure from MarketInfo() by point ?  or just using the value as it is ?  the Spread is also Ask - Bid.

Bid and Ask are updated by using RefreshRates(),  if you use MarketInfo() to get Bid and Ask you don't need to use RefreshRates() . . .  either method is OK but you need to be aware of when prices can become out of date and then take precautions to guard against it happening.

You can do this . . .

You can use either,  you need to understand the difference though.  StopLevel  is the STOPLEVEL expressed as a number of points,  so a STOPLEVEL of 10 is 10 points, the value is 10.    StopLevel.point for the same STOPLEVEL is 0.0001

I would use the code as you have posted it above . . . with some additional changes.

 

I think the issue with the Spread showing as 0 will be fixed if you use DoubleToStr(x, Digits) with the variable,  any variables that are price values must be used with DoubleToStr(x, Digits).  So if you print FreezeLevel you can do it without DoubleToStr(x, Digits),  if you print FreezeLevel.point you must use DoubleToStr(x, Digits) . . .    do you see the difference ? 


Hi RaptorUK,

Thank you for clarification about the last issues.

While waiting for errors to appear I'm working in the part of code that open the opposite order.Here am testing al line of code to achieve that. Here is the code that am using and would like to know if is also necessary to make use of doubleToStr.

The reason that I'm using this code is that I saw it in another ea and it open the orders at precise distance, but here seems to work not so well..........

 void OpenOppositeOrder()
    {//0     
 int Op;  
   for(int Counter = OrdersTotal()-1; Counter >= 0; Counter--)
      {//14
      if(!OrderSelect(Counter,SELECT_BY_POS,MODE_TRADES))continue;          
         {//15
         if(OrderSymbol() == Symbol()&& OrderMagicNumber() == MagicNumber)           
            {//16
             Op = OrderType();            
           // if(Op == OP_BUY && Bid < (OrderOpenPrice() - (OppositeDistance*pips2dbl)) && SellAllowed)
             if (Op == OP_BUY && ((OrderOpenPrice() - OrderClosePrice())/Point) >= OppositeDistance  && SellAllowed) <-------------------------------make use of doubleToStr ?
                
               {//17  
                while(IsTradeContextBusy()) 
                      Sleep(SleepTime);
                      RefreshRates();                             
                SellTicket = OrderSend(Symbol(), OP_SELL, MLots, Bid, Slippage*pips2points, 0, 0, "Sell Opposite Order", MagicNumber, 0, Red);
                if(SellTicket > -1) 
                  {//18
                   BuyAllowed=true;SellAllowed=false;
                   AddLimitsSell();
                                                                                
                  Print("Opposite Sell order placed  ", SellTicket, "Open Price: ", OrderOpenPrice());                 
                  return;
                  }//18
               else
                  {//19                  
                    ErrorCode = GetLastError();
                    string ErrDesc =ErrorDescription(ErrorCode);
                   
                    string ErrAlert = StringConcatenate("Opposite Sell Failed " , ErrorCode,": ", ErrDesc);
                    Alert(ErrAlert);
         
                    string ErrLog = StringConcatenate("Bid: ", DoubleToStr(Bid,Digits),"Open Price: ",DoubleToStr(OrderOpenPrice(),Digits), " Ticket: ", SellTicket, 
                                              "Spread: ", DoubleToStr(Spread,Digits),"Lots: ", MLots, " Stop Level: ", StopLevel," Freeze Level: " , FreezeLevel);
                    Print(ErrLog);
                    
                    Print("Opposite Sell Order Failed ", GetLastError());
                    
                  }//19
                }//17            
           //if(Op == OP_SELL && Ask > (OrderOpenPrice() + (OppositeDistance*pips2dbl)) && BuyAllowed)
            if(Op == OP_SELL && ((OrderClosePrice() - OrderOpenPrice())/Point)  >= OppositeDistance && BuyAllowed)  <-----------------------------------------make use of doubleToStr ?
               {//20  
               while(IsTradeContextBusy()) 
                    Sleep(SleepTime);
                         RefreshRates();                                
               BuyTicket = OrderSend(Symbol(), OP_BUY, MLots, Ask, Slippage*pips2points, 0, 0, "Buy Opposite Order", MagicNumber, 0, Green); 
               if(BuyTicket > -1)
                  {//21
                   BuyAllowed=false;SellAllowed=true; 
                   AddLimitsBuy();
                                                                           
                   Print("Opposite Buy order placed ", BuyTicket);                                    
                   return;
                  }//21
               else
                  {//22  
                   
                   ErrorCode = GetLastError();
                   ErrDesc =ErrorDescription(ErrorCode);
                  
                   ErrAlert = StringConcatenate("Opposite Buy Failed ", ErrorCode,": ", ErrDesc);
                   Alert(ErrAlert);
         
                   ErrLog = StringConcatenate("Ask: ", DoubleToStr(Ask,Digits),"Open Price: ",DoubleToStr(OrderOpenPrice(),Digits), "Ticket: " , BuyTicket, 
                              "Spread: ", DoubleToStr(Spread,Digits), "Lots: ", MLots, "Stop Level: " , StopLevel, "Freeze Level: ", FreezeLevel);
                   Print(ErrLog);
                   
                  Print("Opposite Buy Order Failed, error  ", GetLastError());
                  }//22   
               }//20
            }//16
         }//15    
      }//14      
    }//0
    

 Thank you in advance

Luis 

Simon Gniadkowski
17296
Simon Gniadkowski  
luisneves:


Hi RaptorUK,

Thank you for clarification about the last issues.

While waiting for errors to appear I'm working in the part of code that open the opposite order.Here am testing al line of code to achieve that. Here is the code that am using and would like to know if is also necessary to make use of doubleToStr.

Do you need to convert double values to a string ?  if you do,  for example when you want to print with 5 digits instead of 4 then yes,  use it . . .  but if you want a value and not a string then no,  don't use it.
18081961
687
18081961  
RaptorUK:
Do you need to convert double values to a string ?  if you do,  for example when you want to print with 5 digits instead of 4 then yes,  use it . . .  but if you want a value and not a string then no,  don't use it.


Hi RaptorUK,

 Thank you for your prompt response.

As told before when spread starts to increase to values near of opposite distance some errors start to appear. Perhaps this distance can't be used at all....

For the other issue of not getting the same distance on opening opposite orders while using that line of code in other ea the that ea open orders at precise distance, I mean, id a sell is open and if price goes up after x distance another sell opens at that distance, at least on tester, but in this ea it don't or some times do and others not...

I have download a spread controller and go testing under controlled conditions.

Best regards

Luis 

Simon Gniadkowski
17296
Simon Gniadkowski  
luisneves:


Hi RaptorUK,

 Thank you for your prompt response.

As told before when spread starts to increase to values near of opposite distance some errors start to appear. Perhaps this distance can't be used at all....

I promise you this . . .   if you make your error reporting comprehensive and useful you will be able to determine what the problem was when you get an error . . .  without it you are just guessing.  Most people that post on this forum leave error reporting to a final afterthought,  or don't bother,  it should be something that you make a priority and do as soon as possible when you write any code that uses a function that returns a value that tells you if the function worked or not.

 

We don't have a debugger with mql4,  the only tools you have are outputting variables via Print(), Alert(), Comment() or Files . . .  when the tools are so scarce you MUST take full advantage of what you have got. 

18081961
687
18081961  
RaptorUK:

I promise you this . . .   if you make your error reporting comprehensive and useful you will be able to determine what the problem was when you get an error . . .  without it you are just guessing.  Most people that post on this forum leave error reporting to a final afterthought,  or don't bother,  it should be something that you make a priority and do as soon as possible when you write any code that uses a function that returns a value that tells you if the function worked or not.

 

We don't have a debugger with mql4,  the only tools you have are outputting variables via Print(), Alert(), Comment() or Files . . .  when the tools are so scarce you MUST take full advantage of what you have got. 


Hi RaptorUk,

Thank you for your up most advise regarding the issue.

I already have run that tool just to see if a different spread value could affect the opening of the orders and what I found was that sometimes the opposite order open before or even after it reaches the value to open it for example it should open at 20 points, no less no more.

Now I'm just doing the test with all values that are used to process the orders. Using that tool allowed me to do the test at week end because the last market spread value was 92 points. 

Meanwhile I appreciate your support. 

Luis 

18081961
687
18081961  

Hi RaptorUk,

So, I've run a test using the spread control just to work on week end and to confirm the behaviour of opposite order against spread value.

The result of that test have shown that the orders have been open very near of opposite order value, but in a particular part where a break occurred the opposite orders have open on 30 points instead of 20, from there the next order open at the right value (20 points up) and the next one at 9 points down (no good) and again the next open at 9 points up...

Looking for the errors on Journal tab from Tester no error came up and now I start to get stupid looking for a valid reason why is this happen. In next comment is the log because the text is to long.

Follow is the code to open the opposite order and would like to know if lines marked make sense. 

Thank you for time spent

Luis 

void OpenOppositeOrder()
    {//0     
     int Op; 
  
     for(int Counter = OrdersTotal()-1; Counter >= 0; Counter--)
      {//14
      if(!OrderSelect(Counter,SELECT_BY_POS,MODE_TRADES))continue;          
         {//15
         if(OrderSymbol() == Symbol()&& OrderMagicNumber() == MagicNumber)           
            {//16
             Op = OrderType();            
           // if(Op == OP_BUY && Bid < (OrderOpenPrice() - (OppositeDistance*pips2dbl)) && SellAllowed)
             if (Op == OP_BUY && (OrderOpenPrice() - OrderClosePrice())/Point  >= OppositeDistance  && SellAllowed)                 
               {//17  
                while(IsTradeContextBusy()) 
                      Sleep(SleepTime);
                      RefreshRates();                             
                SellTicket = OrderSend(Symbol(), OP_SELL, MLots, Bid, Slippage*pips2points, 0, 0, "Sell Opposite Order", MagicNumber, 0, Red);
                if(SellTicket > -1) 
                  {//18
                   BuyAllowed=true;SellAllowed=false;
                   AddLimitsSell();
                                                                                
                  Print(" Opposite Sell order placed", SellTicket," Open Price: ", OrderOpenPrice());                 
                  return;<--------------------------------------------------------------------------------- make sense ?
                  }//18
               else
                  {//19                  
                    ErrorCode = GetLastError();
                    string ErrDesc =ErrorDescription(ErrorCode);
                   
                    string ErrAlert = StringConcatenate(" Opposite Sell Failed " , ErrorCode, ": ", ErrDesc);
                    Alert(ErrAlert);
         
                    string ErrLog = StringConcatenate(" Bid: ", DoubleToStr(Bid,Digits)," Open Price: ", DoubleToStr(OrderOpenPrice(),Digits)," Ticket: ", SellTicket," Spread: ", DoubleToStr(Spread,Digits)," Lots: ", MLots," Stop Level: ", StopLevel," Freeze Level: " , FreezeLevel);
                    Print(ErrLog);
                    
                    //Print("Opposite Sell Order Failed", GetLastError());
                    
                  }//19
                }//17            
           //if(Op == OP_SELL && Ask > (OrderOpenPrice() + (OppositeDistance*pips2dbl)) && BuyAllowed)
            if(Op == OP_SELL && (OrderClosePrice() - OrderOpenPrice())/Point >= OppositeDistance && BuyAllowed)  
               {//20  
               while(IsTradeContextBusy()) 
                    Sleep(SleepTime);
                         RefreshRates();                                
               BuyTicket = OrderSend(Symbol(), OP_BUY, MLots, Ask, Slippage*pips2points, 0, 0, "Buy Opposite Order", MagicNumber, 0, Green); 
               if(BuyTicket > -1)
                  {//21
                   BuyAllowed=false;SellAllowed=true; 
                   AddLimitsBuy();
                                                                           
                   Print(" Opposite Buy order placed ", BuyTicket);                                    
                   return; <--------------------------------------------------------------------------------- make sense ?
                  }//21
               else
                  {//22  
                   
                   ErrorCode = GetLastError();
                   ErrDesc =ErrorDescription(ErrorCode);
                  
                   ErrAlert = StringConcatenate(" Opposite Buy Failed", ErrorCode, ": ", ErrDesc);
                   Alert(ErrAlert);
         
                   ErrLog = StringConcatenate(" Ask: ", DoubleToStr(Ask,Digits)," Open Price: ",DoubleToStr(OrderOpenPrice(),Digits)," Ticket: " , BuyTicket," Spread: ", DoubleToStr(Spread,Digits)," Lots: ", MLots," Stop Level: " , StopLevel," Freeze Level: ", FreezeLevel);
                   Print(ErrLog);
                   
                  //Print("Opposite Buy Order Failed, error  ", GetLastError());
                  }//22   
               }//20
            }//16
         }//15    
      }//14      
    }//0
18081961
687
18081961  
2013.03.31 18:48:20     2012.08.14 01:09  market_order_ecn_80_800_v7_v3 EURUSDi,M1: Initial Buy order placed 13
2013.03.31 18:48:20     2012.08.14 01:09  market_order_ecn_80_800_v7_v3 EURUSDi,M1: Ask: 1.23290 Ticket: 13 Spread: 1.00000 Lots: 0 Buy Stop Loss: 1.22790 Stop Level: 0 Freeze Level: 0 <-------- Here Lots should be LotSize, but shows as 0.....
2013.03.31 18:48:20     2012.08.14 01:09  market_order_ecn_80_800_v7_v3 EURUSDi,M1: Alert:  Add Limits Buy Failed 0: no error
2013.03.31 18:48:20     2012.08.14 01:09  market_order_ecn_80_800_v7_v3 EURUSDi,M1: modify #13 buy 0.01 EURUSDi at 1.23290 sl: 1.22790 tp: 1.23790 ok
2013.03.31 18:48:20     2012.08.14 01:09  market_order_ecn_80_800_v7_v3 EURUSDi,M1: open #13 buy 0.01 EURUSDi at 1.23290 ok
2013.03.31 18:48:19     2012.08.14 01:09  market_order_ecn_80_800_v7_v3 EURUSDi,M1: close #8 buy 0.01 EURUSDi at 1.23294 sl: 1.22794 tp: 1.23794 at price 1.23288
2013.03.31 18:48:19     2012.08.14 01:09  market_order_ecn_80_800_v7_v3 EURUSDi,M1: close #9 sell 0.04 EURUSDi at 1.23263 sl: 1.23763 tp: 1.22763 at price 1.23289
2013.03.31 18:48:19     2012.08.14 01:09  market_order_ecn_80_800_v7_v3 EURUSDi,M1: close #10 buy 0.18 EURUSDi at 1.23283 sl: 1.22783 tp: 1.23783 at price 1.23288
2013.03.31 18:48:19     2012.08.14 01:09  market_order_ecn_80_800_v7_v3 EURUSDi,M1: close #11 sell 0.80 EURUSDi at 1.23274 sl: 1.23774 tp: 1.22774 at price 1.23289
2013.03.31 18:48:19     2012.08.14 01:09  market_order_ecn_80_800_v7_v3 EURUSDi,M1: close #12 buy 3.60 EURUSDi at 1.23283 sl: 1.22783 tp: 1.23783 at price 1.23288
2013.03.31 18:48:15     2012.08.14 01:08  market_order_ecn_80_800_v7_v3 EURUSDi,M1:  Opposite Buy order placed 12
2013.03.31 18:48:15     2012.08.14 01:08  market_order_ecn_80_800_v7_v3 EURUSDi,M1: Ask: 1.23283 Ticket: 12 Spread: 1.00000 Lots: 3.6 Buy Stop Loss: 1.22783 Stop Level: 0 Freeze Level: 0
2013.03.31 18:48:15     2012.08.14 01:08  market_order_ecn_80_800_v7_v3 EURUSDi,M1: Alert:  Add Limits Buy Failed 0: no error
2013.03.31 18:48:15     2012.08.14 01:08  market_order_ecn_80_800_v7_v3 EURUSDi,M1: modify #12 buy 3.60 EURUSDi at 1.23283 sl: 1.22783 tp: 1.23783 ok
2013.03.31 18:48:15     2012.08.14 01:08  market_order_ecn_80_800_v7_v3 EURUSDi,M1: open #12 buy 3.60 EURUSDi at 1.23283 ok
2013.03.31 18:48:05     2012.08.14 01:07  market_order_ecn_80_800_v7_v3 EURUSDi,M1:  Opposite Sell order placed11 Open Price: 1.2327
2013.03.31 18:48:05     2012.08.14 01:07  market_order_ecn_80_800_v7_v3 EURUSDi,M1:  Bid: 1.23274 Ticket: 11 Spread: 1.00000 Lots: 0.8Sell Stop Loss: 1.23774 Stop Level: 0 Freeze Level: 0
2013.03.31 18:48:05     2012.08.14 01:07  market_order_ecn_80_800_v7_v3 EURUSDi,M1: Alert:  Add Limits Sell Failed 0: no error
2013.03.31 18:48:05     2012.08.14 01:07  market_order_ecn_80_800_v7_v3 EURUSDi,M1: modify #11 sell 0.80 EURUSDi at 1.23274 sl: 1.23774 tp: 1.22774 ok
2013.03.31 18:48:05     2012.08.14 01:07  market_order_ecn_80_800_v7_v3 EURUSDi,M1: open #11 sell 0.80 EURUSDi at 1.23274 ok
2013.03.31 18:47:26     2012.08.14 01:03  market_order_ecn_80_800_v7_v3 EURUSDi,M1:  Opposite Buy order placed 10
2013.03.31 18:47:26     2012.08.14 01:03  market_order_ecn_80_800_v7_v3 EURUSDi,M1: Ask: 1.23283 Ticket: 10 Spread: 1.00000 Lots: 0.18 Buy Stop Loss: 1.22783 Stop Level: 0 Freeze Level: 0
2013.03.31 18:47:26     2012.08.14 01:03  market_order_ecn_80_800_v7_v3 EURUSDi,M1: Alert:  Add Limits Buy Failed 0: no error
2013.03.31 18:47:26     2012.08.14 01:03  market_order_ecn_80_800_v7_v3 EURUSDi,M1: modify #10 buy 0.18 EURUSDi at 1.23283 sl: 1.22783 tp: 1.23783 ok
2013.03.31 18:47:26     2012.08.14 01:03  market_order_ecn_80_800_v7_v3 EURUSDi,M1: open #10 buy 0.18 EURUSDi at 1.23283 ok
2013.03.31 18:46:26     2012.08.14 00:58  market_order_ecn_80_800_v7_v3 EURUSDi,M1:  Opposite Sell order placed9 Open Price: 1.2326
2013.03.31 18:46:26     2012.08.14 00:58  market_order_ecn_80_800_v7_v3 EURUSDi,M1:  Bid: 1.23263 Ticket: 9 Spread: 1.00000 Lots: 0.04Sell Stop Loss: 1.23763 Stop Level: 0 Freeze Level: 0
2013.03.31 18:46:26     2012.08.14 00:58  market_order_ecn_80_800_v7_v3 EURUSDi,M1: Alert:  Add Limits Sell Failed 0: no error
2013.03.31 18:46:26     2012.08.14 00:58  market_order_ecn_80_800_v7_v3 EURUSDi,M1: modify #9 sell 0.04 EURUSDi at 1.23263 sl: 1.23763 tp: 1.22763 ok
2013.03.31 18:46:26     2012.08.14 00:58  market_order_ecn_80_800_v7_v3 EURUSDi,M1: open #9 sell 0.04 EURUSDi at 1.23263 ok  <-------------------------------------------------------------------- open after break
2013.03.31 18:45:22     2012.08.14 00:46  market_order_ecn_80_800_v7_v3 EURUSDi,M1: Initial Buy order placed 8
2013.03.31 18:45:22     2012.08.14 00:46  market_order_ecn_80_800_v7_v3 EURUSDi,M1: Ask: 1.23294 Ticket: 8 Spread: 1.00000 Lots: 0.18 Buy Stop Loss: 1.22794 Stop Level: 0 Freeze Level: 0
2013.03.31 18:45:22     2012.08.14 00:46  market_order_ecn_80_800_v7_v3 EURUSDi,M1: Alert:  Add Limits Buy Failed 0: no error <-------------------------------------------this message should only appear in case of fail but do not know why it appearing.....
2013.03.31 18:45:22     2012.08.14 00:46  market_order_ecn_80_800_v7_v3 EURUSDi,M1: modify #8 buy 0.01 EURUSDi at 1.23294 sl: 1.22794 tp: 1.23794 ok
2013.03.31 18:45:22     2012.08.14 00:46  market_order_ecn_80_800_v7_v3 EURUSDi,M1: open #8 buy 0.01 EURUSDi at 1.23294 ok  <----------------------------------------------------------------------open before break
2013.03.31 18:45:22     2012.08.14 00:46  market_order_ecn_80_800_v7_v3 EURUSDi,M1: Order with ticketnr: 7 hit SL! Close all open orders
2013.03.31 18:45:22     2012.08.14 00:46  market_order_ecn_80_800_v7_v3 EURUSDi,M1: close #6 buy 0.01 EURUSDi at 1.23332 sl: 1.22832 tp: 1.23832 at price 1.23291
2013.03.31 18:45:22     2012.08.14 00:46  market_order_ecn_80_800_v7_v3 EURUSDi,M1: LastClosedTicket=7
123
To add comments, please log in or register