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

Alternative for CustomEvent, TimerEventProcessor

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

    Alternative for CustomEvent, TimerEventProcessor

    Hello,

    Is there an alternative solution for the TimerEventProcessor?

    This CustomEvents just brings me trouble and does not what it is supposed to do. I am pretty sure I have coded the Timer correctly. All is done by the various examples that are on the forum and the NT support pages. Besides that I have the timer working when I test this to print a line in the output window every timed period. But within the same event an open position has to be closed, which never happens. So a line is printed, but the execution is not processed; weird.

    I rather want to skip the whole timer thing, as it brings nothing but hassle, like the "error on triggering custom event ... more than100 subsequent user events.". I have read about every thread about this, but none of them has a fitting solution, where my goal is rather simple:

    I want to replace the ExitOnClose with an alternative from within the strategy. ExitOnClose and the strategy are more than once not in sync after a trigger from the ExitOnClose, if it is triggered at all. I want to trade around the clock for the whole week, but exit all positions at the end of the session of my choice. As the OnBarUpdate might not be triggered in time to exit possible open positions just before the end of a session, I want to add a coded timer which is set at a fixed hour/minute/second. To check for this time every minute a day, just to hit that one possible set time to Exit open positions seems not the right way to do this.

    Are there any possible alternatives which trigger an execution apart from the OnBarUpdate and not being the CustomEventsHandler like the Timer?

    #2
    Hi Francis, I would not be aware of an alternative here programmatically, as added a finer series in to have access to intrabar timestamps would also run the risk of not getting a call if no trade was seen. There's a general Flatten at time build in NT directly though, which could be used to disable strategies and attempt flattening account positions. It can be accessed via the Tools > Options > Misc settings.

    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hello Bertrand,

      Thank you for your reply.

      So there is no alternative to the CustomEvent? A smaller time series wil not do indeed, for the reason you mention. The option to flatten is also not the solution, while this will deactivate the strategies. These need to stay enabled for the following session.

      Do you have any idea why the timer does print a line to the output window, but does not trigger the order execution? This is rather strange. The code for the order is fine as well, as I use the same all over the code. It just seems it does not want to be fired from within the timer. And besides that there is the error on triggering custom event, something I see much more when searching the support forum. The timer is just not ideal in my situation and seems a bit overdone to check every x seconds to check for just one specific time every 24 hours.

      Kind regards,
      Francis

      Comment


        #4
        Add a button to the toolbar/strip to programitically set some flags to alter your codes logic??

        Originally posted by Francis View Post
        Hello,

        Is there an alternative solution for the TimerEventProcessor?

        This CustomEvents just brings me trouble and does not what it is supposed to do. I am pretty sure I have coded the Timer correctly. All is done by the various examples that are on the forum and the NT support pages. Besides that I have the timer working when I test this to print a line in the output window every timed period. But within the same event an open position has to be closed, which never happens. So a line is printed, but the execution is not processed; weird.

        I rather want to skip the whole timer thing, as it brings nothing but hassle, like the "error on triggering custom event ... more than100 subsequent user events.". I have read about every thread about this, but none of them has a fitting solution, where my goal is rather simple:

        I want to replace the ExitOnClose with an alternative from within the strategy. ExitOnClose and the strategy are more than once not in sync after a trigger from the ExitOnClose, if it is triggered at all. I want to trade around the clock for the whole week, but exit all positions at the end of the session of my choice. As the OnBarUpdate might not be triggered in time to exit possible open positions just before the end of a session, I want to add a coded timer which is set at a fixed hour/minute/second. To check for this time every minute a day, just to hit that one possible set time to Exit open positions seems not the right way to do this.

        Are there any possible alternatives which trigger an execution apart from the OnBarUpdate and not being the CustomEventsHandler like the Timer?

        Comment


          #5
          Originally posted by sledge View Post
          Add a button to the toolbar/strip to programitically set some flags to alter your codes logic??
          Hello Sledge,

          I don't see how I could benefit from a button to the toolbar. My strategies run fully automatic 24/5. The only thing I need is to exit all open position at 22:14 local time from within my strategy code, apart from an OnBarUpdate, because these might not trigger the execution when there is no OnBarUpdate. The ExitOnClose parameter does not interact with the strategy properly, which results in possible out of sync strategies regarding the real account positions.

          I do not understand why it's quite hard to just have a event triggered from within the code at a specific time (from the pc clock) to close al possible open positions, without an OnBarUpdate, but with CalculateOnBarClose is true.

          Comment


            #6
            Francis, you can work with the PC clock reference via DateTime.Now however if you don't get a trade then there would be no event to trigger this call in OnBarUpdate, especially if not processed on each tick like you outline.

            The subsequent user events warning may be overcome by setting the undocumented .MaxProcessedEvents property to a higher value in your script Initialize().

            Would you see a changed outcome if you tried to exit with more buffer towards the close of the market? We've seen cases where an order was generated, but too late to actually get filled until the market close - that is something you could only guard against by not attempting timing things too tight.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              So I understand the CustomEvent timer is the only way to trigger an event outside the OnBarUpdate.

              This would be fine if the order exection which I want to trigger from within the timer did actually occur. As said the timer works fine; it prints out a line in the output window every 30 seconds. The exit order is just not send at all. There is time enough to be settled before market close. Being only liquid ES market orders, it's a matter of a split second to have the order executed. But somehow it just won't work. The same coded execution paramaters work perfect from within the OnBarUpdate on small renko's, but on larger renko's when the timer should take over the job of the OnBarUpdate, nothing happens and the open positions are closed at the first bar of the new session.

              I will alter the MaxProcessedEvents to check if it will hold for a complete session then.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by llanqui, Today, 03:53 AM
              0 responses
              1 view
              0 likes
              Last Post llanqui
              by llanqui
               
              Started by burtoninlondon, Today, 12:38 AM
              0 responses
              10 views
              0 likes
              Last Post burtoninlondon  
              Started by AaronKoRn, Yesterday, 09:49 PM
              0 responses
              14 views
              0 likes
              Last Post AaronKoRn  
              Started by carnitron, Yesterday, 08:42 PM
              0 responses
              11 views
              0 likes
              Last Post carnitron  
              Started by strategist007, Yesterday, 07:51 PM
              0 responses
              14 views
              0 likes
              Last Post strategist007  
              Working...
              X