• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

left , right or middle click ?

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

    left , right or middle click ?

    Hi
    Using the command


    System.Windows.Point cursorPoint = chartControl.MouseDownPoint;
    I can detect where the user clicked on the chart.

    How can I detect, in addition, if he left , right or middle click ?

    #2
    Hello,

    Thank you for the question.

    For mouse events, you would need to add an event handler and subscribe to the event on the object you want this to occur for.

    If you wanted to detect mouse events from the chart control, you would likely need to use the mouse event handlers that are in the ChartControl object such as PreviewMouseLeftButtonDown.

    Event handlers in general is not something NinjaTrader covers because this is a broad subject related to general C# programming, you can find more on events on MSDN here: https://msdn.microsoft.com/en-us/library/ms366768.aspx

    A simple example of subscribing to an event handler could be:

    Code:
    protected override void OnStateChange()
    {
        if (State == State.Historical)
        {
            chartControl.PreviewMouseLeftButtonDown += chartControl_PreviewMouseLeftButtonDown;
        }
    }
    
    private void chartControl_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
    	//do something when the mouse is Down
    }
    There are many events to which you can use, I would suggest reviewing the events in the intelleprompt in the NinjaScript editor, after typing chartControl. the drop down list of properties methods and events should open, events are marked with a lightning bolt icon.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      hi
      thx for your quick response.

      i followed your instructions and created an indicator which should detect leftclick.

      The indicator is attached here


      The indicator does detect the leftclick but each click generate more than 10 events as you can see using the print command.

      can you solve it so that i will have a single event per click ?
      Attached Files

      Comment


        #4
        Hello,

        Thank you for the reply.

        I do not see you are un subscribing from the handler, if you reload the script one time, you would have two subscribed events and so on for each time you reload the script until you restart the platform.

        You would need to utilize the State.Terminated state to un subscribe from the handler that you had subscribed to earlier in the script before it exits.

        For un subscribing from an event, this is listed in the page I had linked in the last post in the Unsubscribing section of the article: https://msdn.microsoft.com/en-us/library/ms366768.aspx

        In your code you have: ChartControl.PreviewMouseLeftButtonDown += ChartControl_PreviewMouseLeftButtonDown;
        To un subscribe, you would use the exact same syntax but with a -= instead to remove the event subscription.

        Please let me know if I may be of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          hi

          thx again

          i did it now but the problem i reported remain
          i.e. i get multiple events per click
          Attached Files

          Comment


            #6
            Hello,

            I wanted to check, have you restarted NinjaTrader in between the tests?

            As stated the event handlers would remain until you restart the platform, in the case you did not initially un subscribe from the events they would still remain in memory even if you remove the indicator completely.

            An example would be if you had tested the indicator 2 times while not using the OnTermination logic, then added the OnTermination logic and re tested. You would likely get 3 prints each click. This would occur until you restart, and then after it should only be 1 click as the event is now being un subscribed from.

            In my test of the script you provided, I am only seeing one print per click event.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              thx

              it is ok now
              probably the problem was the fact that i did non unsubscribed from handler

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Skyfly1715, Yesterday, 03:36 PM
              1 response
              9 views
              0 likes
              Last Post NinjaTrader_Marco  
              Started by samatron, Yesterday, 09:49 PM
              1 response
              10 views
              0 likes
              Last Post NinjaTrader_ChrisSch  
              Started by moulsworth, Today, 12:45 AM
              0 responses
              3 views
              0 likes
              Last Post moulsworth  
              Started by Dr3am, Yesterday, 05:10 PM
              1 response
              6 views
              0 likes
              Last Post NinjaTrader_ChrisSch  
              Started by Captain Jack, Yesterday, 02:53 PM
              1 response
              13 views
              0 likes
              Last Post NinjaTrader_ChrisSch  
              Working...
              X