Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Strategy Builder - way to know if previous bar(s) are red or green?
Collapse
X
-
Strategy Builder - way to know if previous bar(s) are red or green?
I'm testing strategy to go long but wondering if there's a way to check whether previous closing bar was green or red, or closed bullish or bearish? I know it's not always reliable but I'm still interested if there's a way to do that so I can evolve strategy builder from there.Tags: None
-
Hi MatthewLesko,
For the current bar, find the relevant part of the candle with these arrays: Open[0], Close[0], High[0], and Low[0]. Once the bar is open, then Open[0] will remain the same during the current bar lifecycle. High[0] and Low[0] are updated appropriately. Close[0] is constantly updated with the latest Last transaction price.
Likewise, to find the previous bar and the bar before that, use Open[1], Close[1], High[1], and Low[1] for previous and Open[2], Close[2], High[2], and Low[2] the bar before the previous. Hopefully, you get the idea.
So, to your question, now that we have the required information identified, try the following:
bool IsPrevBarGreen = Close[1] > Open [1]; // sets IsPrevBarGreen to true is it the close is higher than the open for the previous bar.
bool IsPrevBarBullish = Close[1] > Close[2]; // set IsPrevBarBullish to true if the previous bar close is higher than its previous bar close.
Of course, depending on how your define bullish, you might have different logic for IsPrevBarBullish. Perhaps, you define it as the close is higher than the previous bar and the high is higher than the previous bar. If so:
bool IsPrevBarBullish = Close[1] > Close[2] && High[1] > High{2];
As you can see, with the Open, Close, High and Low arrays, you can perform significant amount of candle comparison logic to identify any candle pattern you're interested in.
Hope that helps!
Stealth
-
Hello MatthewLesko,
What StealthM93 explained is correct, you can find more details about how to do price comparisons while using the strategy builder in the following link: https://ninjatrader.com/support/help...ataComparisons
To check if the previous bar was red or green would require making a price condition, there is not a way to check if it was a specific color.
Please let me know if I may be of additional assistance.JesseNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by zstheorist, Today, 07:52 PM
|
0 responses
3 views
0 likes
|
Last Post
by zstheorist
Today, 07:52 PM
|
||
Started by pmachiraju, 11-01-2023, 04:46 AM
|
8 responses
149 views
0 likes
|
Last Post
by rehmans
Today, 06:44 PM
|
||
Started by mattbsea, Today, 05:44 PM
|
0 responses
5 views
0 likes
|
Last Post
by mattbsea
Today, 05:44 PM
|
||
Started by RideMe, 04-07-2024, 04:54 PM
|
6 responses
33 views
0 likes
|
Last Post
by RideMe
Today, 05:31 PM
|
||
Started by tkaboris, Today, 05:13 PM
|
0 responses
5 views
0 likes
|
Last Post
by tkaboris
Today, 05:13 PM
|
Comment