Multi Heikin Ashi Smoothed in one indicator

 

Hi all,

I'm very new to MQL4 programming. Still learning and looking how to make some indicator for my own use. I face difficulty when creating multi Heikin Ashi Smoothed indicator.

 Below is my code for the indicator. After I compile, it can only see MAPeriod1 only. If I can MAPeriod1 style to LINE. then I can see MAPeriod2 only. Any possible way to make 3 MAPeriod to show in chart?

 

#property indicator_chart_window

#property indicator_buffers 13

#property indicator_color1 DarkViolet

#property indicator_color2 Aqua

#property indicator_color3 DarkViolet

#property indicator_color4 Aqua

#property indicator_color5 Gold

#property indicator_color6 DarkViolet

#property indicator_color7 Aqua

#property indicator_color8 DarkViolet

#property indicator_color9 Aqua

#property indicator_color10 DarkViolet

#property indicator_color11 Aqua

#property indicator_color12 DarkViolet

#property indicator_color13 Aqua

#property indicator_width1 1

#property indicator_width2 1

#property indicator_width3 4

#property indicator_width4 4

#property indicator_width5 1

#property indicator_width6 1

#property indicator_width7 1

#property indicator_width8 4

#property indicator_width9 4

#property indicator_width10 1

#property indicator_width11 1

#property indicator_width12 4

#property indicator_width13 4

//----

extern int     MAPeriod1    = 10;

extern int     MAPeriod2    = 40;

extern int     MAPeriod3    = 80;

extern int     MAReference  = 200;

extern bool    EnableShadow = False;

extern string  strType    = "Moving Average Types:";

extern string  strm0      = "0 = SMA,  1 = EMA";

extern string  strm1      = "2 = SMMA, 3 = LWMA";

extern int     MAType     = 0;

extern color color1 = DarkViolet;

extern color color2 = Aqua;

extern color color3 = DarkViolet;

extern color color4 = Aqua;

extern color color5 = Gold;



//---- buffers

double ExtMapBuffer1[];

double ExtMapBuffer2[];

double ExtMapBuffer3[];

double ExtMapBuffer4[];

double ExtMapBuffer5[];

double ExtMapBuffer6[];

double ExtMapBuffer7[];

double ExtMapBuffer8[];

double ExtMapBuffer9[];

double ExtMapBuffer10[];

double ExtMapBuffer11[];

double ExtMapBuffer12[];

double ExtMapBuffer13[];

//----

int ExtCountedBars1 = 0;

//int MAType = 0;



//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//|------------------------------------------------------------------|

int init()

{

//---- indicators

//MA Period 1

   SetIndexStyle(0, DRAW_LINE, 0, 1, color1);

   SetIndexBuffer(0, ExtMapBuffer1);

   SetIndexStyle(1, DRAW_LINE, 0, 1, color2);

   SetIndexBuffer(1, ExtMapBuffer2);

   SetIndexStyle(2, DRAW_HISTOGRAM, 0, 4, color3);

   SetIndexBuffer(2, ExtMapBuffer3);

   SetIndexStyle(3, DRAW_HISTOGRAM, 0, 4, color4);

   SetIndexBuffer(3, ExtMapBuffer4);

   SetIndexStyle(4, DRAW_LINE, 0, 1, color5);

   SetIndexBuffer(4, ExtMapBuffer5);

//MA Period 2

   SetIndexStyle(5, DRAW_LINE, 0, 1, color1);

   SetIndexBuffer(5, ExtMapBuffer6);

   SetIndexStyle(6, DRAW_LINE, 0, 1, color2);

   SetIndexBuffer(6, ExtMapBuffer7);

   SetIndexStyle(7, DRAW_HISTOGRAM, 0, 4, color3);

   SetIndexBuffer(7, ExtMapBuffer8);

   SetIndexStyle(8, DRAW_HISTOGRAM, 0, 4, color4);

   SetIndexBuffer(8, ExtMapBuffer9);

//MA Period 3

   SetIndexStyle(9, DRAW_LINE, 0, 1, color1);

   SetIndexBuffer(9, ExtMapBuffer10);

   SetIndexStyle(10, DRAW_LINE, 0, 1, color2);

   SetIndexBuffer(10, ExtMapBuffer11);

   SetIndexStyle(11, DRAW_HISTOGRAM, 0, 4, color3);

   SetIndexBuffer(11, ExtMapBuffer12);

   SetIndexStyle(12, DRAW_HISTOGRAM, 0, 4, color4);

   SetIndexBuffer(12, ExtMapBuffer13);

//----

//MA Period 1

   SetIndexDrawBegin(0, MAPeriod1);

   SetIndexDrawBegin(1, MAPeriod1);

   SetIndexDrawBegin(2, MAPeriod1);

   SetIndexDrawBegin(3, MAPeriod1);

   SetIndexDrawBegin(4, MAReference);

//MA Period 2

   SetIndexDrawBegin(5, MAPeriod2);

   SetIndexDrawBegin(6, MAPeriod2);

   SetIndexDrawBegin(7, MAPeriod2);

   SetIndexDrawBegin(8, MAPeriod2);

//MA Period 3

   SetIndexDrawBegin(9, MAPeriod3);

   SetIndexDrawBegin(10, MAPeriod3);

   SetIndexDrawBegin(11, MAPeriod3);

   SetIndexDrawBegin(12, MAPeriod3);

//---- indicator buffers mapping

   SetIndexBuffer(0,ExtMapBuffer1);

   SetIndexBuffer(1,ExtMapBuffer2);

   SetIndexBuffer(2,ExtMapBuffer3);

   SetIndexBuffer(3,ExtMapBuffer4);

   SetIndexBuffer(4,ExtMapBuffer5);

   SetIndexBuffer(5,ExtMapBuffer6);

   SetIndexBuffer(6,ExtMapBuffer7);

   SetIndexBuffer(7,ExtMapBuffer8);

   SetIndexBuffer(8,ExtMapBuffer9);

   SetIndexBuffer(9,ExtMapBuffer10);

   SetIndexBuffer(10,ExtMapBuffer11);

   SetIndexBuffer(11,ExtMapBuffer12);

   SetIndexBuffer(12,ExtMapBuffer13);



//---- indicator index name

   SetIndexLabel(0,"J-Candlestick");

   SetIndexLabel(1,"High/Low Price");

   SetIndexLabel(2,"Open Price");

   SetIndexLabel(3,"Close Price");

   SetIndexLabel(4,"MA Reference");



//   IndicatorShortName("J-Candlesticks(" + MAPeriod + ")");

//---- initialization done

   return(0);

}



