moving averages' average

 

how can i do this ?

i try but i can't ?

what's wrong ??

//+------------------------------------------------------------------+
//|                                        Custom Moving Average.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red
//---- indicator parameters
extern int MA_Period=13;
extern int MA_Shift=0;
extern int MA_Method=0;
//---- indicator buffers
double ExtMapBuffer[];
//----
int ExtCountedBars=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   int    draw_begin;
   string short_name;
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE);
   SetIndexShift(0,MA_Shift);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
   if(MA_Period<2) MA_Period=13;
   draw_begin=MA_Period-1;
//---- indicator short name
   switch(MA_Method)
     {
      
      default :
         MA_Method=0;
         short_name="SMA(";
     }
   IndicatorShortName(short_name+MA_Period+")");
   SetIndexDrawBegin(0,draw_begin);
//---- indicator buffers mapping
   SetIndexBuffer(0,ExtMapBuffer);
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   if(Bars<=MA_Period) return(0);
   ExtCountedBars=IndicatorCounted();
//---- check for possible errors
   if (ExtCountedBars<0) return(-1);
//---- last counted bar will be recounted
   if (ExtCountedBars>0) ExtCountedBars--;
//----
   switch(MA_Method)
     {
      case 0 : sma();  break;
      
     }
//---- done
   return(0);
  }
//+------------------------------------------------------------------+
//| Simple Moving Average                                            |
//+------------------------------------------------------------------+
void sma()
  {
   double sum=0;
   double sum2=0;
   int    i,pos=Bars-ExtCountedBars-1;
//---- initial accumulation
   if(pos<MA_Period) pos=MA_Period;
   for(i=1;i<MA_Period;i++,pos--)
      sum+=Close[pos];
//---- main calculation loop
   while(pos>=0)
     {
      sum+=Close[pos];
      ExtMapBuffer[pos]=sum/MA_Period;
           sum-=Close[pos+MA_Period-1];
           pos--;
     }
     
     
     if(pos<MA_Period) pos=MA_Period;
   for(i=1;i<MA_Period;i++,pos--)
      sum2+=sum[pos];
//---- main calculation loop
   while(pos>=0)
     {
      sum2+=sum[pos];
      ExtMapBuffer[pos]=sum/MA_Period;
           sum2-=sum[pos+MA_Period-1];
           pos--;
     }
//---- zero initial bars
   if(ExtCountedBars<1)
      for(i=1;i<MA_Period;i++) ExtMapBuffer[Bars-i]=0;
  }
//+------------------------------------------------------------------+
//| Exponential Moving Average                                       |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Smoothed Moving Average                                          |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Linear Weighted Moving Average                                   |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
 
yilmazkahya:

how can i do this ?

i try but i can't ?

what's wrong ??

What are you trying to do ? iMAOnArray() ?
 
i learn iMAOnArray() now :) but i don't know how to do this indicator yet. i will study this. thank u
 

I would caution you against just averaging averages. This is a rather simple article since its from answers.com but you might find it useful getting started

http://wiki.answers.com/Q/Is_an_average_of_averages_accurate

Basically if you just average a few moving average lines your just going to be drawing some other line so you need to ask yourself why you think the average of MA's is going to be useful for you. Additionally you need to determine what averages are going to be most important for your system. That way its not 'just a line' on the chart.

 
Raptor i can't use iMAOnArray(), code is true but i don't know how can i write this :S thanks
 

instead of writing tons of code

iMAOnArray() + iCustom() should solve the problem

 

gjol thank you but i don't know how can i do these, and i must stop for that subject :(

 

heyy i did :)

everybody thank you, and thanks to mehmet, he help me on message

this is ma and ma on array in the same chart :P

one small step for mankind one giant leap for man (me) :P

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 DarkBlue

double ExtMapBuffer1[];
double ExtMapBuffer2[];

extern int MA_period=14;

int init()
  {
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);
   SetIndexBuffer(1,ExtMapBuffer2);
  
   return(0);
  }

int deinit()
  {
   return(0);
  }
  
int start()
  {
   int bar, limit;
   
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   limit=Bars-IndicatorCounted();
    
   
   for(bar=0; bar<limit; bar++)  ExtMapBuffer1[bar] = iMA(NULL, 0, MA_period, 0, MODE_SMA, PRICE_CLOSE, bar);
   //iCCI(NULL,0,CCIDeger,PRICE_TYPICAL,bar);
  
   for(bar=0; bar<limit; bar++)  ExtMapBuffer2[bar]=iMAOnArray(ExtMapBuffer1,Bars,MA_period,0,MODE_SMA,bar);
   
   
   return(0);
  }
  
 
 
yilmazkahya:

heyy i did :)

everybody thank you, and thanks to mehmet, he help me on message

this is ma and ma on array in the same chart :P

one small step for mankind one giant leap for man (me) :P


On your final line of code you used "Bars" in your ma parameters. I've found this can cause problems loading charts at times. "Waiting on Data" message can occur, and never load. I put Bars value into a variable and put your variable in the iMAOnArray parameter, to avoid this.