NexusFi: Find Your Edge


Home Menu

 





OnMouseMove pass X Y..........don't know how


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one vvhg with 6 posts (1 thanks)
    2. looks_two sam028 with 4 posts (6 thanks)
    3. looks_3 KennyK with 2 posts (0 thanks)
    4. looks_4 Big Mike with 1 posts (0 thanks)
    1. trending_up 6,242 views
    2. thumb_up 7 thanks given
    3. group 3 followers
    1. forum 14 posts
    2. attach_file 0 attachments




 
Search this Thread

OnMouseMove pass X Y..........don't know how

  #1 (permalink)
 
vvhg's Avatar
 vvhg 
Northern Germany
 
Experience: Intermediate
Platform: NT
Trading: FDAX, CL
Posts: 1,583 since Mar 2011
Thanks Given: 1,016
Thanks Received: 2,824

I'm lost!

What I want to do is:

1. passing the mouse coordinates for every move (while mouse within active chart) into variables.
2. correcting the Y variable by n ticks.

I have no idea as to how that whole OnMouseMove works as my coding skills are VERY limited, and I haven't even got the slightest idea how to get the size of a tick converted into a y distance.

The background to this is that I want to create an indicator that "attaches" small horizontal lines to the crosshair at +/- n ticks from the horizontal crosshair line.

I'd be really grateful for any help.

vvhg

PS: If I try this without help, I probably end up writing the worst virus imaginable!

Hic Rhodos, hic salta.
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
MC PL editor upgrade
MultiCharts
NexusFi Journal Challenge - May 2024
Feedback and Announcements
Exit Strategy
NinjaTrader
How to apply profiles
Traders Hideout
Trade idea based off three indicators.
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
48 thanks
Just another trading journal: PA, Wyckoff & Trends
31 thanks
Bigger Wins or Fewer Losses?
24 thanks
Tao te Trade: way of the WLD
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks
  #3 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629


Did you already read this thread ?
The code in ChartHelper.cs can give you some clues on how to do that.

As you know, the MouseEvent is already catch, when you use a the Cross Hair cursor, so be careful .

Success requires no deodorant! (Sun Tzu)
Follow me on Twitter Reply With Quote
Thanked by:
  #4 (permalink)
 
vvhg's Avatar
 vvhg 
Northern Germany
 
Experience: Intermediate
Platform: NT
Trading: FDAX, CL
Posts: 1,583 since Mar 2011
Thanks Given: 1,016
Thanks Received: 2,824

Thanks a lot .

Yes, I did read the thread, that's what triggered my idea in the first place. You are capturing the xy of clicks there, right?
My C# abilitiesare very limited though, so I can't modify it for mouse movement without the click.
Thanks for the warning, I will be careful, especially as I haven't got a clou what you are talking about, I just have the feeling this is waaaay out of my league.

All I know is, I basically want to do sth similar to what you posted in the thread you linked to. The difference is that I want to position the levels relative to the mouse location.

Thanks again for your help.

Hic Rhodos, hic salta.
Started this thread Reply With Quote
  #5 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629

Just getting the X Y is easy then, just trap the mouse move with:
 
Code
                            
 protected override void OnStartUp() {
...
  
thisChartControl.ChartPanel.MouseMove += new MouseEventHandler(MouseEventM);
...
}

