Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Force Update Strategy

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

    Force Update Strategy

    Is there a way to force update a strategy during a period in which there is no data coming in? I have a strategy that I want to cancel itself after 15 minutes if no trades occur. The issue I'm running into is that there are periods in which there is no data coming in for the stock I'm looking at(pre-and-post-market). During that time if a trade does not occur I need the strategy to re-calculate and terminate itself, but I can't figure out how to force it to calculate on a given interval.

    #2
    Hello magnatauren,

    If there is not any data coming in that generally means your strategy is not able to execute its logic. You could potentially use a C# timer for this use case, you would need to figure out when to enable the timer so that it could execute after the data stopped.

    Strategies have a CloseStrategy method that can be used to disable the strategy however I am not certain if this would work after hours due to it having to try and close positions: https://ninjatrader.com/support/help...=closestrategy

    This may present an error message stating that it cannot close orders or there is no data to drive the simulation engine.

    A possibly better solution would be to set a bool variable to true when you want to stop trading. If no trades occur in 15 minutes set the bool to true, later in your logic the bool can be used to prevent other logic form happening. That would allow the script to remain enabled and would otherwise just not trade going into the future sessions.


    Please let me know if I may be of additional assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hey Jesse, that's actually what I have set up right now, The issue I'm having is that it will still execute if the stopwatch, which is created during the configure state, which I hope is where I want it, is less than the current time.

      Code:
      else if (State == State.Configure)
      {
          AddDataSeries(Data.BarsPeriodType.Volume, 5000);
          stopWatch = DateTime.Now.AddMinutes(15);
      }
      
      if ((stopWatch <= Time[0] && BarsSinceEntryExecution(1, "Entry", 1) == -1 ))
      {
         SetState(State.Terminated);
         return;
      }
      The issue is, if there's no data coming in then it won't calculate to terminate itself, and still requests data from kinetick. I need it to stop requesting from kinetick if nothing occurs after a certain period.

      Comment


        #4
        Originally posted by magnatauren View Post
        Hey Jesse, that's actually what I have set up right now, The issue I'm having is that it will still execute if the stopwatch, which is created during the configure state, which I hope is where I want it, is less than the current time
        No, use a real timer.

        Good discussion here.

        Comment


          #5
          Originally posted by bltdavid View Post

          No, use a real timer.

          Good discussion here.
          Looks perfect, implemented and going to test tomorrow!
          Thanks!

          Comment


            #6
            Originally posted by magnatauren View Post

            Looks perfect, implemented and going to test tomorrow!
            Thanks!
            Tested live with EURUSD and a stock(that's obviously not in session) and it worked perfectly. Thanks for the solution.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Allse1938, Today, 04:56 AM
            0 responses
            1 view
            0 likes
            Last Post Allse1938  
            Started by Lumbeezl, Today, 01:20 AM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_Jason  
            Started by oz187, Yesterday, 11:31 PM
            1 response
            11 views
            0 likes
            Last Post NinjaTrader_Jason  
            Started by ofiramitai, Today, 01:59 AM
            0 responses
            11 views
            0 likes
            Last Post ofiramitai  
            Started by gravityflyer, Yesterday, 09:51 PM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_Jason  
            Working...
            X