Announcement

Collapse
No announcement yet.

Buttons vs Buttons

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

  • Buttons vs Buttons

    I'm trying to sort out some of the new stuff related to the mouse functions. One of the problems I'm running into is that text buttons and mouse buttons are frequently referred to as buttons in the example code I've found so far. (mousearound, page o buttons, etc)

    I can eventually sort them out from the context, but it seems to me that, now that there are two kinds of buttons to play with, we need to start being more explicit.

    Another problem I'm having is understanding how to tell which of two (text) buttons has been pressed. All I've found so far is the x and y values returned by the mouse functions. But these change with each new bar and as price moves around. If my (text) button is fixed relative to LEFT and /or TOP then it isn't clear to me how to tell them apart in the program.

    And, x values returned by the mouse functions never go positive? Can this be fixed?

    Suggestions, explanations or pointers to example code would be appreciated.

  • #2
    pflash50,

    There are buttons, which is typically drawn by drawTextXXX() functions which specify a callback function within the EFS and mouse functions (could also be referred to as pointer functions). These concepts are seperate and can interact together in the same EFS, but are certainly not required to.

    There was an perhaps unfortuate choice of wording for the mouse functions...in that they do use the term button in their name (onLButtonUp(), etc)...but strictly speaking these are referring to the buttons on the mouse. A better choice would have been OnLClickUp(), etc to clarify the concept that this is different from buttons. Oddly, the button routines have no reference to buttons in thier function name. As stated above it is just typically done by setting the URL parameter of the drawTextXXX() functions and specifying a callback function.

    For buttons, you specify per button which routine will be called when the button is pressed. Therefore once that function is being executed you know which button was pressed. This is the
    URL parmater so:

    drawTextRelative(-10, 20, "MyEFS" + "@URL=EFS:CallBackOne", Color.black, Color.red, Text.Button, null, null, 1);

    would call your efs function named CallBackOne when pressed.

    Note that you don't need to specify Text.Button for this to work, Text.Button just names the text look as if it is a button.

    Hope this helps.

    Garth
    Garth

    Comment


    • #3
      It does indeed. Thanks Garth.

      Comment


      • #4
        Garth,

        A small glitch.

        I can get one callback to work, but others are ignored.

        With the following setup I always get the x/y report in the output window when I click either (text) button.

        I get the "buy" report when I click the buy (texy) button but I do not get a "sell" report when I click the sell (text) button.

        I can change the url for the buy (text) button so it calls the sell function, and that change is reflected in the report. IOW, I get a sell report when I click the buy (text) button.



        Can you tell what I'm missing?



        Code:
        
        function onLButtonDown(barIndex, yValue){
           debugPrintln("===   x/y = " + barIndex  + " / " + yValue + " ===");
        }
        /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/
        function ProcessBuyClick(){
           debugPrintln("BUY");
           UpdateTradeButtons();
           return;
        }
        /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/
        function ProcessSellClick(){
           debugPrintln("SELL");
           UpdateTradeButtons();
           return;
        }
        /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/
        function UpdateTradeButtons(){
        
           //text = "  BUY  " + "@URL=EFS:ProcessSellClick";
           text = "  BUY  " + "@URL=EFS:ProcessBuyClick";
           textID = "buy";
           drawTextRelative(x1, y1, text, FGcolor, Color.white, Flags, fontAM, 12, textID); 
           //
           x1 = 20;
           text = " SELL  " + "@URL=EFS:ProcessSellClick";
           textID = "sell";
           drawTextRelative(x1, y1, text, FGcolor, Color.white, Flags, fontAM, 12, textID); 
           //
        
        
        }
        /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/

        Comment


        • #5
          possible solutions

          Try getting rid of the "return;" statements in your button functions.

          Also, why are you using the "onLButtonDown(barIndex, yValue)" function?? This may be conflicting with your other button functions.

          Try this and let me know.

          B
          Brad Matheny
          eSignal Solution Provider since 2000

          Comment


          • #6
            The onLButtonDown(barIndex, yValue) should have any adverse effect on the other button codes...

            However, I would like to see all of the code (for instance what is happening in main()?)...

            Garth
            Garth

            Comment


            • #7
              No help.

              I had added the return statements because I saw it done in "button example.efs" and wondered if NOT having them was the cause of my problem.

              The onLButtonDown function was there from previous experiments. Removing it changes nothing.

              More suggestions (I hope)?

              Comment


              • #8
                Here is a working example.

                Try this. This is your code with changes to the locations, flags and others. But it works just fine.

                If your code still presents a problem, then I suggest you step thru all of it one variable at a time to debug it.

                B
                Attached Files
                Brad Matheny
                eSignal Solution Provider since 2000

                Comment


                • #9
                  I'm beginning my var by var debug now. In the mean time take a look at this test version I just created. It is cut and paste from the big program (with as few changes as possible to let it run on its own).

                  When I test this version I now get a response from both the buy and the sell (text) buttons [something has changed], but not from either of the exit (text) buttons.

                  I've probably made a typo somewhere, and looked right at it 50 times.

                  Arrrrrgh.



                  Code:
                     //
                     const fontAM = "Arial Monospaced";
                     //
                  
                  /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/
                  function preMain(){
                     debugClear();
                     debugPrintln("buttons.1 @ preMain ");
                     setPriceStudy(true);
                  }
                  /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/
                  function ProcessBuyClick(){
                     debugPrintln("BUY");
                     UpdateTradeButtons();
                     //return;
                  }
                  /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/
                  function ProcessSellClick(){
                     debugPrintln("SELL");
                     UpdateTradeButtons();
                     //return;
                  }
                  /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/
                  function ProcessExitBuyClick(){
                     debugPrintln("EXIT BUY");
                     UpdateTradeButtons();
                  }
                  /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/
                  function ProcessExitSellClick(){
                     debugPrintln("EXIT SELL");
                     UpdateTradeButtons();
                  }
                  /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/
                  function  UpdateTradeButtons(){
                     var x1 = 4;
                     var y1 = 40;
                     var FGcolor = Color.blue;
                     var Flags = Text.RELATIVETOTOP;
                     //
                     x1 = 3;
                     y1 = 35;
                     var text = "    ";
                     var textID = "buttonBG";
                     drawTextRelative(x1, y1, text, FGcolor, Color.white, Flags, fontAM, 60, textID); 
                     //
                     x1 = 4;
                     y1 = 40;
                     text = "  ";
                     textID = "buyBG";
                     drawTextRelative(x1, y1, text, FGcolor, Color.lime, Flags, fontAM, 50, textID); 
                     //
                     x1 = 19;
                     y1 = 40;
                     text = "  ";
                     textID = "sellBG";
                     drawTextRelative(x1, y1, text, FGcolor, Color.red, Flags, fontAM, 50, textID); 
                     //
                     /////////////////
                     //
                     y1 = 50;
                     //Flags = Text.RELATIVETOTOP | Text.ONTOP | Text.BUTTON;
                     Flags = Text.RELATIVETOTOP | Text.ONTOP | Text.FRAME;
                     //
                     x1 = 5;
                     //text = "  BUY  " + "@URL=EFS:ProcessBuyClick";
                     text = "  BUY  " + "@URL=EFS:ProcessExitBuyClick";
                     textID = "buy";
                     drawTextRelative(x1, y1, text, FGcolor, Color.white, Flags, fontAM, 12, textID); 
                     //
                     x1 = 20;
                     text = " SELL  " + "@URL=EFS:ProcessSellClick";
                     textID = "sell";
                     drawTextRelative(x1, y1, text, FGcolor, Color.white, Flags, fontAM, 12, textID); 
                     //
                     x1 = 5;
                     y1 = 80;
                     text = " EXIT  " + "@URL=EFS:ProcessExitBuyClick";
                     textID = "exitBuy";
                     drawTextRelative(x1, y1, text, FGcolor, Color.white, Flags, fontAM, 12, textID); 
                     //
                     x1 = 20;
                     text = " EXIT  " + "@URL=EFS:ProcessExitSellClick";
                     textID = "exitSell";
                     drawTextRelative(x1, y1, text, FGcolor, Color.white, Flags, fontAM, 12, textID); 
                  }
                  /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/
                  /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/
                  /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/
                  function main(){
                     var newBar = getBarState();
                     if(newBar == BARSTATE_NEWBAR){
                        debugPrintln("buttons.1 @ main ");
                     }
                     UpdateTradeButtons();
                  }
                  /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/
                  /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/
                  /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/

                  Comment


                  • #10
                    pflash,

                    You have put together an efs which is stand alone, something I commend you with.

                    FWIW, I would like to use this as an opportunity to recommend to anyone who has a problem with their code to do the same. This allows people on the board to download and provide much better feedback. Plus when it is finished it is an excellent example. In pflash's case, he has 2 of the most capable people on the BB engaged right now helping (Garth and Brad).

                    It probably took pflash an extra 10 minutes to put it together, but the solution will be reached in a fraction of the time and it is one of the best on-line training sessions available. Another good thing is that once you get it done and running, you merely have to stick it back in to your original code. If it runs, life is good, if it doesn't, at least you know which part of the code is responsible for the error.

                    This methods is not only an excellent way to post for help, but it is also a very basic troubleshooting method.

                    Anyways, I apologize getting on the soap box, but this was just too good of an example of cooperative troubleshooting to pass up.

                    Regards,

                    Comment


                    • #11
                      Steve,

                      I appreciate the appreciation ;-).

                      It actually took about 20 minutes to put it together (I had to test and debug it to be sure it actually would run stand alone). But it was well worth the effort.

                      The program I took it from is well over 1000 lines and I'm sure I would have been slammed up one side and down the other if I'd tried to post THAT. No one has the time to wade through that much crap for what is likely to be a typo, although it could still turn out to be soemthing I don't understand (yet).

                      Plus, the big program has a lot of "secret pookie" in it that i don't want you to see ...

                      Don't apologize for doing the soap box thing, especially for something like this. I'm happy to find other programmers that understand how important the "little" things like this are.

                      Comment


                      • #12
                        OK, here it is.

                        The two exit buttons weren't responding because one has the same x coordinate as the buy button and the other has the same x coordinate as the sell button.

                        All I had to do was move the exit buttons to one side (by adjusting their x coordinates), and they started working.

                        (Sometimes the var by var debug is a waste of time, but until you waste it, how are you going to know?)

                        When the debug didn't help, I just about gave up. Then I got to thinking about some of the odd aspects of the way the mouse functuions report x and y coordinates (no positive x values for example). And I had a little flash of inspiration that turned out to be right.

                        Thanks for the assistance. I hope I can return the favor.

                        BTW, this sounds like it coud be a bug, or at least a design flaw.

                        Comment


                        • #13
                          I just wanted to thank all you for your contribution to this thread. It has and will be of great use!

                          Thanks,

                          Fibbgann
                          Excellent book on JavaScript for beginners

                          Comment

                          Working...
                          X