Hi Macavity,
Here is the Stochastic formula with an EMA instead of an SMA. Please let me if you have any further questions or require additional assistance.
Here is the Stochastic formula with an EMA instead of an SMA. Please let me if you have any further questions or require additional assistance.
Code:
/********************************************* Provided By : TS Support, LLC for eSignal. (c) Copyright 2002 **********************************************/ /////////////////////////// Inputs //////////////////////////////////// // nLength - indicates number of bars used in the Stochastic calculation // nSmoothing - indicates number of bars used for smoothing //////////////////////////////////////////////////////////////////////// function preMain() { setStudyTitle("Preferred Stochastic"); setCursorLabelName("percentK", 0); setCursorLabelName("Smoothing", 1); setDefaultBarFgColor(Color.blue, 0); setDefaultBarFgColor(Color.red, 1); addBand(20, PS_SOLID, 1, Color.black); addBand(80, PS_SOLID, 1, Color.black); } var MAVt_1 = 0; function main(nLength, nSmoothing) { if(nLength == null) nLength = 5; if(nSmoothing == null) nSmoothing = 3; var percentK; var ll = 0, hh = 0; var i,j; var sum = 0; var vHigh = getValue("High", 0, -nLength); var vLow = getValue("Low", 0, -nLength); var temp = 0; var MAVt; if(vHigh == null || vLow == null) return; for(j = 0; j < nLength; j++) if(j == 0){ ll = vLow[j]; hh = vHigh[j]; } else{ hh = Math.max(hh, vHigh[j]); ll = Math.min(ll, vLow[j]); } percentK = ((close() - ll) / (hh - ll)) * 100; MAVt = MAVt_1 + (percentK - MAVt_1) / nSmoothing; if (getBarState() == BARSTATE_NEWBAR) MAVt_1 = MAVt; return new Array(percentK,MAVt); }
Comment