PDA

View Full Version : Coding Question


dwalls
03-09-2009, 08:09 PM
Hello,
On the CCI Indicator I am trying to say:
If the CCI(14)[0]>50;
do something
and if the CCI(14)[0]<-50;
do something
I tried using the "private int" like this:
private int period = 14;
private int ccimax = 50;
private int ccimin = -50;
and I also put these under "Properties".
The problem is when I'm in the Indicator settings, it won't accept a negative number, like -50...if I enter in the number -50 it always returns to the number 1. When entering the positive number 50...it works ok.
Should I be using something other that "private int"?
or what can I use to allow indicator setting to accept a negative number like -50 to reflect the -50 line of the CCI?

Thanks

mgbloomfield
03-09-2009, 08:52 PM
Check your "minimum" setting in the properties dialog. The default is 1.

dwalls
03-09-2009, 09:03 PM
Thanks for your help.

Got it now.

Thanks

ch9090
11-15-2011, 02:16 AM
Same issue here. This is what I've done:


private int vleveldown = 10; // Default setting for Vleveldown
private int vlevelup = 90; // Default setting for Vlevelup

[...]

[Description("")]
[GridCategory("Parameters")]
public int Vleveldown
{
get { return vleveldown; }
set { vleveldown = Math.Max(-100, value); }
}

[Description("")]
[GridCategory("Parameters")]
public int Vlevelup
{
get { return vlevelup; }
set { vlevelup = Math.Max(-100, value); }
}


In the backtest window both parameters won't accept negative values. Even if I set it up as the default value.

Any ideas?
Many thanks for the help,

Chris

NinjaTrader_Bertrand
11-15-2011, 02:22 AM
Chris, are you sure you compiled those change in and then tested on a new strategy instance?

ch9090
11-15-2011, 02:32 AM
Good morning Bertrand,

You're right, there's something NT does not like anymore in my strategy.

It compiles OK (no errors) but when I select it in the backtest window it keeps the parameters of the previous strategy I had selected on the list. Strange.

I now have many // in my custom code, could it be the issue?

NinjaTrader_Bertrand
11-15-2011, 02:42 AM
Did you save a parameter template for the strategy at one point in time?

ch9090
11-15-2011, 02:47 AM
Sorry what is a "parameter template". In my strategy there is no "session template" under time frame. Is this what you mean?

I know NT crashed this AM because of exception due to DMIndex (I do not know why). It could be related or not?

NinjaTrader_Bertrand
11-15-2011, 02:50 AM
No, if you right click in your parameters section you could set a default here so your settings would be remembered next time you use the strategy. You can double-check this by shutting NT down and going to the Documents\NinjaTrader 7\templates\Strategy folder > you would then see a template listed here for your strategy, remove it and restart NT and recheck if your changed parameter properties would now show the desired effect.

ch9090
11-15-2011, 03:49 AM
You're right, I used default values a lot. I've deleted the template and re-started NT but the strategy won't load in the backtest window.

NinjaTrader_Bertrand
11-15-2011, 03:52 AM
Great, any error in your log tab then shown?

ch9090
11-15-2011, 04:08 AM
Just that after compiling the strategy.

15/11/2011 12:06:12|3|128|Failed to call method 'Initialize' for strategy 'sy20111110MA/fdbeff33546d4e03bf414c5e52da057a': Index was outside the bounds of the array.

BTW after compiling the backtest window loads another strategy.

NinjaTrader_Bertrand
11-15-2011, 04:11 AM
Yes, you would need to look into this specific strategies Initialize() and debug why index out of bounds is thrown - as the Initialize() is run across all strategies it can impact running your other strategies as well.

ch9090
11-15-2011, 04:23 AM
Thank you Bertrand, there is something NT does not like in:


WilliamsR(Close, Vperiodin).Panel = 1;
WilliamsR(Close, Vperiodin).Lines[0].Value = Vleveldown;
WilliamsR(Close, Vperiodin).Lines[1].Value = Vlevelup;
WilliamsR(Close, Vperiodin).Plots[1].Pen.Color = Color.Transparent;
Add(WilliamsR(Close, Vperiodin));
WilliamsR(Close, Vperiodout).Panel = 1;
WilliamsR(Close, Vperiodout).Lines[0].Value = Vleveldown;
WilliamsR(Close, Vperiodout).Lines[1].Value = Vlevelup;
WilliamsR(Close, Vperiodout).Plots[0].Pen.Color = Color.DarkOrange;
WilliamsR(Close, Vperiodout).Plots[1].Pen.Color = Color.Transparent;
Add(WilliamsR(Close, Vperiodout));


Do you see something I obviously don't?

NinjaTrader_Bertrand
11-15-2011, 04:30 AM
Best would be to comment out parts of it and then rechecking to circle in the area with the issue.

I don't really see anything from here, but are you sure the plot #'s and line #'s are all fitting?

ch9090
11-15-2011, 05:59 AM
None of the panels, plots and lines appears on the chart. There's only the price window. I don't understand what it does not like in the WilliamsR

NinjaTrader_Bertrand
11-15-2011, 06:03 AM
Can you try pushing this oscillator to Panel2, the non price window?

ch9090
11-15-2011, 06:30 AM
I think I got it. It didn't like this one since there's no smooth line for the WilliamsR

WilliamsR(Close, Vperiodin).Plots[1].Pen.Color = Color.Transparent;

NinjaTrader_Bertrand
11-15-2011, 06:33 AM
Great, you're correct - the %R only has one plot.