private 
void MouseEventM(object sender,MouseEventArgs e) {    
  Print(
"x: "+e.Y+" y: "+e.Y);

and don't forget:
 
Code
                            
 protected override void OnTermination() {
  
this.ChartControl.ChartPanel.MouseMove -= MouseEventM;


Success requires no deodorant! (Sun Tzu)
Follow me on Twitter Reply With Quote
  #6 (permalink)
 
vvhg's Avatar
 vvhg 
Northern Germany
 
Experience: Intermediate
Platform: NT
Trading: FDAX, CL
Posts: 1,583 since Mar 2011
Thanks Given: 1,016
Thanks Received: 2,824

I can't thank you enough!

Nearly there now, the only problem is that I seem to get very strange values from ChartHelper:
chartHelper.CalcTickHeight() returns sth like -2147483648. And if I multiply it by 20 the result is zero. Any ideas? Or do you need the code?

vvhg

Hic Rhodos, hic salta.
Started this thread Reply With Quote
  #7 (permalink)
 
vvhg's Avatar
 vvhg 
Northern Germany
 
Experience: Intermediate
Platform: NT
Trading: FDAX, CL
Posts: 1,583 since Mar 2011
Thanks Given: 1,016
Thanks Received: 2,824

I still can't get any values from ChartHelper that make any sense. Perhaps one of the coders that are better than me (not very hard at all!) can have a look?

Here is my disgraceful copy/paste artwork(probably good for a laugh at least) :
 
Code
#region Using declarations
using System;
using System.Reflection;
using System.Windows.Forms;
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.Gui.Chart;
#endregion

// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
            /// <summary>
    /// Enter the description of your new custom indicator here
    /// </summary>
    [Description("Enter the description of your new custom indicator here")]
    public class Crosshair : Indicator
    {
        #region Variables
        // Wizard generated variables
           private bool _found = false;
        private ChartHelper chartHelper; 
        
        private int x = 100;
        private int th = 0;
    
        private double price    = 0.0;
        private int offset1up = 20;
        private int yMouse = 0;
        private double corr1 = 0;
            
        private int yMouse2 = 100; 
        private StringFormat                stringFormat        = new StringFormat();
        private SolidBrush                    textBrush            = new SolidBrush(Color.Green);
        private SolidBrush                    textBrush2            = new SolidBrush(Color.Red);
        private Font                        textFont            = new Font("Arial", 30);
        
        // Default setting for MyInput0
        // User defined variables (add any user defined variables below)
        #endregion

        /// <summary>
        /// This method is used to configure the indicator and is called once before any bar data is loaded.
        /// </summary>
        protected override void OnStartUp() 
        {
        
          this.ChartControl.ChartPanel.MouseMove += new MouseEventHandler(MouseEventM);
        
            
        }
        
        protected override void Initialize()
        {
            Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
           
            CalculateOnBarClose = false;        //### Run on every Tick 
            Overlay                = true;    
            PaintPriceMarkers   = false;
            DisplayInDataBox    = false;
            
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
       protected override void OnBarUpdate()
        {
            if (!_found) {
               
                chartHelper = new ChartHelper ( this.ChartControl, this.Bars, this.TickSize);
               
                _found=true;
            }            
            
                
            
        }
                
        private void MouseEventM(object sender,MouseEventArgs e)
            {   
                if(th==0)
            {
                Update();
            }
              
        th=chartHelper.CalcTickHeight();
        
            //Print("tickh"+th);
                yMouse=    e.Y;
                Print("yMouse...."+yMouse);
                price=chartHelper.ConvertYtoPrice(e.Y);
                Print("price...."+price);
                ChartControl.ChartPanel.Invalidate();
                
        } 
        
        public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
        {
            
            
            
            
            yMouse2=yMouse-th*offset1up;
            int ff =th*offset1up;
            Print("th...."+th);
            Print("yMouse2...."+yMouse2);
            // Plot the line
            float textHeight = ChartControl.Font.GetHeight();
            
                
                    graphics.DrawString("__________", ChartControl.Font, textBrush, bounds.Right -x,yMouse2-textHeight , stringFormat);
                
    
        }
    
        protected override void OnTermination() 
        {
          this.ChartControl.ChartPanel.MouseMove -= MouseEventM;
        }

vvhg

Hic Rhodos, hic salta.
Started this thread Reply With Quote
  #8 (permalink)
 
vvhg's Avatar
 vvhg 
Northern Germany
 
Experience: Intermediate
Platform: NT
Trading: FDAX, CL
Posts: 1,583 since Mar 2011
Thanks Given: 1,016
Thanks Received: 2,824

SOLVED!!!

vvhg

Hic Rhodos, hic salta.
Started this thread Reply With Quote
  #9 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,446 since Jun 2009
Thanks Given: 33,217
Thanks Received: 101,610


vvhg View Post
SOLVED!!!

vvhg

What was the solution, to help others in the future.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #10 (permalink)
 
vvhg's Avatar
 vvhg 
Northern Germany
 
Experience: Intermediate
Platform: NT
Trading: FDAX, CL
Posts: 1,583 since Mar 2011
Thanks Given: 1,016
Thanks Received: 2,824


As stated above I could'nt get anything sensible from ChartHelper, so I calculated TickHeight (as y value) via
 
Code
ChartControl.GetYByValue(this,priceA);
and
 
Code
ChartControl.GetYByValue(this,priceB);
So I had two prices I knew and the corresponding y values. That was really all I needed.

vvhg

Hic Rhodos, hic salta.
Started this thread Reply With Quote
Thanked by:




Last Updated on September 13, 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