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.
Comment