Announcement

Collapse
No announcement yet.

Drawing lines in study

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

  • Drawing lines in study

    I have the following code (also see attached image with notes) with which I would like to draw a line when a signal first hits an upper or lower band in bollinger bands. The color coding seems to be correct, but the lines don't draw correctly. I also want to draw an additional line above or below the bands which is equivalent to the width of the band (after it is first hit).

    Many thanks in advance for any assistance.

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("Bollinger Bands");
    setCursorLabelName("UpperBB", 0 );
    setCursorLabelName("MiddleBB", 1 );
    setCursorLabelName("LowerBB", 2 );
    setDefaultBarFgColor(Color.red, 0); // upper
    setDefaultBarFgColor(Color.blue, 1); // middle
    setDefaultBarFgColor(Color.green, 2); // lower
    setColorPriceBars(true);
    setDefaultPriceBarColor(Color.black);
    }

    var studybb = new BollingerStudy(20, "Close", 2.0);
    var BBwidth = 0;

    function main() {

    var vUpper = studybb.getValue(BollingerStudy.UPPER);
    var vMiddle = studybb.getValue(BollingerStudy.BASIS);
    var vLower = studybb.getValue(BollingerStudy.LOWER);

    if(Strategy.isLong()) setPriceBarColor(Color.lime);
    if(Strategy.isShort()) setPriceBarColor(Color.red);


    if(low() <= vLower && !Strategy.isLong())
    BBwidth = (vUpper - vLower)
    drawLineRelative(getCurrentBarIndex()+1, vLower, 0, vLower, PS_SOLID, 2, Color.green, "Lower_Bar");
    drawLineRelative(getCurrentBarIndex()+1, vLower - BBwidth, 0, vLower - BBwidth, PS_SOLID, 2, Color.green, "Lower_Bar_2");

    Strategy.doLong("Going Up", Strategy.LIMIT, Strategy.THISBAR, null, vLower)

    if(high() >= vUpper && !Strategy.isShort())
    BBwidth = (vUpper - vLower)
    drawLineRelative(getCurrentBarIndex()+1, vUpper, 0, vUpper, PS_SOLID, 2, Color.red, "Upper_Bar");
    drawLineRelative(getCurrentBarIndex()+1, vUpper + BBwidth, 0, vUpper + BBwidth, PS_SOLID, 2, Color.red, "Upper_Bar_2");
    Strategy.doShort("Going Down", Strategy.LIMIT, Strategy.THISBAR, null, vUpper)

    // DebugPrintln("Sample text : "+close()+" : "+BBwidth);

    return new Array(vUpper, vMiddle, vLower);

    }
    Attached Files

  • #2
    I worked out the problem, I didn't put my if statement in braces and the semi-coluns were in the wrong place.

    Comment

    Working...
    X