Coding help - page 362

 
triip:
Guys I need a little bit help to code RSI and SMA relation.

As you see on the image, there are signals(up-down arrows), but some of them are false signals. So I decided to eliminate false signals with RSI14 and SMA20 on it.

Logic behind it is very easy, up-arrow should appear if RSI14 is ABOVE SMA20. Down-arrow should appear if RSI is BELOW SMA20.

I have marked some up-arrows wrong, because RSI is too high, but that part I can code myself.

I have found lot of RSI<MA crossing codes, but most of them goes long/short if cross appears. But I need a term where RSI is ABOVE or BELOW and then do something.

As much I have found for now, I have to use IRSI and array for that but can't put that code together myself.

triip

Did you check the one posted here : https://www.mql5.com/en/forum/general

 
mladen:
triip Did you check the one posted here : https://www.mql5.com/en/forum/general

Yes, but all what I find was crossing signal. I need conditions if RSI is above/below SMA.

I understand that firstly I have to declare what means ABOVE and what means BELOW, after that I can use them in IF sentence.

 
mladen:
triip


Did you check the one posted here : https://www.mql5.com/en/forum/174476



Yes, but all what I find was crossing signal. I need conditions if RSI is above/below SMA. 


I understand that firstly I have to declare what means ABOVE and what means BELOW, after that I can use them in IF sentence.

 
triip:
Yes, but all what I find was crossing signal. I need conditions if RSI is above/below SMA. I understand that firstly I have to declare what means ABOVE and what means BELOW, after that I can use them in IF sentence.

triip

No idea what rsi were you using to get those signals on your picture, so ... that is all I can tell. Without the code can not help more

 
mladen:
triip No idea what rsi were you using to get those signals on your picture, so ... that is all I can tell. Without the code can not help more

Sorry I didn't mention that arrow signals are not coming from RSI. its another code I use. But I saw that RSI with SMA will help to avoid wrong signals. Thats why I like to edit signal code so that it is able to identify RSI conditions too.

What I need is:

Arrow signals come in, but all of them are not true signals. So before the arrow comes then there has to be another if check what controls RSI conditions.

if (my current code && RSI is above/below SMA)

{ show arrow

}

I need that red part.

 
triip:
Sorry I didn't mention that arrow signals are not coming from RSI. its another code I use. But I saw that RSI with SMA will help to avoid wrong signals. Thats why I like to edit signal code so that it is able to identify RSI conditions too.

What I need is:

Arrows signals come in, but all of them are not true signals. So if arrow comes then there has to be another if check what controls RSI conditions.

if (my current code && RSI is above/below SMA)

{ show arrow

}

I need that red part.

triip

You have to do the following :

1. Save the values of RSI to a buffer

2. Use iMAOnArray() to calculate the SMA of that RSI values

3. Compare the value of saved RSI and the value of iMAOnArray() calculated value and that is your condition

 
mladen:
triip

You have to do the following :

1. Save the values of RSI to a buffer

2. Use iMAOnArray() to calculate the SMA of that RSI values

3. Compare the value of saved RSI and the value of iMAOnArray() calculated value and that is your condition

So 1 and 2 something like that?

1.

#property indicator_buffers 2

extern int rsi_p = 14;

extern int MA_Period=20;

extern int MA_Shift=0;

extern int MA_Method=0;

extern int NumberOfBarsToCalculate = 10000;

double Buffer0[];

double Buffer1[];

double Ma[];

double RSi[];

int init()

{

IndicatorBuffers(4);

SetIndexBuffer(0,Buffer0);

SetIndexBuffer(1,Buffer1);

SetIndexBuffer(2,Ma);

SetIndexBuffer(3,RSi);

return(0);

}

[/CODE]

2.

[CODE]int start() {

int shift;

double rsi = 0;

for(shift=NumberOfBarsToCalculate-1;shift>=0;shift--){

RSi[shift] = iRSI(NULL,0,rsi_p,PRICE_CLOSE,shift);

}

for(shift=NumberOfBarsToCalculate-1;shift>=0;shift--){

Ma[shift] = iMAOnArray(RSi,0,MA_Period,MA_Shift,MA_Method,shift);

Buffer0[shift] = RSi[shift];

Buffer1[shift] = Ma[shift];

}

return(0);

}

 
triip:
So 1 and 2 something like that?

1.

#property indicator_buffers 2

extern int rsi_p = 14;

extern int MA_Period=20;

extern int MA_Shift=0;

extern int MA_Method=0;

extern int NumberOfBarsToCalculate = 10000;

double Buffer0[];

double Buffer1[];

double Ma[];

double RSi[];

int init()

{

IndicatorBuffers(4);

SetIndexBuffer(0,Buffer0);

SetIndexBuffer(1,Buffer1);

SetIndexBuffer(2,Ma);

SetIndexBuffer(3,RSi);

return(0);

}

[/CODE]

2.

[CODE]int start() {

int shift;

double rsi = 0;

for(shift=NumberOfBarsToCalculate-1;shift>=0;shift--){

RSi[shift] = iRSI(NULL,0,rsi_p,PRICE_CLOSE,shift);

}

for(shift=NumberOfBarsToCalculate-1;shift>=0;shift--){

Ma[shift] = iMAOnArray(RSi,0,MA_Period,MA_Shift,MA_Method,shift);

Buffer0[shift] = RSi[shift];

Buffer1[shift] = Ma[shift];

}

return(0);

}

Yes, you can do it that way too

And when you need it, simply compare RSi and MA buffer and you will always be able to see their relative position

 
mladen:
Yes, you can do it that way too And when you need it, simply compare RSi and MA buffer and you will always be able to see their relative position

Awesome, big thanks mladen

 
mladen:
apprentice coder Here is an indicator that has such a sorting procedure (it is sorting 2 dimensional array) : spearman_rank_correlation_nmc.mq4

mladen

Any example of c/c++ doing that same thing?

Reason: