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 gm7_forum, Today, 05:51 PM
      0 responses
      1 view
      0 likes
      Last Post gm7_forum  
      Started by cre8able, Today, 03:20 PM
      1 response
      9 views
      0 likes
      Last Post cre8able  
      Started by fiddich, Today, 05:25 PM
      0 responses
      3 views
      0 likes
      Last Post fiddich
      by fiddich
       
      Started by gemify, 11-11-2022, 11:52 AM
      6 responses
      804 views
      2 likes
      Last Post ultls
      by ultls
       
      Started by ScottWalsh, Today, 04:52 PM
      0 responses
      4 views
      0 likes
      Last Post ScottWalsh  
      Working...
      X