NexusFi: Find Your Edge


Home Menu

 





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


Discussion in NinjaTrader

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




 
 

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

 
 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

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
Request for MACD with option to use different MAs for fa …
NinjaTrader
NexusFi Journal Challenge - May 2024
Feedback and Announcements
Looking for an MQL4 MetaTrader programmer/coder
The Elite Circle
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
 

 
 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
 
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,425


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
The following 3 users say Thank You to ratfink for this post:
 
 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
The following user says Thank You to erk707 for this post:

 




Last Updated on August 16, 2014


© 2024 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 - Privacy Policy - Downloads - Top
no new posts