RSI Average Indicator - page 2

 

have made a few minor changes and used a faster period as the ma doesn't cross the 30 and 70 level that often. seems to be doing what it should most of the time...

Files:
rsiea_1.mq4  2 kb
 
19730719:

have made a few minor changes and used a faster period as the ma doesn't cross the 30 and 70 level that often. seems to be doing what it should most of the time...

Hi 19730719, thank you for the response. I backtested the code on 5-min chart from 7/11/2011 to 8/11/2011 (1 day). The RSI crosses the levels more that once even in my original settings. I also used your short periods, but the EA did not generate any trade!

I would also appreciate it if you explain what the iBarShift() and NormalizeDouble() functions did. I read about them, but still not able to find out why they should do any difference, because the variable 'shift' is taken from the variable 'bar' which is in turn taken i. So why would shift correct an error caused by i? The main thing that I'm thinking of is that iCCI has always been giving correct readings. Hence I'm thinking it must be iMAOnArray which can make the difference, although I'm not able to find any problem with it right now. Can you explain what you think?

Cheers,

===============

EDIT: I used the inputs 8 for RSI and 4 for MA instead of 8 and 3 in your code. That happen by mistake when I was trying to simplify the code for my understanding. With 8 and 3, yes the EA generate a lot of trades during the same period of time. HOWEVER, it is still wrong. Here is a screenshot, http://i43.tinypic.com/xcmbgi.png.

 

the changes won't make any difference except maybe processing speed. i've changed the bars to MA1[1] & MA1[0] and still get desired results. your arrays are too small if you get so many trades as the buy condition will be true MA[2] == 0 && MA[1] > 30.

 
19730719:

the changes won't make any difference except maybe processing speed. i've changed the bars to MA1[1] & MA1[0] and still get desired results. your arrays are too small if you get so many trades as the buy condition will be true MA[2] == 0 && MA[1] > 30.

I'm afraid I've not got what you are trying to say. Can you explain why in my code the MA values which are printed in the journal are wrong although the CCI values are correct to the last fractional digit?

Thanks,

 

Hi guys,

If you are seeing this for the first time, it's OK. You don't need to read anything from the above.

I am writing a strategy based on RSI average. First, I successfully wrote an RSI Average indicator that you see attached. Using the same logic, the strategy did not work somehow, and I could not get my head around it. See this screenshot, http://i43.tinypic.com/9u9kk3.png.

The EA keeps giving wrong values for the average. I don't know why. I've tried different thing but nothing worked. Could you please have a look at the code which is very simple and straight forward and see how we can fix this issue.

Thanks a lot,

tapo

============

EDIT: I put the strategy into live test on 1-min chart, and got this screenshot which shows clearly how the EA misses a trigger and later on, opens a short position with no trigger. http://i42.tinypic.com/8yx6e0.png

By the way, 19730719, I did not find the values that I put on the screenshot anywhere else on the chart, which means it cannot be a shift problem. Can it?

 

Hi all, I have just figured it out by myself :-D The market is closed now. I'll put it into test at the beginning of next week and may post the code after making sure it works 100% right.

Have a great weekend,

tapo

 
tapo:

Hi all, I have just figured it out by myself :-D The market is closed now. I'll put it into test at the beginning of next week and may post the code after making sure it works 100% right.

Have a great weekend,

tapo

Why not use the Strategy Tester ?
 
RaptorUK:
Why not use the Strategy Tester ?
I used it, but I'd like to verify it more with live stream.
 
tapo:

Hi all, I have just figured it out by myself :-D The market is closed now. I'll put it into test at the beginning of next week and may post the code after making sure it works 100% right.

Have a great weekend,

tapo

Hi guys,

After having tested the code both back and forwards, it looks like working perfectly and I'd like to share it with you because it seems to be something not so many of you know it.

What drew my attention to this solution is looking through the lines of code of both the indicator and strategy and noticing that the indicator has the SetIndexDrawBegin() which is set in my indicator to

SetIndexDrawBegin(1, RSI_Period + MA_Period);

This means that when the RSI array has just got completely filled with RSI values, the MA array has less values in it. So, I added this line

j = Count - MA_Period;

And with several experiments, printings and comparisons with some other codes that I've found, here you go.

Happy trading :)

tapo

====== The code ======

double RSI1[30], MA1[30];
   int i, Count = ArraySize(RSI1), j = Count - MA_Period;
   
   for (i = 0; i < Count; i++)
   {
      RSI1[i] = iRSI(NULL, 0, RSI_Period, PRICE_CLOSE, i);
      MA1[i] = iMAOnArray(RSI1, 0, MA_Period, 0, MODE_SMA, i);
   }
   
   Comment(MA1[j-1], " ", MA1[j]);    //Comment added
   
   if (MA1[j-2] < 30 && MA1[j-1] > 30)
   {
      OrderSend(Symbol(), OP_BUY, 0.1, Ask, 3, 0, 0, NULL, MagicNo, 0, Green);
      Print(MA1[j-2], " ", MA1[j-1], " ", RSI1[2], " ", RSI1[1]);     //Log added
   }
   else if (MA1[j-2] > 70 && MA1[j-1] < 70)
   {
      OrderSend(Symbol(), OP_SELL, 0.1, Bid, 3, 0, 0, NULL, MagicNo, 0, Red);
      Print(MA1[j-2], " ", MA1[j-1], " ", RSI1[2], " ", RSI1[1]);     //Log added
   }
Reason: