lonerunner Posted September 7, 2011 Report Share Posted September 7, 2011 Hi, My question is about sliding the buffer in custom indicator. I asked in another forum but no avail. E.g: #define MAX_LOOK_BACK 5 int start() { int limit; int counted_bars = IndicatorCounted(); //---- check for possible errors if(counted_bars < 0) return(-1); //---- the last counted bar will be recounted if(counted_bars > 0) counted_bars--; limit=Bars-counted_bars; //---- main loop Print("indicator limit: ", limit); if(MAX_LOOK_BACK < limit) limit = MAX_LOOK_BACK; //Calculate from right to left for(int i = 0; i < limit; i++) { rsiBuf[i] = iRSI(Symbol(), NULL, 14, PRICE_CLOSE, i); } } While running indicator will calculate the latest RSI values of the latest 5 bars. (I put a MAXLOOK_BACK maximum value for easy testing) If for example in a situation that limit==2 (and limit==2 happens alot in my tests when calling via iCustom in a EA) then it will calculate bar 0 and bar 1 values and write to RSI[0] and RSI[1] respectively and won't touch the rest of the buffer. Every custom indicator I've seen is written this way. Shouldn't we slide the buffer if limit < MAX_LOOK_BACK ? as it overwrites the RSI[0] and RSI[1] but the previous values of these elements should be in RSI[2] and RSI[3] am I right? To visualise : Tick=0 AND limit = 5 ==> RSI[0] = 33.33 RSI[1] =44,44 RSI[2]=55,55 RSI[3]=66,66 RSI[4] = 77.77 Now assume latest 2 RSI values are 88,88 and 99,99 and array will look like below: Tick=1 AND limit = 2 ==> RSI[0] = 88,88 RSI[1] =99.99 RSI[2]=55,55 RSI[3]=66,66 RSI[4] = 77.77 BUT shouldn't it be this: Tick=1 AND limit = 2 ==> RSI[0] = 88,88 RSI[1] =99.99 RSI[2]=33,33 RSI[3]=44,44 RSI[4] = 55.55 When 2 new bars come shouldn't we slide previous bar values by 2? previousWhy all indicators written this way and there's no sliding of values. And why they draw trend lines correctly. You can check this example as well: http://docs.mql4.com/customind/IndicatorCounted Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.