Problem moving my indicator from MQL4

To add comments, please log in or register
dmdamiyo
74
dmdamiyo  

Hello, I have a problem with my indicator that I'm rewriting in MQL5.

I have 3 buffers with data, all are meant to display the same symbol (but in different color). The indicator is a separate window, and in MQL4 I was displaying all symbols at 0.0.

#property indicator_minimum -1
#property indicator_maximum 1
#property indicator_plots   3

#property indicator_buffers 3
#property indicator_color1 clrLawnGreen
#property indicator_color2 clrCrimson
#property indicator_color3 clrGold
#property indicator_type1   DRAW_ARROW 
#property indicator_type2   DRAW_ARROW 
#property indicator_type3   DRAW_ARROW 

And the buffers:

double arrowUp[];
double arrowDown[];
double arrowHorizontal[];
...

int OnInit()
  {
// Is it ok?
  SetIndexBuffer(0,arrowUp,INDICATOR_DATA);
   SetIndexBuffer(1,arrowDown,INDICATOR_DATA);
   SetIndexBuffer(2,arrowHorizontal,INDICATOR_DATA);
   PlotIndexSetInteger(0,PLOT_ARROW,143);
   PlotIndexSetInteger(1,PLOT_ARROW,143);
   PlotIndexSetInteger(2,PLOT_ARROW,143);
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,EMPTY_VALUE);

...


But when I test this indicator (with no real instructions yet!!!) I see all 3 colors displayed in the indicator window (I expected to see nothing in the window like in MQL4) and the value showed in Data Tester of Strategy window shows my buffers to be equal to 0.0. This is bad.

This is my onCalculate

if(prev_calculated==0)
    {
     ArrayInitialize(arrowUp,EMPTY_VALUE);
     ArrayInitialize(arrowDown,EMPTY_VALUE);
     ArrayInitialize(arrowHorizontal,EMPTY_VALUE);
    }
int limit=rates_total-prev_calculated;
for(int n=limit-1; n>=0; n--)
     {
// SO FAR NOTHING!
}

return(rates_total-1);

My indicator is meant to display a symbol in separate window. As you can see all 3 symbols are "DRAW_ARROW" and the symbol is the same - only the color is different. But in MQL4 I didn't see anything on the chart until I had arrowUp[n]=0/arrowDown[n]=0...

Could you help me?


This is what I see and from my code I would expect to see nothing at all... because my buffers hold EMPTY_VALUE:


Alain Verleyen
Moderator
35799
Alain Verleyen  
Attach the full code. Nothing bad in the snippets of code you posted.
dmdamiyo
74
dmdamiyo  
Alain Verleyen:
Attach the full code. Nothing bad in the snippets of code you posted.

Here it is. All 3 buffers are drawn for every bar at 0.0 (overlapping each other).

If I understand right 

PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,EMPTY_VALUE);

means that if the buffer nr.2 holds EMPTY_VALUE don't draw anything?


#property copyright "Copyright 2017, Damo"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
#property indicator_minimum -1
#property indicator_maximum 1
#property indicator_plots   3

#property indicator_buffers 3
#property indicator_color1 clrLawnGreen
#property indicator_color2 clrCrimson
#property indicator_color3 clrGold
#property indicator_type1   DRAW_ARROW 
#property indicator_type2   DRAW_ARROW 
#property indicator_type3   DRAW_ARROW 

double arrowUp[];
double arrowDown[];
double arrowHorizontal[];

int OnInit()
  {
   SetIndexBuffer(0,arrowUp,INDICATOR_DATA);
   SetIndexBuffer(1,arrowDown,INDICATOR_DATA);
   SetIndexBuffer(2,arrowHorizontal,INDICATOR_DATA);
   PlotIndexSetInteger(0,PLOT_ARROW,143);
   PlotIndexSetInteger(1,PLOT_ARROW,144);
   PlotIndexSetInteger(2,PLOT_ARROW,144);
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,EMPTY_VALUE);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
   if(prev_calculated==0)
     {
      ArrayInitialize(arrowUp,EMPTY_VALUE);
      ArrayInitialize(arrowDown,EMPTY_VALUE);
      ArrayInitialize(arrowHorizontal,EMPTY_VALUE);
     }

   int limit=rates_total-prev_calculated;
   for(int n=limit-1; n>=0; n--)
     {
         // Nothing yet, I guess it should start drawing
         // when I popluate ex. arrowUp[n]=0...
     }

   return(rates_total-1);
  }
Alain Verleyen
Moderator
35799
Alain Verleyen  
dmdamiyo:

Here it is. All 3 buffers are drawn for every bar at 0.0 (overlapping each other).

If I understand right 

means that if the buffer nr.2 holds EMPTY_VALUE don't draw anything?


No problem.


dmdamiyo
74
dmdamiyo  
Alain Verleyen:

No problem.



I run exactly the code I posted in the tester:


When I attach the indicator to a chart there is no problem, I see what you see. The problem appears in the tester (and I'm moving to MQL5 because of the tester, so I could test multitimeframe indicators etc. :))

So my problem appears in the tester - why?

Alain Verleyen
Moderator
35799
Alain Verleyen  
dmdamiyo:


I run exactly the code I posted in the tester:


When I attach the indicator to a chart there is no problem, I see what you see. The problem appears in the tester (and I'm moving to MQL5 because of the tester, so I could test multitimeframe indicators etc. :))

So my problem appears in the tester - why?

It you would have been more useful to say from the start it was with the tester.

Reason is you didn't set a value for new candles, so the value is unpredictable, usually 0, but could be any value stored in memory.

To add comments, please log in or register