Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

About the OnMouseDown() Method Implementation

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

    About the OnMouseDown() Method Implementation

    Hello everyone,

    I recently encountered an error when implementing the OnMouseDown() method as shown in the documentation. The code provided in the documentation is:

    Code:
    public override void OnMouseDown(ChartControl chartControl, ChartPanel chartPanel, ChartScale chartScale, ChartAnchor dataPoint) { }
    However, during compilation, I get the following error:

    Code:
    'MyStartegy.OnMouseDown(ChartControl, ChartPanel, ChartScale, ChartAnchor)' no suitable method found to override
    This error indicates that there is a compatibility issue between the method signature I'm trying to implement (according to the documentation) and what actually exists in the parent class.

    The error message shows that I'm trying to use the method with all four parameters as indicated in the documentation (ChartControl, ChartPanel, ChartScale, ChartAnchor), but the compiler cannot find a matching method to override in the parent class.

    Is the documentation incorrect regarding the OnMouseDown() method signature? What is the correct signature to use for this method?

    Last edited by Artorias; 03-17-2025, 07:28 PM.

    #2
    Reference : https://developer.ninjatrader.com/do...own#definition
    ​​
    Last edited by Artorias; 03-17-2025, 07:27 PM.

    Comment


      #3
      Is it because you are using ChartControl, as opposed to using a ChartControl variable like how they are using chartControl?

      Comment


        #4
        I use ;

        Code:
        public override void OnMouseDown(ChartControl chartControl, ChartPanel chartPanel, ChartScale chartScale, ChartAnchor dataPoint){ }
        The same for OnMouseMove().

        Comment


          #5
          But the variables in the examples are chartControl, chartPanel, chartScale, etc.
          You posted 'MyStartegy.OnMouseDown(ChartControl, ChartPanel, ChartScale, ChartAnchor)' no suitable method found to override
          That is ChartControl, not chartControl. As I understand it chartControl is a variable name of type ChartControl, so you need to be using the variables for that.
          I could be misunderstanding something, but that would be the first thing I would check first. If anything, copy the sample code from the link you referenced and compare to see if that's still creating the same errors.

          Comment


            #6
            I did it and the error is the same.​

            Comment


              #7
              I see what you mean. I copied the paste into an indicator template and received the same error. However, when I copied it into a Drawing Tool template, I received no errors, other than needing to instantiate Anchor. Are you using this for a Drawing Tool? The link you provided did mention " You must override the method in your Drawing Tool with the following syntax."

              Comment


                #8
                Indeed, it's only good for drawing tools. So what are the functions for having human input while the Strategy is running?

                Comment


                  #9
                  Hello Artorias,

                  As rockmanx00 has mentioned, this method cannot be used in an indicator script or strategy script since an indicator or strategy does not natively have an OnMouseDown event.

                  You can get the mouse events from the ChartControl by creating your own event handling, you can see a sample of that here:

                  Gaby V.NinjaTrader Customer Service

                  Comment


                    #10
                    This code captures a mouse event (left-click while holding Alt key), retrieves the price value at the cursor's Y-coordinate, and draws a horizontal red line at that price level on the chart. This is what I wanted to do originally, so for those who want to do the same and come across this, here's the code.

                    Code:
                    // Placed in the OnRender graphic function
                    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
                    {
                        // Mouse click condition (for example, Alt key pressed + Left click)
                        if (System.Windows.Input.Mouse.LeftButton == System.Windows.Input.MouseButtonState.Pressed
                        && System.Windows.Input.Keyboard.IsKeyDown(System.Win dows.Input.Key.LeftAlt))
                        {
                            // Get the cursor
                            Point cursorPoint = chartControl.MouseDownPoint;
                    
                            // Get Y
                            double yCoordinate = cursorPoint.Y;
                    
                            // Get the price based on Y
                            double price = chartScale.GetValueByY((float)yCoordinate);
                    
                            // DrawLine at the price level of the mouse click
                            Draw.HorizontalLine(this, "tag1", price, Brushes.Red);
                        }
                    }
                    Last edited by Artorias; 03-20-2025, 08:16 AM.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by SheriDi, Today, 02:24 PM
                    1 response
                    11 views
                    0 likes
                    Last Post SheriDi
                    by SheriDi
                     
                    Started by sofortune, Today, 02:41 PM
                    1 response
                    4 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Started by xfactscout, Today, 02:43 PM
                    0 responses
                    4 views
                    0 likes
                    Last Post xfactscout  
                    Started by xfactscout, Today, 02:26 PM
                    0 responses
                    2 views
                    0 likes
                    Last Post xfactscout  
                    Started by ashlyncarson, Today, 02:03 PM
                    0 responses
                    4 views
                    0 likes
                    Last Post ashlyncarson  
                    Working...
                    X