Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Preventing live orders from submitting when backtesting

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

    Preventing live orders from submitting when backtesting

    This isn't a question about the strategy analyzer itself. Rather I want to ask about running a strategy on a chart.

    Is there any way to prevent a strategy from sending a live order on the last bar? As a temporary fix I tried

    if (!Historical) return;

    at the beginning of OnBarUpdate() but it doesn't seem to matter -- if the strategy generated an order on historical data prior to the next live tick, the order gets sent.

    The reason I want to prevent this is so that my ATM backtesting framework will work properly. It uses unmanaged orders on historical data, but I want it to switch over to ATM strategies on live data, and I don't want a lingering historical order to end up sitting there in the DOM ladder.

    -Alex

    #2
    Hi Alex,

    You can work with CurrentBar in relation to Count to identify the last bar on the chart. This will depend on CalculateOnBarClose settings.

    Code:
    bool isLastBar = CalculateOnBarClose ? Count - 2 == CurrentBar : Count - 1 == CurrentBar;
    You could work that bool into your entry conditions. Pseudo code:
    if (entryCondition && !isLastBar)
    {
    }
    Last edited by NinjaTrader_RyanM1; 07-16-2012, 02:33 PM.
    Ryan M.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    144 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    71 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    125 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    79 views
    0 likes
    Last Post PaulMohn  
    Working...
    X