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!
See more
See less

Partner 728x90

Collapse

Bool Turns False Without Code Logic

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Bool Turns False Without Code Logic

    Good evening,

    Please see attached screenshots of prints output window and code logic.

    My bool "LongFloor3Active" is turning from true to false without any code logic directing this change.
    Using prints I have found at what point in the code the change occurs however there is no code at the point of change that should produce the result.
    At line 265 the bool is true.
    Lines 266 to 278 don't produce any prints.
    Line 279 it changes to false (without code)

    What am I not seeing that's causing this change?
    Thanks
    Click image for larger version

Name:	Output Window.png
Views:	146
Size:	9.2 KB
ID:	1164392Click image for larger version

Name:	Code.png
Views:	143
Size:	82.2 KB
ID:	1164393

    #2
    Originally posted by mlprice12 View Post
    My bool "LongFloor3Active" is turning from true to false without any code logic directing this change.
    Using prints I have found at what point in the code the change occurs however there is no code at the point of change that should produce the result.
    At line 265 the bool is true.
    Lines 266 to 278 don't produce any prints.
    Line 279 it changes to false (without code)

    What am I not seeing that's causing this change?
    Your bool is being set to false in a different function.

    Comment


      #3
      Hello mlprice12,

      Thanks for your post.

      I suggest using Ctrl + F to search for "LongFloor3Active" so you can see where that variable is assigned a value that is not explicitly true. I.E. it is being set to false, or it is being assigned a value of a bool, or !LongFloor3Active, etc. Any where the variable is assigned should be checked with your debugging prints to confirm that is where the assignment is question is being made.

      We look forward to assisting.
      JimNinjaTrader Customer Service

      Comment


        #4
        Thanks for the assistance.

        After taking some more debugging steps the issue revolves around the code on lines 266 to 278. If I comment out the code the bool change never occurs.

        Here is the dilemma, that code never fired when the bool change occurred because none of the prints inside printed at the time of the change.
        Also this portion of code doesn't assigned a false value to the bool or trigger other code to set a false value. I have set prints at all instances where the bool is assigned a value.

        attachments show commented out code and new output window.

        Click image for larger version  Name:	stays true.png Views:	0 Size:	7.2 KB ID:	1164501

        Click image for larger version  Name:	Code Cause.png Views:	0 Size:	30.0 KB ID:	1164500
        Attached Files
        Last edited by mlprice12; 07-21-2021, 09:21 AM.

        Comment


          #5
          Hello mlprice12,

          The best way to navigate the issue is to see where the assignment occurs and then trace the code back to see why that line of code (the assignment of the bool) was reached.

          Commenting out sections of code without understanding where the variable was changed and why that line was reached just points out that the code you commented is related to how the lines in question (where the variable gets assigned) get reached. It does not tell you exactly why the variable assignment was reached.

          My recommendation remains the same. Add prints where the variable gets assigned and reproduce the issue so you see where that variable gets assigned. Then read the code back to understand why that section of code was reached.
          JimNinjaTrader Customer Service

          Comment


            #6
            Or use Visual Studio debugger: https://stackoverflow.com/a/20046312/16207949

            Comment


              #7
              Thank you both,

              That's exactly the issue Jim, I placed prints at the location of every moment the bool gets assigned and those prints never triggered.

              Comment


                #8
                Hello mlprice12,

                The variable will not change on its own. Either the prints were not applied to all places where the variable gets assigned (Use Ctrl + F to find all cases where "LongFloor3Active" is used) or the script was not reloaded to bring in those newly added prints, or the issue was not properly reproduced to have the variable assignment code reached.

                Make sure you are checking other methods in the script, not just OnBarUpdate.

                Also make sure to revert your changes to get back to where the issue is seen and reproducible. If you commented out sections of the code that change the behavior of the script, the code may no longer be hitting the spot in question.
                JimNinjaTrader Customer Service

                Comment


                  #9
                  Thanks Jim, I'll send screen shots to show that I have prints in all sections and not just OnBarUpdate.

                  Question just to understand:
                  Why would commenting out a piece of code that doesn't trigger have an effect on any piece of code?

                  Thanks

                  Comment


                    #10
                    The only instances of LongFloor3EntryActive being assigned are found in lines 207, 243, 319 (yes I used the find tool).
                    I don't believe I misused the prints, but you can see in the output window that only the entry order code triggered (line 205 ) setting the bool to true....no more prints are triggered....and the bool is now set to false by the end of OnBarUpdate.

                    Click image for larger version

Name:	Output Window.png
Views:	116
Size:	3.7 KB
ID:	1164567

                    Click image for larger version

Name:	Code.png
Views:	123
Size:	100.6 KB
ID:	1164566

                    Comment


                      #11
                      This is a MTF strategy. Could this play a role?

                      Thanks Jim

                      Comment


                        #12
                        Hello mlprice12,

                        Commenting out unrelated code will not change behavior, but if you have commented out code that changes behavior, it can affect what you are trying to study.

                        Multi Time Frame would not matter as far as seeing where in the code the value is changing, the prints will tell you that.

                        I can't confirm that the prints are added everywhere there is a variable assignment without seeing the full code, and I can't confirm the script was properly reloaded to show the new prints without testing or observing.

                        To be sure, please remove the strategy from the chart, ensuring all other instances are removed from your workspace, and test again after making sure you have compiled the new prints in.

                        If you are still stuck there, please then attach the strategy source code here, and I may check to confirm the prints are added properly and I can confirm when I see those prints.

                        https://ninjatrader.com/support/help...tAsSourceFiles
                        JimNinjaTrader Customer Service

                        Comment


                          #13
                          Hello mlprice12,

                          I am seeing that you are assigning to true in a condition, which is highly discouraged, on line 251.

                          One equal sign is an assignment, two equal signs is a comparison.
                          Code:
                          if([SIZE=14px][B]LongFloor3EntryActive = true[/B][/SIZE]
                          && LongFloor3Entry != null
                          && stopOrderLongEntryFloor31 != null
                          && stopOrderLongEntryFloor31a == null //new
                          && Closes[2][0] > exPriceFloor3 + (profitOverFloor3*TickSize))
                          Is this intentional?
                          If this is intentional to set this to true one line 51, please also include a print for this so that we can see the bool is being set to a new value.


                          To assist, I modified the script to remove all prints that are not related to the one issue at hand. I recommend always reducing the script and reducing the prints to only the issue at hand to prevent confusion with other code. Then I printed the variable after every line it was set.

                          I've given this script a test on the ES 09-21 1 Minute in playback, but I am finding that the variable is never set to true using the default settings. (Set the input defaults to different parameters in State.SetDefaults if you want the script run with different parameters). The only print appearing was print c after the variable is set on line 251.

                          Below is a link to a video of the test.
                          https://drive.google.com/file/d/1ANI...w?usp=drivesdk
                          Last edited by NinjaTrader_ChelseaB; 07-21-2021, 04:19 PM.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Great find Chelsea!
                            That was not intentional. It was meant to be a check not an assignment.
                            That was the fix.

                            Thanks a lot

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by JonesJoker, 04-22-2024, 12:23 PM
                            8 responses
                            41 views
                            0 likes
                            Last Post JonesJoker  
                            Started by timko, Today, 06:45 AM
                            0 responses
                            3 views
                            0 likes
                            Last Post timko
                            by timko
                             
                            Started by Waxavi, 04-19-2024, 02:10 AM
                            2 responses
                            38 views
                            0 likes
                            Last Post poeds
                            by poeds
                             
                            Started by chbruno, Yesterday, 04:10 PM
                            1 response
                            44 views
                            0 likes
                            Last Post NinjaTrader_Gaby  
                            Started by Max238, Today, 01:28 AM
                            1 response
                            25 views
                            0 likes
                            Last Post CactusMan  
                            Working...
                            X