Announcement

Collapse
No announcement yet.

histogram

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

  • histogram

    Can someone tell me where to place the correct text to change histogram to green when above zero and red when below zero?

    Thanks,
    Mike

    function preMain() {
    setStudyTitle("Stoch and MACD");
    setStudyMin(-.5);
    setStudyMax(.5);
    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.cyan, 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(1);

    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(26);

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

    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;

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

  • #2
    try inserting these two lines near the end

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

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

    Comment


    • #3
      MACD histogram

      David,

      Thanks for the reply, but this showed when MACD crosses the zero line. I would like it to change green/red when the MACD line crosses the signal line.

      Thanks,

      Mike

      ps. I just changed MACD to Hist and it worked!

      Thanks again,

      Mike
      Last edited by mplogos; 09-04-2003, 07:08 PM.

      Comment


      • #4
        What is the signal line called?

        vK, vD, vSignal, vMACD, vHist

        Comment

        Working...
        X