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

How to pick bar on screen (to specify period start / end )

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

    How to pick bar on screen (to specify period start / end )

    Dear NT,

    watching some indicators videos I have seen that its possible somehow to specify start / end of desired period simply by click on screen (on the bar chart) and selecting start / end bar.
    This means that user of an indicator can select desired time period on screen (needed for example for some indicator calculation).

    How is possible to code that?



    #2
    Hello libas,

    Thank you for your post.

    You could do this by creating an indicator or addon that listens for mouse clicks, calculates where that click occurred on the screen, and from there you can get the bar at the time of the click and use those values as you wish.

    I'm attaching two examples that demonstrate listening for clicks and getting the time and price that were clicked that should get you going in the right direction.

    Please let us know if we may be of further assistance to you.
    Attached Files
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Hi Kate,

      could you please clarify me in detail purpose of lines 55-57 in provided example MouseXYtoBarTimePriceExample.cs ?


      foreach (ChartScale scale in ChartPanel.Scales)
      if (scale.ScaleJustification == ScaleJustification)
      chartScale = scale;

      Thank you,
      libas

      Comment


        #4
        Hello libas,

        This is obtain the price scale that this indicator is aligned to. The price scale is later used to covert they Y value of the click point to a price.

        Code:
        convertedPrice = Instrument.MasterInstrument.RoundToTickSize(chartScale.GetValueByY((float)clickPoint.Y));
        Last edited by NinjaTrader_ChelseaB; 08-01-2022, 08:15 AM.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi Chelsea,

          but this example indicator works even without this piece of code and I cant see any difference in final result. What could happen if I dont dont use this piece of code in real life indicator? Im more interested in the main idea what led you to use this.




          Comment


            #6
            Hello libas,

            It will matter when the scale justification is set to left or overlay.

            This was used so that the correct scale is selected if the script is not set to scale justification right.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              OK I see now...if scale of the main chart is set to Left then this indicator doesnt work and uses its own Right scale. But that logic doesnt still make any sense to me By such a logic I would expect to check what scale is used by main chart and match scale of indicator with scale of main chart.

              What does tell to your logic that desired scale is Right?
              Why you didnt just simply use following "standart way" :

              if (State == State.SetDefaults)
              ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;

              Comment


                #8
                Hello libas,

                What do you mean scale is used by the main chart? The main chart has 3 scales, right, left, and overlay. Do you mean the chart bars data series? Those may not be aligned to the same scale as the indicator.

                I'm not setting the indicator to the right scale. The user can use any scale they want. The indicator just selects the scale the user has chosen.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Chelsea,

                  "scale is used by the main chart" = selected justification during new/chart set up (data series window)

                  How would look the code to match justification of an indicator with this chart justification?

                  Sorry for mystification...today this indicator doesnt work without that piece of code


                  Comment


                    #10
                    Hello libas,

                    The chart itself does not have a justification. It has 3 scales.

                    The chart bars and indicators will be using one of those scales.

                    "How would look the code to match justification of an indicator with this chart justification?"

                    I'm sorry, I don't understand this question.

                    Do you mean how to force an indicator's justification to match the primary chart bars justification?
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      yes...exactly

                      Comment


                        #12
                        Hello libas,

                        You can assign the ScaleJustification of the indicator to the ChartBars.Properties.ScaleJustification.

                        Chelsea B.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by wzgy0920, 04-20-2024, 06:09 PM
                        2 responses
                        27 views
                        0 likes
                        Last Post wzgy0920  
                        Started by wzgy0920, 02-22-2024, 01:11 AM
                        5 responses
                        32 views
                        0 likes
                        Last Post wzgy0920  
                        Started by wzgy0920, 04-23-2024, 09:53 PM
                        2 responses
                        49 views
                        0 likes
                        Last Post wzgy0920  
                        Started by Kensonprib, 04-28-2021, 10:11 AM
                        5 responses
                        193 views
                        0 likes
                        Last Post Hasadafa  
                        Started by GussJ, 03-04-2020, 03:11 PM
                        11 responses
                        3,235 views
                        0 likes
                        Last Post xiinteractive  
                        Working...
                        X