Error while using IndicatorDataBuffer passed into a ClassMethod()

 

Dear Fellows

I have created a custom Indicator iVSA, which uses CScanVSA.method to get DataBuffer values.

I need to lookback indicator buffers e.g. PreliminarySupply buffer to confirm BuyingClimax in CScanVSA. To achieve this I am using following Method to pass in BufferArrays to the Class.

void    UpdateData(const double &pBuffer_PS[],const double &pBuffer_SC[],const double &pBuffer_PSY[],const double &pBuffer_BC[],const int &pRatesTotal,int pIndex);

Now the error (rather a problem) I face is that pBuffer_PSY[i] EMPTY_VALUES are not recognized in CScanVSA.

void CScanVSA::UpdatePreliminaryStop(const int &pRatesTotal,const double &pBuffer_PS[],const double &pBuffer_PSY[]) {

                string vMethod = "[" + mSymbol + "," + EnumToString(mTimeFrame) + "] " + __FUNCTION__;

                int count    = 0;                                                                                              //Exit if 3 instances of Preliminary Stop have been found
                int lookBack = mIndex + 120;                                                                                   // Look back 120 bars (24 Hours * 5 Days)
                if(pRatesTotal < lookBack)                                                                                     return;
        //+---------------------------------------------------------------------------------------------------------------------------+

        //| Update Preliminary Support (Demand)
        //+---------------------------------------------------------------------------------------------------------------------------+
                ZeroMemory(mSOW_PSY);
                for(int i = mIndex; i < lookBack; i++) {

                        if(pBuffer_PSY != DBL_MAX || pBuffer_PSY[i] != EMPTY_VALUE) {
                                mSOW_PSY.found = true;                                                                          count++;
                                if(DoPrint) PrintFormat("%s [%s] Index[%i] < LookBack[%i] count[%i] PSY EmptyValue[%i][%s]",vMethod,mIndexTime,i,lookBack,count,i,(string)(pBuffer_PSY[i]==EMPTY_VALUE));

                                if(count == 1) {                                
                                        //if(DoPrint) PrintFormat("%s [%s] Preliminary Supply found at Index[%i] < LookBack[%i] count[%i] PSY[%i][%i][%i] [%.1f]",vMethod,mIndexTime,i,lookBack,count,mSOW_PSY.idxC,mSOW_PSY.idxB,i,pBuffer_PSY[i]);
                                        mSOW_PSY.idxA   = i;                                                                    mSOW_PSY.count = count;
                                        continue;                                                                               //First  PSupply Index, continue to next index in loop
                                }
                                if(count == 2) {
                                        //if(DoPrint) PrintFormat("%s [%s] Preliminary Supply found at Index[%i] < LookBack[%i] count[%i] PSY[%i][%i][%i] [%.1f]",vMethod,mIndexTime,i,lookBack,count,mSOW_PSY.idxC,i,mSOW_PSY.idxA,pBuffer_PSY[i]);
                                        mSOW_PSY.idxB   = i;                                                                    mSOW_PSY.count = count;
                                        continue;                                                                               // Second PSupply Index, continue to next index in loop
                                }
                                if(count == 3) {
                                        //if(DoPrint) PrintFormat("%s [%s] Preliminary Supply found at Index[%i] < LookBack[%i] count[%i] PSY[%i][%i][%i] [%.1f]",vMethod,mIndexTime,i,lookBack,count,i,mSOW_PSY.idxB,mSOW_PSY.idxA,pBuffer_PSY[i]);
                                        mSOW_PSY.idxC   = i;                                                                    mSOW_PSY.count = count;
                                        break;                                                                                  // Third  PSupply Index, exit the loop
                                }
                        }
                }
        //+---------------------------------------------------------------------------------------------------------------------------+

} // End of function UpdatePreliminaryStop()
// In Indicator cScanVSA.SOW_PreliminarySupply() returned 'false' and buffer stored as EMPTY_VALUE at index[119]
SOW_PSY[i] = cScanVSA.SOW_PreliminarySupply()	? high[i] : EMPTY_VALUE;
if(DoPrint)		 PrintFormat("%s [%s] SOW_PreliminarySupply[%i][%s] SOW_PSY[%i][%.1f]",vMethod,mIndexTime,i,(string)cScanVSA.SOW_PreliminarySupply(),i,SOW_PSY[i]);
2023.09.22 19:59:55.694 iVSA (US30,H1)  [US30,PERIOD_H1] OnCalculate [2023.09.15 13:00] cScanVSA.SOW_PreliminarySupply[119][false] SOW_PSY[119][179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0]

