StochasticOf_Montage.efs
EFSLibrary - Discussion Board
File Name: StochasticOf_Montage.efs
Description:
Plots the Stochastics of a collection of eSignal Basic Studies.
Formula Parameters:
- Montage Source - Standard
- [Options]
- Open
- High
- Low
- Close
- HL/2
- HLC/3
- OHLC/4
- Standard
- AccDistStudy.ACCDIST
- ADXDMStudy.PDI
- ADXDMStudy.NDI
- ADXDMStudy.ADX
- ATRStudy.ATR
- BollingerStudy.BASIS
- CCIStudy.CCI
- ChopStudy.CHOP
- DonchianStudy.BASIS
- DonchianStudy.LOWER
- DonchianStudy.UPPER
- EnvelopeStudy.BASIS
- EnvelopeStudy.LOWER
- EnvelopeStudy.UPPER
- MAStudy.SIMPLE
- MAStudy.EXPONENTIAL
- MAStudy.WEIGHTED
- MAStudy.VOLUMEWEIGHTED
- MACDStudy.FAST
- MACDStudy.SLOW
- MACDStudy.MACD
- MoneyFlowStudy.MONEYFLOW
- MOMStudy.MOM
- OBVStudy.OBV
- OscStudy.OSC
- PercentRStudy.PERCENTR
- ROCStudy.ROC
- RSIStudy.RSI
- StochStudy.FAST
- Montage Length K - 14
- Montage Smooth K - 1
- Montage Length D - 3
- Montage MA Type - Simple [Simple, Exponential]
- Montage Upper Band - 80
- Montage Lower Band - 20
- Montage Bands' Color - Color.black
- Montage %K Color - Color.blue
- Montage %D Color - Color.red
- Montage %K Thickness - 1
- Montage %D Thickness - 1
- 13-17
The last five parameters are changed dynamically based on the
Basic Study selected from the Montage Source parameter. If
the name of any of these parameters is "NA" then no input is
required for that parameter.
Notes:
Version 1.0 7/20/2004
This formula is designed to calculate stochastics based on the user-defined source selected from the "Montage Source" parameter via Edit Studies. The default, Standard, uses the traditional highest high, lowest low and close similar to the built-in Stochastics study.
Instructions - After selecting a new source for the Montage Source parameter, select "OK" and close the Edit Studies window. Then go back into Edit Studies to view the required parameters for the selected source, if they apply.
Download File:
StochasticOf_Montage.efs
EFS Code:
/********************************************************* Provided By : eSignal © July 2004 Special contributions from Alexis C. Montenegro Version 1.0 7/20/2004 Notes: This formula is designed to calculate stochastics based on the user-defined source selected from the "Montage Source" parameter via Edit Studies. The default, Standard, uses the traditional highes high, lowest low and close similar to the built-in Stochastics study. !!!!!!!!!!! After selecting a new source for the Montage Source parameter, select "OK" and close the Edit Studies window. Then go back into Edit Studies to view the required parameters for the selected source, if they apply. !!!!!!!!!!!!!!!!!!!!!!!!!!!! Formula Parameters: Defaults: 1. Montage Source Standard [Options] Open High Low Close HL/2 HLC/3 OHLC/4 Standard AccDistStudy.ACCDIST ADXDMStudy.PDI ADXDMStudy.NDI ADXDMStudy.ADX ATRStudy.ATR BollingerStudy.BASIS CCIStudy.CCI ChopStudy.CHOP DonchianStudy.BASIS DonchianStudy.LOWER DonchianStudy.UPPER EnvelopeStudy.BASIS EnvelopeStudy.LOWER EnvelopeStudy.UPPER MAStudy.SIMPLE MAStudy.EXPONENTIAL MAStudy.WEIGHTED MAStudy.VOLUMEWEIGHTED MACDStudy.FAST MACDStudy.SLOW MACDStudy.MACD MoneyFlowStudy.MONEYFLOW MOMStudy.MOM OBVStudy.OBV OscStudy.OSC PercentRStudy.PERCENTR ROCStudy.ROC RSIStudy.RSI StochStudy.FAST 2. Montage Length K 14 3. Montage Smooth K 1 4. Montage Length D 3 5. Montage MA Type Simple 6. Montage Upper Band 80 7. Montage Lower Band 20 8. Montage Bands' Color Color.black 9. Montage %K Color Color.blue 10. Montage %D Color Color.red 11. Montage %K Thickness 1 12. Montage %D Thickness 1 13-17 The last five parameters are changed dynamically based on the Basic Study selected from the Montage Source parameter. If the name of any of these parameters is "NA" then no input is required for that parameter. **********************************************************/ var xMA = null; var vBasicStudy = null; var xMA1 = null; var xMA2 = null; var xMA3 = null; function preMain() { setStudyTitle("Stochastic Montage"); setShowTitleParameters(false); setCursorLabelName("%K", 0); setCursorLabelName("%D", 1); setDefaultBarFgColor(Color.blue, 0); setDefaultBarFgColor(Color.red, 1); setDefaultBarThickness(1, 0); setDefaultBarThickness(1, 1); setStudyMax(105); setStudyMin(-5); var fp1 = new FunctionParameter("Source", FunctionParameter.STRING); fp1.setName("Montage Source"); fp1.addOption("Open"); fp1.addOption("High"); fp1.addOption("Low"); fp1.addOption("Close"); fp1.addOption("HL/2"); fp1.addOption("HLC/3"); fp1.addOption("OHLC/4"); fp1.addOption("Standard"); fp1.addOption("AccDistStudy.ACCDIST"); fp1.addOption("ADXDMStudy.PDI"); fp1.addOption("ADXDMStudy.NDI"); fp1.addOption("ADXDMStudy.ADX"); fp1.addOption("ATRStudy.ATR"); fp1.addOption("BollingerStudy.BASIS"); fp1.addOption("CCIStudy.CCI"); fp1.addOption("ChopStudy.CHOP"); fp1.addOption("DonchianStudy.BASIS"); fp1.addOption("DonchianStudy.LOWER"); fp1.addOption("DonchianStudy.UPPER"); fp1.addOption("EnvelopeStudy.BASIS"); fp1.addOption("EnvelopeStudy.LOWER"); fp1.addOption("EnvelopeStudy.UPPER"); fp1.addOption("MAStudy.SIMPLE"); fp1.addOption("MAStudy.EXPONENTIAL"); fp1.addOption("MAStudy.WEIGHTED"); fp1.addOption("MAStudy.VOLUMEWEIGHTED"); fp1.addOption("MACDStudy.FAST"); fp1.addOption("MACDStudy.SLOW"); fp1.addOption("MACDStudy.MACD"); fp1.addOption("MoneyFlowStudy.MONEYFLOW"); fp1.addOption("MOMStudy.MOM"); fp1.addOption("OBVStudy.OBV"); fp1.addOption("OscStudy.OSC"); fp1.addOption("PercentRStudy.PERCENTR"); fp1.addOption("ROCStudy.ROC"); fp1.addOption("RSIStudy.RSI"); fp1.addOption("StochStudy.FAST"); fp1.setDefault("Standard"); var fp4 = new FunctionParameter("LengthK", FunctionParameter.NUMBER); fp4.setName("Montage Length K"); fp4.setLowerLimit(1); fp4.setDefault(14); var fp5 = new FunctionParameter("SmoothK", FunctionParameter.NUMBER); fp5.setName("Montage Smooth K"); fp5.setLowerLimit(1); fp5.setDefault(1); var fp6 = new FunctionParameter("LengthD", FunctionParameter.NUMBER); fp6.setName("Montage Length D"); fp6.setLowerLimit(1); fp6.setDefault(3); var fp7 = new FunctionParameter("MAType", FunctionParameter.STRING); fp7.setName("Montage MA Type"); fp7.addOption("Exponential"); fp7.addOption("Simple"); fp7.setDefault("Simple"); var fp8 = new FunctionParameter("Upper", FunctionParameter.NUMBER); fp8.setName("Montage Upper Band"); fp8.setLowerLimit(0); fp8.setDefault(80); var fp9 = new FunctionParameter("Lower", FunctionParameter.NUMBER); fp9.setName("Montage Lower Band"); fp9.setLowerLimit(0); fp9.setDefault(20); var fp10 = new FunctionParameter("cBands", FunctionParameter.COLOR); fp10.setName("Montage Bands' Color"); fp10.setDefault(Color.black); var fp11 = new FunctionParameter("cK", FunctionParameter.COLOR); fp11.setName("Montage \%K Color"); fp11.setDefault(Color.blue); var fp12 = new FunctionParameter("cD", FunctionParameter.COLOR); fp12.setName("Montage \%D Color"); fp12.setDefault(Color.red); var fp13 = new FunctionParameter("nK", FunctionParameter.NUMBER); fp13.setName("Montage \%K Thickness"); fp13.setLowerLimit(1); fp13.setDefault(1); var fp14 = new FunctionParameter("nD", FunctionParameter.NUMBER); fp14.setName("Montage \%D Thickness"); fp14.setLowerLimit(1); fp14.setDefault(1); fp15 = new FunctionParameter("nNum1", FunctionParameter.NUMBER); fp15.setName("Study Number Parameter1"); fp15.setDefault(5); fp16 = new FunctionParameter("nNum2", FunctionParameter.NUMBER); fp16.setName("Study Number Parameter2"); fp16.setDefault(10); fp17 = new FunctionParameter("nNum3", FunctionParameter.NUMBER); fp17.setName("Study Number Parameter3"); fp17.setDefault(1); fp18 = new FunctionParameter("sString1", FunctionParameter.STRING); fp18.setName("Study Price Source"); fp18.addOption("Open"); fp18.addOption("High"); fp18.addOption("Low"); fp18.addOption("Close"); fp18.addOption("HL/2"); fp18.addOption("HLC/3"); fp18.addOption("OHLC/4"); fp18.setDefault("Close"); fp19 = new FunctionParameter("sString2", FunctionParameter.STRING); fp19.setName("Study Boolean Parameter"); fp19.addOption("true"); fp19.addOption("false"); fp19.setDefault("false"); } var aSource = null; var aHiVal = null; var aLoVal = null; var vEMA = null; var vEMA1 = null; var dPercent = 0.0; var bPrimed = false; var aValue = null; var bEdit = true; function main(Source, LengthK, SmoothK, LengthD, MAType, Upper, Lower, cBands, cK, cD, nK, nD, nNum1, nNum2, nNum3, sString1, sString2) { if (bEdit == true) { drawTextPixel(5, 5, " Edit @URL=EFS:editStudies", null, null, Text.RELATIVETOLEFT|Text.RELATIVETOBOTTOM|Text.BOLD|Text.CENTER|Text.BUTTON, null, 10, "Edit"); for (var i = 15; i < 20; i++) { eval("fp" + i + ".setName('NA')"); } if(Source=="Standard") { setStudyTitle("Stochastic - Standard"); if(xMA1 == null) xMA1 = new MAStudy(1,0,"Close",MAStudy.SIMPLE); if(xMA2 == null) xMA2 = new MAStudy(1,0,"High",MAStudy.SIMPLE); if(xMA3 == null) xMA3 = new MAStudy(1,0,"Low",MAStudy.SIMPLE); } else { if(Source=="Open"||Source=="High"||Source=="Low"||Source=="Close"||Source=="HL/2"||Source=="HLC/3"||Source=="OHLC/4"){ setStudyTitle("Stochastic of - " + Source); if(xMA == null) xMA = new MAStudy(1,0,Source,MAStudy.SIMPLE); if(xMA1 == null) xMA1 = new MAStudy(1,0,xMA,MAStudy.MA,MAStudy.SIMPLE); } else switch (Source) { case "AccDistStudy.ACCDIST" : setStudyTitle("Stochastic of - AccDist"); if(vBasicStudy == null) vBasicStudy = new AccDistStudy(); if(xMA1 == null) xMA1 = new MAStudy(1,0,vBasicStudy,eval(Source),MAStudy.SIMPLE); break; case "ADXDMStudy.PDI" : setStudyTitle("Stochastic of - ADXDM.PDI"); fp15.setName("DI Length"); fp16.setName("ADX Length"); if(vBasicStudy == null) vBasicStudy = new ADXDMStudy(nNum1, nNum2); if(xMA1 == null) xMA1 = new MAStudy(1,0,vBasicStudy,eval(Source),MAStudy.SIMPLE); break; case "ADXDMStudy.NDI" : setStudyTitle("Stochastic of - ADXDM.NDI"); fp15.setName("DI Length"); fp16.setName("ADX Length"); if(vBasicStudy == null) vBasicStudy = new ADXDMStudy(nNum1, nNum2); if(xMA1 == null) xMA1 = new MAStudy(1,0,vBasicStudy,eval(Source),MAStudy.SIMPLE); break; case "ADXDMStudy.ADX" : setStudyTitle("Stochastic of - ADXDM.ADX"); fp15.setName("DI Length"); fp16.setName("ADX Length"); if(vBasicStudy == null) vBasicStudy = new ADXDMStudy(nNum1, nNum2); if(xMA1 == null) xMA1 = new MAStudy(1,0,vBasicStudy,eval(Source),MAStudy.SIMPLE); break; case "ATRStudy.ATR" : setStudyTitle("Stochastic of - ATR"); fp15.setName("ATR Length"); if(vBasicStudy == null) vBasicStudy = new ATRStudy(nNum1); if(xMA1 == null) xMA1 = new MAStudy(1,0,vBasicStudy,eval(Source),MAStudy.SIMPLE); break; case "BollingerStudy.BASIS" : setStudyTitle("Stochastic of - Bollinger.BASIS"); fp15.setName("Bollinger Length"); fp16.setName("Bollinger Standard Deviation"); fp18.setName("Bollinger Price Source"); if(vBasicStudy == null) vBasicStudy = new BollingerStudy(nNum1, sString1, nNum2); if(xMA1 == null) xMA1 = new MAStudy(1,0,vBasicStudy,eval(Source),MAStudy.SIMPLE); break; case "CCIStudy.CCI" : setStudyTitle("Stochastic of - CCI"); fp15.setName("CCI Length"); fp18.setName("CCI Price Source"); if(vBasicStudy == null) vBasicStudy = new CCIStudy(nNum1, sString1); if(xMA1 == null) xMA1 = new MAStudy(1,0,vBasicStudy,eval(Source),MAStudy.SIMPLE); break; case "ChopStudy.CHOP" : setStudyTitle("Stochastic of - Chop"); fp15.setName("Chop Length"); if(vBasicStudy == null) vBasicStudy = new ChopStudy(nNum1); if(xMA1 == null) xMA1 = new MAStudy(1,0,vBasicStudy,eval(Source),MAStudy.SIMPLE); break; case "DonchianStudy.BASIS" : setStudyTitle("Stochastic of - Dochian.BASIS"); fp15.setName("Donchian Length"); fp16.setName("Donchian Offset"); if (nNum2 > 0) nNum2 = 0; if(vBasicStudy == null) vBasicStudy = new DonchianStudy(nNum1, nNum2); if(xMA1 == null) xMA1 = new MAStudy(1,0,vBasicStudy,eval(Source),MAStudy.SIMPLE); break; case "DonchianStudy.LOWER" : setStudyTitle("Stochastic of - Dochian.LOWER"); fp15.setName("Donchian Length"); fp16.setName("Donchian Offset"); if (nNum2 > 0) nNum2 = 0; if(vBasicStudy == null) vBasicStudy = new DonchianStudy(nNum1, nNum2); if(xMA1 == null) xMA1 = new MAStudy(1,0,vBasicStudy,eval(Source),MAStudy.SIMPLE); break; case "DonchianStudy.UPPER" : setStudyTitle("Stochastic of - Dochian.UPPER"); fp15.setName("Donchian Length"); fp16.setName("Donchian Offset"); if (nNum2 > 0) nNum2 = 0; if(vBasicStudy == null) vBasicStudy = new DonchianStudy(nNum1, nNum2); if(xMA1 == null) xMA1 = new MAStudy(1,0,vBasicStudy,eval(Source),MAStudy.SIMPLE); break; case "EnvelopeStudy.BASIS" : setStudyTitle("Stochastic of - Envelope.BASIS"); fp15.setName("Envelope Length"); fp16.setName("Envelope Offset"); fp17.setName("Envelope Percent"); fp18.setName("Envelope Price Source"); fp19.setName("Envelope Exponential"); if (nNum2 > 0) nNum2 = 0; if(vBasicStudy == null) { vBasicStudy = new EnvelopeStudy(nNum1, nNum2, sString1, eval(sString2), nNum3); } if(xMA1 == null) xMA1 = new MAStudy(1,0,vBasicStudy,eval(Source),MAStudy.SIMPLE); break; case "EnvelopeStudy.LOWER" : setStudyTitle("Stochastic of - Envelope.LOWER"); fp15.setName("Envelope Length"); fp16.setName("Envelope Offset"); fp17.setName("Envelope Percent"); fp18.setName("Envelope Price Source"); fp19.setName("Envelope Exponential"); if (nNum2 > 0) nNum2 = 0; if(vBasicStudy == null) { vBasicStudy = new EnvelopeStudy(nNum1, nNum2, sString1, eval(sString2), nNum3); } if(xMA1 == null) xMA1 = new MAStudy(1,0,vBasicStudy,eval(Source),MAStudy.SIMPLE); break; case "EnvelopeStudy.UPPER" : setStudyTitle("Stochastic of - Envelope.UPPER"); fp15.setName("Envelope Length"); fp16.setName("Envelope Offset"); fp17.setName("Envelope Percent"); fp18.setName("Envelope Price Source"); fp19.setName("Envelope Exponential"); if (nNum2 > 0) nNum2 = 0; if(vBasicStudy == null) { vBasicStudy = new EnvelopeStudy(nNum1, nNum2, sString1, eval(sString2), nNum3); } if(xMA1 == null) xMA1 = new MAStudy(1,0,vBasicStudy,eval(Source),MAStudy.SIMPLE); break; case "MAStudy.SIMPLE" : setStudyTitle("Stochastic of - MA.SIMPLE"); fp15.setName("MA Length"); fp16.setName("MA Offset"); fp18.setName("MA Price Source"); if (nNum2 > 0) nNum2 = 0; if(vBasicStudy == null) { vBasicStudy = new MAStudy(nNum1, nNum2, sString1, MAStudy.SIMPLE); } if(xMA1 == null) xMA1 = new MAStudy(1,0,vBasicStudy,MAStudy.MA,MAStudy.SIMPLE); break; case "MAStudy.EXPONENTIAL" : setStudyTitle("Stochastic of - MA.EXPONENTIAL"); fp15.setName("MA Length"); fp16.setName("MA Offset"); fp18.setName("MA Price Source"); if (nNum2 > 0) nNum2 = 0; if(vBasicStudy == null) { vBasicStudy = new MAStudy(nNum1, nNum2, sString1, MAStudy.EXPONENTIAL); } if(xMA1 == null) xMA1 = new MAStudy(1,0,vBasicStudy,MAStudy.MA,MAStudy.SIMPLE); break; case "MAStudy.WEIGHTED" : setStudyTitle("Stochastic of - MA.WEIGHTED"); fp15.setName("MA Length"); fp16.setName("MA Offset"); fp18.setName("MA Price Source"); if (nNum2 > 0) nNum2 = 0; if(vBasicStudy == null) { vBasicStudy = new MAStudy(nNum1, nNum2, sString1, MAStudy.WEIGHTED); } if(xMA1 == null) xMA1 = new MAStudy(1,0,vBasicStudy,MAStudy.MA,MAStudy.SIMPLE); break; case "MAStudy.VOLUMEWEIGHTED" : setStudyTitle("Stochastic of - MA.VOLUMEWEIGHTED"); fp15.setName("MA Length"); fp16.setName("MA Offset"); fp18.setName("MA Price Source"); if (nNum2 > 0) nNum2 = 0; if(vBasicStudy == null) { vBasicStudy = new MAStudy(nNum1, nNum2, sString1, MAStudy.VOLUMEWEIGHTED); } if(xMA1 == null) xMA1 = new MAStudy(1,0,vBasicStudy,MAStudy.MA,MAStudy.SIMPLE); break; case "MACDStudy.FAST" : setStudyTitle("Stochastic of - MACD.FAST"); fp15.setName("MACD Fast Length"); fp16.setName("MACD Slow Length"); fp17.setName("MACD Signal Smoothing"); fp18.setName("MACD Price Source"); fp19.setName("MACD Simple MA"); if(vBasicStudy == null) vBasicStudy = new MACDStudy(nNum1, nNum2, nNum3, sString1, eval(sString2)); if(xMA1 == null) xMA1 = new MAStudy(1,0,vBasicStudy,eval(Source),MAStudy.SIMPLE); break; case "MACDStudy.SLOW" : setStudyTitle("Stochastic of - MACD.SLOW"); fp15.setName("MACD Fast Length"); fp16.setName("MACD Slow Length"); fp17.setName("MACD Signal Smoothing"); fp18.setName("MACD Price Source"); fp19.setName("MACD Simple MA"); if(vBasicStudy == null) vBasicStudy = new MACDStudy(nNum1, nNum2, nNum3, sString1, eval(sString2)); if(xMA1 == null) xMA1 = new MAStudy(1,0,vBasicStudy,eval(Source),MAStudy.SIMPLE); break; case "MACDStudy.MACD" : setStudyTitle("Stochastic of - MACD.MACD"); fp15.setName("MACD Fast Length"); fp16.setName("MACD Slow Length"); fp17.setName("MACD Signal Smoothing"); fp18.setName("MACD Price Source"); fp19.setName("MACD Simple MA"); if(vBasicStudy == null) vBasicStudy = new MACDStudy(nNum1, nNum2, nNum3, sString1, eval(sString2)); if(xMA1 == null) xMA1 = new MAStudy(1,0,vBasicStudy,eval(Source),MAStudy.SIMPLE); break; case "MoneyFlowStudy.MONEYFLOW" : setStudyTitle("Stochastic of - MoneyFlow"); fp15.setName("Money Flow Length"); if(vBasicStudy == null) vBasicStudy = new MoneyFlowStudy(nNum1); if(xMA1 == null) xMA1 = new MAStudy(1,0,vBasicStudy,eval(Source),MAStudy.SIMPLE); break; case "MOMStudy.MOM" : setStudyTitle("Stochastic of - MOM"); fp15.setName("MOM Length"); fp18.setName("MOM Price Source"); if(vBasicStudy == null) vBasicStudy = new MOMStudy(nNum1, sString1); if(xMA1 == null) xMA1 = new MAStudy(1,0,vBasicStudy,eval(Source),MAStudy.SIMPLE); break; case "OBVStudy.OBV" : setStudyTitle("Stochastic of - OBV"); if(vBasicStudy == null) vBasicStudy = new OBVStudy(); if(xMA1 == null) xMA1 = new MAStudy(1,0,vBasicStudy,eval(Source),MAStudy.SIMPLE); break; case "OscStudy.OSC" : setStudyTitle("Stochastic of - OSC"); fp15.setName("OSC Fast Length"); fp16.setName("OSC Slow Length"); fp18.setName("OSC Price Source"); fp19.setName("OSC Exponential"); if(vBasicStudy == null) vBasicStudy = new OscStudy(nNum1, nNum2, sString1, eval(sString2)); if(xMA1 == null) xMA1 = new MAStudy(1,0,vBasicStudy,eval(Source),MAStudy.SIMPLE); break; case "PercentRStudy.PERCENTR" : setStudyTitle("Stochastic of - PercentR"); fp15.setName("PercentR Length"); if(vBasicStudy == null) vBasicStudy = new PercentRStudy(nNum1); if(xMA1 == null) xMA1 = new MAStudy(1,0,vBasicStudy,eval(Source),MAStudy.SIMPLE); break; case "RSIStudy.RSI" : setStudyTitle("Stochastic of - RSI"); fp15.setName("RSI Length"); fp18.setName("RSI Price Source"); if(vBasicStudy == null) vBasicStudy = new RSIStudy(nNum1, sString1); if(xMA1 == null) xMA1 = new MAStudy(1,0,vBasicStudy,eval(Source),MAStudy.SIMPLE); break; case "ROCStudy.ROC" : setStudyTitle("Stochastic of - ROC"); fp15.setName("ROC Length"); fp18.setName("ROC Price Source"); if(vBasicStudy == null) vBasicStudy = new ROCStudy(nNum1, sString1); if(xMA1 == null) xMA1 = new MAStudy(1,0,vBasicStudy,eval(Source),MAStudy.SIMPLE); break; case "StochStudy.FAST" : setStudyTitle("Stochastic of - Stoch.FAST"); fp15.setName("Stoch \%K Length"); fp16.setName("Stoch \%K Smoothing"); fp17.setName("Stoch \%D Length"); if(vBasicStudy == null) vBasicStudy = new StochStudy(nNum1, nNum2, nNum3); if(xMA1 == null) xMA1 = new MAStudy(1,0,vBasicStudy,eval(Source),MAStudy.SIMPLE); break; } } // Study formatting addBand( Upper, PS_SOLID, 1, eval(cBands), 2); addBand( Lower, PS_SOLID, 1, eval(cBands), 3); setDefaultBarFgColor(cK, 0); setDefaultBarFgColor(cD, 1); setDefaultBarThickness(nK, 0); setDefaultBarThickness(nD, 1); bEdit = false; } if (Source=="Standard") { vMA1 = xMA1.getValue(MAStudy.MA); vMA2 = xMA2.getValue(MAStudy.MA); vMA3 = xMA3.getValue(MAStudy.MA); } else { vMA1 = xMA1.getValue(MAStudy.MA); vMA2 = xMA1.getValue(MAStudy.MA); vMA3 = xMA1.getValue(MAStudy.MA); } if(vMA1==null||vMA2==null||vMA3==null) return; if(aSource == null) aSource = new Array(LengthK+SmoothK); if(aHiVal == null) aHiVal = new Array(LengthK+SmoothK); if(aLoVal == null) aLoVal = new Array(LengthK+SmoothK); if(getBarState()==BARSTATE_NEWBAR){ aSource.pop(); aHiVal.pop(); aLoVal.pop(); aSource.unshift(vMA1); aHiVal.unshift(vMA2); aLoVal.unshift(vMA3) }else{ aSource[0] = vMA1; aHiVal[0] = vMA2; aLoVal[0] = vMA3; } var Offset; var cc = 0; var hh = 0; var ll = 0; var percentK; var sum = 0; if (aHiVal[(LengthK+SmoothK)-1] == null) return; if (aLoVal[(LengthK+SmoothK)-1] == null) return; var i; for(i = 0; i < SmoothK; i++) { Offset = i; cc = aSource[Offset]; // The portion of the array to get stochK is from Offset to LengthK+Offset. var vValueH = aHiVal.slice(Offset,LengthK+Offset); if(vValueH == null) return ; var vValueL = aLoVal.slice(Offset,LengthK+Offset); if(vValueL == null) return ; var j; for(j = 0; j < LengthK; j++) { if(j == 0) { hh = vValueH[j]; ll = vValueL[j]; } else { hh = Math.max(hh, vValueH[j]); ll = Math.min(ll, vValueL[j]); } } percentK = ((cc - ll) / (hh - ll)) * 100; sum += percentK; } sum /= SmoothK; var vPlot = sum; if (aValue == null) { aValue = new Array(LengthD); } if (getBarState() == BARSTATE_NEWBAR) { aValue.pop(); aValue.unshift(vPlot); } else { aValue[0] = vPlot; } var k=0; var nSum = 0; for (k = 0; k < LengthD; ++k) { nSum += aValue[k]; } var vSMA = nSum/LengthD; if(MAType=="Exponential"){ if(aValue[LengthD-1] != null) vEMA = EMA(LengthD, aValue); return new Array (sum,vEMA); }else{ return new Array (sum,vSMA); } } function EMA(LengthD, aValue) { var dSum = 0.0; if(getBarState() == BARSTATE_ALLBARS || bPrimed == false) { dPercent = (2.0 / (LengthD + 1.0)); bPrimed = false; } if (getBarState() == BARSTATE_NEWBAR) { vEMA1 = vEMA; } if(bPrimed == false) { for(var i = 0; i < LengthD; i++) { dSum += aValue[i]; } bPrimed = true; return (dSum / LengthD); } else { return (((aValue[0] - vEMA1) * dPercent) + vEMA1); } } function editStudies() { askForInput("Stochastic Montage"); }