Welcome to NexusFi: the best trading community on the planet, with over 150,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 -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
How to create strategy that looks at multiple bars?
I have some basic programming experience but am new to NinjaScript and NinjaTrader.
I would like to create a strategy that executes when conditions across multiple bars are met. For example, look for swing high, then if next bar opens at or below previous bar and closes at certain point, isSecondBarCondition = true and check next bar for certain conditions, etc.
I'm struggling to figure out how to do this. The NinjaTrader help file only provides limited information on syntax, and I can't find many other resources. The strategy builder only seems to be able to handle basic conditions and I have no idea how to approach this.
My guess is when scripting I need to create an on state event that looks back x number of bars, and use several if conditions to check each subsequent bar and use booleans to manage which conditions are true.
Is there a more comprehensive resource to learn NinjaScript thoroughly so I can teach myself how to do this? I may just have to pay someone to do it for me, but I would really prefer to learn it myself so I can develop my skills. I just can't find any way to learn this platform.
Is there some resource I'm overlooking or a course somewhere, or if not how can I become proficient in NinjaScript? Is it just a matter of knowing C# and memorizing the reference material?
Or is there a course that would walk me through creating complex strategies so I can develop my abilities?
Can you help answer these questions from other members on NexusFi?
Having recently started experimenting with the Strategy Builder myself, I totally relate to what you're experiencing. But there are ways to get to what you want to do. My approach with SB is how I approach other projects whether they are programming projects or home improvement :-). Start small and build on it as you go and gain more experience. But I agree with you that there is no easy primer/course you can read to walk you through how to get started. Or at least, I haven't found one yet.
Having said that, to address your specific example, what you can do is define a Custom Series under Additional Data in SB. This will hold your state based on your swing high/low criteria or any other criteria you're looking at. Then you can use this in the next cycle to combine with other conditions to make a decision on what action to take. You can look back at the state of your Custom Series (or any other data series for that matter) for as many bars as you wish. There is probably functionality in SB to do majority of what you need, you just need to find it out of the haystack - so to speak. It seems a bit clunky, limited and non-intuitive at first (especially if you're a programmer), but as you spend some time fiddling with it and figuring things out, you start to see how it works and how to implement your strategy with the seemingly awkward interface.
One thing you should feel free to utilize is the Ninja Platform Support email. I find the support staff at Ninja very knowledgeable, courteous and prompt. Any time I can't find the answer in the online help, they're able to point me to a resource or help me with code snippets. Sometimes the exact answer you're looking for is in the response to another support case and they point you to it. This same exact thing happened to me last week with a question I had. I wish they would do a better job of incorporating that scattered knowledge back into the help pages. But at least you have a path to get to that knowledge through support.
I don't know much about the Strategy Builder, but if you are writing a script the current bar is refered to as [0] the previous bar as [1] and so on back to the first bar in the chart.
You can refer to the different prices within each bar, each is a double value, so you could write -
double someValue = (Open[0] + Close[3] - High[299]) * Low[1]; // But make sure the chart has at least 298 bars.
Or maybe just
double currentHigh = High[0];
High, Low, Open, Close above are series objects. You could also look at some examples.
The Strategy Builder is good for creating code snippets, but is limited. Coding is the way to go. Learning is a slow process and joining the support forum is a good way to get help. Response is normally within an hour.
You access bar Open, High, Low Close values using the 'bars ago' index [0][1][2] etc