Code help for crossover signal

 
Please help.

See attached screenshot...

Ideally, the indicator is supposed to draw an up or down arrow in the main chart window when the RSI and the RSIMA cross each other. The arrows in the screenshot are from a crossover indicator that I have, but for some reason they don't line up at all with the RSI and RSIMA thatis shown in the lower window.

Any help is appreciated.

_Dan

//+------------------------------------------------------------------+
//| Fozzy-Crossover-Arrow-Indicator |
//| https://forum.mql4.com ;;;; |
//+------------------------------------------------------------------+
#property copyright " "
#property link " "

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_level1 80
#property indicator_level2 20
#property indicator_levelcolor Green
#property indicator_buffers 6
#property indicator_color1 DodgerBlue
#property indicator_color2 Red
#property indicator_color3 Green
#property indicator_color4 Red


//---- indicator parameters
extern int RSIPeriod = 8;
extern int RSIMAPeriod = 8;
extern int ATRPeriod = 8;
double CrossUp[];
double CrossDown[];
double RSI[];
double RSIMA[];
double ATR[];

//---- buffers

int i;

int init()
{

IndicatorBuffers(6);

//---- drawing settings
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID);
SetIndexDrawBegin(0,i-1);
SetIndexBuffer(0, RSI);
SetIndexLabel(0,"RSI");

SetIndexStyle(1,DRAW_LINE,STYLE_DOT);
SetIndexDrawBegin(1,i-1);
SetIndexBuffer(1, RSIMA);
SetIndexLabel(1,"RSI-MA");

{
//---- indicators
SetIndexStyle(0, DRAW_ARROW, EMPTY);
SetIndexArrow(0, 233);
SetIndexBuffer(0, CrossUp);
SetIndexStyle(1, DRAW_ARROW, EMPTY);
SetIndexArrow(1, 234);
SetIndexBuffer(1, CrossDown);
//----
return(0);
}



return(0);
}

int start()
{int limit, i, counter;
double RSIMAnow;
double RSIMAprevious;
double RSIMAafter;
double RSInow;
double RSIprevious;
double RSIafter;
double Range, AvgRange;
int counted_bars=IndicatorCounted();
i=Bars-RSIPeriod;
while(i>=0) {
RSI[i] = iRSI(NULL,0,RSIPeriod,PRICE_CLOSE,i);
i--;
}

i=Bars-RSIMAPeriod;
while(i>=0) {
RSIMA[i] = iMAOnArray(RSI,0,RSIMAPeriod,0,MODE_EMA,i);
i--;
}

i=Bars-ATRPeriod;
while(i>=0) {
ATRPeriod[i] = iMAOnArray(RSI,0,RSIMAPeriod,0,MODE_EMA, i);
i--;
}

//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

for(i = 0; i <= limit; i++) {

counter=i;
Range=0;
AvgRange=0;
for (counter=i ;counter<=i+9;counter++) {
AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
}
Range=AvgRange/10;

RSIMAnow = iMA(NULL, 0, RSIMA, 0, MODE_EMA, PRICE_CLOSE, i);
RSIMAprevious = iMA(NULL, 0, RSIMA, 0, MODE_EMA, PRICE_CLOSE, i+1);
RSIMAafter = iMA(NULL, 0, RSIMA, 0, MODE_EMA, PRICE_CLOSE, i-1);

RSInow = iMA(NULL, 0, RSI, 0, MODE_CLOSE, );
RSIprevious = iMA(NULL, 0, RSI, 0, MODE_CLOSE, i+1);
RSIafter = iMA(NULL, 0, RSI, 0, MODE_CLOSE, i-1);

if ((RSIMAnow > RSInow) && (RSIMAprevious < RSIprevious) && (RSIMAafter > RSIafter)) {
CrossUp[i] = Low[i] - Range*0.5;
}
else if ((RSIMAnow < RSInow) && (RSIMAprevious > RSIprevious) && (RSIMAafter < RSIafter)) {
CrossDown[i] = High[i] + Range*0. 5;
}
}


return(0);
}
//+---
 
Correct will be such
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_level1 80
#property indicator_level2 20
#property indicator_levelcolor Green
//#property indicator_buffers 6
#property indicator_color1     DodgerBlue
#property indicator_color2     Red
#property indicator_color3     Green
#property indicator_color4     Red
 
 
//---- indicator parameters
extern int    RSIPeriod = 8;
extern int    RSIMAPeriod = 8;
extern int    ATRPeriod   = 8;
double        CrossUp[];
double        CrossDown[];
double        RSI[];
double        RSIMA[];
double        ATR[];
 
//---- buffers
 
int i;
 
int init()
  {
 
  //IndicatorBuffers(6);
 
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID);
   SetIndexDrawBegin(0,i-1);
   SetIndexBuffer(0, RSI);
   SetIndexLabel(0,"RSI");
 
   SetIndexStyle(1,DRAW_LINE,STYLE_DOT);
   SetIndexDrawBegin(1,i-1);
   SetIndexBuffer(1, RSIMA);
   SetIndexLabel(1,"RSI-MA");
   
     {
//---- indicators
   SetIndexStyle(2, DRAW_ARROW, EMPTY);
   SetIndexArrow(2, 233);
   SetIndexBuffer(2, CrossUp);
   SetIndexStyle(3, DRAW_ARROW, EMPTY);
   SetIndexArrow(3, 234);
   SetIndexBuffer(3, CrossDown);
 
Thanks for that help. Now something else has me stuck:

Compiling 'fozzy-crossover--arrow-broken.mq4'...
')' - wrong parameters count C:\Program Files\PFG FX Trader\experts\indicators\fozzy-crossover--arrow-broken. mq4 (116, 50)
')' - wrong parameters count C:\Program Files\PFG FX Trader\experts\indicators\fozzy-crossover--arrow-broken. mq4 (117, 57)
')' - wrong parameters count C:\Program Files\PFG FX Trader\experts\indicators\fozzy-crossover--arrow-broken. mq4 (118, 54)
3 error(s), 0 warning(s)



which relates to these lines:

RSInow = iMA(NULL, 0, RSI, 0, MODE_CLOSE, i );
RSIprevious = iMA(NULL, 0, RSI, 0, MODE_CLOSE, i+1);
RSIafter = iMA(NULL, 0, RSI, 0, MODE_CLOSE, i-1);


I need these to do the caculations, and really don't understand what is wrong with the code.

Thanks again for your help.