indicator not showing

samjesse

Active Trader
Aug 30, 2011
118
0
27
Hi

I am not getting my indicator on the screen when I compile and run the code below. do I need to drag it to a chart or to id a window?
Please take a look to see if all else is Ok. :)

thx

MQL5:
#property description "stoch_change"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
#property indicator_type1   DRAW_LINE
#property indicator_style1  STYLE_SOLID
#property indicator_color1  Blue
 
//--- indicator
double rlBuffer [300];
 
int OnInit()
  {
// a class here populates the rlBuffer
   return(0);
  }
 
int OnCalculate(const int rates_total,
...
  {
   SetIndexBuffer(0,rlBuffer,INDICATOR_DATA);
 
Last edited by a moderator:

samjesse

Active Trader
Aug 30, 2011
118
0
27
SetIndexBuffer(0,rlBuffer,INDICATOR_DATA); should go into OnInit() handler. You should be filling the array (rlBuffer) with actual indicator values in the OnCalculate().

thanks for that.
Why this is not plotting as expected?

MQL5:
#property description "test"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
#property indicator_type1   DRAW_LINE
#property indicator_style1  STYLE_SOLID
#property indicator_color1  Blue
 
double iBuf[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
    SetIndexBuffer(0,iBuf,INDICATOR_DATA);
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//---
   iBuf[0] = high[0];
   iBuf[1] = high[1];
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+---------------------------------------
 
Last edited by a moderator:

samjesse

Active Trader
Aug 30, 2011
118
0
27
iBuf[0] is the oldest bar on the chart in MetaTrader 5 (unless you use ArraySetAsSeries() on it), not the newest. So, are you sure it's not plotting?

I tried to populate the indicator buffer in OnInt() since the markets are closed and OnCalculate will not fire but I am not getting the indicator to show

GBPJPY H4


MQL5:
//+------------------------------------------------------------------+
//|                                                         test.mq5 |
//|                                             Copyright 2011, titi |
//|                                     http://www.test.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2011, test"
#property link      "http://www.test.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_label1  "alosh"
#property indicator_type1   DRAW_LINE
#property indicator_color1  Red
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
 
double iBuf[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
    SetIndexBuffer(0,iBuf,INDICATOR_DATA);
    ArraySetAsSeries(iBuf, true);
 
    iBuf[0] = 123.200;  
    iBuf[1] = 123.200;
 
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//---
    iBuf[0] = 123.200;  
    iBuf[1] = 123.200;
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
Last edited by a moderator:

samjesse

Active Trader
Aug 30, 2011
118
0
27
thx for that. I got it to work, now I tired to modify it with my "real" indicator but this is not plotting. Please take another look :) thx

MQL5:
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_label1  "alosh"
#property indicator_type1   DRAW_LINE
#property indicator_color1  Red
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
 
   double rlBuffer [300];
   CLASS_TYPE h4_alosh("GBPJPY", PERIOD_H4); 
 
 
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,rlBuffer,INDICATOR_DATA);
   ArrayInitialize(rlBuffer,EMPTY_VALUE);
   h4_alosh.set_SOMTHIN();
   h4_alosh.set_ANOTHER();     
 
//---
   return(0);
  }
 
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[])
  {
   h4_alosh.get_POPULATE_INDICATOR(2, rlBuffer, false);    
ushort n = ArraySize(rlBuffer)-1; for(ushort i=0; i<=50; i++) Alert("index, value=== " + i + "        " +rlBuffer[i]); //n-i
 
// YES IT PRINTED THE VALUES SUITABLE FOR PLOTTING.
 
//--- return value of prev_calculated for next call
   return(rates_total);
  }
 
Last edited by a moderator:

samjesse

Active Trader
Aug 30, 2011
118
0
27
Indicator data array should be dynamic. .... Hope that helps.

Well.
Yes and No.
thanks for that.

this code I am writing for an EA but want to see it on the screen while I am developing it.
Static Array is very lean/cheap comparing to dynamic ones when running. Now what would I do to have my cake and eat it at the same time? :D

Will typecasting help? i.e. by CopyBuffer for the indicator and leave it static for the EA?

OnCalculate()...

ArrayCopy(indicator_Buf, static_rlBuffer, 0, 0, WHOLE_ARRAY);
 
Last edited:

samjesse

Active Trader
Aug 30, 2011
118
0
27
I tried to test it myself but it gives strange information.

MQL5:
//--- in the code heading
   double iBuf[];
 
//---  in OnCalculate
 
   Alert(ArrayIsDynamic(iBuf));    //<<<<<<< FALSE <<<< WHY <<<<<
   ArrayCopy(iBuf, rlBuffer, 0, 0, WHOLE_ARRAY);
   Alert(ArrayIsDynamic(iBuf));     //<<<<<<< FALSE <<<< WHY <<<<<
 
Last edited by a moderator:

Enivid

Administrator
Staff member
Nov 30, 2008
16,141
838
144
Odessa
www.earnforex.com
Well.
this code I am writing for an EA but want to see it on the screen while I am developing it.
Static Array is very lean/cheap comparing to dynamic ones when running. Now what would I do to have my cake and eat it at the same time? :D

Will typecasting help? i.e. by CopyBuffer for the indicator and leave it static for the EA?

OnCalculate()...

ArrayCopy(indicator_Buf, static_rlBuffer, 0, 0, WHOLE_ARRAY);

Wouldn't it more correct to create an indicator and load it with iCustom() to your EA? Then you can just add them both to the chart and see how they work.

I tried to test it myself but it gives strange information.

MQL5:
//--- in the code heading
   double iBuf[];
 
//---  in OnCalculate
 
   Alert(ArrayIsDynamic(iBuf));    //<<<<<<< FALSE <<<< WHY <<<<<
   ArrayCopy(iBuf, rlBuffer, 0, 0, WHOLE_ARRAY);
   Alert(ArrayIsDynamic(iBuf));     //<<<<<<< FALSE <<<< WHY <<<<<

No idea. Looks like a bug of ArrayIsDynamic().
 
Last edited: