Announcement

Collapse
No announcement yet.

MACD of RSI

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

  • MACD of RSI

    Alex , I an attempting to set up this efs so that I can edit it without opening up the efs. I want to control whether it shows the histogram ,MACD lines , drop down lines ,or any combination thereof. Your help is needed and as always appreciated. /************************************************** *******
    Alexis C. Montenegro © July 2003
    Use and/or modify this code freely. If you redistribute it
    please include this and/or any other comment blocks and a
    description of any changes you make.
    ************************************************** ********/

    var vRSI = null;
    var vMACD = null;

    function preMain() {
    setStudyTitle("MACDofRSI");
    setCursorLabelName("MACDHist",0);
    setCursorLabelName("MACD",1);
    setCursorLabelName("MACDSig",2);
    setDefaultBarFgColor(Color.lightyellow,0);
    setDefaultBarFgColor(Color.blue,1);
    setDefaultBarFgColor(Color.red,2);
    setDefaultBarThickness(5,0);
    setDefaultBarThickness(2,1);
    setDefaultBarThickness(1,2);
    setPlotType(PLOTTYPE_HISTOGRAM);
    addBand (0, PS_SOLID,1,Color.lightyellow,1);


    var fp1 = new FunctionParameter("Length", FunctionParameter.NUMBER);
    fp1.setName("RSILength");
    fp1.setLowerLimit(1);
    fp1.setDefault(14); //Edit this value to set a new default

    var fp2 = new FunctionParameter("Source", FunctionParameter.STRING);
    fp2.setName("RSISource");
    fp2.addOption("Close");
    fp2.addOption("High");
    fp2.addOption("Low");
    fp2.addOption("Open");
    fp2.addOption("HL/2");
    fp2.addOption("HLC/3");
    fp2.addOption("OHLC/4");
    fp2.setDefault("Close"); //Edit this value to set a new default

    var fp3 = new FunctionParameter("Fast", FunctionParameter.NUMBER);
    fp3.setLowerLimit(1);
    fp3.setDefault(12); //Edit this value to set a new default

    var fp4 = new FunctionParameter("Slow", FunctionParameter.NUMBER);
    fp4.setLowerLimit(1);
    fp4.setDefault(26); //Edit this value to set a new default

    var fp5 = new FunctionParameter("Smoothing", FunctionParameter.NUMBER);
    fp5.setLowerLimit(1);
    fp5.setDefault(9); //Edit this value to set a new default

    var fp6 = new FunctionParameter("TypeOsc", FunctionParameter.BOOLEAN);
    fp6.setName("SMA (Oscillator)");
    fp6.setDefault(false); //Edit this value to set a new default

    var fp7 = new FunctionParameter("TypeSig", FunctionParameter.BOOLEAN);
    fp7.setName("SMA (Signal)");
    fp7.setDefault(false); //Edit this value to set a new default

    var fp8 = new FunctionParameter("bHist", FunctionParameter.STRING);
    fp8.setName("Display Histogram");
    fp8.addOption("Yes");
    fp8.addOption("No");
    fp8.setDefault("Yes");

    var fp9 = new FunctionParameter("bMACD", FunctionParameter.STRING);
    fp9.setName("Display MACD");
    fp9.addOption("Yes");
    fp9.addOption("No");
    fp9.setDefault("No");

    var fp10 = new FunctionParameter("bSignal", FunctionParameter.STRING);
    fp10.setName("Display Signal");
    fp10.addOption("Yes");
    fp10.addOption("No");
    fp10.setDefault("No");

    var fp11 = new FunctionParameter("bDropLines", FunctionParameter.STRING);
    fp11.setName("Display Drop Lines");
    fp11.addOption("Yes");
    fp11.addOption("No");
    fp11.setDefault("No");
    }













    function main(Length, Source, Fast, Slow, Smoothing, TypeOsc, TypeSig) {

    if (vRSI == null) vRSI = new RSIStudy(Length, Source);
    if (vRSI.getValue(RSIStudy.RSI)==null)
    return;
    if (vMACD == null) vMACD = new MACDStudy(Fast, Slow, Smoothing, vRSI, RSIStudy.RSI, TypeOsc, TypeSig);

    /*********************************************
    Insert your code following this text block
    Use vMACD.getValue(MACDStudy.HIST) and
    vMACD.getValue(MACDStudy.MACD) and
    vMACD.getValue(MACDStudy.SIGNAL) for your code
    **********************************************/

    if (vMACD.getValue(MACDStudy.HIST) > vMACD.getValue(MACDStudy.HIST,-1))
    setBarFgColor(Color.lime);
    if (vMACD.getValue(MACDStudy.HIST) < vMACD.getValue(MACDStudy.HIST,-1))
    setBarFgColor(Color.red);










    return new Array (vMACD.getValue(MACDStudy.HIST),vMACD.getValue(MAC DStudy.MACD),vMACD.getValue(MACDStudy.SIGNAL));

    }

  • #2
    colours
    You will first need to include all the parameters you added ie bHist, bMACD etc inside function main(Length, Source, Fast, Slow, Smoothing, TypeOsc, TypeSig). They need to be in the order in which you list them.
    Then you will need to add the conditions based on those user defined function parameters. For example if you want to be able to switch on and off the plot of the MACD then you would do the following
    var nSignal = vMACD.getValue(MACDStudy.SIGNAL);
    if(nSignal==null) return;
    if(bSignal=="No")
    nSignal=nSignal.toFixed(2);

    You also need to replace vMACD.getValue(MACDStudy.SIGNAL) in the return new Array with nSignal.
    Repeat the process for every line you want to be able to display or hide.
    Alex

    Comment


    • #3
      Thanks Alex ,I'll give it a go . Your assistance is always appreciated.

      Comment

      Working...
      X