View Full Version : changing indicator parameter has no effect
ATI user
06-02-2008, 05:43 AM
under what circumstances will a parameter change not have an effect?
i have the following code:
public int trigger = 120;
Add(new Line(Color.Red, Trigger, "Level 1"));
[Description("Trigger line. Minimum 1.")]
[Category("Parameters")]
public int Trigger
{
get { return trigger; }
set { trigger = Math.Max(1, value); }
}
when i change the parameter in the indicator settings (i.e. when just using the indicator in a chart and not using it via a strategy) from 120 to 100, the line does not change
however...when i change the setting via my strategy, which calls the indicator, no problem
thanks
NinjaTrader_Dierk
06-02-2008, 06:25 AM
That is expected. You need to removed and add the indicator to chart again.
ATI user
06-02-2008, 06:34 AM
Thanks Dierk. I had already tried that however and it does not make a difference.
In the code trigger is set at 120
When I load the inidicator to the chart, I change the 120 to 200 and the line stays at 120...even though the parameter is shown in the title as being accepted as 200.
I think something in the Ninjascript code that is automatically added to the indicator is keeping the setting at the default value...i.e. it seems to use 'trigger' instead of 'Trigger'
I have noticed in other instances that the auto Ninjascript does not always adapt to changes I make in my code. In some cases I had to start over...and may have to this time also.
NinjaTrader_Dierk
06-02-2008, 06:48 AM
Unfortunately what you are trying to achieve (setting the "line" value by a parameter configurable on the properties dialog) is not supported.
ATI user
06-02-2008, 06:50 AM
to test the theory in my last reply, I copied all my code from the indicator and pasted it into a new one..compiled and loaded it...same problem...so the issue is not the ninjascript code
the problem is no doubt something that I do not understand about the code. Note in attached chart that the plot (at pointer) remains at 120 (default) although the parameter was changed to 200 and accepted by the indicator.
This must have something to do with the way NT uses the additional parameter section 'Lines' which I do not know how to override/avoid.
so...I have been changing the default each time instead of the parameter setting as a workaround
NinjaTrader_Dierk
06-02-2008, 06:53 AM
Please see my post #4
ATI user
06-02-2008, 07:00 AM
ok...that explains it..thanks
1. is this something you might add in the future?
2. why is it configurable from a parameter when I call the indicator from my strategy and pass the parameter setting that way?
NinjaTrader_Dierk
06-02-2008, 07:02 AM
This is a NT internal limitation. I'll add it to the list of future considerations.
ATI user
06-02-2008, 07:07 AM
2. why is it configurable from a parameter when I call the indicator from my strategy and pass the parameter setting that way?
NinjaTrader_Dierk
06-02-2008, 07:08 AM
Since a different logic is triggered NT internally.
ATI user
06-02-2008, 07:10 AM
thanks...will stick with the workaround
higler
06-06-2008, 04:34 PM
ATI user
I tried your approach in an indicator and got the same result that you did. Try putting the following code in your OnBarUpdate() method:
Lines[0].Value = Trigger;
The Lines[0] assumes that the line you want to change is the first line in your Add(new Line(etc.)) in your Initialize() method. Adjust the index for whichever line you want to change. That allowed me to dynamically change the position of an oscillator line in an indicator. If you then make the change to Trigger in the Indicators dialog box and hit apply then you should see the line adjust in the indicator. However, you won't see the new value in the Lines portion of the Indicators dialog box until you close the dialog box and reopen it, showing that the change has taken effect.
I don't know why this works in the OnBarUpdate() method but not in the Initialize() method.
ATI user
06-06-2008, 04:59 PM
higler
very cool...works great...thanks
higler
06-06-2008, 07:04 PM
Glad it works for you. The only thing that you might want to do is put some conditions on how often that line of code executes (maybe just on the first bar, maybe when some other condition is met, etc). Otherwise, since it is in the OnBarUpdate() method, it executes everytime the bar is updated which can be a lot of repetition of the same assignment statement (every tick) in some instances. If you can come up with some limiting logic then you can reduce the unnecessary repetition. It all depends on exactly what you want your indicator to do. Other than that, it also worked for me.
ATI user
06-06-2008, 08:45 PM
right
I am using
if ( Bars.FirstBarOfSession )
Lines[0].Value = Trigger;
which works fine...and only sets it once
thanks again....great workaround/solution