Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Add time-based event handler into the Strategy

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

    Add time-based event handler into the Strategy

    There are many cases, where strategy needs to evaluate something
    periodically or in some time-based frequency.

    For example:
    • Strategy need to move stoploss behind drawdown after 5 minutes in trades.
    • Or wants to enter the trades 15 seconds before 8:30 AM CST.


    With current events - like OnBarUpdate() this is not able to achieve in a timely manner,
    because this event comes once for a bar-update, which can be much more later,
    then required.

    Example of problem:
    strategy used M15 timeframe and if there is no bar update (in the night time),
    then the strategy cannot detect such an time-based event.

    I know, the solution can be custom implemented, for example with some new thread calling our strategy each 5 seconds, but time-based events are very common thing
    used in trading strategies. And such a basic thing should not require much of custom programmin - they should be implemented in the strategy and should just use it.

    Solution:
    Add new virtual method OnTimeUpdate(),
    which would be empty by default and called with default 1 second frequency.
    User can then implement any time-based events.

    #2
    Hello misova,

    There are two options you can take.

    One, you can write code into OnMarketData() which triggers on every received data (which is required for an order to submit). In this you can check the time and see if it is greater than 5 minutes or another time interval than the bar or a variable that holds the last value of the time when it was saved.

    http://www.ninjatrader.com/support/h...marketdata.htm


    Two, you can use a timer but this is unsupported by NinjaTrader to do.
    Attached is an example of using a timer I've made previously to guide you in the right direction.
    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you,
      the provided code looks very useful for time-based actions.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by bmartz, Today, 09:30 AM
      2 responses
      11 views
      0 likes
      Last Post bltdavid  
      Started by f.saeidi, Today, 11:02 AM
      1 response
      2 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by geotrades1, Today, 10:02 AM
      4 responses
      12 views
      0 likes
      Last Post geotrades1  
      Started by rajendrasubedi2023, Today, 09:50 AM
      3 responses
      16 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by lorem, Today, 09:18 AM
      2 responses
      11 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X