NexusFi: Find Your Edge


Home Menu

 





Indi works on chart, not in Market Analyzer. Null ref check?


Discussion in NinjaTrader

Updated
    1. trending_up 3,107 views
    2. thumb_up 2 thanks given
    3. group 0 followers
    1. forum 5 posts
    2. attach_file 1 attachments




 
 

Indi works on chart, not in Market Analyzer. Null ref check?

 
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800

Guys this one has me scratching my head. Here is the guts of a simple indicator that takes today's Highs and Lows from IQFeed and plots them on a chart:

 
Code
protectedoverridevoid Initialize()
{
Add(new Plot(Color.FromKnownColor(KnownColor.Violet), PlotStyle.Line, "MyHi"));
Add(new Plot(Color.FromKnownColor(KnownColor.LightSkyBlue), PlotStyle.Line, "MyLo"));
Overlay = true;
}
///<summary>
/// Called on each bar update event (incoming tick)
///</summary>
protectedoverridevoid OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
MyHi.Set(MarketData.DailyHigh.Price);
MyLo.Set(MarketData.DailyLow.Price);
}
Nothing special, no errors. But when I try to use that indicator in Market Analyzer, I get the "Object reference not set to an instance of an object." error. Specifically:


Quoting 
Error on calling 'OnBarUpdate' method for indicator 'MyHiLoPlots' on bar 0: Object reference not set to an instance of an object.

I am sure I am missing something simple like a null ref check. Any suggestions?

Started this thread

Can you help answer these questions
from other members on NexusFi?
Are there any eval firms that allow you to sink to your …
Traders Hideout
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Better Renko Gaps
The Elite Circle
Futures True Range Report
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
39 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
Battlestations: Show us your trading desks!
26 thanks
The Program
18 thanks
 
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800


Also tried this. No joy:

 
Code
protectedoverridevoid OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
double lo = MarketData.DailyLow.Price;
double hi = MarketData.DailyHigh.Price;

if (hi != null) MyHi.Set(hi);
if (lo != null) MyLo.Set(lo);
}

Started this thread
 
 
NinjaTrader's Avatar
 NinjaTrader  NinjaTrader is an official Site Sponsor
Site Sponsor

Web: NinjaTrader
AMA: Ask Me Anything
Webinars: NinjaTrader Webinars
Elite offer: Click here
 
Posts: 1,713 since May 2010
Thanks Given: 203
Thanks Received: 2,686

MXASJ,

The reason MarketData doesn’t work in the Market Analyzer is because this unsupported property is specifically programmed in a manner to be for charts only. To work around this you could try using these other unsupported properties: e.MarketData.DailyHigh.Price and e.MarketData.DailyLow.Price in the OnMarketData() method. Using it this way will only be applicable to real-time data going forward though.

Please find an attached sample of this combining both worlds with use of MarketData for the historical points on the chart, and the OnMarketData() usage for real-time and the Market Analyzer.

Attached Files
Elite Membership required to download: DailyHighLow.zip
Follow me on Twitter
Thanked by:
 
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800

Thanks Ray. The use of if(Historical) is a good idea for charting, but that code still does not work on both a Chart and in Market Analyzer.

My end game is some additional code I'm working on for the MarketAnalyzerTools indicator I started here:

At present the user of that indicator gets his daily High and Low data via calculations done in Ninja that are reliant on Session Templates, and then an equivalence check is run to see if we are trading at the High or Low (if(Close[0]==DailyHigh[0]), for example) so you get an audio and/or visual alert in Market Analyzer.

I'm trying to add the option to use vendor-provided High/Low data instead of Ninja calculated High/Low data.

I think I need to functional equivalent of the GetCurrentBid() method, but where e.MarketData is DailyHigh or DailyLow. That could then be called in OnBarUpdate().

I'll dig out the C# book and have a look at creating two Custom methods, GetDailyHigh() and GetDailyLow().

If anyone thinks I'm approaching this the hard way I'm open to input! Thanks.

Started this thread
 
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800

This appears to work for my purposes and doesn't throw exceptions when used in Market Analyzer:

 
Code
protectedoverridevoid OnBarUpdate()
{
}
protectedoverridevoid OnMarketData(MarketDataEventArgs e)
{
if (e.MarketData.DailyHigh != null)
Plot0.Set(e.MarketData.DailyHigh.Price);

if (e.MarketData.DailyLow != null)
Plot1.Set(e.MarketData.DailyLow.Price);
}
I'll update the code in the other thread after a few more hours of testing. The High/Low alerts in Market Analyzer can now come from either Ninja calculated data or vendor provided data.

Started this thread

 



Last Updated on May 12, 2011


© 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