How can I detect, in addition, if he left , right or middle click ?
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
left , right or middle click ?
Collapse
X
-
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 }
I look forward to being of further assistance.JesseNinjaTrader Customer Service
-
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
-
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
-
hi
thx again
i did it now but the problem i reported remain
i.e. i get multiple events per clickAttached Files
Comment
-
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
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by ninza33, Today, 09:10 AM
|
1 response
10 views
0 likes
|
Last Post Today, 09:46 AM | ||
Started by goodknight777, Today, 08:43 AM
|
1 response
5 views
0 likes
|
Last Post Today, 09:25 AM | ||
Started by kramnor2001, Yesterday, 02:30 PM
|
3 responses
21 views
0 likes
|
Last Post
by kramnor2001
Today, 09:20 AM
|
||
Started by Padan, Today, 02:02 AM
|
3 responses
11 views
0 likes
|
Last Post Today, 08:54 AM | ||
Started by Tim-c, Today, 08:36 AM
|
1 response
3 views
0 likes
|
Last Post Today, 08:45 AM |
Comment