Announcement

Collapse
No announcement yet.

Stoch and sma

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Stoch and sma

    I would like to replace the MACD in this efs with a 3/16 simple oscillator which is centered on the Stochastics. How can I get it to calculate simple instead of exponential? Do I change the default to true on the bottom text and just change the values for the MACD? Thanks. Mike

    function preMain() {
    setStudyTitle("Stoch and MACD");
    setStudyMin(-.4);
    setStudyMax(.4);
    setCursorLabelName("Stoch K" ,0);
    setCursorLabelName("Stoch D" ,1);
    setCursorLabelName("Signal" ,2);
    setCursorLabelName("MACD" ,3);
    setCursorLabelName("Hist" ,4);
    addBand(.3, PS_DASH, 1, Color.lightgrey);
    addBand(-.3, PS_DASH, 1, Color.lightgrey);
    setPlotType(PLOTTYPE_HISTOGRAM, 4);
    setDefaultBarThickness(1, 1);


    setDefaultBarFgColor(Color.lightyellow, 0); //%K
    setDefaultBarFgColor(Color.blue, 1); // %D
    setDefaultBarFgColor(Color.black, 2); // Signal
    setDefaultBarFgColor(Color.black, 3); // MACD
    setDefaultBarFgColor(Color.red, 4); // Hist


    var fp1 = new FunctionParameter("nKlength", FunctionParameter.NUMBER);
    fp1.setName("Stoch %K Length");
    fp1.setLowerLimit(1);
    fp1.setDefault(21);

    var fp2 = new FunctionParameter("nKsmooth", FunctionParameter.NUMBER);
    fp2.setName("Stoch %K Smoothing");
    fp2.setLowerLimit(1);
    fp2.setDefault(8);

    var fp3 = new FunctionParameter("nDlength", FunctionParameter.NUMBER);
    fp3.setName("Stoch %D Length");
    fp3.setLowerLimit(1);
    fp3.setDefault(4);

    var fp4 = new FunctionParameter("nFastLength", FunctionParameter.NUMBER);
    fp4.setName("MACD Fast Length");
    fp4.setLowerLimit(1);
    fp4.setDefault(12);

    var fp5 = new FunctionParameter("nSlowLength", FunctionParameter.NUMBER);
    fp5.setName("MACD Slow Length");
    fp5.setLowerLimit(1);
    fp5.setDefault(21);

    var fp6 = new FunctionParameter("nSignalSmooth", FunctionParameter.NUMBER);
    fp6.setName("MACD Signal Smoothing");
    fp6.setLowerLimit(1);
    fp6.setDefault(8);

    var fp7 = new FunctionParameter("sPriceSource", FunctionParameter.STRING);
    fp7.setName("MACD Price Source");

    fp7.setDefault("Close");

    var fp8 = new FunctionParameter("bSimpleMA", FunctionParameter.STRING);
    fp8.setName("MACD Simple MA");

    fp8.setDefault("false");

    //addBand(0, PS_SOLID, 1, Color.black, "zero");
    }

    var study1 = null;
    var study2 = null;

    function main(nKlength, nKsmooth, nDlength, nFastLength, nSlowLength,
    nSignalSmooth, sPriceSource, bSimpleMA) {

    if (study1 == null || study2 == null) {
    study1 = new StochStudy(nKlength, nKsmooth, nDlength);
    study2 = new MACDStudy(nFastLength, nSlowLength, nSignalSmooth, sPriceSource, eval(bSimpleMA));
    }

    var vK = study1.getValue(StochStudy.FAST);
    var vD = study1.getValue(StochStudy.SLOW);
    if (vK == null || vD == null) return;

    var vSignal = study2.getValue(MACDStudy.SIGNAL);
    var vMACD = study2.getValue(MACDStudy.MACD);
    var vHist = study2.getValue(MACDStudy.HIST);
    if (vSignal == null || vMACD == null || vHist == null) return;


    vK = (vK - 50)/100;
    vD = (vD - 50)/100;

    if(vHist<0)setBarFgColor(Color.red,4);
    if(vHist>=0)setBarFgColor(Color.lime,4);

    return new Array(vK, vD, vSignal, vMACD, vHist);

  • #2
    Mike
    Yes, set the MACD Simple MA to "true" and change the values of the MACD to 3-16-1.
    You may also want to implement the following changes to the efs

    Substitute

    var fp8 = new FunctionParameter("bSimpleMA", FunctionParameter.STRING);
    fp8.setName("MACD Simple MA");

    fp8.setDefault("false");

    with the following

    var fp8 = new FunctionParameter("bSimpleMA", FunctionParameter.BOOLEAN);
    fp8.setName("MACD Simple MA");

    fp8.setDefault(false);

    and substitute

    study2 = new MACDStudy(nFastLength, nSlowLength, nSignalSmooth, sPriceSource, eval(bSimpleMA));

    with the following

    study2 = new MACDStudy(nFastLength, nSlowLength, nSignalSmooth, sPriceSource, bSimpleMA);

    The above changes will save you having to type true or false when you want to change the MA type from simple to exponential.
    Alex

    Comment

    Working...
    X