Announcement

Collapse
No announcement yet.

clearShape()

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

  • clearShape()

    I want to draw a shape above the current bar if RSI(7) goes above 70 and below the current bar of RSI (7) falls below 30.

    I wrote a sript that seemed to work except that when the RSI fell back below 70 (or above 30) the shape remained.

    I introduced clearShape() which is supposed to clear the shapes drawn during the current bar but this has introduced two new problems:

    1. I suspect it deletes everything, not just shapes drawn during the current bar because when a new bar forms the shape on the previous bar is deleted too.

    2. When I load the EFS it correctly draws all my shapes but, obvioulsy, then deletes them all.

    How can I draw my shape and delete it when without deleting all the other shapes?

    I've thought of a workaround using shapes the same color as my background but I don't find the very satisfactory.

    Here is my code so far:

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("RSI");
    setCursorLabelName("7");
    }

    function main() {
    var vRSI=rsi(7);

    clearShape();

    if(vRSI<30) drawShapeRelative(0, high()+5*getMinTick(), Shape.DOWNARROW, "", Color.lime, Shape.BOTTOM);
    if(vRSI>70) drawShapeRelative(0, low()-5*getMinTick(), Shape.UPARROW, "", Color.magenta, Shape.TOP);

    return null;
    }

    Thank you!

  • #2
    Re: clearShape()

    BerkoBob
    clearShape() removes all drawn shapes. To remove specific shapes you will need to first assign unique tagIDs to each shape you are drawing and then use removeShape() tied to the unique tagID to remove those that you specifically do not want (see the link to the article in the EFS KnolwedgeBase for the syntax of this function)
    Also if you search the forums for the keyword removeshape* you will find examples of its use as this has been covered before
    Alex


    Originally posted by BerkoBob
    I want to draw a shape above the current bar if RSI(7) goes above 70 and below the current bar of RSI (7) falls below 30.

    I wrote a sript that seemed to work except that when the RSI fell back below 70 (or above 30) the shape remained.

    I introduced clearShape() which is supposed to clear the shapes drawn during the current bar but this has introduced two new problems:

    1. I suspect it deletes everything, not just shapes drawn during the current bar because when a new bar forms the shape on the previous bar is deleted too.

    2. When I load the EFS it correctly draws all my shapes but, obvioulsy, then deletes them all.

    How can I draw my shape and delete it when without deleting all the other shapes?

    I've thought of a workaround using shapes the same color as my background but I don't find the very satisfactory.

    Here is my code so far:

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("RSI");
    setCursorLabelName("7");
    }

    function main() {
    var vRSI=rsi(7);

    clearShape();

    if(vRSI<30) drawShapeRelative(0, high()+5*getMinTick(), Shape.DOWNARROW, "", Color.lime, Shape.BOTTOM);
    if(vRSI>70) drawShapeRelative(0, low()-5*getMinTick(), Shape.UPARROW, "", Color.magenta, Shape.TOP);

    return null;
    }

    Thank you!

    Comment


    • #3
      It worked! As usual!

      Thank you Alex!

      Comment


      • #4
        BerkoBob
        You are welcome
        Alex


        Originally posted by BerkoBob
        It worked! As usual!

        Thank you Alex!

        Comment

        Working...
        X