How is this physically possible? - page 2

To add comments, please log in or register
Alain Verleyen
39026
Alain Verleyen  
calioranged:

Now the problem is reoccurring!

I closed MT5 and then reloaded, and the lines reappeared... in totally different places.

I have also just typed out another blank custom indicator that only has the properties included, exactly the same problem with this program too, here is a screenshot:


It's probably due to :

#property indicator_buffers 2
#property indicator_plots 2

You declared 2 buffers/plots, so the memory is reserved, but you don't initialize them or anything, so they got random contents.

calioranged
45
calioranged  
Alain Verleyen:

It's probably due to :

You declared 2 buffers/plots, so the memory is reserved, but you don't initialize them or anything, so they got random contents.

If this is the case then surely the problem could be reproduced on your system... but you said you were unable to, which makes me think something has gone seriously wrong with mine. 

Even with SetIndexBuffer added the problem still occurs.

Marco vd Heijden
Moderator
12472
Marco vd Heijden  
You could try to set all buffer values to EMPTY_VALUE or at least make an attempt initializing them properly else it would just plot residual memory junk.
Ilham Djumatov
498
Ilham Djumatov  
I agree with Alain and Marco, you should initialize buffers properly.
Also to add up, I'd like to emphasize that you must set each elemet inside the buffer to either EMPTY_VALUE or 0.0 depending on your plot type whenever you receive prev_calculated 0.
Believe me, I've fought this issue for a really long time, and it took me a lot of debugging.
Alain Verleyen
39026
Alain Verleyen  
calioranged:

If this is the case then surely the problem could be reproduced on your system... but you said you were unable to, which makes me think something has gone seriously wrong with mine. 

Even with SetIndexBuffer added the problem still occurs.

No it depends of available memory and usage. It's random because the memory reserved is not initialized, on my side memory is empty so nothing show, on your side there are some "old" data so it draws them. Either don't use unneeded buffers or initialize them.
calioranged
45
calioranged  
Alain Verleyen:
No it depends of available memory and usage. It's random because the memory reserved is not initialize, on my side memory is empty so nothing show, on your side there are some "old" data so it draws them. Either don't use unneeded buffers or initialize them.

Okay thank you.

koranged
448
koranged  

I have managed to eradicate most of the problems that were occurring yesterday, but I am still having some issues with the buffers printing 'old data', despite the buffers all being properly initialised from the first compile. 

The indicator in the picture below works fine, except for at the start of each line printing where some totally random stuff is still happening. In the picture below, the arrow points to the random data that the indicator is still drawing.

I have installed a totally separate version of the MT5 client terminal and compiled the code to run on this new terminal, and unfortunately, the issue still occurs.

I am a bit lost in terms of trying to figure out what exactly I am doing (or what I am not doing), which is causing this error. 

I have posted the code underneath the below screenshot, if anyone is able to advise on possible issues inside the program which may be causing this random plotting, or  if somebody can just compile this on their terminal and see if they get the same result it would be greatly appreciated.

EDIT: If I compile the program whilst it is still attached to the chart, SOME of the lines disappear. Vertical lines remain in position of the first plotted element.


//+------------------------------------------------------------------+
//|                                                         Test.mq5 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_plots 3
// Senkouspan_B
#property indicator_type1  DRAW_LINE
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
#property indicator_color1 LightCoral
#property indicator_label1 "Senkouspan_B"
// Tenkansen
#property indicator_type2  DRAW_LINE
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
#property indicator_color2 Blue
#property indicator_label2 "Tenkansen"
// Kijunsen
#property indicator_type3  DRAW_LINE
#property indicator_style3 STYLE_SOLID 
#property indicator_width3 1
#property indicator_color3 Red
#property indicator_label3 "Kijunsen"
// Constants
extern int Period_1 = 18;
extern int Period_2 = 52;
extern int Period_3 = 104;
// Variables
double Highest;
double Lowest;
double Tenkansen[];
double Kijunsen[];
double Senkouspan_B[];
// double Senkouspan_A[];
int i;
int Limit_1;
int Limit_2;
int Limit_3;
int Count=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   SetIndexBuffer(0,Senkouspan_B,INDICATOR_DATA);
   SetIndexBuffer(1,Tenkansen,INDICATOR_DATA);
   SetIndexBuffer(2,Kijunsen,INDICATOR_DATA);          
   ArraySetAsSeries(Senkouspan_B,true);
   ArraySetAsSeries(Tenkansen,true);
   ArraySetAsSeries(Kijunsen,true);
   PlotIndexSetInteger(0,PLOT_SHIFT,Period_2);        // Shift senkouspans forward 52 bars
   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[])
  {
   // index of first tenkansen line
   Limit_1 = rates_total - Period_1;
   // index of first kijunsen line
   Limit_2 = rates_total - Period_2;
   // index of first senkouspan_b line
   Limit_3 = rates_total - Period_3; 
   //-------------------------------
   if(prev_calculated==0)
      i = Limit_1;
   else
      i = rates_total - prev_calculated;
   
   while(i>=0)
      {
      Tenkansen[i]       = KTsen(Period_1); // 18  period lookback
      if(i<=Limit_2)
         Kijunsen[i]     = KTsen(Period_2); // 52  period lookback  
      if(i<=Limit_3)
         Senkouspan_B[i] = KTsen(Period_3); // 104 period lookback       
      i--;
      }
   
   return(rates_total);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+  
double KTsen(double Lookback)
   {
   for(int j=i; j<i+Lookback; j++)
      {
      double High = iHigh(_Symbol,_Period,j);
      double Low  = iLow(_Symbol,_Period,j);
      if(High>Highest)
         Highest = High;
      if(Low<Lowest)
         Lowest  = Low;   
      }
      double Temp = (Highest + Lowest) / 2;
      Highest = 0;
      Lowest  = 1000.0;
      return(Temp);
   }  
//+------------------------------------------------------------------+
Alain Verleyen
39026
Alain Verleyen  
koranged:

I have managed to eradicate most of the problems that were occurring yesterday, but I am still having some issues with the buffers printing 'old data', despite the buffers all being properly initialised from the first compile. 

...

Wrong. Your buffers are not initialized at all.

if(prev_calculated==0)
  {
   ArrayInitialize(your_buffer,EMPTY_VALUE);
   ...
   i=Limit_1;
  }
else
   i=rates_total-prev_calculated;
koranged
448
koranged  
Alain Verleyen:

Wrong. Your buffers are not initialized at all.

Ah. I wasn't aware of this function. By 'initialise' I thought you meant using SetIndexBuffer in OnInit(). 

The documentation states that "The function initializes a numeric array by a preset value." - why do we need to do this? I apoligise if my questions sound silly, I understand that this is probably why my program is failing but I just don't really understand how setting all the elements to empty value 'initialises' the array. Would you mind explaining this a bit further? Again I apologise if my question sounds silly I just can't really get my head around it. Thanks.

koranged
448
koranged  

And I'm still having random lines appear on the chart even after using that function. I have deleted and removed the program from the recycle bin, then retyped the whole program out, with ArrayInitialize added, pressed compile ONCE, and I'm still getting three vertical lines on the chart where each line starts printing. 


123
To add comments, please log in or register