/* Only for illustration purposes. Please test the logic and signals before using it in any meaningful way. eSignal doesnt take any responsibility for any bugs OR wrong signal values - AM / eSignal */ var vCntr = 0; var vCMA1 , vCMA2 = null; var xSpeedCMA , xSMASpeedCMA = null; var Offset1 , Offset2; var nCMA1, nCMA2; var nCMAOsc, nCMAOsc_1; var nSpeed; var nCMA,nSMACMA; addBand(0, PS_SOLID, 1, Color.blue, "0-axis") function preMain() { setPriceStudy(false); setStudyTitle("CenteredMA_Oscillator"); setCursorLabelName("V", 0); setDefaultBarStyle(PS_SOLID, 0); setDefaultBarFgColor(Color.magenta, 0); setDefaultBarThickness(1, 0); setPlotType(PLOTTYPE_LINE, 0); setCursorLabelName("V-SMA", 1); setDefaultBarStyle(PS_SOLID, 1); setDefaultBarFgColor(Color.black, 1); setDefaultBarThickness(1, 1); setPlotType(PLOTTYPE_LINE, 1); var fp1 = new FunctionParameter("MALength1", FunctionParameter.NUMBER); fp1.setLowerLimit(1); fp1.setDefault(32); var fp2 = new FunctionParameter("MALength2", FunctionParameter.NUMBER); fp2.setLowerLimit(1); fp2.setDefault(64); var fp3 = new FunctionParameter("MASource", FunctionParameter.STRING); fp3.setName("MASource"); fp3.addOption("Close"); fp3.addOption("High"); fp3.addOption("Low"); fp3.addOption("Open"); fp3.addOption("HL/2"); fp3.addOption("HLC/3"); fp3.addOption("OHLC/4"); fp3.setDefault("Close"); var fp4 = new FunctionParameter("MAType", FunctionParameter.STRING); fp4.setName("MAType"); fp4.addOption("MAStudy.SIMPLE"); fp4.addOption("MAStudy.EXPONENTIAL"); fp4.addOption("MAStudy.WEIGHTED"); fp4.addOption("MAStudy.VOLUMEWEIGHTED"); fp4.setDefault("MAStudy.SIMPLE"); } function main(MALength1, MALength2, MASource, MAType) { if (xSpeedCMA == null) xSpeedCMA = efsInternal("retSpeedCMA", MALength1, MALength2, MASource, MAType); if (xSMASpeedCMA == null) xSMASpeedCMA = sma(10, xSpeedCMA); if(xSpeedCMA.getValue(0) !=0) nCMA_last= xSpeedCMA.getValue(0); if(xSMASpeedCMA.getValue(0) !=0) nSMACMA_last= xSMASpeedCMA.getValue(0); if (xSpeedCMA.getValue(0)==0) nCMA=nCMA_last; else nCMA=xSpeedCMA.getValue(0); if (xSMASpeedCMA.getValue(0)==0) nSMACMA = nSMACMA_last; else nSMACMA=xSMASpeedCMA.getValue(0); return new Array(nCMA, nSMACMA); } function retSpeedCMA (MALength1, MALength2, MASource, MAType) { if (getBarState() == BARSTATE_NEWBAR) vCntr += 1; if (vCntr < MALength1 * 2) return; Offset1 = Math.ceil(MALength1 / 2) * ( - 1); Offset2 = Math.ceil(MALength2 / 2) * ( - 1); if (vCMA1 == null) vCMA1 = new MAStudy(MALength1, Offset1, MASource, eval(MAType)); if (vCMA2 == null) vCMA2 = new MAStudy(MALength2, Offset2, MASource, eval(MAType)); nCMA1 = vCMA1.getValue(0); nCMA2 = vCMA2.getValue(0); if (nCMA1 != null && nCMA2 != null) nCMAOsc = (nCMA1 - nCMA2); if (nCMAOsc_1 != null) nSpeed = nCMAOsc - nCMAOsc_1; nCMAOsc_1 = nCMAOsc; return nSpeed; }