void deinit() {

   ObjectsDeleteAll(); 

}



//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

int start()

{

   double MAOpen1, MAHigh1, MALow1, MAClose1;

   double MAOpen2, MAHigh2, MALow2, MAClose2;

   double MAOpen3, MAHigh3, MALow3, MAClose3;

   double MARef, CurrentPrice;

   datetime t3;



//MAPeriod 1

   if(Bars <= (MAPeriod1)) return(0);

   ExtCountedBars1 = IndicatorCounted();



//---- check for possible errors

   if (ExtCountedBars1<0) return(-1);



//---- last counted bar will be recounted

   if (ExtCountedBars1>0) ExtCountedBars1--;



   int pos = Bars - ExtCountedBars1 - 1;



   while(pos >= 0)

   {

      MAClose1 = iMA(NULL, 0, MAPeriod1, 0, MODE_SMA, PRICE_CLOSE, pos);

      MAOpen1 = iMA(NULL, 0, MAPeriod1, 0, MODE_SMA, PRICE_OPEN, pos);    

      MAHigh1 = iMA(NULL, 0, MAPeriod1, 0, MODE_SMA, PRICE_HIGH, pos);

      MALow1 = iMA(NULL, 0, MAPeriod1, 0, MODE_SMA, PRICE_LOW, pos);

            

      MAClose2 = iMA(NULL, 0, MAPeriod2, 0, MODE_SMA, PRICE_CLOSE, pos);

      MAOpen2 = iMA(NULL, 0, MAPeriod2, 0, MODE_SMA, PRICE_OPEN, pos);    

      MAHigh2 = iMA(NULL, 0, MAPeriod2, 0, MODE_SMA, PRICE_HIGH, pos);

      MALow2 = iMA(NULL, 0, MAPeriod2, 0, MODE_SMA, PRICE_LOW, pos);

      

      MAClose3 = iMA(NULL, 0, MAPeriod3, 0, MODE_SMA, PRICE_CLOSE, pos);

      MAOpen3 = iMA(NULL, 0, MAPeriod3, 0, MODE_SMA, PRICE_OPEN, pos);    

      MAHigh3 = iMA(NULL, 0, MAPeriod3, 0, MODE_SMA, PRICE_HIGH, pos);

      MALow3 = iMA(NULL, 0, MAPeriod3, 0, MODE_SMA, PRICE_LOW, pos);



      ExtMapBuffer3[pos]=MAOpen1;

      ExtMapBuffer4[pos]=MAClose1;

      ExtMapBuffer8[pos]=MAOpen2;

      ExtMapBuffer9[pos]=MAClose2;

      ExtMapBuffer12[pos]=MAOpen3;

      ExtMapBuffer13[pos]=MAClose3;

          pos--;

   }
 

It may be faster to google and mayy just to amend what you have found!

BTW, please use the SRC-button for posting code here.

 
gooly:

It may be faster to google and mayy just to amend what you have found!

BTW, please use the SRC-button for posting code here.

Sorry. This is my first time in this forum.

 I'm trying to find something similar but not possible to get anything like this. Do you have any idea what kind of indicator have similar function? then i may change according to my usage.

Thank. 

Reason: