• 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

Are GetValueByY() and GetValueByYWpf() working?

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

    Are GetValueByY() and GetValueByYWpf() working?

    Another OnMouseMove() issue. Am I doing something wrong, or is there a bug here? I move the cursor up and down, yielding Y values frm 0-724. In all cases, both GetValueByY() and GetValueByYWpf() return zero.
    Code:
    using System.Windows;
    using System.Windows.Input;
    using NinjaTrader.Gui.Chart;
    
    //This namespace holds Indicators in this folder and is required. Do not change it. 
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public class VsaNew : Indicator
        {
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    IsOverlay                    = true;
    
                } else if (State == State.DataLoaded) {
                    if (this.ChartPanel != null)
                        this.ChartPanel.MouseMove += new MouseEventHandler(OnMouseMove);
    
                }
            }
    
            protected override void OnBarUpdate()
            {
                //Add your custom indicator logic here.
            }
            
            internal void OnMouseMove(object sender, MouseEventArgs e)
            {
                ChartControl cc = ChartControl;
                ChartScale cs = new ChartScale(/*cc.PrimaryBars.*/ChartPanel, cc.PrimaryBars.Properties.ScaleJustification);
                Point cursorPos = e.GetPosition(ChartPanel);
    
                float fy = (float)cursorPos.Y;
                double tmp = cs.GetValueByY((float)cursorPos.Y);
                double tmp2 = cs.GetValueByYWpf((float)cursorPos.Y);
                Print("VsaNew: cursor Y: " + fy + "   GetValueByY: " + tmp + "   GetValueByYWpf: " + tmp2);
            }
        }
    }
    --EV

    #2
    Get the ChartScale from the Chart's ChartPanel.Scales object:

    ChartScale cs = ChartPanel.Scales[ChartPanel.PanelIndex];

    The below is working for me. Let me know if you see any issues

    Code:
    public class MyCustomIndicator3 : Indicator
    {
    	protected override void OnStateChange()
    	{
    		if (State == State.SetDefaults)
    		{
    			IsOverlay = true;
    		}
    		else if (State == State.DataLoaded)
    			if (ChartPanel != null) ChartPanel.MouseMove += OnMouseMove; 
    
    		else if (State == State.Terminated)
    			if (ChartPanel != null) ChartPanel.MouseMove -= OnMouseMove;
    	}
    
    	protected override void OnBarUpdate()
    	{
    		//Add your custom indicator logic here.
    	}
    
    	internal void OnMouseMove(object sender, MouseEventArgs e)
    	{
    		try
    		{
    			ChartScale cs = ChartPanel.Scales[ChartPanel.PanelIndex];
    			Point cursorPos = e.GetPosition(ChartPanel);
    
    			float fy = (float) cursorPos.Y;
    			if (cs != null)
    			{
    				double tmp = cs.GetValueByY((float) cursorPos.Y);
    				double tmp2 = cs.GetValueByYWpf((float) cursorPos.Y);
    				Print("VsaNew: cursor Y: " + fy + "   GetValueByY: " + tmp + "   GetValueByYWpf: " + tmp2);
    			}
    		}
    		catch (Exception exception)
    		{
    			Print(exception);
    		}
    	}
    }
    Last edited by NinjaTrader_Matthew; 08-24-2015, 08:28 AM.
    MatthewNinjaTrader Product Management

    Comment


      #3
      Originally posted by NinjaTrader_Matthew View Post
      Get the ChartScale from the Chart's ChartPanel.Scales object:

      ChartScale cs = ChartPanel.Scales[ChartPanel.PanelIndex];

      The below is working for me. Let me know if you see any issues
      Thank you. That does it. Getting ChartScale your way works fine.

      --EV

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by yeshujbp, Today, 02:40 PM
      0 responses
      5 views
      0 likes
      Last Post yeshujbp  
      Started by Venom, Today, 01:05 PM
      0 responses
      7 views
      0 likes
      Last Post Venom
      by Venom
       
      Started by Dert66, Today, 12:11 PM
      0 responses
      7 views
      0 likes
      Last Post Dert66
      by Dert66
       
      Started by jjanguda, Today, 10:04 AM
      0 responses
      225 views
      0 likes
      Last Post jjanguda  
      Started by sambo81, Today, 09:20 AM
      1 response
      12 views
      0 likes
      Last Post sambo81
      by sambo81
       
      Working...
      X