View Single Post
  #2 (permalink)  
Old 12-20-2005, 04:46 PM
codersguru's Avatar
codersguru codersguru is offline
Senior Member
 
Join Date: Oct 2005
Posts: 987
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
Arrow iMAOnArray

Quote:
Originally Posted by alanlaw
Dear All,

Could anyone tell me how to declare a array and than use the iMAOnArray or IMA function and to program a moving average on indicators, like macd histogram or momentum?

Please help me. Urgent.I have spend few days on working this.

Thank you very much.


Victor
Hi Victor,
If I understood your problem correctly this code might help:
PHP Code:
//+------------------------------------------------------------------+
//|                                             iMAOnArray Demo.mq4 |
//|                                                     Codersguru |
//|                                         http://www.forex-tsd.com |
//+------------------------------------------------------------------+
#property copyright "Codersguru"
#property link      "http://www.forex-tsd.com"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Blue

//---- buffers
double ExtMapBuffer1[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   
SetIndexStyle(0,DRAW_LINE);
   
SetIndexBuffer(0,ExtMapBuffer1);
   
string short_name "iMAOnArray demo";
   
IndicatorShortName(short_name);
//----
   
return(1);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                     |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   
return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                             |
//+------------------------------------------------------------------+
int start()
  {
   
int i,limit;

   
double MyArray[]; //declare an array
   
   
int counted_bars=IndicatorCounted();
   if(
counted_bars>0counted_bars--;
   
limit=Bars-counted_bars;
   
   
ArrayResizeMyArraylimit); //resize the array to the number of bars
   
ArraySetAsSeries(MyArray,true); //reverse the array direction. 



   
for(i=0i<limiti++)
   {
   
MyArray[i] = iMA(NULL,0,13,8,MODE_EMA,PRICE_CLOSE,i);
   Print(
"MyArray = ",MyArray[i]);
   }
   for(
i=0i<limiti++)
   {
   
ExtMapBuffer1[i] = iMAOnArray(MyArray,limit,13,8,MODE_EMA,i);
   Print(
"ExtMapBuffer1 = " ExtMapBuffer1[i]);
   }


   return(
0);
  }
//+------------------------------------------------------------------+ 
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Reply With Quote