NexusFi: Find Your Edge


Home Menu

 





need help :: cant fix :: Object reference not set to an instance of an object


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Trader.Jon with 4 posts (0 thanks)
    2. looks_two fluxsmith with 3 posts (1 thanks)
    3. looks_3 mrticks with 2 posts (0 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 5,906 views
    2. thumb_up 1 thanks given
    3. group 1 followers
    1. forum 9 posts
    2. attach_file 1 attachments




 
Search this Thread

need help :: cant fix :: Object reference not set to an instance of an object

  #1 (permalink)
 
Trader.Jon's Avatar
 Trader.Jon 
Near the BEuTiFULL Horse Shoe
 
Experience: Beginner
Platform: NinjaTrader
Broker: MBTrading Dukascopy ZenFire
Trading: $EURUSD when it is trending
Posts: 473 since Jul 2009
Thanks Given: 401
Thanks Received: 184

I have a strategy I have been building, and there is an error that logs when I try a Strategy Analyzer backtest (NT 6.5.16). """Error on calling the 'OnBarUpdate' method for indicator ...: Object reference not set to an instance of an object., """

I tried to make the code down to base essential, and also used the Strategy Wizard, but I get the same error. The strategy compiles ok, and actually does output on chart and take trades on historical data.

I have tried the suggestion in the NT forums to use the 'try - catch' :
Object reference not set to an instance of an object - [AUTOLINK]NinjaTrader[/AUTOLINK] Support Forum
but the output window never prints out my specified statement so I am very frustrated.

I have even requested minimum 2000 bars of data to start the backtest with no difference in error in log. The error has made crazy me for the whole day. I would appreciate a fix for the code if anyone would please assist.

The basic stratagy is attached, exported from NT 6.5. The code I am trying to use is real simple, I can comment out either one of the two SuperTrend conditions and have the same error in log. My preference is to use the second line where ..Value == true, the other was to test the Strategy Wizard code:


 
Code
                            
protected override void OnBarUpdate() {
  
// Condition set 1
  
if (
    
SuperTrendRetracement(Typical2020142.61833).MaUpTrend[0] < Typical[0]
    && 
SuperTrendRetracement(Typical2020142.61833).MaUpTrend.ContainsValue(0) == true)
    {
      
EnterLong(DefaultQuantity"");} 

If anyone can assist it would be extremely helpful, and I will bless you in my prayers !!

Trader.Jon

Attached Files
Elite Membership required to download: AFIX.zip
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
What broker to use for trading palladium futures
Commodities
Trade idea based off three indicators.
Traders Hideout
Quant vue
Trading Reviews and Vendors
ZombieSqueeze
Platforms and Indicators
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
 
  #3 (permalink)
 fluxsmith 
Santa Maria
 
Experience: Advanced
Platform: NinjaTrader, ThinkOrSwim
Broker: Mirus/Zen-Fire
Trading: ES
Posts: 290 since May 2010
Thanks Given: 97
Thanks Received: 322



Trader.Jon View Post
I have a strategy I have been building, and there is an error ...

I'm guessing based on the code you posted (I don't have time to really examine or test it at the moment). My guess is that .MaUpTrend is a series that doesn't always have a value defined, and you're trying to test for that because the error your getting must be what Ninja gives if the value is undefined.
Try putting the .ContainsValue test first. For details google "short circuit evaluation".

 
Code
// Condition set 1
if ( SuperTrendRetracement(Typical, 20, 20, 14, 2.618, 3, 3).MaUpTrend.ContainsValue(0) == true
  && SuperTrendRetracement(Typical, 20, 20, 14, 2.618, 3, 3).MaUpTrend[0] < Typical[0] )
{
   EnterLong(DefaultQuantity, "");
}
// Condition set 2
if ( SuperTrendRetracement(Typical, 20, 20, 14, 2.618, 3, 3).MaDownTrend.ContainsValue(0) == true
  && SuperTrendRetracement(Typical, 20, 20, 14, 2.618, 3, 3).MaDownTrend[0] > Typical[0] )
{
   ExitLong("", "");
}

Visit my NexusFi Trade Journal Reply With Quote
  #4 (permalink)
 
Trader.Jon's Avatar
 Trader.Jon 
Near the BEuTiFULL Horse Shoe
 
Experience: Beginner
Platform: NinjaTrader
Broker: MBTrading Dukascopy ZenFire
Trading: $EURUSD when it is trending
Posts: 473 since Jul 2009
Thanks Given: 401
Thanks Received: 184

JHL,

Thanks for that suggestion ... I did try both methods separately before combining the code and had the same errors each way. Sorry that I wasnt more explicit about that in my explanation.

Tried your suggest ... even restarted NT first to clear out anything in the cache .. still same error ..

Also tried it without that .MaUp/DownTrend in the line and still get the same error :
(( SuperTrendRetracement(Typical, 20, 20, 14, 2.618, 3, 3)[0] < Typical[0]))

TJ

Started this thread Reply With Quote
  #5 (permalink)
 fluxsmith 
Santa Maria
 
Experience: Advanced
Platform: NinjaTrader, ThinkOrSwim
Broker: Mirus/Zen-Fire
Trading: ES
Posts: 290 since May 2010
Thanks Given: 97
Thanks Received: 322

Still looking at it. Problem's not in your strategy, that's why your catch isn't hit. Problem's in the indicator.

Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #6 (permalink)
 fluxsmith 
Santa Maria
 
Experience: Advanced
Platform: NinjaTrader, ThinkOrSwim
Broker: Mirus/Zen-Fire
Trading: ES
Posts: 290 since May 2010
Thanks Given: 97
Thanks Received: 322

Well, I'm a little stumped here. I'm willing to keep working on it if someone can tell me in English what SuperTrendRetracement is supposed to do. The comments are in Spanish, so they don't help me. And the code (in the version in the posted AFix.zip) has some problems. The 'diff' DataSeries and the HullMovingAverage of same serve no purpose, but I assume they were intended to.

On the chart I'm using for testing the final bar is returning an 'UpTrend' of 0, even though the SuperTrend UpTrend value for the same bar is valid, I really can't see why, I'm even beginning to suspect some kind of NT7 bug (but I wouldn't say so yet).
I think my next approach would be to reimplement it from scratch if I understood exactly what it's supposed to do.

