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.

      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


          Hey, Just saw it... Honestly I don't remember anything from this issue... Good you figured it... Lol Yeah it took a bit of searching around but finally got it. One great thing with forums is that you do get solutions and help if you need but there are many partial or incorrect postings that lead you the wrong way. And when something is incorrect / partial, generally there is no follow up to it. So you dont know why a particular approach does not work. :-) Anyways, I am happy I get what I am looking …


          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


            Hey, Just saw it... Honestly I don't remember anything from this issue... Good you figured it... Lol Yeah it took a bit of searching around but finally got it. One great thing with forums is that you do get solutions and help if you need but there are many partial or incorrect postings that lead you the wrong way. And when something is incorrect / partial, generally there is no follow up to it. So you dont know why a particular approach does not work. :-) Anyways, I am happy I get what I am looking …


            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 bmartz, 03-12-2024, 06:12 AM
                    5 responses
                    32 views
                    0 likes
                    Last Post NinjaTrader_Zachary  
                    Started by Aviram Y, Today, 05:29 AM
                    4 responses
                    12 views
                    0 likes
                    Last Post Aviram Y  
                    Started by algospoke, 04-17-2024, 06:40 PM
                    3 responses
                    28 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by gentlebenthebear, Today, 01:30 AM
                    1 response
                    8 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by cls71, Today, 04:45 AM
                    1 response
                    7 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Working...
                    X