Download MetaTrader 5

why indicator line empty value ?

To add comments, please log in or register
joshatt
340
joshatt  

Hi,

I'm trying to write this indicator with 2 colors: up red, down white. But why the result is total empty?

//+------------------------------------------------------------------+
//|                                                       macdup.mq4 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#property indicator_color1 White
#property indicator_color2 Red

//---- input parameters
extern int fast_ema_period=12;
extern int slow_ema_period=26;
extern int signal_period=9;

double Ext1Buffer[];
double Ext2Buffer[];
double Ext3Buffer[];

#property indicator_separate_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexDrawBegin(0,slow_ema_period);
SetIndexDrawBegin(1,slow_ema_period);

//---- 4 indicator buffers mapping
   SetIndexBuffer(0,Ext1Buffer);
SetIndexBuffer(1,Ext2Buffer);


//---- drawing settings
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexStyle(1,DRAW_HISTOGRAM);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
  int tfup;
  switch(Period())
  {
  case 5:
    tfup = 30;
    break;
  case 15:
    tfup = 60;
    break;
  case 30:
    tfup = 240;
    break;
  case 60:
    tfup = 240;
    break;
  case 240:
    tfup = 1440;
    break; 
  default:
    tfup = 240;
    break;                 
  }
  
   int limit;
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//---- main loop

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

     Ext3Buffer[i]=iMACD(NULL, tfup, fast_ema_period, slow_ema_period, signal_period, PRICE_CLOSE,MODE_MAIN,i);
     }
     
      for( i=0; i<limit-1; i++)
     {
     if(Ext3Buffer[i]>Ext3Buffer[i+1])   
       {     Ext2Buffer[i]=Ext3Buffer[i];
             Ext1Buffer[i]=EMPTY_VALUE;
        }
     if(Ext3Buffer[i]<Ext3Buffer[i+1])   
       {     Ext1Buffer[i]=Ext3Buffer[i];
             Ext2Buffer[i]=EMPTY_VALUE;
        }       
     if(Ext3Buffer[i]==Ext3Buffer[i+1])   
       {     Ext2Buffer[i]=EMPTY_VALUE;
             Ext1Buffer[i]=EMPTY_VALUE;
        }       
       

     }  
//----
   return(0);
  }
//+------------------------------------------------------------------+
Tjipke de Vries
6362
Tjipke de Vries  
joshatt
340
joshatt  
Oh, I'm foolish. Thanks.
joshatt
340
joshatt  
Still empty line, must have another error. Any idea?
whroeder1
15326
whroeder1  
double Ext3Buffer[]; // not a buffer - no SetIndexBuffer
joshatt
340
joshatt  
WHRoeder:

Thanks for the help.

Yes, but Ext3Buffer[] is just a variable, not a line to draw.

Tjipke de Vries
6362
Tjipke de Vries  

your chartperiod is not the period you calculate ext3buffer

you're not using ibarshift to calculate the right value on each bar

there are more bars on chartperiod then you can calculate on tfup

whroeder1
15326
whroeder1  
joshatt: Yes, but Ext3Buffer[] is just a variable, not a line to draw.
     Ext3Buffer[i]=iMACD(NULL, tfup, fast_ema_period, slow_ema_period, signal_period, PRICE_CLOSE,MODE_MAIN,i);
  1. "[]" means it's a zero length array - no elements. It is not a auto sizing buffer and you don't give it a size with ArrayResize. You can NOT store anything in it. Make it a buffer. "#property indicator_buffers" tells how many buffers are drawn. IndicatorBuffers - MQL4 Documentation tells mql4 how many total you have.
  2. Like deVries said "i" is the index of your buffers of your charts timeframe. You can't use it in the iMACD call when tfup is NOT Period() or zero. Apples and Oranges
joshatt
340
joshatt  
WHRoeder:
  1. "[]" means it's a zero length array - no elements. It is not a auto sizing buffer and you don't give it a size with ArrayResize. You can NOT store anything in it. Make it a buffer. "#property indicator_buffers" tells how many buffers are drawn. IndicatorBuffers - MQL4 Documentation tells mql4 how many total you have.
  2. Like deVries said "i" is the index of your buffers of your charts timeframe. You can't use it in the iMACD call when tfup is NOT Period() or zero. Apples and Oranges


Wow, this corrects my several wrong thoughts in years.... I never really understood.

Many thanks, WHRoeder and deVries. I really appreciate it.

To add comments, please log in or register