NexusFi: Find Your Edge


Home Menu

 





How to create strategy that looks at multiple bars?


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one TheNomadicAspie with 2 posts (0 thanks)
    2. looks_two sg72 with 1 posts (1 thanks)
    3. looks_3 DaveS with 1 posts (0 thanks)
    4. looks_4 IanC55 with 1 posts (0 thanks)
    1. trending_up 2,174 views
    2. thumb_up 1 thanks given
    3. group 4 followers
    1. forum 4 posts
    2. attach_file 0 attachments




 
Search this Thread

How to create strategy that looks at multiple bars?

  #1 (permalink)
 TheNomadicAspie 
Las Vegas, NV
 
Experience: Beginner
Platform: NinjaTrader 8
Trading: Emini ES
Posts: 9 since May 2020
Thanks Given: 2
Thanks Received: 1

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?

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
REcommedations for programming help
Sierra Chart
How to apply profiles
Traders Hideout
Better Renko Gaps
The Elite Circle
MC PL editor upgrade
MultiCharts
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
29 thanks
Tao te Trade: way of the WLD
24 thanks
Just another trading journal: PA, Wyckoff & Trends
23 thanks
Bigger Wins or Fewer Losses?
21 thanks
GFIs1 1 DAX trade per day journal
17 thanks
  #2 (permalink)
 sg72 
Orange County, CA, USA
 
Experience: Intermediate
Platform: NinjaTrader, Fidelity ATP
Trading: ES/NQ/RTY, Equity ETFs, Options
Posts: 59 since Sep 2018
Thanks Given: 44
Thanks Received: 48

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.

Hope this helps.

Reply With Quote
Thanked by:
  #3 (permalink)
 TheNomadicAspie 
Las Vegas, NV
 
Experience: Beginner
Platform: NinjaTrader 8
Trading: Emini ES
Posts: 9 since May 2020
Thanks Given: 2
Thanks Received: 1



sg72 View Post
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.

Hope this helps.

Thank you so much for the info. That will definitely help me get started, thanks for the help!

Started this thread Reply With Quote
  #4 (permalink)
 DaveS 
Uxbridge UK
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Futures
Posts: 21 since Sep 2012
Thanks Given: 2
Thanks Received: 17

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.

Reply With Quote
  #5 (permalink)
IanC55
Aberdeen Scotland
 
Posts: 5 since Feb 2019
Thanks Given: 0
Thanks Received: 0

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

(Not sure what the reference to Facebook is )

Reply With Quote




Last Updated on May 30, 2020


© 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