Announcement

Collapse
No announcement yet.

Color Histogram

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

  • Color Histogram

    Anyone knows how to make a change the histogram color to red when below 0 and blue when above ? Thank you

    /Z-score indicator/

    var ma=null;

    function preMain()
    {
    setPlotType(PLOTTYPE_HISTOGRAM);
    setStudyTitle("Zscore");
    setCursorLabelName("Zscore",0);
    setDefaultBarFgColor(Color.red,2);
    addBand(1,PS_DOT,1,Color.black);
    addBand(-1,PS_DOT,1,Color.black);
    addBand(2.5,PS_SOLID,2,Color.black);
    addBand(-2.5,PS_SOLID,2,Color.black);
    addBand(2,PS_SOLID,1,Color.black);
    addBand(-2,PS_SOLID,1,Color.black);
    }

    function main(Period) {
    var StdDev = 0;
    var SumSqr = 0;
    var counter = 0;

    if(Period == null)
    Period = 20;

    if(ma == null)
    ma = new MAStudy(Period, 0, "HLC/3", MAStudy.Simple);

    for(counter = - Period + 1; counter <=0; counter++)
    SumSqr +=Math.pow((close(counter) - ma.getValue(MAStudy.MA)),2);

    StdDev = Math.sqrt(SumSqr / Period);

    return (close() - ma.getValue(MAStudy.MA)) / StdDev;
    }

  • #2
    Here you go...

    PHP Code:
    var ma=null;

    function 
    preMain()
    {
    setPlotType(PLOTTYPE_HISTOGRAM);
    setStudyTitle("Zscore");
    setCursorLabelName("Zscore",0);
    setDefaultBarFgColor(Color.red,2);
    addBand(1,PS_DOT,1,Color.black);
    addBand(-1,PS_DOT,1,Color.black);
    addBand(2.5,PS_SOLID,2,Color.black);
    addBand(-2.5,PS_SOLID,2,Color.black);
    addBand(2,PS_SOLID,1,Color.black);
    addBand(-2,PS_SOLID,1,Color.black);
    }

    function 
    main(Period) {
    var 
    StdDev 0;
    var 
    SumSqr 0;
    var 
    counter 0;

    if(
    Period == null)
    Period 20;

    if(
    ma == null)
    ma = new MAStudy(Period0"HLC/3"MAStudy.Simple);

    for(
    counter = - Period 1counter <=0counter++)
    SumSqr +=Math.pow((close(counter) - ma.getValue(MAStudy.MA)),2);

    StdDev Math.sqrt(SumSqr Period);

    if ( ((
    close() - ma.getValue(MAStudy.MA)) / StdDev) > 0.0) {
      
    setBarFgColor(Color.blue);
    } else {
      
    setBarFgColor(Color.red);
    }

    return (
    close() - ma.getValue(MAStudy.MA)) / StdDev;

    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Thank you very much Doji3333, I appreciate your help.

      Comment


      • #4
        Re: Reply to post 'Color Histogram'

        Elmar
        I think this should do what you want
        Alex


        /Z-score indicator/

        var ma=null;

        function preMain()
        {
        setPlotType(PLOTTYPE_HISTOGRAM);
        setStudyTitle("Zscore");
        setCursorLabelName("Zscore",0);
        setDefaultBarFgColor(Color.red,2);
        addBand(1,PS_DOT,1,Color.black);
        addBand(-1,PS_DOT,1,Color.black);
        addBand(2.5,PS_SOLID,2,Color.black);
        addBand(-2.5,PS_SOLID,2,Color.black);
        addBand(2,PS_SOLID,1,Color.black);
        addBand(-2,PS_SOLID,1,Color.black);
        }

        function main(Period) {
        var StdDev = 0;
        var SumSqr = 0;
        var counter = 0;

        if(Period == null)
        Period = 20;

        if(ma == null)
        ma = new MAStudy(Period, 0, "HLC/3", MAStudy.Simple);

        for(counter = - Period + 1; counter <=0; counter++)
        SumSqr +=Math.pow((close(counter) -
        ma.getValue(MAStudy.MA)),2);

        StdDev = Math.sqrt(SumSqr / Period);
        vX = (close() - ma.getValue(MAStudy.MA)) / StdDev;
        if (vX > 0.0
        ) onAction1()
        else if (
        1 == 1
        ) onAction2();

        return vX;
        }

        function postMain() {
        }
        function onAction1() {
        setBarFgColor(Color.blue);
        }
        function onAction2() {
        setBarFgColor(Color.red);
        }

        Comment

        Working...
        X