Announcement

Collapse
No announcement yet.

Grabbing Mouse Click Data

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

  • Grabbing Mouse Click Data

    I used the sample code found in library and was able to capture the barIndex and yValue from a mouse doubleclick to vPickBar and vPickValue. I want the last doubleclick I used to store these two values so that my Main() program can use them. But vPickBar and vPickValue always seem to have no value.

    The 2nd drawTextReative confirms I have the numbers as vPickBar and vPickValue for I see two lines of text.

    function onLButtonDblClk( barIndex, yValue,vPickBar, vPickValue) {
    updateClickInfo(barIndex, yValue, vPickBar, vPickValue);
    }

    function updateClickInfo(barIndex, yValue, vPickBar, vPickValue) {
    drawTextRelative(barIndex, yValue, "DblClicked bar " + barIndex + " at " + yValue.toFixed(2), Color.white, Color.navy, Text.BOLD, null, 14, "ClickInfo");
    vPickBar = barIndex;
    vPickValue = yValue;
    drawTextRelative(vPickBar+20, vPickValue+.0006, "DblClicked ALEX bar " + vPickBar + " at " + vPickValue.toFixed(2), Color.red, Color.white, Text.BOLD, null, 14, "ClickInfo2");

    Now in my Main program, as a test, I use vPickBar

    function main( vPickBar, vPickValue ) {

    setStudyTitle( PASS THRU (LIVE)" + vPickBar);

    and I get

    "PASS THRU (LIVE)undefined"

    as my title, confirming that my math operations later on with vPickBar are doing me nothing. vPickbar and vPickValue are also "var"ed above Premain.

    It seems these two values have an instantaneous value and then go immediately to nothing, or they can not exist outside of the special mouse click function. I want to grab these click values and stores them for use later. Even if I remove "vPickBar, vPickValue" as additional parameters to all used functions, this changes nothing.

    What am I missing?

  • #2
    Hi alexmihh,

    Your variables that you are assigning your values are local variables to the functions and are not recognized outside the functions in which they are used. Try creating two variables outside all functions and use them as your repository for your mouse click information.

    Comment


    • #3
      Originally posted by stevehare2003
      Hi alexmihh,

      Your variables that you are assigning your values are local variables to the functions and are not recognized outside the functions in which they are used. Try creating two variables outside all functions and use them as your repository for your mouse click information.
      But in the same EFS is had the code in question, at the top I had these assignments

      /************************************************** **************************************************
      3:31 pm 09FEB06 PASS THRU.efs
      Last fix:
      TO DO:
      get line yvalue with mouse not manual enter

      ************************************************** ************************************************** */
      var bLocalControl = false;
      var vAlexLine = null;
      var vPassedLine = null;
      var vChartTitle = null;
      var vPickBar = null;
      var vPickValue = null;

      // ****************** PREMAIN -- EXECUTE AT LOADUP *****************
      function preMain() {
      setPriceStudy(true);
      // setComputeOnClose(); // *********** IMPORTANT!! for mouse clicks to work
      vThisSymbol = getSymbol() ;

      if (vThisSymbol == "AB #F") { // RUSSELL 2000
      vChartTitle = "RUS" ;
      }

      if (vThisSymbol == "YM #F") { // DOW mini-Futures $5/pt
      vChartTitle = "DOW" ;
      }
      }

      // ****************** MAIN -- EXECUTE AT EACH BAR/TICK *****************
      function main( vPickBar, vPickValue ) {

      setStudyTitle(vChartTitle + " PASS THRU (LIVE)" + vPickBar);

      etc.

      So, have I not already done what you said I needed to do with the var=vPickBar, var=vPickValue statements at very top?? These assignments make these variables accessable to all functions, right?

      Comment


      • #4
        alexmihh,

        I could guess again as to what the issue is, but instead of having to look in my crystal ball, I am going to default to the posting guidelines and ask you to post a working copy of your efs that demonstrates the issue. TIA

        Comment


        • #5
          Originally posted by stevehare2003
          alexmihh,

          I could guess again as to what the issue is, but instead of having to look in my crystal ball, I am going to default to the posting guidelines and ask you to post a working copy of your efs that demonstrates the issue. TIA
          here is the complete code of the issue (it is stripped out of a much more complex code that does nothing for me until I get this resolved). Load it with Russel 2000 emini futuresd contract -- see PIC below, and you see I get the two lines of text, but you see that nothing is passed thru to the chart title, where vPickBar is suppose to hold the value of -76

          /************************************************** **************************************************
          3:31 pm 09FEB06 PASS THRU.efs
          Last fix:
          TO DO:
          get line yvalue with mouse not manual enter

          ************************************************** ************************************************** */

          var vAlexLine = null;
          var vPassedLine = null;
          var vChartTitle = null;
          var vPickBar = null;
          var vPickValue = null;
          var ThisSymbol = null;

          // ****************** PREMAIN -- EXECUTE AT LOADUP *****************
          // ****************** PREMAIN -- EXECUTE AT LOADUP *****************
          // ****************** PREMAIN -- EXECUTE AT LOADUP *****************
          function preMain() {
          setPriceStudy(true);
          // setComputeOnClose(); // *********** IMPORTANT!! for mouse clicks to work

          vThisSymbol = getSymbol() ;

          if (vThisSymbol == "AB #F") { // RUSSELL 2000
          vChartTitle = "RUS" ;
          }

          if (vThisSymbol == "YM #F") { // DOW mini-Futures $5/pt
          vChartTitle = "DOW" ;
          }

          }

          // ****************** MAIN -- EXECUTE AT EACH BAR/TICK *****************
          // ****************** MAIN -- EXECUTE AT EACH BAR/TICK *****************
          // ****************** MAIN -- EXECUTE AT EACH BAR/TICK *****************
          function main( vPickBar, vPickValue ) {

          setStudyTitle(vChartTitle + " PASS THRU (LIVE)" + vPickBar);


          return ;

          } // FINAL ENDIF


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

          function onLButtonDblClk( barIndex, yValue, vPickBar, vPickValue) {
          updateClickInfo(barIndex, yValue, vPickBar, vPickValue);
          }

          function updateClickInfo(barIndex, yValue, vPickBar, vPickValue) {
          drawTextRelative(barIndex, yValue, "DblClicked bar " + barIndex + " at " + yValue.toFixed(2), Color.white, Color.navy, Text.BOLD, null, 14, "ClickInfo");
          vPickBar = barIndex;
          vPickValue = yValue;
          drawTextRelative(vPickBar+2, vPickValue+0.5, "DblClicked with ALEX " + vPickBar + " at " + vPickValue.toFixed(2), Color.red, Color.white, Text.BOLD, null, 14, "ClickInfo2"); //no works

          }

          Comment


          • #6
            here is pic
            Attached Files

            Comment


            • #7
              alexmihh,

              Thank you for posting your code. You are defining the variable as a global variable then establishing seperate instances in all the different functions, which only have meaning in that local function.

              As you indicated that you are working on complex code, it may help if you take a look at this link with regards to variable scope. Also will need to look at this FunctionParameter link so that you learn how you access the parameters in the main() function.

              I hope this helps a bit, let me know if you need some additional assistance.

              Comment


              • #8
                Originally posted by stevehare2003
                alexmihh,

                Thank you for posting your code. You are defining the variable as a global variable then establishing seperate instances in all the different functions, which only have meaning in that local function.

                As you indicated that you are working on complex code, it may help if you take a look at this link with regards to variable scope. Also will need to look at this FunctionParameter link so that you learn how you access the parameters in the main() function.

                I hope this helps a bit, let me know if you need some additional assistance.
                Yes, please do me this favor, and correct this simple code in any way to make it work so that I can use the mouse clicked values in Main(). I need to get this resolved ASAP, this weekend so I can backtest tis weekend. The rest of my code wil work superbly because I have tested it with setting vPickBar to a specific value (715.5). I want that to be the mouse clicked value.

                I would greatly appreciate that

                Comment


                • #9
                  Originally posted by alexmihh
                  Yes, please do me this favor, and correct this simple code in any way to make it work so that I can use the mouse clicked values in Main(). I need to get this resolved ASAP, this weekend so I can backtest tis weekend. The rest of my code wil work superbly because I have tested it with setting vPickBar to a specific value (715.5). I want that to be the mouse clicked value.

                  I would greatly appreciate that
                  Yes...

                  Comment


                  • #10
                    I am sorry but I do not understand your response and explanation.

                    I assign vPickBar as a global variable, which can be used in any function. I then define vPickbar only in one place -- in function UpdateClickInfo. It's value never changes in any other place in the efs. And then I pass that value through back to Main, so that that value can be used there, to define other variables. So, it should have defnition and value in Main, that is, the value of the mouse click.

                    I do not know what you mean by "establishing seperate instances." All I thought I was dong was passing the variable through. If I have blank arguments in Main (), I get "null" in the ChartTitle. Even if I remove vPickBar and vPickValue from all arguments everywhere, I still get "null" on ChartTitle

                    I have tried countless combinations of argument using, and not using, vPickBar and vPickValue in any/all argument lists t trying to get this to work. All I get is vPickBar being a) null, b) undefined, or c) formaul error "vPickBar is not defined." Only if I "var vPickBar = 77" at the top, can I get something meaningful in Chart title, but this defeats the whole thing of getting the mouse to set the value.

                    I just can not get this to work. Maybe the asnwer is super simply I am not seeing it, but with this small code and the number of diferent things I have tried, I have not stumbled on the right order of variable assignment to get this to work.

                    I am surpised there is no sample efs of how to do this since I would think this is a very common thing users want to do. The sample given just tells you how to get the value, but not how to USE the value (once gotten) afterwards in a different function (like Main).

                    Which leads me to my original thought -- I wonder if this mouse clicked data exists for more than an instant (at click time) and then vanishes, and then this data can never be grabbed and captured and used used in any other function. Hopefully this is not the case.
                    Last edited by alexmihh; 02-10-2006, 06:21 PM.

                    Comment


                    • #11
                      I am busy this weekend so this will have to wait to next week. You indicate you are trying to pass the value back to main(), however, one of the links I provided shows the only way to provide input parameters to the main function (calling main() is done by the efs engine).

                      Regardless, you may want to look in my fileshare, Functions, for some examples or use the Search functionality of the forum to look for posts on button usage. If you cannot code this yourself or do not have the time, I would suggest you contact an efs consultant.

                      Comment


                      • #12
                        If you can look at this like real soon, I would REALLY be thankful to you.

                        I somehow think that if I am wriong, I am wrong in a **very** obvious way, that would be immediately and clealry evident to any experiended EFSer who could solve the problem in less than 10 seconds.

                        The problem is simple. Define a value outside of Main and then bring it back into Main to be used there. This has to be done all the time and has to be so common a thing that EFSers do, that it should be a piece of cake to correct me.

                        I do not want to wrack mt head over this IF it is a case that mouse data will not work like this when all other data will. Everything I will read will tell me it can be done, when maybe it can not be done. It may be that the special mouse click functions are unique in some way

                        My code is SUPER simple. Please just make the single line correction where needed

                        Thnaks

                        Comment


                        • #13
                          If you look at this code from Chris K's efs Developers Reference, maybe that will help.



                          onLButtonDblClk( barIndex, yValue [,x] [,y] )



                          This function is an event handler for left-button double-click mouse events. Be aware that onLButtonDown and onLButtonUp also get called on double-click events.



                          Parameters



                          barIndex
                          the bar index where mouse was clicked

                          yValue
                          the price value where mouse was clicked

                          x
                          optional. x coordinate in study pane

                          y
                          optional. y coordinate in study pane




                          Usage



                          function preMain() {



                          setPriceStudy(true);

                          setStudyTitle("Mouse Button Clicks");

                          setShowCursorLabel(false);



                          }



                          function main() {



                          }



                          function onLButtonDown( barIndex, yValue) {



                          debugPrintln("LeftDown: " + barIndex + ", " + yValue);

                          updateClickInfo(barIndex, yValue);



                          }



                          function onLButtonUp( barIndex, yValue) {



                          debugPrintln("LeftUp: " + barIndex + ", " + yValue);

                          updateClickInfo(barIndex, yValue);



                          }



                          function onRButtonDown( barIndex, yValue) {



                          debugPrintln("RightDown: " + barIndex + ", " + yValue);

                          updateClickInfo(barIndex, yValue);



                          }



                          function onRButtonUp( barIndex, yValue) {



                          debugPrintln("RightUp: " + barIndex + ", " + yValue);

                          updateClickInfo(barIndex, yValue);



                          }



                          function onLButtonDblClk( barIndex, yValue) {



                          debugPrintln("LeftDblClk: " + barIndex + ", " + yValue);

                          updateDblClickInfo(barIndex, yValue);



                          }



                          function onRButtonDblClk( barIndex, yValue) {



                          debugPrintln("RightDblClk: " + barIndex + ", " + yValue);

                          updateDblClickInfo(barIndex, yValue);



                          }





                          function updateClickInfo(barIndex, yValue) {



                          drawTextAbsolute(5, 15, "Clicked bar " + barIndex + " at " + yValue.toFixed(2),

                          Color.white, Color.navy, Text.RELATIVETOLEFT|Text.RELATIVETOBOTTOM|Text.BOL D, null, 14, "ClickInfo");



                          }



                          function updateDblClickInfo(barIndex, yValue) {



                          drawTextAbsolute(5, 35, "Double Clicked bar " + barIndex + " at " + yValue.toFixed(2),

                          Color.white, Color.navy, Text.RELATIVETOLEFT|Text.RELATIVETOBOTTOM|Text.BOL D, null, 14, "DblClickInfo");

                          }

                          Comment


                          • #14
                            Originally posted by dloomis
                            If you look at this code from Chris K's efs Developers Reference, maybe that will help.
                            Thanks for the suggestion. I am quite familar with these functions, I have read all about them and have coded with them 100x, but I still can not find a way to capture and return barIndex and yValue to be used in Main, which is my issue. If you look at the code provided with these examples, you see Main() is totally empty. I want Main to do something with these values.

                            The EFS examples show you how yo DISPLAY these values, and of course how you might use these values within the (sub)function, but it seems to be just for diaplay purposes. Once you leave that function, these values seem to disapear.

                            I wish I could find an example of someone using a funtion NOT called from Main/PreMain and returning that to Main somehow

                            One thought is to call these mouse finctions from within Main, but how do you do that since these functions are really event handlers, sort of special functions? Can I run in Main, and then call onLButtonDown at a specific instance ONLY? Does not look like it to me because one these functions ar in the EFS thare are ALWAYS working, as you can see from the EFS examples - where Main is totally empty.

                            This is why reading the EFS links about functions and parameters tells me nothing because the normal case is you define a function and then call that ot use it from main in a specific instance when needed. How many functions always work even main Main is totally empty?? The EFS help links about funtions and parametes seem to be useless info for thes special event handler functions, and the "standard" description of functions and parameters does not apply in these cases -- these functions work even when Main is a total blank. So directing me to links to read about standard functions and parameters just misses the whole point for me.

                            Putting/calling these event handlers in Main changes nothing. The parameters of these mouse funtions can/do exist when Main does nothing, and thus they have no connection to Main, which is why I can not pass them back to Main

                            That is why I think I am getting nowhere fast.

                            There seems to be only one thing I can think of that I think will work. With the mouse function write barIndex and yValue to a file on the hard disk. That preserves these values for sure. Then use Main to open this file and read "grab" the values. In this way you have taken values of a function never called from Main, and return it to Main for use there. This involves additonal I/O which I wish to avoid, but fortunately I will only be gragbbing the mouse info very occassionally, and in Main I can create a button to grab that info when I choose (just after grabbing the info), so I do the file I/O only when I decide to, which will not be that often anyway.

                            Maybe I am just stupid because it is hard for me to believe that no one has ever addressed this situation before (grab a value from mouse click for purposes other than simple display on the chart and use it in Main for mathemetical/logical operations) and that the forum gurus here have so far just misdirected me and not understood clearly this issue, and that there is no EFS help on this particualr type of issue, and not a single EFS example anywhere that deals with this issue.

                            That is amazing to me, **if** that is true. How many developers are there that have written special trading programs in EFS that have not come across this issue at some point?

                            Comment


                            • #15
                              Here is one method to accomplish what you requested.

                              PHP Code:
                              var vChartTitle " Double Click Values";
                              var 
                              uRa = new TenSec(vChartTitle);
                              function 
                              preMain() 
                              {
                               
                              setPriceStudy(true);
                              }
                              function 
                              main() {

                              function 
                              onLButtonDblClk(barIndexyValue
                              {
                               
                              uRa.aS(barIndex+","yValue.toFixed(2));
                              }
                              function 
                              TenSec(ar)
                              {
                               
                              this.aR ar;
                               
                              this.aS = aT;
                               
                              setStudyTitle(ar);
                               function 
                              aT(au){
                                
                              setStudyTitle(this.aR+" "+au);
                               }

                              Comment

                              Working...
                              X