EA clashing when using multiple pairs... - page 3

 
Ah I figured it out!

I needed to call the order modify from the "int start()" function when "If(IsNewCandle())" is called too. Therefore, on EVERY hour close, the "void OrderModify" that modify's the PENDING order if the orderstoploss > iMA-ATR, will be modified and calibrated accordingly.

So that is now doing it's job properly :) Now to read until my eyes bleed... :)
 
RaptorUK:

This is the issue . . . (similar for the OP_SELL)

. . . and when you get an error 1 it is because OrderStopLoss() == BuyStopPrice so you are modifying the order to have the same StopLoss value, hence error 1 so now you are wondering how on one hand OrderStopLoss() == BuyStopPrice and on the other hand OrderStopLoss() < BuyStopPrice

Did you follow the link in the post and read it till your eyes bled ? I bet you didn't . . . https://www.mql5.com/en/forum/146380 if you keep ignoring this issue it will keep catching you out and you will keep wasting time . . . get to grips with it, understand it, don't suffer from it any longer, be happy


except with zero never compare doubles for equality < Might this be what I was looking for by WHRoeder...?
if (a > b)
if (a - b > Point / 2.)
if (a >= b)
if (a - b > -Point)
if (a != b)
if (MathAbs(a - b) > Point / 2.)
 
DomGilberto:

except with zero never compare doubles for equality < Might this be what I was looking for by WHRoeder...?
Certainly that will work, do you understand why and what the issue is ?
 
To be perfectly honest, no I don't understand... I did experiment with writing it out and printing the comparisons though...
 
DomGilberto:
To be perfectly honest, no I don't understand... I did experiment with writing it out and printing the comparisons though...

1.51234000001 is not the same as 1.51234000002 but from the point if view of a price they are both 1.51234 so are the same . . . so they are the same but one is greater than the other. It's all to do with the way floating point numbers are represented in binary, it's inexact so there is generally a little error here and there . . .

Have a look at this: floating point numbers

 

But why would NormalizedDouble, Digits not sort that out? Why are the extra unnecessary decimal places be included? I appreciate the fact you do not need to use NormalizeDouble on predefined variables, but whats the point in using NormalizeDouble on non predefined variables, and then trying to compare them when they'll never match up :s?

Strange!

If I wanted to do "If(Bid > OrderOpenPrice())" that wouldnt work would it? Would I need to do the rules stated above, on every comparison statement? i.e. "If(Bid - OrderOpenPrice() > Point / 2.)?


Oh and what If(Bid == OrderOpenPrice()), is there anything I need to do with that statement?

 
DomGilberto:

But why would NormalizedDouble, Digits not sort that out? Why are the extra unnecessary decimal places be included? I appreciate the fact you do not need to use NormalizeDouble on predefined variables, but whats the point in using NormalizeDouble on non predefined variables, and then trying to compare them when they'll never match up :s?

NormalizeDouble does not fix the issue, it does not turn 1.51234000001 into 1.51234 it just "messes" with it in a different way . . . so by using it you are hoping that it messes with all your values in the same way.

DomGilberto:


If I wanted to do "If(Bid > OrderOpenPrice())" that wouldnt work would it? Would I need to do the rules stated above, on every comparison statement? i.e. "If(Bid - OrderOpenPrice() > Point / 2.)?

Yes, if you wanted to be sure your comparison was giving you an accurate result, yes.

DomGilberto:

Oh and what If(Bid == OrderOpenPrice()), is there anything I need to do with that statement?

Yes, it will suffer from exactly the same issue . . .
 
Ok thanks - I have dramatically reduced the OrderModify error 1 - however, I am still getting a little bit now and again? Seems like it is the MA_trail void? Also, how would I correctly write "If(Bid == OrderOpenPrice())?
//+----------------------------------------------------------------------------------------------------------------------------------------+  
//Moving Average Trailing Stop Function
//+----------------------------------------------------------------------------------------------------------------------------------------+   
void MA_Trail()

{

   double ATR = iATR(NULL,60,14,1);
   double MA = iMA(NULL,60,MA_Period,0,1,0,1);
   
   double BuyStopPriceMath = MA - ATR;
   double SellStopPriceMath = MA + ATR;
   
   double BuyStopPrice = NormalizeDouble(BuyStopPriceMath,5);
   double SellStopPrice = NormalizeDouble(SellStopPriceMath,5);

   for(int b=OrdersTotal()-1; b>=0; b--)
     {
      if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES))
         if(OrderMagicNumber()==MagicNumber)
            if(OrderSymbol()==Symbol())
               {

               if(OrderType()==OP_BUY)
                  {
                  if(OrderStopLoss() - BuyStopPrice > Point / 2.) continue;
                  if(BuyStopPrice - OrderStopLoss() > Point / 2.)
                     bool BuyModify = OrderModify(OrderTicket(),OrderOpenPrice(),BuyStopPrice,OrderTakeProfit(),0,CLR_NONE);
                   if(!BuyModify)Print(" Buy Trailing Stop Failed: ", GetLastError());
                   }     

    
               if(OrderType()==OP_SELL)
                  {
                  if(SellStopPrice - OrderStopLoss() > Point / 2. ) continue;
                  if(OrderStopLoss() - SellStopPrice > Point / 2. )
                     bool SellModify = OrderModify(OrderTicket(),OrderOpenPrice(),SellStopPrice,OrderTakeProfit(),0,CLR_NONE);
                  if(!SellModify)Print(" Sell Trailing Stop Failed: ", GetLastError());
                  }
              }   
      }
} 
 
DomGilberto:
Ok thanks - I have dramatically reduced the OrderModify error 1 - however, I am still getting a little bit now and again? Seems like it is the MA_trail void? Also, how would I correctly write "If(Bid == OrderOpenPrice())?

Your eyes aren't bleeding enough . . .

You could do something like this:

!( MathAbs(FirstPrice - SecondPrice) > HalfAPoint )

be careful about the !

From here: https://www.mql5.com/en/forum/136997/page4#781986

 
Are you suggesting this in connection to the code above or in relation to "If(Bid == OrderOpenPrice())"?
Reason: