Point() causing error

 

Hello,

I have a strange problem when I add Point() in code it causes buffers to disappear from candles for some candlesticks. When i remove point it works fine on all bar. How can i fix this?

//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2020, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#property copyright "MQ5, Copyright 2023"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2
//--- plot BUY
#property indicator_label1  "BUY"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrDeepSkyBlue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot SELL
#property indicator_label2  "SELL"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  clrOrangeRed
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1

input group             "Arrows"
input uchar                Inp_BUY_ArrowCode       = 116;      // Arrow 'BUY': code (font Wingdings)
input int                  Inp_BUY_ArrowShift      = 10;       // Arrow 'BUY': vertical shift in pixel
input uchar                Inp_SELL_ArrowCode      = 116;      // Arrow 'SELL': code (font Wingdings)
input int                  Inp_SELL_ArrowShift     = 10;       // Arrow 'SELL': vertical shift in pixel
//--- indicator buffers
double   BUYBuffer[];
double   SELLBuffer[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit() {
//--- indicator buffers mapping
   SetIndexBuffer(0,BUYBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,SELLBuffer,INDICATOR_DATA);
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
   PlotIndexSetInteger(0,PLOT_ARROW,Inp_BUY_ArrowCode);
   PlotIndexSetInteger(1,PLOT_ARROW,Inp_SELL_ArrowCode);
//--- set the vertical shift of arrows in pixels
   PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,Inp_BUY_ArrowShift);
   PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,-Inp_SELL_ArrowShift);
//--- an empty value for plotting, for which there is no drawing
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);
//---
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[]) {
//---
   if(rates_total<3)
      return(0);

   int limit=4;
   for(int i=0; i<limit; i++) {
      BUYBuffer[i]=0.0;
      SELLBuffer[i]=0.0;
   }
   for(int i=limit; i<rates_total; i++) {
      BUYBuffer[i]=0.0;
      SELLBuffer[i]=0.0;

      //when i remove point, it works fine for all bars
      if(close[i-1]==(open[i]+Point()) )
         BUYBuffer[i]=high[i];

      //--- Bearish
      if(close[i-1]==(open[i])-Point())//left
         SELLBuffer[i]=low[i];


   }
//--- return value of prev_calculated for next call
   return(rates_total);
}
//+------------------------------------------------------------------+

When Point is added on code

When Point is removed from code


 

Can price != price ?

The problem is not with Point(), but with how you compare these values

if(close[i-1]==(open[i]+Point()))
if(close[i-1]==(open[i])-Point())
Can price != price ? - I'm trying to understand something strange that I am seeing so I can better code in the future
Can price != price ? - I'm trying to understand something strange that I am seeing so I can better code in the future
  • 2011.12.08
  • www.mql5.com
I'm trying to understand something strange that i am seeing so i can better code round it in the future. I understand the idea behind your suggestions, thank you, but i think they may have negative effect on the readability of my code and hence the ease of modification in future
 
Vladislav Boyko #:

Can price != price ?

The problem is not with Point(), but with how you compare these values

Its still not working,

 
Arpit T #:

Its still not working,

What exactly is not working? Show your changes

 

Just typed (didn't compile or run):

for(int i=limit; i<rates_total; i++) {
      BUYBuffer[i]=0.0;
      SELLBuffer[i]=0.0;
      double closeNorm = NormalizeDouble(close[i-1], Digits());
      
      if(closeNorm==NormalizeDouble(open[i]+Point(), Digits()))
         BUYBuffer[i]=high[i];

      //--- Bearish
      if(closeNorm==NormalizeDouble(open[i]-Point(), Digits()))//left
         SELLBuffer[i]=low[i];
   }

This is the most primitive way. And this method is not the fastest.

You can Google something like "How to compare two float or double numbers".

I don't know why you didn't like this thread.

There's a ton of information in this post (and it's just one of 85 posts in this thread):

Forum on trading, automated trading systems and testing trading strategies

Can price != price ?

William Roeder, 2023.06.16 14:05

NormalizeDouble, It's use is usually wrong.

  1. Floating point has an infinite number of decimals, it's you were not understanding floating point and that some numbers can't be represented exactly. (like 1/10.)
              Double-precision floating-point format - Wikipedia, the free encyclopedia

    See also The == operand. - MQL4 programming forum (2013)

  2. Print out your values to the precision you want with DoubleToString - Conversion Functions - MQL4 Reference.

  3. SL/TP (stops) need to be normalized to tick size (not Point) — code fails on non-currencies.
              On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 programming forum #10 (2011)

    And abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 programming forum (2012)

  4. Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on non-currencies. So do it right.
              Trailing Bar Entry EA - MQL4 programming forum (2013)
              Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 programming forum (2012)

  5. Lot size must also be adjusted to a multiple of LotStep and check against min and max. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
              (MT4 2013)) (MT5 2022))

  6. MathRound() and NormalizeDouble() are rounding in a different way. Make it explicit.
              MT4:NormalizeDouble - MQL5 programming forum (2017)
              How to Normalize - Expert Advisors and Automated Trading - MQL5 programming forum (2017)

  7. Prices you get from the terminal are already correct (normalized).

  8. PIP, Point, or Tick are all different in general.
              What is a TICK? - MQL4 programming forum (2014)


 
Vladislav Boyko #:
NormalizeDouble(open[i]-Point(), Digits())

 Now i understand this, I was not Normalizing, Many thanks for your help on solving my question. 

Reason: