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

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 Rapine Heihei, Today, 08:19 PM
            0 responses
            1 view
            0 likes
            Last Post Rapine Heihei  
            Started by f.saeidi, Today, 08:01 PM
            1 response
            4 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by Rapine Heihei, Today, 07:51 PM
            0 responses
            4 views
            0 likes
            Last Post Rapine Heihei  
            Started by frslvr, 04-11-2024, 07:26 AM
            5 responses
            96 views
            1 like
            Last Post caryc123  
            Started by algospoke, 04-17-2024, 06:40 PM
            6 responses
            49 views
            0 likes
            Last Post algospoke  
            Working...
            X