Visit my NexusFi Trade Journal Reply With Quote
  #7 (permalink)
 
Trader.Jon's Avatar
 Trader.Jon 
Near the BEuTiFULL Horse Shoe
 
Experience: Beginner
Platform: NinjaTrader
Broker: MBTrading Dukascopy ZenFire
Trading: $EURUSD when it is trending
Posts: 473 since Jul 2009
Thanks Given: 401
Thanks Received: 184

I revisited the SuperTrend thread in NT Forums and found the indicator posting: he is from Italy. My visual on the indicator is that it draws out arrows at retracement points (hopefully) giving re-entry points in direction of the overall trend. ..OR .. it can guesstimate that the trend hasnt reversed yet and we are getting out of chop. Cant say for sure that the arrows are too late to matter yet or not.

The poster doesnt post often, and there is no real discussion of his contribution to give more to go on: Super Trend For [AUTOLINK]Ninja Trader[/AUTOLINK] Needed - Page 5 - [AUTOLINK]NinjaTrader[/AUTOLINK] Support Forum

Thanks for the effort: I think there are likely better use of our mutual time awaiting us.

Jon


fluxsmith View Post
Well, I'm a little stumped here. I'm willing to keep working on it if someone can tell me in English what SuperTrendRetracement is supposed to do. The comments are in Spanish, so they don't help me. And the code (in the version in the posted AFix.zip) has some problems. The 'diff' DataSeries and the HullMovingAverage of same serve no purpose, but I assume they were intended to.

On the chart I'm using for testing the final bar is returning an 'UpTrend' of 0, even though the SuperTrend UpTrend value for the same bar is valid, I really can't see why, I'm even beginning to suspect some kind of NT7 bug (but I wouldn't say so yet).
I think my next approach would be to reimplement it from scratch if I understood exactly what it's supposed to do.


Started this thread Reply With Quote
  #8 (permalink)
 
mrticks's Avatar
 mrticks 
Dublin, Ireland.
 
Experience: Advanced
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Trading: FDAX, cable/yen, FX, options on commodities
Posts: 67 since Jun 2009
Thanks Given: 16
Thanks Received: 10


Trader.Jon View Post
I have a strategy I have been building, and there is an error that logs when I try a Strategy Analyzer backtest (NT 6.5.16). """Error on calling the 'OnBarUpdate' method for indicator ...: Object reference not set to an instance of an object., """

I tried to make the code down to base essential, and also used the Strategy Wizard, but I get the same error. The strategy compiles ok, and actually does output on chart and take trades on historical data.

I have tried the suggestion in the NT forums to use the 'try - catch' :
Object reference not set to an instance of an object - [AUTOLINK]NinjaTrader[/AUTOLINK] Support Forum
but the output window never prints out my specified statement so I am very frustrated.

I have even requested minimum 2000 bars of data to start the backtest with no difference in error in log. The error has made crazy me for the whole day. I would appreciate a fix for the code if anyone would please assist.

The basic stratagy is attached, exported from NT 6.5. The code I am trying to use is real simple, I can comment out either one of the two SuperTrend conditions and have the same error in log. My preference is to use the second line where ..Value == true, the other was to test the Strategy Wizard code:


 
Code
                            
protected override void OnBarUpdate() {
  
// Condition set 1
  
if (
    
SuperTrendRetracement(Typical2020142.61833).MaUpTrend[0] < Typical[0]
    && 
SuperTrendRetracement(Typical2020142.61833).MaUpTrend.ContainsValue(0) == true)
    {
      
EnterLong(DefaultQuantity"");} 
If anyone can assist it would be extremely helpful, and I will bless you in my prayers !!

Trader.Jon

Hi Jon,

Would the code to enter long if the overall direction of supertrend is up look like the following? Not a crossover signal, just confirm that the general direction is bullish.


 
Code
                            
protected override void OnBarUpdate() {
  
// Condition set 1
  
if (
    
Close[1] > Open[1
   && (
SuperTrend(103).UpTrend[0])
   )

    {
      
EnterLong(DefaultQuantity"");} 
Would the reverse hold true for a short entry?
(!SuperTrend(10, 3).UpTrend[0])

I'd like to test code that goes long/short after an initial signal which will then also check the supertrend to verify if it is up/down.

Reply With Quote
  #9 (permalink)
 
Trader.Jon's Avatar
 Trader.Jon 
Near the BEuTiFULL Horse Shoe
 
Experience: Beginner
Platform: NinjaTrader
Broker: MBTrading Dukascopy ZenFire
Trading: $EURUSD when it is trending
Posts: 473 since Jul 2009
Thanks Given: 401
Thanks Received: 184


mrticks View Post
Hi Jon,

Would the code to enter long if the overall direction of supertrend is up look like the following? Not a crossover signal, just confirm that the general direction is bullish.


 
Code
                            
protected override void OnBarUpdate() {

  
// Condition set 1
  
if (
    
Close[1] > Open[1
   && (
SuperTrend(103).UpTrend[0])
   )

    {
      
EnterLong(DefaultQuantity"");} 
Would the reverse hold true for a short entry?
(!SuperTrend(10, 3).UpTrend[0])

I'd like to test code that goes long/short after an initial signal which will then also check the supertrend to verify if it is up/down.

On glance, I think that would work.. I use TS_SuperTrend for strategy input.

Jon

Started this thread Reply With Quote
  #10 (permalink)
 
mrticks's Avatar
 mrticks 
Dublin, Ireland.
 
Experience: Advanced
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Trading: FDAX, cable/yen, FX, options on commodities
Posts: 67 since Jun 2009
Thanks Given: 16
Thanks Received: 10



Trader.Jon View Post
On glance, I think that would work.. I use TS_SuperTrend for strategy input.

Jon

Thanks Jon.

Reply With Quote




Last Updated on November 3, 2010


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts