I am trying to create an MA of a StochasticRSI. The Formula Wizard does not contain the Stochastic RSI as a function. Any help would be appreciated.
Announcement
Collapse
No announcement yet.
MA of StochasticRSI
Collapse
X
-
Dear Linsar,
Please see the code below and let me know if you have any quetions or problems, I'll help you at once.
Regards,
Andy
Code:/****************************************** Provided By : TS Support, LLC for eSignal *****************************************/ //////////////////////////////////// Inputs /////////////////////////////////// // nInputLength - number of bars to use in the StochRSI calculation // // AverageLength - number of bars to use in the StochRSI average calculation // /////////////////////////////////////////////////////////////////////////////// function preMain() { setStudyTitle("StochasticRSI"); setCursorLabelName("S-RSI",0); setCursorLabelName("Average",1); setDefaultBarFgColor(Color.blue, 0); setDefaultBarFgColor(Color.red, 1); setStudyMin(0); setStudyMax(100); addBand(20, PS_SOLID, 1, Color.black); addBand(80, PS_SOLID, 1, Color.black); } var aryRSI = null; var nRsiCount = 0; vStochRSI = new Array(); function main(nInputLength,AverageLength) { if(nInputLength == null) nInputLength = 14; if(AverageLength == null) AverageLength = 3; var Sum = 0; var nBarState = getBarState(); if(nBarState == BARSTATE_ALLBARS) { aryRSI = null; nRsiCount = 0; } if(aryRSI == null) { aryRSI = new Array(nInputLength); nRsiCount = 0; } var vRSI = call("/Library/RSIEnhanced.efs", nInputLength); if(vRSI == null) return; if(nRsiCount < nInputLength) { // prime the array aryRSI[nRsiCount] = vRSI; nRsiCount++; return; } if(nBarState == BARSTATE_NEWBAR) { aryRSI.shift(); aryRSI.push(vRSI); } else if(nBarState == BARSTATE_CURRENTBAR) { aryRSI[nInputLength-1] = vRSI; } var vRSIHH = aryRSI[0]; var vRSILL = aryRSI[0]; var i; for(i = 1; i < nInputLength; i++) { vRSIHH = Math.max(vRSIHH, aryRSI[i]); vRSILL = Math.min(vRSILL, aryRSI[i]); } var StochRSI = ((vRSI - vRSILL) / (vRSIHH - vRSILL)) * 100; for(i = AverageLength - 1; i > 0; i--) vStochRSI[i] = vStochRSI[i - 1]; vStochRSI[0] = StochRSI; for(i = 0; i < AverageLength; i++) Sum += vStochRSI[i]; return new Array(StochRSI,Sum / AverageLength); }
-
linsar
Attached is the efs containing Andy's code
AlexAttached Files
Comment
Comment