Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Reference Chart Bar Type in Code

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

    Reference Chart Bar Type in Code

    I am using a volumetric type chart with a base period type of "tick" and a base period value of "1000". I am looking to write some code that says if the current bar is at 90% of the selected base period value (in this case 1000) and Condition #1 is met then draw a up arrow. My question is how do I reference the current chart base period value in the code? For example, if I change the chart from a 1000 tick chart to a 2000 tick chart then I want to draw the up arrow at 1800 trades (90% of 2000) instead of 900 trades (90% of 1000).

    #2
    Hello algospoke,

    The bars object .BarsPeriod will have the base bar type.

    Code:
    NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType barsType = Bars.BarsSeries.BarsType as
    NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType;
    
    if (barsType != null)
    Print(barsType.BarsPeriod.BaseBarsPeriodType.ToString());​
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Chelsea,

      I think you misunderstood my question. I already have that in my code. See below pic. When the number of trades on the bar gets to 90% of the 1000 tick bar then I want to draw an up arrow. In the below pic the current bar is at 397 trades. Once it gets to 900 trades, I want to draw the up arrow. How do I incorporate this in my code? I want it to always be 90% of whatever chart bar you use. So if you use a 2000 tick bar, then it does it on 90% of 2000 which is 1800.

      Click image for larger version

Name:	image.png
Views:	72
Size:	49.1 KB
ID:	1319910

      Thanks for your help!

      Comment


        #4
        Hello algospoke,

        If you want to reference the Trades property of Volumetric bars this would be barsType.Volumes[CurrentBar].Trades.

        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Chelsea,

          I understand how to access the trades property for volumetric bar. My question is how do i access what tick chart I am using? For example, if I use a 1000 tick chart and i reach 90% of the tick for that bar (i.e. 900 trades) then draw a up arrow. However, if i change the chart to 1500 tick chart then i want to code to automatically recalculate based on the new 1500 tick chart so that it will draw an up arrow on 90% of 1500 tick (i.e. 1,350 trades). How do i reference the chart value in ninjascript so that the up arrow is always drawn when it reaches 90% of whatever value you have the chart set at?

          Thanks for your help

          Comment


            #6
            Hello algospoke,

            This is Gaby following up for Chelsea who is out of office.

            My question is how do i access what tick chart I am using?
            As Chelsea suggested, you can get this information from BarsPeriod. BarsPeriod.Value will get you the integer value representing the period parameter.

            For example (this is from the Help Guide page Chelsea linked),

            Code:
            // Calculate only if there is a 100 tick chart or greater
            protected override void OnBarUpdate()
            {
            if (BarsPeriod.BarsPeriodType == BarsPeriodType.Tick && BarsPeriod.Value >= 100)
            {
            // Indicator calculation logic here
            }
            }


            Please let us know if this doesn't guide you in the right direction.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            607 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            353 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            105 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            560 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            561 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X