Announcement

Collapse
No announcement yet.

Drawing shapes and PRESET

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

  • Drawing shapes and PRESET

    I think the PRESET flag is afffecting my drawShape commands. When a setup is detected I'm want to put a square on BottomRow1 at current bar and an arrow BelowBar2 on the previous bar. I want to color the setp bar purple but the crossover can't be confirmed until NEWBAR by checking the previous 2 bars. Cannot setPriceBarColor for a previous bar so monitor and set color tic-by-tic. (3-bAR Trigger to be added later)

    PHP Code:
    /*    8 open / close crossover
        Show the direction of the trend on the bottom row:
           green if 8 close > 8 open and red if open > close
        Trigger bar is the cross over.  Show the direction
        of the cross using a Red arrow above the price bar or 
        green arrow below the bar & color the price bar purple.
        if not triggered price bar will be aqua (use a 3-bar trigger)
    */

    function preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("Test drawShape");
        
    setCursorLabelName("8-Open"0); 
        
    setDefaultBarFgColor(Color.olive0); 
        
    setCursorLabelName("8-Close"1); 
        
    setDefaultBarFgColor(Color.magenta1);
    }
    var 
    xCls null;
    var 
    xOpn null;
    var 
    bInit false;
    var 
    bSetup false;
    var 
    n8Opnn8Clsn8Cls_1n8Cls_2n8Opn_1n8Opn_2;
    function 
    main(nLen) {
        if (
    bInit == false) {
            
    xCls sma(8close() );
            
    xOpn sma(8open() );
            
    bInit true;
        }

        if (
    getBarState() == BARSTATE_NEWBAR) {
            
    n8Cls_1 xCls.getValue(-1);
            
    n8Cls_2 xCls.getValue(-2);
            
    n8Opn_1 xOpn.getValue(-1);
            
    n8Opn_2 xOpn.getValue(-2);
            if (
    n8Cls_1 == null || n8Cls_2 == null || 
                
    n8Opn_1 == null || n8Opn_2 == null) {return;} 
            
            if ( 
    bSetup == true ) {
                
    bSetup false;
            } else {
                if (
    n8Cls_2 <= n8Opn_2 && n8Cls_1 n8Opn_1) {
                    
    drawShapeRelative( -1BelowBar2Shape.UPARROWnull
                        
    Color.greenShape.ONTOP Shape.PRESET );
                        
    // will not draw the green arrow 
                    
    setPriceBarColor(Color.aqua);
                    
    drawShapeRelative0BottomRow1Shape.SQUAREnull
                        
    Color.greenShape.ONTOP Shape.PRESET );
                        
    // but will draw the green sqaure below price bar
                    
    bSetup true;
                }
                if (
    n8Cls_2 >= n8Opn_2 && n8Cls_1 n8Opn_1) {
                    
    drawShapeRelative( -1AboveBar2Shape.DOWNARROWnull
                        
    Color.redShape.ONTOP Shape.PRESET );
                    
    // if 2nd draw turned off will draw the arrow
                    // above the purple bar (like its supposed to)
                    
    setPriceBarColor(Color.aqua);
                    
    // if this draw is turned on - no arrow & square moves 
                    //drawShapeRelative( 0, BottomRow1, Shape.SQUARE, null, 
                    //    Color.red, Shape.ONTOP | Shape.PRESET );
                    
    bSetup true;
                }
            }
        }
        
        
    n8Cls xCls.getValue(0);
        
    n8Opn xOpn.getValue(0);
        if (
    bSetup == true) {
            
    // do stuff
        
    } else {    // check tic-by-tic to see if the crossover occured on this bar
            
    if (n8Cls_1 n8Opn_1) {            // prev bar was bearish
                
    if (n8Cls n8Opn) {            // bullish crossover
                    
    setPriceBarColor(Color.purple);    
                } else {                        
    // trend is still bearish
                    
    drawShapeRelative0BottomRow1Shape.SQUAREnull
                        
    Color.redShape.ONTOP Shape.PRESET );
                    
    setPriceBarColor(Color.red);
                }
            } else if (
    n8Cls_1 n8Opn_1) {        // prev bar was bullish     
                
    if  ( n8Cls n8Opn) {            // bearish crossover
                    
    setPriceBarColor(Color.purple);    
                } else {                        
    // trend is still bullish
                    
    drawShapeRelative0BottomRow1Shape.SQUAREnull
                        
    Color.greenShape.ONTOP Shape.PRESET );
                    
    setPriceBarColor(Color.green);        
                }
            }
        }    
        return new Array(
    n8Opnn8Cls);


  • #2
    pj909
    Shape.PRESET has nothing to do with it. You need to add a tagID that is unique to each graphical object you draw on the chart
    Aside from that you also have an issue with the logic that draws the squares which are drawn intrabar when the condition is true but are not removed when during the same bar the condition is no longer true.
    If you search the forums [for instances of the keywords tagid or removeshape*] you will find a number of examples on either issue as these topics have been covered before
    Alex


    Originally posted by pj909 View Post
    I think the PRESET flag is afffecting my drawShape commands. When a setup is detected I'm want to put a square on BottomRow1 at current bar and an arrow BelowBar2 on the previous bar. I want to color the setp bar purple but the crossover can't be confirmed until NEWBAR by checking the previous 2 bars. Cannot setPriceBarColor for a previous bar so monitor and set color tic-by-tic. (3-bAR Trigger to be added later)

    PHP Code:
    /*    8 open / close crossover
        Show the direction of the trend on the bottom row:
           green if 8 close > 8 open and red if open > close
        Trigger bar is the cross over.  Show the direction
        of the cross using a Red arrow above the price bar or 
        green arrow below the bar & color the price bar purple.
        if not triggered price bar will be aqua (use a 3-bar trigger)
    */

    function preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("Test drawShape");
        
    setCursorLabelName("8-Open"0); 
        
    setDefaultBarFgColor(Color.olive0); 
        
    setCursorLabelName("8-Close"1); 
        
    setDefaultBarFgColor(Color.magenta1);
    }
    var 
    xCls null;
    var 
    xOpn null;
    var 
    bInit false;
    var 
    bSetup false;
    var 
    n8Opnn8Clsn8Cls_1n8Cls_2n8Opn_1n8Opn_2;
    function 
    main(nLen) {
        if (
    bInit == false) {
            
    xCls sma(8close() );
            
    xOpn sma(8open() );
            
    bInit true;
        }

        if (
    getBarState() == BARSTATE_NEWBAR) {
            
    n8Cls_1 xCls.getValue(-1);
            
    n8Cls_2 xCls.getValue(-2);
            
    n8Opn_1 xOpn.getValue(-1);
            
    n8Opn_2 xOpn.getValue(-2);
            if (
    n8Cls_1 == null || n8Cls_2 == null || 
                
    n8Opn_1 == null || n8Opn_2 == null) {return;} 
            
            if ( 
    bSetup == true ) {
                
    bSetup false;
            } else {
                if (
    n8Cls_2 <= n8Opn_2 && n8Cls_1 n8Opn_1) {
                    
    drawShapeRelative( -1BelowBar2Shape.UPARROWnull
                        
    Color.greenShape.ONTOP Shape.PRESET );
                        
    // will not draw the green arrow 
                    
    setPriceBarColor(Color.aqua);
                    
    drawShapeRelative0BottomRow1Shape.SQUAREnull
                        
    Color.greenShape.ONTOP Shape.PRESET );
                        
    // but will draw the green sqaure below price bar
                    
    bSetup true;
                }
                if (
    n8Cls_2 >= n8Opn_2 && n8Cls_1 n8Opn_1) {
                    
    drawShapeRelative( -1AboveBar2Shape.DOWNARROWnull
                        
    Color.redShape.ONTOP Shape.PRESET );
                    
    // if 2nd draw turned off will draw the arrow
                    // above the purple bar (like its supposed to)
                    
    setPriceBarColor(Color.aqua);
                    
    // if this draw is turned on - no arrow & square moves 
                    //drawShapeRelative( 0, BottomRow1, Shape.SQUARE, null, 
                    //    Color.red, Shape.ONTOP | Shape.PRESET );
                    
    bSetup true;
                }
            }
        }
        
        
    n8Cls xCls.getValue(0);
        
    n8Opn xOpn.getValue(0);
        if (
    bSetup == true) {
            
    // do stuff
        
    } else {    // check tic-by-tic to see if the crossover occured on this bar
            
    if (n8Cls_1 n8Opn_1) {            // prev bar was bearish
                
    if (n8Cls n8Opn) {            // bullish crossover
                    
    setPriceBarColor(Color.purple);    
                } else {                        
    // trend is still bearish
                    
    drawShapeRelative0BottomRow1Shape.SQUAREnull
                        
    Color.redShape.ONTOP Shape.PRESET );
                    
    setPriceBarColor(Color.red);
                }
            } else if (
    n8Cls_1 n8Opn_1) {        // prev bar was bullish     
                
    if  ( n8Cls n8Opn) {            // bearish crossover
                    
    setPriceBarColor(Color.purple);    
                } else {                        
    // trend is still bullish
                    
    drawShapeRelative0BottomRow1Shape.SQUAREnull
                        
    Color.greenShape.ONTOP Shape.PRESET );
                    
    setPriceBarColor(Color.green);        
                }
            }
        }    
        return new Array(
    n8Opnn8Cls);

    Comment


    • #3
      Thanks Alex
      Your help is always appreciated!!!
      PJ

      Comment


      • #4
        PJ
        You are welcome
        Alex


        Originally posted by pj909 View Post
        Thanks Alex
        Your help is always appreciated!!!
        PJ

        Comment

        Working...
        X