Announcement

Collapse
No announcement yet.

EFS Button question

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

  • EFS Button question

    Next question.

    I cannot understand why the attached code does not execute the way I want it to.

    Basically, I want a buy button drawn if PSL < open0 and a sell button drawn if PSL>open. Despite my many effort , BOTH buttons continue to be drawn.

    Could someone point me in the correct direction please?

    Code:
    function main(){
     
    var PSL = 51.80
    var Chase = .02
    
    var bLng
    var nAsk
    var nBid
    
    
       if (open(0) > PSL) {  
            bLng = true;
            nEntry = (nAsk +Chase);
            DrawBuy();
        } else {
                bLng = false;
                nEntry = (nBid -Chase);
                DrawSell();
    debugPrintln(bLng)
    
    }
    }
        function DrawBuy(){
          		drawTextPixel(20, 65, " Buy @URL=EFS:BuyCallBack", 
    			Color.white, Color.green, 
    			Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.FRAME  | Text.ONTOP | Text.BOLD | Text.CENTER, 
    			"Arial", 12, "OB");
                }
    			
        function DrawSell(){
                drawTextPixel(20, 40, " Sell @URL=EFS:SellCallBack", 
    			Color.white, Color.red, 
    			Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.FRAME | Text.ONTOP | Text.BOLD | Text.CENTER, 
    			"Arial", 12, "OS");
                }
    both both

  • #2
    Patch227
    Once you apply a graphic object to a chart it will remain drawn on the chart unless it is specifically removed or replaced by another graphic object of the same type with the same tagID.
    In your case the simplest solution is to use the same tagID for both buttons. By virtue of the fact that there can only be one graphic object per tagID the other one will be automatically removed.
    Another solution is to add to each function that draws a button a removeText() command to remove the button drawn by the other function (see the link for the description and syntax of the function).
    Alex


    Originally posted by Patch227
    Next question.

    I cannot understand why the attached code does not execute the way I want it to.

    Basically, I want a buy button drawn if PSL < open0 and a sell button drawn if PSL>open. Despite my many effort , BOTH buttons continue to be drawn.

    Could someone point me in the correct direction please?

    Code:
    function main(){
     
    var PSL = 51.80
    var Chase = .02
    
    var bLng
    var nAsk
    var nBid
    
    
       if (open(0) > PSL) {  
            bLng = true;
            nEntry = (nAsk +Chase);
            DrawBuy();
        } else {
                bLng = false;
                nEntry = (nBid -Chase);
                DrawSell();
    debugPrintln(bLng)
    
    }
    }
        function DrawBuy(){
          		drawTextPixel(20, 65, " Buy @URL=EFS:BuyCallBack", 
    			Color.white, Color.green, 
    			Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.FRAME  | Text.ONTOP | Text.BOLD | Text.CENTER, 
    			"Arial", 12, "OB");
                }
    			
        function DrawSell(){
                drawTextPixel(20, 40, " Sell @URL=EFS:SellCallBack", 
    			Color.white, Color.red, 
    			Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.FRAME | Text.ONTOP | Text.BOLD | Text.CENTER, 
    			"Arial", 12, "OS");
                }
    both both

    Comment


    • #3
      Thanks Alex

      but would you mind explaining to me why both buttons being drawn.

      The way I see it
      if (open(0) > PSL)
      should then ONLY call

      function DrawBuy() or function SellBuy() and not both of them or one after another.

      I just want to get the logic behind this clear in my mind.

      As the DrawBuy() and DrawSell() are both in the postmain i cannot see why two seprate functions should be called.

      Comment


      • #4
        Patch227
        Assume for example that at 9:30 the Open is above the PSL value. This condition will call the DrawBuy function which will draw the Buy button. Then on the next bar at 9:31 the Open is below the PSL value. This condition will call the DrawSell() function which draws the Sell button. However because you have not specifically added an instruction to remove the Buy button [and you are using different tagIDs for the two graphical objects] the Buy button remains drawn on the chart regardless of the fact that the DrawBuy() function is not being called.
        Also keep in mind that as the formula is being loaded in the chart it executes once on each historical bar evaluating the conditions. During this process if the Open of each historical bar is above or below your PSL value the main function will call either the DrawBuy() or the DrawSell() function which will draw the corresponding button. By the time the efs is fully loaded and is processing the current bar it may have already drawn multiple times one or both buttons.
        Alex


        Originally posted by Patch227
        Thanks Alex

        but would you mind explaining to me why both buttons being drawn.

        The way I see it
        if (open(0) > PSL)
        should then ONLY call

        function DrawBuy() or function SellBuy() and not both of them or one after another.

        I just want to get the logic behind this clear in my mind.

        As the DrawBuy() and DrawSell() are both in the postmain i cannot see why two seprate functions should be called.

        Comment

        Working...
        X