RSI Average Indicator

 

I have rewritten the RSI indicator using the RSI function and added a moving average to it. As you can see in the code, I've written 2 'for' loops for each of the RSI and MA. In this way, I have no issues with the indicator. I tried to put them both in a single loop but got the indicator to plot only the current value of the MA upon attaching it to a chart. No issue with the RSI graph. And when I compile the indicator again while attached, the MA gets potted completely. Is there a way to resolve this issue?

Secondly, how can we make the indicator show the 20, 50 and 80 levels?

Regards,

Files:
 


Do you mean like that?

 

Or see the SFX_MA_On_RSI indi here

-BB-

 
APeng:


Do you mean like that?


Yes, this is my 2nd question. Is there a way to program these levels so they'd come by default?

And my 1st question is more important to me. Is there a way to use a single look but still make the MA get potted fully when attached to a chart?

 

have to fill the array first before you can do further calculations hence the multiple loops. don't think there's a workaround.

yes you can create levels dynamically like this

extern double level_1 = 20,
              level_2 = 50,
              level_3 = 80;
              
 int init()
  {
   SetLevelStyle(STYLE_DOT,1,LightSlateGray); 
   SetLevelValue(0,level_1);
   SetLevelValue(1,level_2);
   SetLevelValue(2,level_3);

or

#define LEVELS  3


double level[LEVELS] = {20,50,80};

int init()
  {
   for(int i=0;i<LEVELS;i++)  {
   SetLevelValue(i,level[i]);} 
   SetLevelStyle(STYLE_DOT,1,LightSlateGray); 
 
19730719:

have to fill the array first before you can do further calculations hence the multiple loops. don't think there's a workaround.

yes you can create levels dynamically like this

or


I have tried the second method and got the same issue with of the MA when using a single loop. I am not talking about the MA here because you said they have to be in 2 separate loops. But I'm talking about the levels not showing when I attach the indicator to a chart in the beginning. They only show when I compile the indicator while it is already attached.

I have replaced the file above with the latest version.

 
#property indicator_level1 20
#property indicator_level2 50
#property indicator_level3 80
#property indicator_levelcolor LightSlateGray
#property indicator_levelstyle STYLE_DOT
#property indicator_levelwidth 1
 

Thank you for this code. It is the most direct code to write I believe. I used only the first 3 and removed the second 3 as they don't make any difference.

 

Hi,

The indicator which is attached above works perfectly, I believe. I created a sample strategy based on the same logic, but could not get the calculations right. I've been trying moving the code around with on success. Here is a screenshot of one of the backtests that I've performed, http://i39.tinypic.com/15ot6v6.png, and you can find the log attached. Notice how the EA gives right readings for the RSI, but wrong ones for its Average.

How can we correct this error?

Thank you,

tapo

Files:
log.txt  1 kb
rsiea.mq4  2 kb
 
tapo:

I have rewritten the RSI indicator using the RSI function and added a moving average to it. As you can see in the code, I've written 2 'for' loops for each of the RSI and MA. In this way, I have no issues with the indicator. I tried to put them both in a single loop but got the indicator to plot only the current value of the MA upon attaching it to a chart. No issue with the RSI graph. And when I compile the indicator again while attached, the MA gets potted completely. Is there a way to resolve this issue?

You can't do the average on array until the array has values. Either 1) two separate loops, or 2) COUNT DOWN
 
WHRoeder:
You can't do the average on array until the array has values. Either 1) two separate loops, or 2) COUNT DOWN

Hi WHRoeder,

As our friend, 19730719, said before, I kept the 2 loops for this purpose, and the indicator the way it's coded looks to me working perfectly. You can find it attached to post # 1 above.

Now, we want to make the EA works perfectly as well. As you can see I used the very same logic as in the indicator, but got wrong calculations. I tried to move different lines around like making all the variables global and putting the loop in the Start() function, plus some other things, but nothing worked.

I also took your count-down suggestion and made the second loop (MA loop) like this

for (i = MA_Count - 1; i >=0; i--)

but it did not help. In fact, I got exactly the same values for the average!! I am not sure if I got you correctly.

Can you look at the RSIEA code and advice.

Regards,

tapo