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 argusthome, 03-08-2026, 10:06 AM
    0 responses
    61 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    40 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    21 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    23 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    51 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X