Thanks!
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Strategy Builder and price crossing indicators
Collapse
X
-
Strategy Builder and price crossing indicators
Here's my basic strategy I'm trying to setup with the Strategy Builder but can't seem to get it to work. I'd like to take a trade after the price crosses above a certain indicator (like an EMA, pivot point, etc.) within the last set number of bars (for example last 10 bars). Then when the price comes back to that indicator within the set number of bars, it enters the trade. Ideally with a limit order at the level of the indicator. I think the trouble I'm having is when the price crosses the indicator. Not quite sure how to do that. I've only ever done it to show indicators crossing each other. What is the easiest way to setup something like this?
Thanks!Tags: None
-
Hello srtrader,
Thank you for your post.
You would basically need to do this in steps, and use a custom series to keep track of the bar on which the initial cross occurs. You can use CrossAbove/CrossBelow to find out if the strategy has crossed over an indicator plot. When you see the crossover, save the current bar number to the custom series, and set a bool to true. You can then check whether that bool is true, whether or not the Current Bar number is less than the value we've saved to the custom series + the number of bars within which to allow entry, and if the current price has crossed back over the indicator plot. If so, submit an order.
I'm attaching a relatively simple example strategy that illustrates.
Please let us know if we may be of further assistance to you.Attached Files
- Likes 1
-
Thanks for the quick response! I downloaded the sample strategy and still can't wrap my head around this. I've used the strategy builder quite a bit, but this all seems to be way over my head and I'm not even sure where to start. Are there any training videos that dive deeper into these concepts you are using? Like the bools and custom series.
Thanks!
Comment
-
Hello srtrader,
Thank you for your reply.
I'd suggest starting with our Strategy Builder 301 video from our publicly available YouTube channel, as it touches on those concepts:
Strategy Builder 301
If you are new to C#, to get a basic foundation for the concepts and syntax used in NinjaScript I would recommend this section of articles in our NT7 help guide first:
Basic Programming Concepts
For general C# education I have personally found Dot Net Perls to be a great reference site with easy to understand examples.
We also have some Reference samples online as well as ‘Tips and Tricks’ for both indicators and strategies:
Click here to see our NinjaScript Reference Samples
Click here to see our NinjaScript Tips
These samples can be downloaded, installed and modified from NinjaTrader and hopefully serve as a good base for your custom works.
Further, the following link is to our help guide with an alphabetical reference list to all supported methods, properties, and objects that are used in NinjaScript.
Alphabetical Reference
And our Educational Resources in the NinjaTrader 8 help guide.
Educational Resources
A set of specific tutorials for creating conditions in the NinjaTrader 8 Strategy Builder in the NinjaTrader 8 help guide.
Condition Builder
You can also contact one of our professional NinjaScript Consultants or Educators who would be eager to create or modify this script at your request or assist you with your script. Please let me know if you would like a list of professional NinjaScript Consultants or Educators who would be happy to create or modify any script at your request or assist you in learning NinjaScript.
Please let me know if I may be of further assistance.
- Likes 1
Comment
-
So I went through the sample strategy you sent and got it to work exactly as planned. Thanks so much! My next question is how to setup this same type of thing but instead of crossing an indicator, it crosses a bar. For example, if I have a signal bar that meets certain criteria, it gets marked. And then for a long trade, when prices break above this signal bar, I enter long. I've tried to use the same criteria as the example strategy you sent that works with the indicator, but I can't seem to get it to work with a single signal bar. Does it need to be structured differently?
Comment
-
Hello srtrader,
Thank you for your reply.
You'd need to save the high of the signal bar to a variable so it can be referred back to. From there, you can compare the current price against the signal bar's saved high value and if the price exceeds that, then do something, like entering long.
Please let us know if we may be of further assistance to you.
- Likes 1
Comment
-
Hello srtrader,
Thank you for your reply.
I'm not seeing anything amiss in your screenshots. Could you supply the strategy so I may test on my end? You can export it from Tools > Export > NInjaScript Add-on. Do not check the box to export as a compiled assembly or I will not be able to review your logic. Please attach the resulting .Zip file to your reply.
Thanks in advance; I look forward to assisting you further.
Comment
-
Good evening,
I want the condition that after the emas cross and that bar closes, only take the trade if price closes above or below the ema cross price. How would I modify the example above?
Comment
-
Hello conniejforextrader,
Thank you for your inquiry.
You would need two custom series to accomplish this. One to save the value of CurrentBar (CurrentBarCounter) and another to save the CurrentBar value at the time your cross occurs (myCounter).
Set 1 initializes both series on the first bar(zero) of the data series.
Set 2 contains no conditions so it will run on each OnBarUpdate(). Set 2 will copy the previous value of “myCounter” to bring it to the current bar [0] index. Set 2 will also copy the current bar number into CurrentBarCounter (again this is needed because you cannot do math on the system variable CurrentBar.
Then you would need to create a set that checks for the EMA cross, and when this is true save CurrentBar to a custom series and save the price the cross occurred on to a variable.
Then in your set to check if the price crosses above or below your saved price, add another condition to check the CurrentBar minus the current value of your counter is greater than 1 (meaning at least 1 bar has elapsed since the cross occurred).
This sample script ExampleBarCounter demonstrates how you can save the value of CurrentBar and the CurrentBar value at the time of your cross, and how to do the math to check that 1 bar has elapsed.
Last edited by NinjaTrader_Gaby; 08-26-2024, 08:38 AM.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
116 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
61 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
40 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
43 views
0 likes
|
Last Post
|
||
|
Started by Mindset, 02-28-2026, 06:16 AM
|
0 responses
82 views
0 likes
|
Last Post
by Mindset
02-28-2026, 06:16 AM
|

Comment