Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Signals from the previous day triggering trades

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

    Signals from the previous day triggering trades

    I have an intermittent problem whereby signals from the previous day are triggering positions at the start of the current day.

    All of the variables are reset using the If(Bars.FirstOfSession) function so I cannot understand why this is happening. As the variables that form the signals should be reset at the start of a new session.

    If there a way to just apply the strategy to the current day. It seems the strategy has to load at least one prior day’s worth of data to allow it to be enabled or is there a better way of resetting all the various variable at the start of a new trading day/session?

    Thanks

    mark

    #2
    Mark, that sounds correct but I would still suggest to print all variables used for triggering signals to judge in which state they are indeed at the session break. Does your strategy need historical data to arrive at the current day's trades?

    Thanks,

    Comment


      #3
      How would I do this Bernard?

      It does not need historical data no. It uses some from differing timeframes but the variables that trigger the entry and exits are all intraday and the stategy is applied to minute bars.

      Thanks

      Comment


        #4
        Mark, you would insert Print statements into your code to inspect which values they hold at which bars / times of the day, this way you would know which states are leading to the unexpected events seen - it might be helpful to work with TraceOrders as well in this context :



        If you don't need historical data, you can use Historical to process only realtime seen bars by the strategy and then enable it at your desired time so it could trigger trades moving forward:

        Comment


          #5
          I am ready have print statements showing when certain signals are triggered hence knowing they come from the previous day.

          How do i print the variable values? Say at the start of the session?

          The if (Historical) return; function looks like a good idea, do i just drop this at the start of the code?

          Comment


            #6
            Yes, you would just for example say at the OnBarUpdate() start: if (Historical) return;

            This will effectively ignore any calls to OnBarUpdate() for historical data.

            If you see it's coming from the prior day, this would then mean either your reset is not triggering / working, or a signal is generated at the last bar of the previous session and not expired by the TIF setting applied to the strategy for example.

            Would it make a difference in your case if you used Bars.SessionBreak here for the reset?

            Comment


              #7
              I don't see why. I'll give it a go.

              Thanks Bernard.

              Comment


                #8
                Didn't work Bernard. Just ran it live from the open and it did the same thing this is despite resetting all variables with both If(Bars.FirstOfSession) and If(Bars.SessionBreak). I also used the If(Historic) sugestion as well.

                Any other ideas?

                Comment


                  #9
                  Mark, then I would be out of ideas here - what needs to happen is simplifying the strategy code and then debugging / understanding why you would see the issue based on the conditions the strategy is using - perhaps there's another component outside of OnBarUpdate() contributing here?

                  Comment


                    #10
                    It is already a fairly simple code and has been debugged with print statements and trace orders.

                    There is nothing outside the OnBarUpdate section that would cause the various code logic to run from yesturday.

                    Comment


                      #11
                      Is there a way of resetting the variables at the end of session as well?

                      Comment


                        #12
                        How do you start the strategy up for realtime trading? In WaitUntilFlat or Immediately Submit mode?

                        You could try resetting then at Bars.LastBarOfSession as well, however this would be an unsupported property.

                        Comment


                          #13
                          It is set on the "wait until flat" mode.

                          What do you mean by unsupported property?

                          Comment


                            #14
                            Ok, then it would be taking the next fresh generated live signal, which is what you seek here but need to still determine where your conditions are being thrown off. Unsupported means it's an undocumented property, which you might be able to use - but we would not offer support for it and it could break / give a different behavior potentially in futures NinjaScript versions.

                            Comment


                              #15
                              Bernard

                              Looking at my output window, what is happening is not related to variables being re-set.

                              What is happening is entry signals are being generated from the previous session and entry is occuring as soon as the session starts. The code then runs as it should in the current session apart from this entry at the beginning.

                              This just should not be happening and I can't help but think it is a bug?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              670 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              379 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              111 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              575 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              582 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X