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

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 andrewtrades, Today, 04:57 PM
      1 response
      5 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by chbruno, Today, 04:10 PM
      0 responses
      3 views
      0 likes
      Last Post chbruno
      by chbruno
       
      Started by josh18955, 03-25-2023, 11:16 AM
      6 responses
      436 views
      0 likes
      Last Post Delerium  
      Started by FAQtrader, Today, 03:35 PM
      0 responses
      6 views
      0 likes
      Last Post FAQtrader  
      Started by rocketman7, Today, 09:41 AM
      5 responses
      19 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Working...
      X