Can price != price ? - page 6

 

That's what I call a double can of worms.... (pun intended;)

It sounds like out of several custom functions proposed, none reached a consensus. Anyone care to share at this point (no pun intended), which one they use as their day to day CompareDouble function?

Obviously we must use some custom CompareDouble function, if we want reliable systems.

 

The problem can be ignored, mostly unless the EXACT value is important.

If I'm looking to open above a (possibily unnormallized) trigger price I use Bid > trigger. If it happens to trigger at the price because of round off, I really don't care.

If I'm looking to open AT or around a (possibily unnormallized) trigger price I test for a gap: Bid > trigger && Bid < trigger+3*pips2dbl. Market can easily move a whole pip in one tick so Bid == trigger is always wrong and MathAbs(bid-trigger) < Point/2 is correct but most likely will not work.

If the equals is important, such as looking to move a SL but I'm too close to the market (stop level) then and I use Bid - newSL > StopLelvel - Point/2

 
WHRoeder:

The problem can be ignored, mostly unless the EXACT value is important.

If I'm looking to open above a (possibily unnormallized) trigger price I use Bid > trigger. If it happens to trigger at the price because of round off, I really don't care.

If I'm looking to open AT or around a (possibily unnormallized) trigger price I test for a gap: Bid > trigger && Bid < trigger+3*pips2dbl. Market can easily move a whole pip in one tick so Bid == trigger is always wrong and MathAbs(bid-trigger) < Point/2 is correct but most likely will not work.

If the equals is important, such as looking to move a SL but I'm too close to the market (stop level) then and I use Bid - newSL > StopLelvel - Point/2


Thanks. Now that's what I'd call decocted thread..

In fact what you mentioned is very close to my application: I'm establishing if the new TakeProfit is different (according broker or MQL4 standards) than the original TakeProfit already set and sent. I'm comparing two indicator values and two TakeProfit values before OrderModify is called.

if (Volume[0]>1)return;
 
       for(int b=OrdersTotal()-1;b>=0; b--)
       {
       if(atr2kTP == atr2kTPAdjust|| btphold==btp)) return;//-----------This is where I am comparing them, and where the function would go.
         if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES))
           if(OrderMagicNumber()==MAGICMA)
             if(OrderSymbol()==Symbol())
                if(OrderType()==OP_BUY)                                  
                  atr2kTPAdjust=atr2kTP; 
                       OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),btp,0,CLR_NONE);                          
 
       }              
         for(int s=OrdersTotal()-1;s>=0; s--)
         {
          if(atr2kTP == atr2kTPAdjust|| stphold==stp) return;
           if(OrderSelect(s,SELECT_BY_POS,MODE_TRADES))
             if(OrderMagicNumber()==MAGICMA)
               if(OrderSymbol()==Symbol())
                  if(OrderType()==OP_SELL)                      
                      atr2kTPAdjust=atr2kTP;                      
                        OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),stp,0,CLR_NONE);
         }
 }
 

This was my final OrderMod code, using the Point/2 filter for comparing Double order values. Worked error-FREE and modified orders every time. Thanks!

void AutoAdjustTakeProfit()
{
if (Volume[0]>1 || atr2kTP == atr2kTPAdjust)return;  

       for(int b=OrdersTotal()-1;b>=0; b--)
          { 
            if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES))
               if(OrderMagicNumber()==MAGICMA)
                 if(OrderSymbol()==Symbol())
                    {          
                      if(OrderType()==OP_BUY)// buy ordeer section
                        {  
                          if((btphold-btp> Point/2) || (btphold-btp<-Point/2))  //--------------------------This is the DoubleCompare Code
                            {                                                                             
                              atr2kTPAdjust=atr2kTP; 
                              OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),btp,0,CLR_NONE);                          
                            }
                        } 
                     
                      if(OrderType()==OP_SELL) // Sell ordeer section
                        {   
                          if((stphold-stp>Point/2) || (stphold-stp <-Point/2)) //--------------------------This is the DoubleCompare Code
                            {                                                  
                               atr2kTPAdjust=atr2kTP;                      
                               OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),stp,0,CLR_NONE);
                            }
                        }
                    }
           }
}
 
  1. if (Volume[0]>1)return;
    If you miss some ticks at the start of a new bar, your code doesn't execute. Always use time
  2.   if((stphold-stp>Point/2) || (stphold-stp <-Point/2))
      if( MathAbs(stphold - stp) > Point/2) // Simplified
    Again, do you really care about the equals? If you used:
      if( MathAbs(stphold - stp) >= Point)
    it might trigger at slightly less than a point. That is still the same as not equal.
  3. Why move it a point, move them by pips and avoid the roundoff problem, and ERR_TOO_FREQUENT_REQUESTS
 

newBar works great.

MathAbs rocks, I thought it only converted negatives on the left hand side of equations, didn't know it would also convert the difference to positive value.

Point/2 precision is not important for my signal purposes. I only wanted to avoid round-off errors to avoid feeble coding.

I'd prefer to stomp frequency errors just as well as round-off errors. So I want to use the most error-free stable calculations, as opposed to the most accurate calculation code.

So by increasing my TakeProfit MathAbs (stphold - stp) comparisons even more to >2*pips I should have the greatest chance of eliminating the round-off errors and the frequency errors ?

thanks much.

removed.

 
moneycode:

newBar works great.

Previously I found issues with IsNewCandle, that's why I switched to a Volume trigger. If volume ticks processing can be slow or missing, then candles could be too. So both were a bad idea..

Since newBar works fine, I now tried to identify the IsNewCandle fail occurrences, with this code below:

IsNewCandle() function call is inside start(), ABOVE the newBar code line. (sell lowest code pic) This print test did not work, instead it printed on every new bar.

In my opinion it's a bad idea to put a new bar check into a function, a function is used to make code reusable . . . try calling IsNewCandle() twice during the same first tick of a new bar and see what answers you get . . .

By the way . . . this is off topic for this thread, if you wish to continue the discussion please move it to a new thread. I'll tidy up later . .

 
WHRoeder:

....Since prices can only change by a multiple of point, point/2 is just that....


If you are comparing prices, fine. If you are comparing doubles however, e.g. averages of price, Point/2 wont do
 
HarriMQL4:

If you are comparing prices, fine. If you are comparing doubles however, e.g. averages of price, Point/2 wont do


Did you notice the title of this topic ?

;)

 
HarriMQL4:

If you are comparing prices, fine. If you are comparing doubles however, e.g. averages of price, Point/2 wont do
Prices are doubles . . .
Reason: