![]() |
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Senior Member
Join Date: Nov 2009
Posts: 205
Thanks: 0
Thanked 0 times in 0 posts
|
Hi,
I have compiled and added my indicator to my chart but dont see any plot - trying to debug it using print statements to the output window yet dont see anything there either.. This is my first custom script.... Another question - when you recompile the indicator does the chart get automatically updated? or do you have to remove and add again? Here are my variables #region Variables: // Wizard generated variables private int length = 10; // Default setting for Length private int length1 = 14; // Default setting for Length1 // User defined variables (add any user defined variables below) private int Trend_flo =0; private DataSeries PercentR; // Define a DataSeries variable private int PerR =0; private double StDev =0; private int LastBar =0; private DataSeries TrStop; #endregion Here is my initialize region: protected override void Initialize() { Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Trend")); CalculateOnBarClose = true; Overlay = false; PriceTypeSupported = true; } Here is main code: protected override void OnBarUpdate() { // Use this method for calculating your indicator values. Assign a value to each // plot below by replacing 'Close[0]' with your own formula. if(Time[0].Date != Time[1].Date) { Trend_flo =0; Print("Trend_flo initial condition: "+ Trend_flo); } double StDev = StdDev(length1)[0]; //double PerR = PercentR(length); double HH =0.0; double Divisor = 0.0; HH = MAX(High, length)[0]; Divisor = HH - MIN(Low, length)[0]; if (Divisor != 0) PercentR.Set(100 - ( ( HH - Close[0] ) / Divisor ) * 100); else PercentR.Set(0.0); if ((PercentR[0] >= 70) && (PercentR[1] < 70) && (Trend_flo < 1) && (Close[0] > TrStop[0])) { TrStop.Set(Low[0] - StDev*1.382); Trend_flo = 1; Print("Trend_flo Long: "+ Trend_flo); LastBar = CurrentBar; } if ((PercentR[0] <= 30) && (PercentR[1] > 30) && (Trend_flo > -1) && (Close[0] < TrStop[0])) { TrStop.Set(High[0] + StDev*1.382); Trend_flo = -1; Print("Trend_flo Short: "+ Trend_flo); LastBar = CurrentBar; } if (Trend_flo == 1) { if ((Open[0] <= TrStop[0]) | (High[0] <= TrStop[0]) | (Low[0] <= TrStop[0]) | (Close[0] <= TrStop[0])) { Trend_flo =0; Print("End of Trend_flo Long: "+ Trend_flo); } else { if (LastBar < CurrentBar) { if (TrStop[0] == 0) TrStop.Set(Close[0]); if (Close[0] > Close[1]) TrStop.Set(Low[0] - StDev * 1.382); if (Low[0] - High[1] > StDev) TrStop.Set(Low[0] - StDev * 0.618); if (TrStop[0] < TrStop[1]) TrStop.Set(TrStop[1]); } } } if (Trend_flo == -1) { if ((Open[0] >= TrStop[0]) | (High[0] >= TrStop[0]) | (Low[0] >= TrStop[0]) | (Close[0] >= TrStop[0])) { Trend_flo =0; Print("End of Trend_flo Short: "+ Trend_flo); } else { if (LastBar < CurrentBar) { if (TrStop[0] == 0) TrStop.Set(Close[0]); if (Close[0] < Close[1]) TrStop.Set(High[0] + StDev * 1.382); if (Low[1] - High[0] > StDev) TrStop.Set(High[0] + StDev * 1.382); if (TrStop[0] > TrStop[1]) TrStop.Set(TrStop[1]); } } } // Set the plot value Trend.Set(Trend_flo); //Trend.Set(1); } |
|
|
|
|
|
#2 |
|
Certified NinjaScript Consultant
Join Date: Sep 2006
Location: New York, USA
Posts: 774
Thanks: 1
Thanked 7 times in 5 posts
|
Check the log tab for any errors.
Yes, you must refresh (F5) the chart after you compile
"You look closely enough, you can find everything has a ... weak spot where it can break, sooner or later"
PureLogikTrading |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Nov 2009
Posts: 205
Thanks: 0
Thanked 0 times in 0 posts
|
Checked the Logfile after doing a F5 and got the following message
"Error on calling the 'OnBarUpdate' method for indicator 'mfPercentRBrkout' on bar 0: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name:index I presume it is referring to PercentR[1] in the following command ? if ((PercentR[0] >= 70) && (PercentR[1] < 70) && (Trend_flo < 1) && (Close[0] > TrStop[0])) Do I have initialiase a data series ? How does one do that? |
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Nov 2009
Posts: 205
Thanks: 0
Thanked 0 times in 0 posts
|
I have changed the start of the main code to
protected override void OnBarUpdate() { // Use this method for calculating your indicator values. Assign a value to each // plot below by replacing 'Close[0]' with your own formula. if (CurrentBar < length1) { //PercentR.Set(0,0.0); //PercentR.Set(1,0.0); return; } if(Time[0].Date != Time[1].Date) { Trend_flo =0; Print("This is a message"); Print("Trend_flo initial condition: "+ Trend_flo); } double StDev = StdDev(length1)[0]; Print("StDev: "+ StDev); //double PerR = PercentR(length); double HH =0.0; double Divisor = 0.0; HH = MAX(High, length)[0]; Print("HH: "+ HH); Divisor = HH - MIN(Low, length)[0]; Print("Divisor: "+ Divisor); if (Divisor != 0) PercentR.Set(100 - ( ( HH - Close[0] ) / Divisor ) * 100); else PercentR.Set(0.0); Print("PercentR[0]: "+ PercentR[0].ToString()); if ((PercentR[0] >= 70) && (PercentR[1] < 70) && (Trend_flo < 1) && (Close[0] > TrStop[0])) { TrStop.Set(Low[0] - StDev*1.382); Trend_flo = 1; Print("This is a message"); Print("Trend_flo Long: "+ Trend_flo); LastBar = CurrentBar; } It gets evaluated down as far as the highlighted in the red last line but I get the following error? Error on calling the 'OnBarUpdate' method for indicator 'mfPercentRBrkout' on bar 14: Object reference not set to an instance of an object. length1 is set to 14 so that makes sense but what does ' Object reference not set to an instance of an object." mean? Where can one get a detailed explanation of possible Log Errors? |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Nov 2009
Posts: 205
Thanks: 0
Thanked 0 times in 0 posts
|
seems to be complaining about the following line
PercentR.Set(100 - ( ( HH - Close[0] ) / Divisor ) * 100); |
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 89 times in 81 posts
|
The error message 'Object reference not set...' usually refers to accessing an object without first performing a null check (if (someObject !=null) {...}). If you post the complete code, I'll take a look and see if anything else looks out of place.
Austin
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Certified NinjaScript Consultant
Join Date: Sep 2006
Location: New York, USA
Posts: 774
Thanks: 1
Thanked 7 times in 5 posts
|
mefTrader,
Is PercentR a plot, or a DataSeries you create for use internally? If you create it for internal use you have to instantiate it in the Initialize() function Code:
PercentR = new DataSeries(this); mrLogik
"You look closely enough, you can find everything has a ... weak spot where it can break, sooner or later"
PureLogikTrading |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Debugging | douggreen | Version 7 Beta General Questions & Bug Reports | 6 | 10-16-2009 06:20 PM |
| More verbose debugging | Argo1 | Strategy Development | 1 | 09-06-2009 01:00 PM |
| Debugging Strategy | Socrato | General Programming | 4 | 07-20-2009 03:40 PM |
| JIT debugging issue | SamuelHiggins | Miscellaneous Support | 5 | 01-15-2008 01:12 AM |
| Debugging using Visual Studio | guym | Indicator Development | 2 | 11-28-2006 12:41 AM |