NexusFi: Find Your Edge


Home Menu

 





ChartControl.ChartPanel.MouseMove += new System.Windows.Forms.MouseEventHandler issue


Discussion in NinjaTrader

Updated
    1. trending_up 2,696 views
    2. thumb_up 4 thanks given
    3. group 1 followers
    1. forum 4 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 erk707 
Irvine, CA
 
Experience: Intermediate
Platform: Ninjatrader
Trading: Piano, ES, GC, CL, NQ, 6E
Posts: 21 since Feb 2011
Thanks Given: 5
Thanks Received: 4

I have a strategy that tracks the Y axis of the mouse pointer with ChartControl.ChartPanel.MouseMove += new System.Windows.Forms.MouseEventHandler

Everything works fine if I open a brand new chart. Anytime I reload ninjascript it appears my MouseMove is no longer tracked and it stops printing to the screen. The only way i can fix it is if I close the chart and open a brand new one.

I am handling it in OnTermination().

Any ideas?


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Bookmap Global Plus Lifetime + Lifetime Addons For Sale
Platforms and Indicators
One Wallet Made $200K in Hours: AP Probes Polymarket Cea …
Prediction Markets & Event Contracts
Saylors 41-Month HODL Breaks: Strategy Sells 32 BTC as $ …
Prediction Markets & Event Contracts
CME Launches Bitcoin Volatility Futures June 1 -- First …
Cryptocurrency
Kharg Island at 6%, Regime Fall at 1.5% -- The Black Swa …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
24 thanks
2026 Jlab journal
10 thanks
Lady Vols Primer: Trading Volatility Journal
8 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Trying to learn Volume and price action correlation
5 thanks
  #3 (permalink)
 erk707 
Irvine, CA
 
Experience: Intermediate
Platform: Ninjatrader
Trading: Piano, ES, GC, CL, NQ, 6E
Posts: 21 since Feb 2011
Thanks Given: 5
Thanks Received: 4


Below is the sample code if anyone can help

 
Code
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;

using System.Windows.Forms;
#endregion

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    /// <summary>
    /// Enter the description of your strategy here
    /// </summary>
    [Description("Enter the description of your strategy here")]
    public class MouseMoveTest : Strategy
    {
        #region Variables
        // Wizard generated variables
        private int myInput0 = 1; // Default setting for MyInput0
        // User defined variables (add any user defined variables below)
        #endregion

        /// <summary>
        /// This method is used to configure the strategy and is called once before any strategy method is called.
        /// </summary>
        protected override void Initialize()
        {
            CalculateOnBarClose = false;
        }

		protected override void OnStartUp()
		{
			ChartControl.ChartPanel.MouseMove += new System.Windows.Forms.MouseEventHandler(OnChartPanelMouseEventMove);
		}
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
			
        }
		
		public int cursor;
		public bool isMouseDown;
		private void OnChartPanelMouseEventMove(Object sender, MouseEventArgs e)
		{
			cursor = e.Y;
			DrawTextFixed("jk2jf83f344", "Mouse Y Coord: " + cursor.ToString(), TextPosition.TopRight);
			Print("Mouse down " + isMouseDown);
			if(!isMouseDown)
				return;
			Print("Mouse down " + isMouseDown);
			
//			chartTraderForm.adjustTakeProfit("mouseMoveEvent", cursor);
		}
		
		protected override void OnTermination()
		{
			ChartControl.ChartPanel.MouseMove += new System.Windows.Forms.MouseEventHandler(OnChartPanelMouseEventMove);
		}
		
        #region Properties
        [Description("")]
        [GridCategory("Parameters")]
        public int MyInput0
        {
            get { return myInput0; }
            set { myInput0 = Math.Max(1, value); }
        }
        #endregion
    }
}


Started this thread Reply With Quote
  #4 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,550 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,430


erk707 View Post
Below is the sample code if anyone can help

You need '-=' instead of '+=' to remove the handler in OnTermination.


Travel Well
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #5 (permalink)
 erk707 
Irvine, CA
 
Experience: Intermediate
Platform: Ninjatrader
Trading: Piano, ES, GC, CL, NQ, 6E
Posts: 21 since Feb 2011
Thanks Given: 5
Thanks Received: 4

Rookie mistake

Dont know how many times i looked at that and didnt catch it.


Started this thread Reply With Quote
Thanked by:




Last Updated on August 16, 2014


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts