[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
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
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:
Code:if (priceflipup == true) { buysetupmoveiscompleted = true; lastBuyMoveBar = CurrentBar; }
Code:if(lastBuyMoveBar < CurrentBar) buysetupmoveiscompleted = false;
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?
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 Stanfillirenfro, Today, 07:23 AM
|
1 response
4 views
0 likes
|
Last Post Today, 07:37 AM | ||
Started by cmtjoancolmenero, Yesterday, 03:58 PM
|
2 responses
22 views
0 likes
|
Last Post Today, 07:24 AM | ||
Started by olisav57, Yesterday, 07:39 PM
|
1 response
9 views
0 likes
|
Last Post Today, 07:23 AM | ||
Started by cocoescala, 10-12-2018, 11:02 PM
|
7 responses
944 views
0 likes
|
Last Post
by Jquiroz1975
Today, 07:21 AM
|
||
Started by oviejo, Today, 12:28 AM
|
1 response
12 views
0 likes
|
Last Post Today, 07:20 AM |
Comment