Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Bool value being set to true after I set it to false
Collapse
X
-
Bool value being set to true after I set it to false
I have a private bool that I can toggle in the parameters section. My code is set up to do one thing if the bool is true and not do it if it is false. My indicator keeps printing the draw object when the bool is set to false. The draw object should only print when the bool is true. I added a print() statement to my code and the bool value is coming back both and true and false and changes back and forth even though I am not changing it in the parameters??? I double and triple checked my code and there is no place in the code that should be changing this bool value. I am sure there is something basic I am missing but I am unable to identify it. Any help would be appreciated.Tags: None
-
If the bool is in the parameters, then it is public, so can be changed by code outside of the class. Without seeing the scheme, and probably, the specifics, of the code, it will be hard to say why the value is changing, and whether the trigger is internal or external.Originally posted by jhowinvest View PostI have a private bool that I can toggle in the parameters section. My code is set up to do one thing if the bool is true and not do it if it is false. My indicator keeps printing the draw object when the bool is set to false. The draw object should only print when the bool is true. I added a print() statement to my code and the bool value is coming back both and true and false and changes back and forth even though I am not changing it in the parameters??? I double and triple checked my code and there is no place in the code that should be changing this bool value. I am sure there is something basic I am missing but I am unable to identify it. Any help would be appreciated.
-
The code and an output window is attached. If I change the public bools "showShorts" and "showLongs" several times while running this through market replay it finally starts the behavior shown in the output window image....it switches from true to false on its own. It seems to work fine when I change the bools once, twice, three times and maybe four but after that it gets stuck in the pattern shown in the output window where the bools are switching back and forth. If I need to attach any additional information please let me know.
Comment
-
Your code is doing the resets. To determine how and why, you are going to have to use more elaborate Print() statements, that identify the bars on which events occur, and when, so that you can track what is happening at each stage. You can start with as little as:Originally posted by jhowinvest View PostThe code and an output window is attached. If I change the public bools "showShorts" and "showLongs" several times while running this through market replay it finally starts the behavior shown in the output window image....it switches from true to false on its own. It seems to work fine when I change the bools once, twice, three times and maybe four but after that it gets stuck in the pattern shown in the output window where the bools are switching back and forth. If I need to attach any additional information please let me know.
every time you do a set or reset of the bools.Code:Print("Current Bar: " + CurrentBar); Print(showLongs); Print (showShorts);
Comment
-
Okay thank you for the print statement example because that makes sense to make them more specific. I added the print statements and included the line of code the print statement appeared in to track the two bools I am wanting to stay either true or false until I change them myself in the parameters. I am watching the output window and it is flipping back and forth but I am checking all of those lines and none of them have "showShorts = true;" or "showShorts = false" and I don't understand how the code can be changing them without a line that says specifically to do so. The only place the bools are set directly is in the variables section which reads like this:
private bool showShorts = true;
private bool showLongs = true;
There isn't any other place that should be changing these? I do reference the showShorts and showLongs in the if statements but they aren't being set, just referenced in the if statement like in this example:
if (showShorts == true && shortReset == true && MACD(BarsArray[1],12,26,1)[0] < MACD(BarsArray[1],12,26,1)[1] && MACD(BarsArray[1],12,26,1)[1] > MACD(BarsArray[1],12,26,1)[2]
&& MACD(BarsArray[1],12,26,1)[2] > MACD(BarsArray[1],12,26,1)[3] && MACD(BarsArray[1],12,26,1)[3] > MACD(BarsArray[1],12,26,1)[4])
{
showshortSignal = true;
shortReset = false;
Print("Current Bar: Line 130 " + CurrentBar);
Print(showLongs);
Print (showShorts);
}
if (MACD(BarsArray[1],12,26,1)[0] > MACD(BarsArray[1],12,26,1)[1])//used to reset for new short signals
{
shortReset = true;
Print("Current Bar: line 139 " + CurrentBar);
Print(showLongs);
Print (showShorts);
}
There must be something very simple that I am missing but I still am not seeing why the bools would be changed unless I manually change them in the parameters of my indicator. I can't see where the code itself should be doing it. See the attached image of the output window.
Comment
-
It looks like you may have other instances running on another time frame in a different workspace?Originally posted by jhowinvest View PostOkay thank you for the print statement example because that makes sense to make them more specific. I added the print statements and included the line of code the print statement appeared in to track the two bools I am wanting to stay either true or false until I change them myself in the parameters. I am watching the output window and it is flipping back and forth but I am checking all of those lines and none of them have "showShorts = true;" or "showShorts = false" and I don't understand how the code can be changing them without a line that says specifically to do so. The only place the bools are set directly is in the variables section which reads like this:
private bool showShorts = true;
private bool showLongs = true;
There isn't any other place that should be changing these? I do reference the showShorts and showLongs in the if statements but they aren't being set, just referenced in the if statement like in this example:
if (showShorts == true && shortReset == true && MACD(BarsArray[1],12,26,1)[0] < MACD(BarsArray[1],12,26,1)[1] && MACD(BarsArray[1],12,26,1)[1] > MACD(BarsArray[1],12,26,1)[2]
&& MACD(BarsArray[1],12,26,1)[2] > MACD(BarsArray[1],12,26,1)[3] && MACD(BarsArray[1],12,26,1)[3] > MACD(BarsArray[1],12,26,1)[4])
{
showshortSignal = true;
shortReset = false;
Print("Current Bar: Line 130 " + CurrentBar);
Print(showLongs);
Print (showShorts);
}
if (MACD(BarsArray[1],12,26,1)[0] > MACD(BarsArray[1],12,26,1)[1])//used to reset for new short signals
{
shortReset = true;
Print("Current Bar: line 139 " + CurrentBar);
Print(showLongs);
Print (showShorts);
}
There must be something very simple that I am missing but I still am not seeing why the bools would be changed unless I manually change them in the parameters of my indicator. I can't see where the code itself should be doing it. See the attached image of the output window.
Comment
-
I did have the same instrument running in a different workspace so I closed all other workspaces and now the current bar numbers are showing to be coming from the same place. I still have the issue of the bools changing when I don't want them to but still can't figure out why. Is there any other possible way for bool values to be changed without a specific code stating "showShorts = true" or by manually changing them in the indicator parameters? They should not be changing. Attached image is from the output window after I closed all other workspaces and opened a single chart for a specific instrument where I know there are no other instances of the indicator. The bool values are changing and I have print statements at every action point but can see no way in my code the bools should be changing ?
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
666 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
376 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
110 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
575 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
580 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment