plotting a line that is a sum of 2 SMA.

 
Hi,

Im a newbie trying some simple programming.. Hope some kind souls can pardon my ignorance and give some advise.. 

Trying to plot a line that is a sum of 2 SMA output.. Tried using the code below.. can anyone advise how to rectify?


thanks!


#property indicator_chart_window

#property indicator_buffers 2

#property indicator_color1 DodgerBlue

#property indicator_width1 1 



extern int MA_TF = PERIOD_H4;

extern int MA1_Period = 10;

extern int MA2_Period = 40;

extern int MA_ma_method = MODE_SMA;

//extern int MA1_applied_price = PRICE_TYPICAL;

extern int MA_ma_shift = 0;



double S1[];

double S2[];

double S1a[];

double S1b[];

double S2a[];

double S2b[];





//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



void init()

{

  SetIndexBuffer(0, S1);

  SetIndexBuffer(1, S2);

  SetIndexBuffer(2, Sk1a);

  SetIndexBuffer(3, S1b);

  SetIndexBuffer(4, S2a);

  SetIndexBuffer(5, S2b);

  SetIndexStyle(0, DRAW_LINE);

  SetIndexStyle(1, DRAW_LINE);

  SetIndexEmptyValue(0, 0.0);

  SetIndexEmptyValue(1, 0.0);

  

  SetIndexDrawBegin(0, MA1_Period);

  SetIndexDrawBegin(1, MA2_Period);

  

}



void deinit()

{

}



void start()

{

  int counted_bars = IndicatorCounted();

  if(counted_bars < 0) return;

  if(counted_bars > 0) counted_bars--;



  int limit = Bars-counted_bars;

  limit += MA_TF/Period();



  for (int i=limit; i >= 0; i--)

  {

    int shift = iBarShift(NULL, MA_TF, Time[i], true);

    if (shift == -1) continue;

    

    S1a[i] = iMA(NULL, MA_TF, MA1_Period, MA_ma_shift, MA_ma_method, High[0], shift);

    S1b[i] = iMA(NULL, MA_TF, MA1_Period, MA_ma_shift, MA_ma_method, Low[0], shift);

    S2a[i] = iMA(NULL, MA_TF, MA2_Period, MA_ma_shift, MA_ma_method, High[0], shift);

    S2b[i] = iMA(NULL, MA_TF, MA2_Period, MA_ma_shift, MA_ma_method, Low[0], shift);

    

    

       

    S1[i] = (S1a[i] + S1b[i]);

    S2[i] = (S2a[i] + S2b[i]);

    

  }

}

 
Perhaps you should read the manual.
Your code
 Documentation
  S1a[i] = iMA(
NULL, 
MA_TF, 
MA1_Period, 
MA_ma_shift, 
MA_ma_method, 
High[0],       
shift
);
double  iMA(
 string             symbol,        // symbol
 ENUM_TIMEFRAMES    timeframe,     // timeframe
 int                ma_period,     // MA averaging period
 int                ma_shift,      // MA shift
 ENUM_MA_METHOD     ma_method,     // averaging method
 ENUM_APPLIED_PRICE applied_price, // applied price
 int                shift          // shift
);
 

plus...

if you want to use this indicator on chart window ( your code so..) you should divide 2 to S1 and S2

    S1[i] = (S1a[i] + S1b[i])/2;

    S2[i] = (S2a[i] + S2b[i])/2;