Hi. You are making a few errors defining buffers and using the iMAonArray function. You also need an explicit check for zero divide situations.
Anyway here is what results. Any pointers on its usage?
Code:
#property copyright "Metatrader4 Code by jjk2. Based on MBA Thesis from Simon Fraser University written by C.E. ALDEA."
#property link ""
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicator drawing
IndicatorBuffers(2);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,3,Green);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_NONE,STYLE_SOLID,3,Yellow);//DRAW_NONE,EMPTY,EMPTY);
SetIndexBuffer(1,ExtMapBuffer2);
///-----Name of Indicator
string short_name = "ZigZag BETA Current value calculated by indicator:";
IndicatorShortName(short_name);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars = IndicatorCounted();
int pos = Bars - counted_bars - 9;
int temp = pos;
//----
if (counted_bars<0) return(-1);
if (counted_bars>0) counted_bars--;
while(pos>0)
{
//string xxx = "pos";
double MACD = iMACD(NULL,0,12,26,9,PRICE_CLOSE,0,pos);
double Stoch = iStochastic(NULL,0,9,6,2,MODE_SMA,1,0,pos);
double RSI = iRSI(NULL,0,9,PRICE_CLOSE,pos);
double moment = (iMomentum(NULL,0,9,PRICE_CLOSE,pos));
//double momentum = (Close[pos]-Close[pos+9]);
//double Roc = (Close[pos]/Close[pos+9])*100;
double Volu = iVolume(NULL,0,pos);
//Main Forumla
//double preFormula = (/Momentum);
if (moment != 0)
ExtMapBuffer2[pos] = Stoch*(RSI)/moment;
//Alert("MACD: ", MACD," ","Stoch: ", Stoch," ", "RSI: ", RSI," ","Momentum: ", momentum," ","Volume: ", Volu);
//Alert(Stoch*(RSI)/Roc);
pos--;
}
while (temp > 0) {
double Formula = iMAOnArray(ExtMapBuffer2,0,2,0,MODE_SMA,temp);
ExtMapBuffer1[temp] = Formula;
temp--; }
//----
return(0);
}
//+------------------------------------------------------------------+