// CScanVSA if(pBuffer_PSY[i] != EMPTY_VALUE) condition was passed, yet the BufferSOW_PSY passed in has EMPTY_VALUE on index 119. (I have used ArraySetAsSeried(SOW_PSY,true) ... still the same problem)
2023.09.22 19:59:55.694 iVSA (US30,H1)  [US30,PERIOD_H1] CScanVSA::UpdatePreliminaryStop [2023.09.15 13:00] Index[119] < LookBack[239] count[1] PSY EmptyValue[119][false] // This index has EMPTY_VALUE
2023.09.22 19:59:55.694 iVSA (US30,H1)  [US30,PERIOD_H1] CScanVSA::UpdatePreliminaryStop [2023.09.15 13:00] Index[120] < LookBack[239] count[2] PSY EmptyValue[120][false] // This index has EMPTY_VALUE
2023.09.22 19:59:55.694 iVSA (US30,H1)  [US30,PERIOD_H1] CScanVSA::UpdatePreliminaryStop [2023.09.15 13:00] Index[121] < LookBack[239] count[3] PSY EmptyValue[121][false] // This index has EMPTY_VALUE

I have failed to identify the reason, why if(pBuffer_PSY[i] != DBL_MAX || pBuffer_PSY[i] != EMPTY_VALUE) { } is not able to recognize the EMPTY_VALUE in passed in buffer.

It looks pBuffer_PSY[] is having Zero value for all indexs Even on Index where it is supposed to have Bar's High value!!! Now since (0.00 != EMPTY_VALUE) it pass the if condition.

2023.09.22 21:19:14.459 iVSA (US30,H1)  [US30,PERIOD_H1] CScanVSA::UpdatePreliminaryStop [2023.09.15 13:00] rates_total[36692] ArraySize[36692] Index[158] < LookBack[240] count[39] PSY[0.0] EmptyValue[158][false]
2023.09.22 21:19:14.459 iVSA (US30,H1)  [US30,PERIOD_H1] CScanVSA::UpdatePreliminaryStop [2023.09.15 13:00] rates_total[36692] ArraySize[36692] Index[159] < LookBack[240] count[40] PSY[0.0] EmptyValue[159][false]
2023.09.22 21:19:14.459 iVSA (US30,H1)  [US30,PERIOD_H1] CScanVSA::UpdatePreliminaryStop [2023.09.15 13:00] rates_total[36692] ArraySize[36692] Index[160] < LookBack[240] count[41] PSY[0.0] EmptyValue[160][false]

Support from members to debug the matter, is highly appreciated.

Thanks in Advance.

Regards

Averaging Price Series for Intermediate Calculations Without Using Additional Buffers
Averaging Price Series for Intermediate Calculations Without Using Additional Buffers
  • www.mql5.com
This article is about traditional and unusual algorithms of averaging packed in simplest and single-type classes. They are intended for universal usage in almost all developments of indicators. I hope that the suggested classes will be a good alternative to 'bulky' calls of custom and technical indicators.
 

Your code shows :

pBuffer_PSY != DBL_MAX
 
Alain Verleyen #:

Your code shows :

Hi @Alain Verleyen

Yeh I am trying options such as pBuffer_PSY[i] (it was a typo) != DBL_MAX or pBuffer_PSY[i] != EMPTY_VALUE.

Problem looks to be the whole array contains Zero Values, and not EMPTY_VALUES. Which is confirmed by pBuffer_PSY[i] != 0.00, than loop does not pass.

2023.09.22 21:19:14.459 iVSA (US30,H1)  [US30,PERIOD_H1] CScanVSA::UpdatePreliminaryStop [2023.09.15 13:00] rates_total[36692] ArraySize[36692] Index[158] < LookBack[240] count[39] PSY[0.0] EmptyValue[158][false]
2023.09.22 21:19:14.459 iVSA (US30,H1)  [US30,PERIOD_H1] CScanVSA::UpdatePreliminaryStop [2023.09.15 13:00] rates_total[36692] ArraySize[36692] Index[159] < LookBack[240] count[40] PSY[0.0] EmptyValue[159][false]
2023.09.22 21:19:14.459 iVSA (US30,H1)  [US30,PERIOD_H1] CScanVSA::UpdatePreliminaryStop [2023.09.15 13:00] rates_total[36692] ArraySize[36692] Index[160] < LookBack[240] count[41] PSY[0.0] EmptyValue[160][false]

I am not sure why the array is passed in with Zero values.

I can not use CopyBuffer() as the CScanVSA itself supplies data to the indicator. iVSA include this class 

#include  "..\\..\\..\\Experts\\AlgoBulls\\Includes\\CScanner\\ScanVSA.mqh"
CScanVSA                                                                                                                                *cScanVSA;

When I use if(pBuffer_PSY[i] != 0.00 || pBuffer_PSY[i] != EMPTY_VALUE) { } than it returns the following

2023.09.22 21:49:46.967 iVSA (US30,H1)  [US30,PERIOD_H1] CScanVSA::UpdatePreliminaryStop [2023.09.15 13:00] rates_total[36693] ArraySize[36693] Index[159] < LookBack[241] count[39] PSY[0.0] EmptyValue[159][false] // if not EMPTY_VALUE than what is the value here?
2023.09.22 21:49:46.967 iVSA (US30,H1)  [US30,PERIOD_H1] CScanVSA::UpdatePreliminaryStop [2023.09.15 13:00] rates_total[36693] ArraySize[36693] Index[160] < LookBack[241] count[40] PSY[0.0] EmptyValue[160][false]
2023.09.22 21:49:46.967 iVSA (US30,H1)  [US30,PERIOD_H1] CScanVSA::UpdatePreliminaryStop [2023.09.15 13:00] rates_total[36693] ArraySize[36693] Index[161] < LookBack[241] count[41] PSY[0.0] EmptyValue[161][false]

I am confused a lot now !!!

How can I print correct value of pBuffer_PSY[idxN] !!! 

 
Anil Varma #:
if(pBuffer_PSY[i] != 0.00 || pBuffer_PSY[i] != EMPTY_VALUE) { }
This condition is always true, should be "and" and not "or".
 
Alain Verleyen #:
This condition is always true, should be "and" and not "or".

Thanks @Alain Verleyen

Yeh replacing with 'and' worked out.

Now the problem is array returns 'Zero value' for all indexes, so the if condition never fulfills. :(

What could be alternate way to pass in the DataBufferArray to the Class? As this way seems having problem.

Seems I am exhausted now for almost 13 hours on screen. We try again tomorrow with fresh mind.

Update: I figured it out Alan, I was using reverse loop in the Indicator, so prior values are always zero :)

Thanks again for your direction.
 
Anil Varma #:

Thanks @Alain Verleyen

Yeh replacing with 'and' worked out.

Now the problem is array returns 'Zero value' for all indexes, so the if condition never fulfills. :(

What could be alternate way to pass in the DataBufferArray to the Class? As this way seems having problem.

Seems I am exhausted now for almost 13 hours on screen. We try again tomorrow with fresh mind.

Update: I figured it out Alan, I was using reverse loop in the Indicator, so prior values are always zero :)

Thanks again for your direction.
Very good. You are most welcome.
Reason: