[FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] (priceflipup == [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000])[/COLOR]
{
buysetupmoveiscompleted = [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]}
[/SIZE][/FONT][/SIZE][/FONT]
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
If I have a bool which is "true" at the close of the CurrentBar
Collapse
X
-
If I have a bool which is "true" at the close of the CurrentBar
How can I make that bool false on the next bar? Ideally I need the bool to remain true for the whole bar. Currently, CalculateOnBarClose is true.
Code:Tags: None
-
Hi kaywai,
Thank you for your post.
You can check if your CurrentBar increased since the signal and turn it off. You will need an integer variable to hold the last CurrentBar #. Something like this in your variables section;
int lastBuyMoveBar = -1;
Then add a line to keep track of the bar the buy setup occured on:
Add this code where you want to reset the boolean. if we're on a new bar, reset buysetupmoveiscompleted:Code:if (priceflipup == true) { buysetupmoveiscompleted = true; lastBuyMoveBar = CurrentBar; }
This code will work w/ CalculateOnBarClose true or false. If you are going to stick with true, you could just toggle buysetupmove back off if it was true at the start of a new bar since OnBarUpdate() is only called once per bar.Code:if(lastBuyMoveBar < CurrentBar) buysetupmoveiscompleted = false;
Please let me know if I can assist you any further.Code:// in top of OnBarUpdate if (buysetupmoveiscompleted) buysetupmoveiscompleted = false;DexterNinjaTrader Customer Service
-
Problem with this solution when priceflipup is true each CurrentBar
Hello:
It appears you have not taken into account the situation where a boolean such as priceflipup is true all the time. For example:
// ... Initialize()
CalculateOnBarClose = false;
// ... OnBarUpdate()
if (buysetupmoveiscompleted) buysetupmoveiscompleted = false;
{***code where variable PRICE is calculated, making priceflipup true all the time***}
if (priceflipup == true)
{
buysetupmoveiscompleted = true;
lastBuyMoveBar = CurrentBar;
}
if(lastBuyMoveBar < CurrentBar) buysetupmoveiscompleted = false;
The key in this scenario is how to know when lastBuyMoveBar is less than the CurrentBar. Any ideas? Thanks.
Tony
Comment
-
Hello Tony,
If we assume priceflipup always ends up true after some calculation, the code will work the same, assigning the current bar to lastBuyMoveBar and resetting on new bar (just to re-set it to current bar again of course).
I am not following 100% what you are asking to achieve. Do you want to only update the buysetupmoveiscomplete once per bar and only when priceflipup is true and it was previously enabled?
Please let me know if this is what you were looking for.Code:if (priceflipup == true) { if(lastBuyMoveBar < CurrentBar && buysetupmoveiscompleted) buysetupmoveiscompleted = false; else if(!buysetupmoveiscompleted) { buysetupmoveiscompleted = true; lastBuyMoveBar = CurrentBar; } }DexterNinjaTrader Customer Service
Comment
-
priceflipup boolean ALWAYS true: CalculateOnBarClose = false;
Hello Dexter:
Yes, my desire is to know what the last calculation was on the CurrentBar before CurrentBar increments. If priceflipup is always true, the logic you have created will work, up to a point. I will use FirstTickOfBar in conjunction with this code to handle the situation.
Thanks.
Tony
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
574 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
332 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
553 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
551 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment