crossing of Ma and RSI line,giving arrow on chart (please advice)

 

I wrote an indicator of an RSI and an MA of that RSI. It work fine.

Now I want to change the indicator that it draws arrows when the lines crossing in the chart window.

This is the indicator that is working OK:

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_width1 2
#property indicator_width2 1
#property indicator_style2 STYLE_DOT
#property indicator_level1 50
#property indicator_levelcolor Black
#property indicator_levelstyle STYLE_DOT

//--- externe variabelen
extern int iRSI_waarde = 14;
extern int iMA_RSI = 5;

//--- buffers
double Rsi[];// Rsi
double MARsi[];// MA van de RSI

int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
   SetIndexBuffer(0,Rsi);
   SetIndexLabel(0,"RSI");
   
   SetIndexStyle(1,DRAW_LINE,STYLE_DOT,1);
   SetIndexBuffer(1,MARsi);
   SetIndexLabel(1,"MA_RSI");
      
   return(0);
  }

int deinit()
  {
//----
   
//----
   return(0);
  }
int start()
  {
   int    counted_bars=IndicatorCounted();
   if(counted_bars > 0) counted_bars--;
   int BerekenCandles = Bars - counted_bars;
   
   for(int t = BerekenCandles; t >= 0; t--)
      {
      Rsi[t] = iRSI(NULL,0,iRSI_waarde,PRICE_CLOSE,t);
      }
   for(int s = BerekenCandles - 1; s>=0; s--)
      {
       MARsi[s]=iMAOnArray(Rsi, 0, iMA_RSI, 0, MODE_EMA, s); 
       }
   return(0);
  }
//+------------------------------------------------------------------+

Now I try to modify this indicator, so I get the arrows. It is not working, please advice what is wrong

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_width1 2
#property indicator_width2 1

//--- externe variabelen
extern int iRSI_waarde = 14;
extern int iMA_RSI = 5;

//--- buffers
double CrossUp[];
double CrossDown[];

int init()
  {
//---- 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);
  }

int deinit()
  {
//----
   
//----
   return(0);
  }
int start()
  {
  double Rsi[];
  double MARsi[];
  
   int    counted_bars=IndicatorCounted();
   if(counted_bars > 0) counted_bars--;
   int BerekenCandles = Bars - counted_bars;
   
   for(int t = BerekenCandles; t >= 0; t--)
      {
      Rsi[t] = iRSI(NULL,0,iRSI_waarde,PRICE_CLOSE,t);
      }
   for(int s = BerekenCandles - 1; s>=0; s--)
      {
       MARsi[s]=iMAOnArray(Rsi, 0, iMA_RSI, 0, MODE_EMA, s); 
       }
   for(int q = BerekenCandles - 1; q>=0; q--)
      {
      if(Rsi[q] > MARsi[q] && Rsi[q+1] < MARsi[q+1])CrossUp[q] = Low[q+1];
      if(Rsi[q] < MARsi[q] && Rsi[q+1] > MARsi[q+1])CrossDown[q] = High[q+1]; 
      }   
   return(0);
  }
//+------------------------------------------------------------------+
 

Your Rsi/MARsi buffers have no size. You can't use them.

put them back like you had before and ADD the cross up/down buffers and change to total

#property indicator_buffers 4
 
WHRoeder:

Your Rsi/MARsi buffers have no size. You can't use them.

put them back like you had before and ADD the cross up/down buffers and change to total


Thank you WHRoeder,

I have changed the #property indicator_buffers to 4, but still no arrows. There is something not right in my program. i hope you can help

 

u have to initialize the array

double Rsi[1000];
double MARsi[1000]; or some no.
 
qjol:

u have to initialize the array


I do not know what you mean by that.
 

When I change the program so that I get arrows when the RSI cross the 50 line, it is working.

But how do I get an arrow when the RSI crosses his MA line? The code below shows it

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_width1 2
#property indicator_width2 1

//--- externe variabelen
extern int iRSI_waarde = 14;
extern int iMA_RSI = 5;

//--- buffers
double CrossUp[];
double CrossDown[];

int init()
  {
//---- 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);
  }

int deinit()
  {
//----
   
//----
   return(0);
  }
int start()
  {
  double Rsi[];
  double MARsi[];
  
   int    counted_bars=IndicatorCounted();
   if(counted_bars > 0) counted_bars--;
   int BerekenCandles = Bars - counted_bars;
   
   for(int t = BerekenCandles; t >= 0; t--)
      {
      Rsi[t] = iRSI(NULL,0,iRSI_waarde,PRICE_CLOSE,t);
      }
   for(int s = BerekenCandles - 1; s>=0; s--)
      {
       MARsi[s]=iMAOnArray(Rsi, 0, iMA_RSI, 0, MODE_EMA, s); 
       }
   for(int q = BerekenCandles - 1; q>=0; q--)
      {
       double myRSInow = iRSI(NULL,0,iRSI_waarde,PRICE_CLOSE,q);
       double myRSI2 = iRSI(NULL,0,iRSI_waarde,PRICE_CLOSE,q+1); //RSI One bar ago
 
       if(myRSInow>50 && myRSI2<50)CrossUp[q] = Low[q+1];//RSI crosses the 50 line UP
       if(myRSInow<50 && myRSI2>50)CrossDown[q] = High[q+1];// RSI crosses the 50 line down
       
      }   
   return(0);
  }
//+------------------------------------------------------------------+
 

You added 2 arrays . . .

  double Rsi[];
  double MARsi[];

did you mean to add 2 new buffers ?

Arrays and buffers are similar . . . yet different. It is the difference that are important. You can't just have an array without telling it how big it is . . . you can with a buffer.

 
RaptorUK:

You added 2 arrays . . .

did you mean to add 2 new buffers ?

Arrays and buffers are similar . . . yet different. It is the difference that are important. You can't just have an array without telling it how big it is . . . you can with a buffer.



Thank you RaptorUK,

I changed the code and yes, it is working. Thanks