Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exiting after minutes instead of number of Bars

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

    Exiting after minutes instead of number of Bars

    Hello, this topic was addressed in NT7 here

    Support for the development of custom automated trading strategies using NinjaScript.


    Without searching, I was curious if it is possible to create an input which exits a trade after a set amount of minutes not bars.

    For example, say we have a strategy on a 20 min chart, but we want to exit after 5 minutes. Is that possible? Any examples out there?

    Thanks

    #2
    Hello EC_Chris,

    Thanks for opening the thread.

    This can be possible by adding a secondary series for the instrument and to place your exit logic within code that checks for the BarsInProgress of the finer data series.

    Another approach would be to add a timer for your own time based events. An example indicator using a timer is included with the SampleCustomEvents example in the Reference Samples section of our forums. The timer could be extracted and implemented in a strategy to have your own time based events. The timer must use TriggerCustomEvent() so pointers for objects used in the instrument thread are realigned and up to date so you can use them appropriately.

    For taking the first route, please refer to the Multi Series NinjaScript documentation. For the second approach, please refer to the SampleCustomEvents indicator to see how the indicator implements a timer. The timer will then need to be modified for your interval, and you logic will need to be within TriggerCustomEvent() attached to the Timer's tick event handler. (OnMarketDepth code may be ignored.)

    Multi Series NinjaScripts (Important read!) - https://ninjatrader.com/support/help...nstruments.htm

    SampleCustomEvents - https://ninjatrader.com/support/foru...ead.php?t=5965

    Please let me know if you have any questions.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    42 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    20 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    29 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    46 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    38 views
    0 likes
    Last Post CarlTrading  
    Working...
    X