Hi all!
I´ve been struggling to find out why my custom indicator is plotting "no sense" lines, even before any calculation.
To eliminate any problem on my locig, I created a new Indicator using the MQL5 Template, and set it up with no logic at all, just assigning a value to the buffer on rates_total -1.
It does reproduces the same behavior, plotting the lines way back on the chart, with crazy values on the buffer (see the image).
Does anyone has any idea on this issue?
Image and code attached.
To paste the code use or . DO NOT INSERT CODE AS A PICTURE!
Here is the code anyway
//+------------------------------------------------------------------+ //| Indicator_Test.mq5 | //| Copyright 2020, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2020, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property indicator_chart_window #property indicator_buffers 1 #property indicator_plots 1 //--- plot Buffer_Test #property indicator_label1 "Buffer_Test" #property indicator_type1 DRAW_LINE #property indicator_color1 clrWhite #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- indicator buffers double Buffer_TestBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,Buffer_TestBuffer,INDICATOR_DATA); //--- 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[]) { //--- Buffer_TestBuffer[rates_total-1]=95955; //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
Use:
//+------------------------------------------------------------------+ //| Indicator_Test.mq5 | //| Copyright 2020, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2020, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property indicator_chart_window #property indicator_buffers 1 #property indicator_plots 1 //--- plot Buffer_Test #property indicator_label1 "Buffer_Test" #property indicator_type1 DRAW_LINE #property indicator_color1 clrBlueViolet #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- indicator buffers double Buffer_TestBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,Buffer_TestBuffer,INDICATOR_DATA); //--- 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[]) { //--- int limit=prev_calculated-1; if(prev_calculated==0) limit=0; for(int i=limit; i<rates_total; i++) Buffer_TestBuffer[i]=high[i]; //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
Result:
Try this :
//+------------------------------------------------------------------+ //| Indicator_Test.mq5 | //| Copyright 2020, Republic Of Mars | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2020, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property indicator_chart_window #property indicator_buffers 1 #property indicator_plots 1 //--- plot Buffer_Test #property indicator_label1 "Buffer_Test" #property indicator_type1 DRAW_LINE #property indicator_color1 clrWhite #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- indicator buffers double Buffer_TestBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,Buffer_TestBuffer,INDICATOR_DATA); //--- 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[]) { int i_from=rates_total-2,i_diff=rates_total-prev_calculated,i_to=0; if(i_diff<=1){i_from=i_diff;} if(i_from<0){i_from=0;} for(int i=i_from;i>=i_to;i--) { int j=rates_total-i-1; //crude method if(ArrayGetAsSeries(Buffer_TestBuffer)&&ArrayGetAsSeries(high)){Buffer_TestBuffer[i]=high[i+1];} if(ArrayGetAsSeries(Buffer_TestBuffer)&&!ArrayGetAsSeries(high)){Buffer_TestBuffer[i]=high[j-1];} if(!ArrayGetAsSeries(Buffer_TestBuffer)&&ArrayGetAsSeries(high)){Buffer_TestBuffer[j]=high[i+1];} if(!ArrayGetAsSeries(Buffer_TestBuffer)&&!ArrayGetAsSeries(high)){Buffer_TestBuffer[j]=high[j-1];} } //You have zero values , and during plotting ,a line connects from that 0 value to your data //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
Thank you @Lorentzos Roussos and @Vladimir Karputov
With your examples I was able to better understant the issue and problem now is solved!
Appreciate your help on that!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi all!
I´ve been struggling to find out why my custom indicator is plotting "no sense" lines, even before any calculation.
To eliminate any problem on my locig, I created a new Indicator using the MQL5 Template, and set it up with no logic at all, just assigning a value to the buffer on rates_total -1.
It does reproduces the same behavior, plotting the lines way back on the chart, with crazy values on the buffer (see the image).
Does anyone has any idea on this issue?
Image and code attached.