Announcement

Collapse
No announcement yet.

2 shapes per bar problem

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

  • 2 shapes per bar problem

    Would someone please explain why this EFS draws just the triangle at the High of each bar. I am trying to draw a circle at each bar's Low and a triangle at each bar's High.

    Thanks.


    PHP Code:
    //{{EFSWizard_Description
    //
    //    This formula was generated by the Alert Wizard
    //
    //}}EFSWizard_Description


    //{{EFSWizard_Declarations
    var vLastAlert = -1;
    //}}EFSWizard_Declarations


    function preMain() {
       
    /**
        *  This function is called only once, before any of the bars are loaded.
        *  Place any study or EFS configuration commands here.
        */
    //{{EFSWizard_PreMain
        
    setPriceStudy(true);
        
    setStudyTitle("shapes");
    //}}EFSWizard_PreMain

    }

    function 
    main() {
       
    /**
        *  The main() function is called once per bar on all previous bars, once per
        *  each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
        *  in your preMain(), it is also called on every tick.
        */

    //{{EFSWizard_Expressions
        //{{EFSWizard_Expression_1
            
    if (
                
    == 1
            
    onAction1();
        
    //}}EFSWizard_Expression_1
        
    //}}EFSWizard_Expressions


    //{{EFSWizard_Return
        
    return null;
    //}}EFSWizard_Return

    }

    function 
    postMain() {
       
    /**
        *  The postMain() function is called only once, when the EFS is no longer used for
        *  the current symbol (ie, symbol change, chart closing, or application shutdown).
        */
    }

    //{{EFSWizard_Actions
        //{{EFSWizard_Action_1
        
    function onAction1() {
            
    drawShapeRelative(0low(), Shape.CIRCLE""Color.RGB(155,0,0), Shape.LEFT);
            
    drawShapeRelative(0high(), Shape.TRIANGLE""Color.RGB(155,0,0), Shape.LEFT);
            
    vLastAlert 1;
        }
        
    //}}EFSWizard_Action_1
        
    //}}EFSWizard_Actions 

  • #2
    checkraise
    That is happening because you did not assign a tagName to each graphical object you want to draw on the chart hence it will draw only the last one you declared.
    In order to resolve this you need to assign a tagName such as for example "CircleLow", "TriangleHigh", etc.



    However if you just assign a name then the script will plot only the very last of each object because there can be only one graphical object with that name
    So you need to assign a tagName that is not only unique for each object but also to each bar. The easiest way to do this is to use either the rawtime() or getCurrentBarCount() functions which return values that are unique to each bar
    Try both examples shown so as to see the difference in behavior
    Alex

    Comment


    • #3
      Hi Alex,

      Adding a unique tag to each object and also to each bar gives what I want, a shape to mark the High and Low on each and every bar. Adding a unique tag to just each shape (and not to each bar) displays a High and Low shape for the current bar only. Once a new bar starts, the shapes disappear from the (-1) bar and are only on the 0 bar.

      Thanks for the lesson and the speedy reply. First rate as usual.

      One final question on this subject of shapes: Even using Shape.TOP and Shape.BOTTOM, the High of the bar is in the center of the triangle, and the Low in the center of the circle. To have the entire triangle sit on top of the High I had to add a constant to the high() parameter, and subtract a constant from the low() for the outer edge of the circle to be right at the Low. I tried using the location flags AboveBar1 and BelowBar1, but nothing changed, the bars' Highs and Lows still went inside the shapes. Can those location flags be used in the Wizard to situate the outer edge of the shapes on the bar's High/Low? Or is there a better way to accomplish this? Or is using constants the only way to go?

      Comment


      • #4
        checkraise
        As always you are most welcome.
        You can use the pre-defined location flags ie AboveBar1, AboveBar2, BelowBar1, etc but you need to add Shape.PRESET in the flag parameter. So replace Shape.BOTTOM and Shape.TOP with Shape.PRESET or you can OR them together with a pipe |
        Alex

        Comment

        Working...
        X