Calling the data of the custom indicator, why is the data 2147483647?

 

I wrote a custom indicator and it works fine. I want to implement automatic placing of orders through EA calls, but I always cannot get the correct indicator value.

void OnTick()
  {
//---
   //printf("0.time: "+time);
   //printf("0.Time[0]: "+Time[0]);
   if(TimeCurrent()==Time[0])
   //if(time!=Time[0])
   {
      //time=Time[0];
      double CusIndi_high_0=iCustom(NULL,0,"High_Low_Price",1300,0,0);
      printf("1.CusIndi_high_0: "+CusIndi_high_0);
      double CusIndi_high_1=iCustom(NULL,0,"High_Low_Price",1300,0,1);
      printf("1.CusIndi_high_1: "+CusIndi_high_1);
      double CusIndi_low_0=iCustom(NULL,0,"High_Low_Price",1300,1,0);
      double CusIndi_low_1=iCustom(NULL,0,"High_Low_Price",1300,1,1);
...

When debugging the strategy, the values obtained were not what I expected.

2023.05.02 19:00:00  test_EA_000 XAUUSD,H1: 1.CusIndi_high_0: 2147483647
2023.05.02 19:00:00  test_EA_000 XAUUSD,H1: 1.CusIndi_high_1: 2147483647

In the data window, you can see the two output items of the custom indicator, but the values are empty.

I checked other posts with the same problem and it seems to be a for loop problem.

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[])
  {
//---
   int bars;
   if(prev_calculated==0)
   {
      bars=rates_total-1;
   }
   else
   {
      bars=rates_total-prev_calculated;
   }
   if(bars<=count) return(0);
   ArraySetAsSeries(high10,true);
   ArraySetAsSeries(low10,true);
   for(int i=0;i<bars;i++)
   {
      CopyHigh(Symbol(),0,i,count,high10);
      CopyLow(Symbol(),0,i,count,low10);
      ArraySort(high10,WHOLE_ARRAY,0,MODE_DESCEND);
      ArraySort(low10);
      high10Buffer[i]=high10[count/100];
      low10Buffer[i]=low10[count/100];
   }
//--- return value of prev_calculated for next call
   return(rates_total);
  }

But how should it be modified?



Step on New Rails: Custom Indicators in MQL5
Step on New Rails: Custom Indicators in MQL5
  • www.mql5.com
I will not list all of the new possibilities and features of the new terminal and language. They are numerous, and some novelties are worth the discussion in a separate article. Also there is no code here, written with object-oriented programming, it is a too serous topic to be simply mentioned in a context as additional advantages for developers. In this article we will consider the indicators, their structure, drawing, types and their programming details, as compared to MQL4. I hope that this article will be useful both for beginners and experienced developers, maybe some of them will find something new.
 
Tancy W:

I wrote a custom indicator and it works fine. I want to implement automatic placing of orders through EA calls, but I always cannot get the correct indicator value.

When debugging the strategy, the values obtained were not what I expected.

In the data window, you can see the two output items of the custom indicator, but the values are empty.

I checked other posts with the same problem and it seems to be a for loop problem.

But how should it be modified?



There is a value INT_MAX = Maximal value, which can be represented by int type = 2147483647 = EMPTY_VALUE
Try to reason and learn.

 
Tancy W: why is the data 2147483647? why is the data 2147483647?
EMPTY Value
List of MQL4 Constants - MQL4 Reference
List of MQL4 Constants - MQL4 Reference
  • docs.mql4.com
List of MQL4 Constants - MQL4 Reference
 
William Roeder #:
EMPTY Value
I know that is a null value, I want to know why there is a null value, what is the reason? How to fix it. Because there is no problem with loading my indicator alone, there should be no problem with calling the instruction of the indicator. How can I get the correct result I want? Thank you so much.
 
Tancy W: it seems to be a for loop problem.
      bars=rates_total-prev_calculated;
   }
   if(bars<=count) return(0);
  1. After the first run (where prev_calculated is zero), bars will be zero and the code doesn't do anything.

    Do your lookbacks correctly #9#14 & #19. (2016)

  2. No need for the (slow) sort. Just find the min/max (faster).

Reason: