Welcome to NexusFi: the best trading community on the planet, with over 200,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- discounts are available after registering.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
I need to buy a vowel. I have been working on a strategy that bases exits on the Pivots indicator. I was having some problems getting the indicator to properly report the pivots and s/r levels so I decided to write my own pivot and s/r level calculations. The problem is I'm getting a "**NT** Error on calling 'OnStartUp' method for strategy 'PivotPlay/d93c1269d8904ff99817bfaa496ee2a4': Object reference not set to an instance of an object."
I have troubleshot it down to the statements in bold in the code that follows. Warning, this is a work in progress. it compiles fine but pitches the error on enabling.
Any help you can provide on this would be greatly appreciated.
Thanks
Ragdoll
Can you help answer these questions from other members on NexusFi?
**NT** Error on calling 'OnBarUpdate' method for strategy 'PivotPlay/d93c1269d8904ff99817bfaa496ee2a4': Object reference not set to an instance of an object.
Your error message is most likely because you aren't listening to @Fat Tails and didn't check for CurrentBar or a session count before trying to call Bars.GetDayBar() 1 bar back. I haven't tested your code to know for sure.
Wrap that stuff around a (Bars.FirstBarOfSession && FirstTickOfBar) in #onbarupdate so it's only called at the beginning of a new session, and set a counter so you don't look to call it on the first session in the chart, wait until the second day to call it.
The NinjaTraderpivots indicator only returns values, once it has detected a day break. Therefore it does not return any values for the first day. Before you access the pivots you actually need to check, whether a value is returned. This can be done with
Also follow the suggestion by @Big Mike to use an instance of mypivots, but do that in OnStartUp()!
I reread your post and saw where you said the Print statement was giving you the errors.
I use a snippet like this when I am using indicators that take a few sessions to populate values, just to prevent me from taking signals due to missing or invalid data.
#variables
private int _totalsessions = 0;
#onbarupdate
if (Bars.FirstBarOfSession && FirstTickOfBar)
{
_totalsessions++;
}
if (_totalsessions < 5) return;
So I don't process any signal code unless we are in session 5 (day 5) or higher, when using weekly indicators like for example a weekly VWAP.
My apologies for not being clear in my earlier post. I don't want to use the Pivots indicator. I want to write my own pivots based on the previous trading days high, low, and close. I know the formula and I have coded it in Thinkscript before. It should be fairly straight forward. I have cleaned up the code a bit to remove extraneous stuff and enclosed the code in the if section as @Big Mike suggested. I have two basic questions. How do I ensure the GetDayBar call returns data? And how do I put my code in a code box like you did in the previous post?
Here is the latest code:
I got the second question figured out
I've had my RTFM moment and have solved the object problem with a little help from Bertrand. I added an if statement to check for a null on GetDayBar(1). The problem now is it is always null.