Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Counting the number of touches of the rectangle.

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

    #16
    Hello NinjaTrader_ChelseaB for your reply.

    I have attached the output in .txt format.

    In the screenshot there are no prints that say State: Historical. There is only one print that says State: Realtime.
    Yes only one zone is retested since I have refreshed the indicator.

    Do you have code to prevent the code from evaluating in historical? (like if (State == State.Historical) return; )
    I do not have any code preventing the code from evaluating in historical.

    Where is the retests variable?
    Is this in the code?​
    Yes it is in the code (int Count2 += 1), post #12.
    Attached Files
    Last edited by Stanfillirenfro; 10-10-2024, 11:20 AM.

    Comment


      #17
      Hello Stanfillirenfro,

      The issue is that the logic is not being evaluated in historical.

      Is there historical data on the chart or is the chart blank?

      If the chart is not blank, there is code in the script that preventing the logic from being evaluated in historical.

      What other logic is in the script?
      Chelsea B.NinjaTrader Customer Service

      Comment


        #18
        Hello NinjaTrader_ChelseaB and many thanks for your reply.

        Is there historical data on the chart or is the chart blank?
        The chart is not blank. I have the rectangles representing the supply and demand zones. I do not have any problem with the rectangles drawn on these zones. I also have texts indicating the zones (support untested, verified or proven...) Also here, I do not have any problem. The only prblem is to count the retests.

        What other logic is in the script?
        I also have OnRender() in the script, with which I have rendered the texts.
        I also have the enumeration. The script is more than 2600 lines including the properties.

        Comment


          #19
          Hello Stanfillirenfro,

          What other code is in OnBarUpdate()?

          Something you've coded in the script is preventing logic from evaluating in historical data.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #20
            Hello NinjaTrader_ChelseaB for your reply.

            In OnBarUpdate(), after initializing my variables, the first condition is: if(NewBar() == true) in which I am calling functions implemented in the region Helpers such as: FindZones(); DrawZones();​ ​

            I also have the code I am using to track the counts of the retests of my zones. This code is not in the condition mentioned above.

            Comment


              #21
              Hello Stanfillirenfro,

              Without the specific code it would be hard to provide direction.

              You will need to debug the script to identify what code is preventing the logic from being reached in historical.

              Try adding:

              Print(Time[0].ToString() + " | State: " + State.ToString());

              as the first line in OnBarUpdate().

              Provide the output text file.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #22
                Hello NinjaTrader_ChelseaB and many thanks for your reply.

                I have attached the output.
                Attached Files

                Comment


                  #23
                  Hello Stanfillirenfro,

                  This confirms OnBarUpdate is running historically and something in the code below this print is preventing logic below from being evaluated in historical.

                  Move the print down below the next line of code.

                  Is this print still printing in historical?

                  Move the print down one line at a time until the print stops appearing in historical.

                  What is the line of code just above the print when the print stops appearing in historical?
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #24
                    Hello NinjaTrader_ChelseaB and thanks for the reply.

                    I have attached two files. Before compiling the code after moving the Print() function below the next line of code, I have the output with name ending with a. After moving the code, I have the output with the name ending with b.

                    I have attached both files.
                    Attached Files

                    Comment


                      #25
                      Hello Stanfillirenfro,

                      Clear the output window before you run the script each time.

                      What is the line of code above the print when the print stops appearing in historical?
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #26
                        Hello NinjaTrader_ChelseaB and many thanks for your reply.

                        Here is what I am observing.
                        1) I have moved the Print() function in the first condition of OnBarUpdate(). On the output window there are only Sate: Historical when the bars is not closed. But when the bars is close, I have only State: Real.
                        2) I habe moved the print() outside of the condition and I am observing the same result.
                        Last edited by Stanfillirenfro; 10-10-2024, 01:26 PM.

                        Comment


                          #27
                          Hello NinjaTrader_ChelseaB.

                          Below is the condition in which I am calling my functions in OnBarUpdate()

                          HTML Code:
                          bool NewBar()
                          {
                              LastTime = DateTime.MinValue; 
                              if(Time[0] != LastTime)
                              {
                                  LastTime = Time[0];
                                  return (true);
                              }
                              else
                                  return (false);
                          }​

                          Comment


                            #28
                            Hello Stanfillirenfro,

                            To confirm, you are declaring a method inside of the OnBarUpdate() method?

                            I would suggest against this as this can cause issues with access. I recommend that you declare all methods in the scope of the class.

                            That said, is the NewBar() method returning false in historical?
                            If so, that would be the issue. Try removing that code, or correct it so that this returns true in historical.
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #29
                              Hello NinjaTrader_ChelseaB and thanks for your reply.

                              HTML Code:
                              To confirm, you are declaring a method inside of the OnBarUpdate() method?
                              No, I am NOT. It would not be possible according to my knowledge. I have declared it in the region Helpers.

                              HTML Code:
                              That said, is the NewBar() method returning false in historical?
                              Here is what I am observing: When the indicator is online, let`s say at Time[0], the State is historical until the current bar is closed. Immediately after Time[0] when this bar is closed, the state turns to Realtime until the indicator is swhiched off again.

                              I have simply removed the condition with NewBar() and there is NO CHANGE.

                              Comment


                                #30
                                Hello Stanfillirenfro,

                                "When the indicator is online, let`s say at Time[0], the State is historical until the current bar is closed."

                                The State is historical for all historical bars being processed. Once all historical bars are processed the State becomes Realtime and the realtime bars are processed as they are built.

                                "I have simply removed the condition with NewBar() and there is NO CHANGE."

                                I'm assuming you have compiled and reloaded the script.
                                This would mean there is still something in your custom logic preventing the logic from being evaluated in historical.

                                You will need to determine on which line the logic stops evaluating. Until the logic for your condition is evaluated in historical, the script won't be recalculating the values in historical.

                                You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.
                                Chelsea B.NinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                580 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                335 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                102 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                554 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                552 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X