Issue to plot value from my array in my indicator

 

Hi, 


I have create a new indicator, it is my first one and I have an issue to display the value in my chart.

The value is stock in my array  Buffer_yhat1 and the value comes from my function ->  nadaraya(close, ArraySize(close), h)

Can you help me ?

Here is the code : 


//------------------------------------------------------------------
#property copyright   "Vincent V."
#property link        ""
#property description "NW estimator"
#property version     "1.00"
//------------------------------------------------------------------

#property indicator_buffers 1 
#property indicator_plots    1

#property indicator_style1 STYLE_SOLID
#property indicator_color1   clrLime

#property indicator_chart_window

input int                inpBarsToCalculate = 500;
input float h   = 8.0; //Lookback Window         | The number of bars used for the estimation. This is a sliding value that represents the most recent historical bars. Recommended range: 3-50
input float r   = 8.0; //Relative Weighting      | Relative weighting of time frames. As this value approaches zero, the longer time frames will exert more influence on the estimation. As this value approaches infinity, the behavior of the Rational Quadratic Kernel will become identical to the Gaussian kernel. Recommended range: 0.25-25
input int   x_0 = 25 ; //Start Regression at Bar | Bar index on which to start regression. The first bars of a chart are often highly volatile, and omission of these initial bars often leads to a better overall fit. Recommended range: 5-25 
float bk = 0.0;
input ENUM_APPLIED_PRICE inpPrice           = PRICE_CLOSE; // Price

//--- indicator buffers
double Buffer_yhat1[];

//------------------------------------------------------------------
//
//------------------------------------------------------------------

int OnInit()
{
//--- indicator buffers mapping
   SetIndexBuffer(0,Buffer_yhat1);
   ArraySetAsSeries(Buffer_yhat1, true);

   return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason) { return; }

//------------------------------------------------------------------
//
//------------------------------------------------------------------
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 <= h) { return 0;}
   if(IsStopped()) return 0;
   int count = (prev_calculated == 0) ? (rates_total-h) : (rates_total - prev_calculated+1)
   double TempValue[];

   for (int i = count-1 ; i >= 0 ; i--)
   {
      Buffer_yhat1[i] = nadaraya(close, ArraySize(close), h);
      PrintFormat("RESULT : "+ nadaraya(close, ArraySize(close), h) + " ARRAY : " + ArraySize(Buffer_yhat1)  + " | " + Buffer_yhat1[i] );
   }

   return(rates_total);
}

//------------------------------------------------------------------
//                                                  
//------------------------------------------------------------------

double nadaraya(const double& src[], int _size, float _h)
{
       float _currentWeight = 0.0;
       float _cumulativeWeight = 0.0;
       double y = 0.0;
       double w = 0.0;
       float result = 0.0;  
       ArraySetAsSeries(src, true);

       for (int i = 0  ; i < _size ; i++){

           double y = src[i] ;
           int t =  _size + i * -1;
           float w = MathPow(1 + (MathPow(i, 2) / ((MathPow(h, 2) * 2 * 8.0))), -8.0);
           _currentWeight += y*w;
           _cumulativeWeight += w;
       }   
   return(NormalizeDouble(_currentWeight / _cumulativeWeight, _Digits));
}
Documentation on MQL5: Language Basics / Preprocessor / Program Properties (#property)
Documentation on MQL5: Language Basics / Preprocessor / Program Properties (#property)
  • www.mql5.com
Program Properties (#property) - Preprocessor - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Files:
 
Check your data window, if the values are showing.
 
Thank-god Avwerosuoghene Odukudu #:
Check your data window, if the values are showing.
Yes it shows but it looks like it calculate only from the bars when I open MT5.
 
#property indicator_style1 STYLE_SOLID
#property indicator_color1   clrLime
How about setting what you want to display
#property indicator_type1   DRAW_LINE
 
William Roeder #:
How about setting what you want to display

Hi William, 


Thanks for your Help. I have add your suggested property it works ! thank you. 

Reason: