Announcement

Collapse
No announcement yet.

help on how to use the text button

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

  • help on how to use the text button

    Can somebody give me the urls about how to draw the text button using drawTextRelative() and drawTextAbsolute(), especially how to detect the mouse action on those buttons. Right now I can do some simple job using the text buttom. However when I draw many buttons on the chart, for example 10 buttons. Because the difference among the functions associated with these 10 buttons is very small, I would like write only one function and use the button id to distinguish which button is clicked. How can I achieve this? Thanks in advance.

  • #2
    This is how I use them...

    This is how I use them...

    var PEButtonNegOffset = -3; // Button Placement Variable
    var RBtnText = ""; // Button Text (built dynamically)
    var vStopLevel = 0; // System Stop Level;


    function RButton() {
    // this function is executed when the button is clicked..
    }


    function main() {

    RBtnText = " STOP : "+formatPriceNumber(vStopLevel)+" ";
    drawTextRelative(PEButtonNegOffset, high(), RBtnText+ "@URL=EFS:RButton", Color.black, Color.RGB(0x00, 0xE0, 0xE0), Text.FRAME | Text.ONTOP | Text.LEFT, null, LabelFontSize, "RBtn");

    }

    Attached is an example of working buttons...
    Attached Files
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Re: This is how I use them...

      Thanks for the reply. However my question is only partially answered. How can I tell which button is clicked in the funtion itself instead of writing one function for each button?


      Originally posted by Doji3333
      This is how I use them...

      var PEButtonNegOffset = -3; // Button Placement Variable
      var RBtnText = ""; // Button Text (built dynamically)
      var vStopLevel = 0; // System Stop Level;


      function RButton() {
      // this function is executed when the button is clicked..
      }


      function main() {

      RBtnText = " STOP : "+formatPriceNumber(vStopLevel)+" ";
      drawTextRelative(PEButtonNegOffset, high(), RBtnText+ "@URL=EFS:RButton", Color.black, Color.RGB(0x00, 0xE0, 0xE0), Text.FRAME | Text.ONTOP | Text.LEFT, null, LabelFontSize, "RBtn");

      }

      Attached is an example of working buttons...

      Comment


      • #4
        Possible solution...

        You might be able to pass a "parameter" in the button code, then write your own function for the use of the parameter..

        PHP Code:
        var PEButtonNegOffset = -3// Button Placement Variable
        var RBtnText ""// Button Text (built dynamically)
        var vStopLevel 0// System Stop Level;


        function RButton(ButtonClicked) {
        // this function is executed when the button is clicked..
          
        if (ButtonClicked == 1) {

          }
          if (
        ButtonClicked == 2) {

          }
        }


        function 
        main() {

        RBtnText " STOP : "+formatPriceNumber(vStopLevel)+" ";
        drawTextRelative(PEButtonNegOffsethigh(), RBtnText"@URL=EFS:RButton(1)"Color.blackColor.RGB(0x000xE00xE0), Text.FRAME Text.ONTOP Text.LEFTnullLabelFontSize"RBtn");

        RBtnText " ENTRY: "+formatPriceNumber(vStopLevel)+" ";
        drawTextRelative(PEButtonNegOffsetlow(), RBtnText"@URL=EFS:RButton(2)"Color.blackColor.RGB(0x000xE00xE0), Text.FRAME Text.ONTOP Text.LEFTnullLabelFontSize"RBtn");


        This might work, I have never tried it...

        Brad
        Brad Matheny
        eSignal Solution Provider since 2000

        Comment


        • #5
          Re: Possible solution...

          Thanks a lot. This is exactly what I want.

          Originally posted by Doji3333
          You might be able to pass a "parameter" in the button code, then write your own function for the use of the parameter..

          PHP Code:
          var PEButtonNegOffset = -3// Button Placement Variable
          var RBtnText ""// Button Text (built dynamically)
          var vStopLevel 0// System Stop Level;


          function RButton(ButtonClicked) {
          // this function is executed when the button is clicked..
            
          if (ButtonClicked == 1) {

            }
            if (
          ButtonClicked == 2) {

            }
          }


          function 
          main() {

          RBtnText " STOP : "+formatPriceNumber(vStopLevel)+" ";
          drawTextRelative(PEButtonNegOffsethigh(), RBtnText"@URL=EFS:RButton(1)"Color.blackColor.RGB(0x000xE00xE0), Text.FRAME Text.ONTOP Text.LEFTnullLabelFontSize"RBtn");

          RBtnText " ENTRY: "+formatPriceNumber(vStopLevel)+" ";
          drawTextRelative(PEButtonNegOffsetlow(), RBtnText"@URL=EFS:RButton(2)"Color.blackColor.RGB(0x000xE00xE0), Text.FRAME Text.ONTOP Text.LEFTnullLabelFontSize"RBtn");


          This might work, I have never tried it...

          Brad

          Comment


          • #6
            Re: Possible solution...

            Too bad. It doesn't work.


            Originally posted by Doji3333
            You might be able to pass a "parameter" in the button code, then write your own function for the use of the parameter..

            PHP Code:
            var PEButtonNegOffset = -3// Button Placement Variable
            var RBtnText ""// Button Text (built dynamically)
            var vStopLevel 0// System Stop Level;


            function RButton(ButtonClicked) {
            // this function is executed when the button is clicked..
              
            if (ButtonClicked == 1) {

              }
              if (
            ButtonClicked == 2) {

              }
            }


            function 
            main() {

            RBtnText " STOP : "+formatPriceNumber(vStopLevel)+" ";
            drawTextRelative(PEButtonNegOffsethigh(), RBtnText"@URL=EFS:RButton(1)"Color.blackColor.RGB(0x000xE00xE0), Text.FRAME Text.ONTOP Text.LEFTnullLabelFontSize"RBtn");

            RBtnText " ENTRY: "+formatPriceNumber(vStopLevel)+" ";
            drawTextRelative(PEButtonNegOffsetlow(), RBtnText"@URL=EFS:RButton(2)"Color.blackColor.RGB(0x000xE00xE0), Text.FRAME Text.ONTOP Text.LEFTnullLabelFontSize"RBtn");


            This might work, I have never tried it...

            Brad

            Comment


            • #7
              OK....

              Explain to me what you are trying to do...

              You want ONE BUTTON that does a bunch of things - right??

              What kinds of things do you want it to do.?

              Brad
              Brad Matheny
              eSignal Solution Provider since 2000

              Comment


              • #8
                Hello Brad/Clearpicks,

                Unfortunately, we can't pass parameters to the EFS function called on the button click. The "@URL=EFS:functionName" portion of the drawText functions only allow for the name of the function to be called. It would be nice to be able to add parameters here and I will certainly suggest that to our development team. For now, the code example below is the best we can do. You still have to create a separate function for each button, but you can have those functions pass the necessary parameters to your central button function.

                PHP Code:

                function preMain() {
                    
                setPriceStudy(true);
                    
                setStudyTitle("Buttons");
                    
                setShowCursorLabel(false);
                }

                function 
                doButton(ButtonClicked) {
                    if (
                ButtonClicked == "b1") {
                        
                debugPrintln("Button 1 clicked");
                    }
                    if (
                ButtonClicked == "b2") {
                        
                debugPrintln("Button 2 clicked");
                    }
                }

                function 
                doB1() {
                    
                doButton("b1");
                }

                function 
                doB2() {
                    
                doButton("b2");
                }

                var 
                bDone false;
                var 
                sButton null;

                function 
                main() {

                    if (
                bDone == false) {
                        
                drawTextAbsolute(1040"Button 1 @URL=EFS:doB1"nullnull
                            
                Text.BUTTON Text.CENTER Text.RELATIVETOLEFT Text.RELATIVETOBOTTOM
                            
                null12"Btn1");
                        
                drawTextAbsolute(1020"Button 2 @URL=EFS:doB2"nullnull
                            
                Text.BUTTON Text.CENTER Text.RELATIVETOLEFT Text.RELATIVETOBOTTOM
                            
                null12"Btn2");
                        
                bDone true;
                    }

                    return;

                Jason K.
                Project Manager
                eSignal - an Interactive Data company

                EFS KnowledgeBase
                JavaScript for EFS Video Series
                EFS Beginner Tutorial Series
                EFS Glossary
                Custom EFS Development Policy

                New User Orientation

                Comment


                • #9
                  Re: OK....

                  I need to create a bunch of buttons. All bottuns do the same thing except for the value of one variable in the function. Right now, it seems I have to create a bunch of buttons according to JasonK's post.



                  Originally posted by Doji3333
                  Explain to me what you are trying to do...

                  You want ONE BUTTON that does a bunch of things - right??

                  What kinds of things do you want it to do.?

                  Brad

                  Comment


                  • #10
                    Maybe Not...

                    Clear,

                    Maybe you can adopt BUTTON GROUPS like I do in my "Trade Buttons" application. Visit the STRATEGY section of this board and download the TradeButtons V1 PT program. This is a program that allows users to use buttons to place trades (using stop levels and PT levels). It also allows user to select between 4 unique stop systems and 4 unique PT systems.

                    Everything is automatic and easy to use. Plus you can see how I use buttons in this case. It might give you some ideas.

                    Here is a hint. Use "Button Control Variables" in your code.

                    Brad
                    Brad Matheny
                    eSignal Solution Provider since 2000

                    Comment


                    • #11
                      Re: Maybe Not...

                      Doji3333,

                      Thanks a lot.

                      Clearpicks


                      Originally posted by Doji3333
                      Clear,

                      Maybe you can adopt BUTTON GROUPS like I do in my "Trade Buttons" application. Visit the STRATEGY section of this board and download the TradeButtons V1 PT program. This is a program that allows users to use buttons to place trades (using stop levels and PT levels). It also allows user to select between 4 unique stop systems and 4 unique PT systems.

                      Everything is automatic and easy to use. Plus you can see how I use buttons in this case. It might give you some ideas.

                      Here is a hint. Use "Button Control Variables" in your code.

                      Brad

                      Comment


                      • #12
                        Jason

                        In your example below

                        drawTextAbsolute(10, 20, "Button 2 @URL=EFS:doB2", null, null,
                        Text.BUTTON | Text.CENTER | Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM,
                        null, 12, "Btn2");


                        where should the file doB2 be located?

                        In Formulas?

                        Comment


                        • #13
                          Hello David,

                          doB2 is actually a function within the formula, not a separate EFS file.

                          PHP Code:
                          function doB2() {
                              
                          doButton("b2");

                          Jason K.
                          Project Manager
                          eSignal - an Interactive Data company

                          EFS KnowledgeBase
                          JavaScript for EFS Video Series
                          EFS Beginner Tutorial Series
                          EFS Glossary
                          Custom EFS Development Policy

                          New User Orientation

                          Comment


                          • #14
                            Are there any examples of BUTTON_RIGHT around or any hints on how to tell if the right mouse button is clicked?

                            I saw this

                            //This will display a button that, when clicked, calls a button-handler function

                            drawTextAbsolute( -x, 55.0, "Move Bar@URL=EFS:MyCallBack1", Color.Blue, null, Text.BUTTON, "Courier", 10, x );


                            //Elsewhere in your EFS script you would write your button-handler functions as follows:

                            function MyCallBack1( nButtonPressed ) {
                            if (getButtonPressed( nButtonPressed ) == 1 ) {

                            //Our button was pressed so do something here
                            }
                            return;
                            }

                            function getButtonPressed( nButtonPressed ) {
                            //We only want to know if left mouse button was pressed
                            if ( nButtonPressed == BUTTON_LEFT ) {
                            return( 1 );
                            }
                            return( 0 );
                            }


                            but can't figure it out.

                            Comment


                            • #15
                              drawTextAbsolute( 0, 1033, "Click@URL=EFS:rClick", Color.blue, null, Text.FRAME, "Courier", 10, 94 );

                              draws a button

                              function rClick(nButtonPressed ){
                              if ( nButtonPressed == 1 )
                              debugPrintln("left pressed");
                              if ( nButtonPressed == 2 )
                              debugPrintln("right pressed");
                              }

                              tells you which buttonwas pressed.

                              Are there other return codes for nButtonPressed besides 1 or 2?

                              Comment

                              Working...
                              X