Download MetaTrader 5

Histogram indicator problem

To add comments, please log in or register
How to earn at MQL5.community? Come and find out!
saklas
22
saklas 2013.12.14 10:32 

Hi, I want to make a series of indicators that will be presented as a histogram with three buffers (for long, short and range). I started with a simple one but it looks like I stuck. It is a simple MA. If close [i] is less than the value MA [i] then Sell [i] = 1. What is wrong in the code? Thank you.

the code:

#property  copyright ""
#property  link      ""
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 2
#property  indicator_color1  Blue
#property  indicator_color2  Red
#property  indicator_color3  Aqua
#property  indicator_width1 3
#property  indicator_width2 3
#property  indicator_maximum 1.25
#property  indicator_minimum -0.25

extern int    MAPeriod=50;

//---- indicator buffers
double     Buy[];
double     Sell[];
double     C[];
double     MA_buff[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   
   //---- drawing settings
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexStyle(1,DRAW_HISTOGRAM);

   SetIndexDrawBegin(0,MAPeriod);
   SetIndexDrawBegin(1,MAPeriod);
   
   SetIndexBuffer(0,Buy);
   SetIndexBuffer(1,Sell);
   SetIndexBuffer(2,C);
   SetIndexBuffer(3,MA_buff);

   IndicatorShortName("MA Lamp ("+MAPeriod+")");//+", "+Kijun+", "+Senkou+")");
   SetIndexLabel(0,"Buy");
   SetIndexLabel(1,"Sell");
//---- initialization done
   return(0);
  }

int start()
  {
   int counted_bars=IndicatorCounted();
   int limit,i;
   
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
           limit=Bars-counted_bars;

   for(i=0; i<limit; i++)
      {
      MA_buff[i]=iMA(NULL,0,MAPeriod,0,MODE_SMA,PRICE_CLOSE,i);
      C[i]=iClose(NULL,0,i);
      }          
   for(i=0; i<limit; i++)
     {
      if(C[i]>MA_buff[i])
        {
         Buy[i]=1;
         Sell[i]=0;
        }
      if(C[i]<MA_buff[i])
        {
         Sell[i]=1;
         Buy[i]=0;
        }
     }
   return(0);
  }
Ubzen
5394
Ubzen 2013.12.14 20:33  
saklas: Hi, I want to make a series of indicators that will be presented as a histogram with three buffers (for long, short and range). I started with a simple one but it looks like I stuck. It is a simple MA. If close [i] is less than the value MA [i] then Sell [i] = 1. What is wrong in the code? Thank you.
What is it suppose to be doing that its not? Histograms.
saklas
22
saklas 2013.12.15 07:26  
ubzen:
What is it suppose to be doing that its not? Histograms.
It was suppose to draw a bar blue if the close is above MA(25) and red if the close is below MA(25). however the problem is solved. thx
To add comments, please log in or register