MQL4 - automated forex trading   /  

Forum

BreakEven Error1 problem (SOLVED)

Back to topics list To post a new topic, please log in or register

avatar
238
DayTrader 2012.01.20 20:03 

Error1 means: "No error returned, but the result is unknown." Typically one gets this if one makes a change and change nothing... eg doing an OrderModify without changing any of the params.

I get many of those from this function, but cant figure out why. As you can see before modifying the SL I first check that the order has a different SL. Can you spot the problem ?

BreakEvenTrigger (BET), BreakEvenLevel (BEL). LATEST: if I also do a change to TP the errors disappear. Isnt it possible to change the value of only one parameter, without getting peppered with errors ??

Turned out the problem was with the OpenPrice. THIS solved the problem:

OrderModify(OrderTicket(), 0, NormalizeDouble(OrderOpenPrice() + (BEL * Point), Digits), OrderTakeProfit(), 0, Yellow);
Changing the OrderOpenPrice of a market order is obviously not allowed... Making no change to that price generates errors....When I DO make a change (to price = 0) I get no errors... Now go figure that one out. Must be a Terminal bug !

//----------------------------------------------------------------------------------
void BreakEven()
   {
   if(OrdersTotal() < 1) return(0);//No open orders so get out and save time!
   double BET = BreakEvenTrigger;//Local copy
   double BEL = BreakEvenLevel;//Local copy
   if(BET == 0 ) return(0);//Nothing to do here
   //if(BET < BEL) BEL = BET;
   for (int i = OrdersTotal() - 1; i >= 0; i--)
      {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
         {
//--------
         if(OrderType() == OP_BUY)
            {         
            if ((Bid - OrderOpenPrice() > ( (BET+BEL) * Point) ) && OrderStopLoss() != NormalizeDouble(OrderOpenPrice() + (BEL * Point), Digits))
               {
               DrawVline(Aqua, iTime(NULL,PERIOD_M1,0));
               OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(OrderOpenPrice() + (BEL * Point), Digits), OrderTakeProfit(), 0, Yellow);                  
               }
            }
//--------
         if(OrderType() == OP_SELL) 
            {          
            if (OrderOpenPrice() - Ask > (BET * Point) && MathAbs(OrderOpenPrice() - (BEL * Point) - OrderStopLoss()) > Point) 
               {
               //DrawVline(Aqua, Time[0]);
               //OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(OrderOpenPrice() - (BEL * Point), Digits), OrderTakeProfit(), 0, Yellow);            
               }
            }    
         }    
      }      
   return (0);
   }
//----------------------------------------------------------------------------------

Filtering by History

Filtering by History

The article describes the usage of virtual trading as an integral part of trade opening filter.


avatar
4224
RaptorUK 2012.01.20 20:31 

If you look here: Execution errors, you will see Error 1 means: "OrderModify attempts to replace the values already set with the same values. One or more values must be changed, then modification attempt can be repeated."

It may well be a double variable type precision issue . . . try checking if the difference between your current SL and the one you want to set is more than a Point


avatar
238
DayTrader 2012.01.20 20:42 

As mentioned I did check that I actually made a difference to the SL value, in this case by 50 points, and Normalize was used to get control of precision and digits in the numbers.

Also see the comment on Open Price.


avatar
4224
RaptorUK 2012.01.20 21:16 
DayTrader:

As mentioned I did check that I actually made a difference to the SL value, in this case by 50 points, and Normalize was used to get control of precision and digits in the numbers.

Also see the comment on Open Price.

Normalize is not reliable in the way you have used it . . IMO . . . and it does not "get control of precision" . . . that is an illusion.

This is your test . . .

OrderStopLoss() != NormalizeDouble(OrderOpenPrice() + (BEL * Point), Digits)

and if that is true, i.e. not equal, even in not equal by 0.0000000001 then you go on and use NormalizeDouble(OrderOpenPrice() + (BEL * Point), Digits) as your NEW SL

OrderModify(OrderTicket(), OrderOpenPrice(),   NormalizeDouble(OrderOpenPrice() + (BEL * Point), Digits),   OrderTakeProfit(), 0, Yellow); 

So you aren't checking for a difference of 50 points between the old and new SL . . . . maybe between the OpenPrice and SL . . . but that doesn't stop you setting the same SL time after time after time.

I think your issue hasn't been solved . . .


avatar
238
DayTrader 2012.01.20 22:09 

Yeah more testing and the error came up again.

Despite the NormalizeDouble we could see rounding effects in the API floating point math routines causing the last digit to change up or down by 1.

So what I should do is to check if my new SL and the existing one differ by MORE than 1 point ? I did just that earlier but I guess other errors in the code also generated Error1.


avatar
238
DayTrader 2012.01.21 18:54 

Ok got it working now. Tested over 1000's of orders, with just about any combination of positive and negative BET and BEL... stops moved where I want'em and no errors.


avatar
4224
RaptorUK 2012.01.21 20:07 
Well done, the first step is to know you have an issue :-)
Back to topics list  

To add comments, please log in or register