Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Point and Click indicator?

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

    Point and Click indicator?

    Is it possible to write an indicator that monitors the chart so that when you click the mouse on Panel 1, the indicator can capture the bar number and price where the user clicked? I'm not interested in the X,Y grid value though, unless I can derive the bar number and price from that.

    Thanks!
    Bryan
    cassb
    NinjaTrader Ecosystem Vendor - Logical Forex

    #2
    Hello cassb,
    Thanks for writing in and I am happy to assist you.

    Yes it is possible to calculate the bar number from the mouse click using unsupported NinjaScript functions.

    Please refer to this thread for more http://ninjatrader.com/support/forum...ight=dsdatabox

    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      That's perfect, Joydeep, thank you! Just for reference, here's a link to the web page you need if you want to monitor mouse clicks. It's an indicator that shows an alternative data box.

      http://www.volumedigger.com/NinjaTra...dsDataBox.aspx
      cassb
      NinjaTrader Ecosystem Vendor - Logical Forex

      Comment


        #4
        Actually, if you could help with one more thing. I see that you derive the bar number from the X position like this:

        int barclick = (int)(xpos/ChartControl.BarSpace); //gets the bar, from the painted ones where the mouse is clicked


        How would I also derive the price value using the Y position?

        Thanks!
        cassb
        NinjaTrader Ecosystem Vendor - Logical Forex

        Comment


          #5
          Hello cassb,
          It is possible to get the price from the Y value. Please refer here to these posts for some ideas

          http://www.ninjatrader.com/support/f...6&postcount=14
          http://www.bigmiketrading.com/ninjat...ime-price.html

          Please let me know if I can assist you any further.
          JoydeepNinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Joydeep View Post
            Hello cassb,
            It is possible to get the price from the Y value. Please refer here to these posts for some ideas

            http://www.ninjatrader.com/support/f...6&postcount=14
            http://www.bigmiketrading.com/ninjat...ime-price.html

            Please let me know if I can assist you any further.
            Yes, thank you. I found that ChartHelper code and it really did help! :-) The key to getting the price from the Y value is knowing the size and position of the Y axis at the time of the click. So this override routine is critical:

            Code:
            public override void Plot(Graphics graphics, Rectangle bounds, double min, double max) 
            {     
                  priceMin = min;     
                  priceMax = max;     
                  boundsTop = bounds.Top;     
                  boundsHeight = bounds.Height;
            }
            cassb
            NinjaTrader Ecosystem Vendor - Logical Forex

            Comment


              #7
              Hello cassb,
              Yes, you have to know the min and max values.
              To avoid double paint you can also use the unsupported overload GetMinMaxValues instead of the Plot.

              Please let me know if I can assist you any further.
              JoydeepNinjaTrader Customer Service

              Comment


                #8
                OK Joydeep, I have been testing the code that finds the bar index from the X position:

                Code:
                                int barclick = (int)(xpos/ChartControl.BarSpace);    //gets the bar, from the painted ones where the mouse is clicked
                                int idx = ChartControl.BarsPainted - barclick ;
                                idx = Bars.Count - 2 - ChartControl.LastBarPainted + idx;
                The only flaw I can find is that if you scroll the chart to the left and then refresh (F5) the chart, when you click on a bar then the idx value is messed up. Somehow, it's offsetting the idx value based on the number of bars that have scrolled out of view off the right side of the chart? If you don't refresh after scrolling though, the idx is still fine. It only gets messed up when you refresh the chart after scrolling.

                Thanks!
                Bryan
                cassb
                NinjaTrader Ecosystem Vendor - Logical Forex

                Comment


                  #9
                  Hello cassb,
                  Please use the Print function to get the value of all the methods. If you are getting an unexpected value then you have to recalculate for the right x value.

                  A sample code will be like
                  Code:
                  idx = Math.Min(CurrentBar , Bars.Count - 2) - ChartControl.LastBarPainted + idx;
                  Please let me know if I can assist you any further.
                  JoydeepNinjaTrader Customer Service

                  Comment


                    #10
                    That did it, thank you!
                    cassb
                    NinjaTrader Ecosystem Vendor - Logical Forex

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by TAJTrades, Today, 06:12 AM
                    1 response
                    3 views
                    0 likes
                    Last Post NinjaTrader_Jim  
                    Started by jack121, Yesterday, 05:59 PM
                    1 response
                    20 views
                    0 likes
                    Last Post NinjaTrader_PaulH  
                    Started by trader3000a, Today, 04:23 AM
                    0 responses
                    5 views
                    0 likes
                    Last Post trader3000a  
                    Started by apratm, Today, 03:05 AM
                    3 responses
                    27 views
                    0 likes
                    Last Post apratm
                    by apratm
                     
                    Started by 05arminia, Today, 02:48 AM
                    1 response
                    5 views
                    0 likes
                    Last Post NinjaTrader_Marco  
                    Working...
                    X