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
Draw only once
Collapse
X
-
You need to create a condition that resets the doOnce bool variable back to true.
Code:if(SomeConditionToReset) { doOnce = true; // Reset the doOnce bool when we want to allow it to trigger again }
Leave a comment:
-
Via Print method I found out that it did print the arrow up one time, (like 20 days ago), the first time when conditions agreed upon as it should do - but never again.
Any Idea why it was not resetting to look for the conditions later on?
Leave a comment:
-
Hello Tzachi,
Please use Print() statements to monitor your logic as it executes. Likely, the arrow drew on the first time the condition became true, and since the bool is no longer set to true, the arrow never draws again.
You will want to create Print statements that tell you the values of the variables you use in your if statement before the if statement is reached so you can see how it is evaluated.
I've included a forum post for more information on debugging your code:
Debugging - https://ninjatrader.com/support/foru...ead.php?t=3418
Please let us know if we can be of further assistance.
Leave a comment:
-
Oops!
I forgot to include the type with the declaration.
Should be: private bool doOnce = true;
Leave a comment:
-
Many thanks for your quick reply.
When I added "private doOnce = true;"
and the condition into the If... I get an error below:
Invalid token '=' in class, struct, or interface member declaration
Leave a comment:
-
Hello Tzachi,
Thanks for your inquiry.
You can accomplish such a task by creating a doOnce bool and including that with your if statement.
I've attached a hypothetical example below:
Code:private bool doOnce = true; protected override void OnBarUpdate() { if(VariableA > VariableB && doOnce == true) { // Do something doOnce = false; // Set to false so we don't do it again. } if(SomeConditionToReset) { doOnce = true; // Reset the doOnce bool when we want to allow it to trigger again } }
Please let me know if you have any questions.Last edited by NinjaTrader_Jim; 11-27-2017, 01:47 PM.
Leave a comment:
-
Draw only once
Hi all,
I have this simple kind of "if":
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
Plot0.Set(Close[0]);
if (CurrentBar < 26)return;
if (CrossAbove(CCI(14), 5,5)&&XYZ[0]>XYZ[1] )
{
///Do something
DrawArrowUp("Dot"+ CurrentBar , false, 1,High[0]- 8*TickSize, Color.Gold);
}
The problem is that it will draw the arrow below EVERY bar that match the above condition when all what I want ids to draw it only one (first time conditions met)
Help to fix the code will be greatly appreciated.Tags: None
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by usazencort, Today, 01:16 AM
|
0 responses
1 view
0 likes
|
Last Post
by usazencort
Today, 01:16 AM
|
||
Started by kaywai, 09-01-2023, 08:44 PM
|
5 responses
603 views
0 likes
|
Last Post Today, 12:32 AM | ||
Started by xiinteractive, 04-09-2024, 08:08 AM
|
6 responses
22 views
0 likes
|
Last Post Today, 12:31 AM | ||
Started by Pattontje, Yesterday, 02:10 PM
|
2 responses
21 views
0 likes
|
Last Post
by Pattontje
Yesterday, 11:49 PM
|
||
Started by flybuzz, 04-21-2024, 04:07 PM
|
17 responses
230 views
0 likes
|
Last Post
by TradingLoss
Yesterday, 11:45 PM
|
Leave a comment: