Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bars.Period problems

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

    Bars.Period problems

    I often have problems with Bars.Period related coding.

    I have a few indicators that should do one thing if it's a Range Bar Chart and behave differently if it isn't but have never managed to get the coding to work so have to load and unload certain indicators when changing chart types, make 2 indicators instead of one, or manage templates etc.

    For example: I have an experimental indicator that shows stops and profit targets after an indicator-based condition occurs. It works fine except that I would like it to:

    1. If it's a Range Bar Chart, have the stops be configured as the Range Bar + 2 ticks + 1 tick for the entry &
    2. If it's not a Range Bar, use the initial stop amount by referencing a public int.

    Oops! I just figured out the problem:

    Ninja Language does not recognise(Bars.Period.Id == PeriodType.Range) if you are using RangeAlt charts, which I always do with Range charts.

    So I guess this should be a suggestion for NT7 to find a way to include alternative bar-forming methods that appear in the Format Data Series menus and recognise them.

    OR: is there some way to code it in now so that they will be recognised?

    So perhaps this post should read:

    How can one get Ninja Script to recognise RangeAlt bars ?

    Even though I have gotten it to work when I use Range Bars versus Range Alt, I am still getting an error log message:

    Failed to call method Initialize... object reference not set to an instance of the object. (Very helpful, eh?)

    The code looks like this (and I have tried many variations with the same results):

    if (Bars.Period.Id == PeriodType.Range)
    stopxx = (Bars.Period.Value) +3; // *
    if (Bars.Period.Id != PeriodType.Range)
    stopxx = stopx;

    +++++++++

    * 3 because: 1 tick above for entry long with 1 tick below bar for stop long and vice versa for shorts + 1 because the entry is one tick above the Close onto which is added the Bar + 3 ticks for the target. i.e. with 6 tick bar closing at 1040.20 and .10 per tick, the entry is at 1040.3, the low of the bar is 1039.6 so the stop is 1039.5 = 8 ticks risk, so if the ratio of profit target to stop is 1, the PT is 8 from entry = 1040.3 + .80 = 1041.1 = 9 ticks above the close of 1040.2.

    ++++++++++++++++++++++++++

    In this case, stopxx is a private double, and stopx is a public double that can be changed in the menu panel when not using Range Bar charts.
    Last edited by cclsys; 11-01-2009, 04:30 PM.

    #2
    Originally posted by cclsys View Post
    I often have problems with Bars.Period related coding.

    I have a few indicators that should do one thing if it's a Range Bar Chart and behave differently if it isn't but have never managed to get the coding to work so have to load and unload certain indicators when changing chart types, make 2 indicators instead of one, or manage templates etc.

    For example: I have an experimental indicator that shows stops and profit targets after an indicator-based condition occurs. It works fine except that I would like it to:

    1. If it's a Range Bar Chart, have the stops be configured as the Range Bar + 2 ticks + 1 tick for the entry &
    2. If it's not a Range Bar, use the initial stop amount by referencing a public int.

    Oops! I just figured out the problem:

    Ninja Language does not recognise(Bars.Period.Id == PeriodType.Range) if you are using RangeAlt charts, which I always do with Range charts.

    So I guess this should be a suggestion for NT7 to find a way to include alternative bar-forming methods that appear in the Format Data Series menus and recognise them.

    OR: is there some way to code it in now so that they will be recognised?

    So perhaps this post should read:

    How can one get Ninja Script to recognise RangeAlt bars ?

    Even though I have gotten it to work when I use Range Bars versus Range Alt, I am still getting an error log message:

    Failed to call method Initialize... object reference not set to an instance of the object. (Very helpful, eh?)

    The code looks like this (and I have tried many variations with the same results):

    if (Bars.Period.Id == PeriodType.Range)
    stopxx = (Bars.Period.Value) +3; // *
    if (Bars.Period.Id != PeriodType.Range)
    stopxx = stopx;

    +++++++++

    * 3 because: 1 tick above for entry long with 1 tick below bar for stop long and vice versa for shorts + 1 because the entry is one tick above the Close onto which is added the Bar + 3 ticks for the target. i.e. with 6 tick bar closing at 1040.20 and .10 per tick, the entry is at 1040.3, the low of the bar is 1039.6 so the stop is 1039.5 = 8 ticks risk, so if the ratio of profit target to stop is 1, the PT is 8 from entry = 1040.3 + .80 = 1041.1 = 9 ticks above the close of 1040.2.

    ++++++++++++++++++++++++++

    In this case, stopxx is a private double, and stopx is a public double that can be changed in the menu panel when not using Range Bar charts.

    cclsys,

    If you want to use RangeAltBars, Instead of typing "Range" type "Final1"

    if (Bars.Period.Id == PeriodType.Range) Range Bars

    if (Bars.Period.Id == PeriodType.Final1) RangeAltBars


    RJay
    RJay
    NinjaTrader Ecosystem Vendor - Innovative Trading Solutions

    Comment


      #3
      RJay,

      WOW! Can't believe how many people on this forum with more experience are so helpful so quickly! Thanks a lot. Works perfectly.

      I moved the section down to the onbar update section and the log error message has gone.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by sjsj2732, 03-23-2026, 04:31 AM
      0 responses
      69 views
      0 likes
      Last Post sjsj2732  
      Started by NullPointStrategies, 03-13-2026, 05:17 AM
      0 responses
      312 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      306 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      146 views
      1 like
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      108 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Working...
      X