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 Wessel, 03-23-2024, 02:37 PM
|
3 responses
23 views
0 likes
|
Last Post Today, 04:58 PM | ||
Started by martini, Yesterday, 04:45 PM
|
4 responses
31 views
0 likes
|
Last Post
by martini
Today, 04:48 PM
|
||
Started by catinabag, 04-13-2023, 05:46 AM
|
34 responses
1,464 views
0 likes
|
Last Post
by mcosta72
Today, 04:44 PM
|
||
Started by adeelshahzad, Today, 11:49 AM
|
6 responses
24 views
0 likes
|
Last Post
by mcosta72
Today, 04:35 PM
|
||
Started by sidlercom80, 05-05-2020, 07:20 AM
|
4 responses
308 views
0 likes
|
Last Post
by Bidder
Today, 04:35 PM
|
Comment