
iMAOnArray needs an array MainMA is not. Create a fourth buffer, non-displayed buffer.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Below is what I have.
Can some talented programmer tell me were I am going wrong? I would be extremely grateful for any help.
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_width1 1
#property indicator_width2 1
#property indicator_color1 Green
#property indicator_color2 Red
//---- input parameters
extern int MAPeriod =34;
extern int ArrayPeriod =8;
double bufferUp[];
double bufferDo[];
double bufferTr[];
int init()
{
IndicatorBuffers(3);
SetIndexBuffer(0,bufferUp);
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,233);
SetIndexLabel(0,"UpArrow");
SetIndexBuffer(1,bufferDo);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,234);
SetIndexLabel(1,"DownArrow");
SetIndexBuffer(2,bufferTr);
return(0);
}
int deinit()
{
return(0);
}
int start()
{
int limit;
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(int i=limit; i >= 0; i--)
{
bufferUp[i] = EMPTY_VALUE;
bufferDo[i] = EMPTY_VALUE;
bufferTr[i] = bufferTr[i+1];
double MainMA = iMA(Symbol(),Period(),MAPeriod,0,1,0,i);
double ArrayMA = iMAOnArray(MainMA,0,ArrayPeriod,0,0,i);
if (MainMA>ArrayMA) bufferTr[i] = -1;
if (MainMA<ArrayMA) bufferTr[i] = 1;
if (bufferTr[i]!=bufferTr[i+1])
if (bufferTr[i]==-1) bufferDo[i]=High[i]+iATR(NULL,0,20,i);
else bufferUp[i]= Low[i]-iATR(NULL,0,20,i);
}
return(0);
}