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 CarlTrading, Yesterday, 11:51 AM
    0 responses
    12 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, Yesterday, 11:48 AM
    0 responses
    19 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-25-2026, 09:53 PM
    0 responses
    16 views
    0 likes
    Last Post CaptainJack  
    Started by CaptainJack, 03-25-2026, 09:51 PM
    0 responses
    13 views
    0 likes
    Last Post CaptainJack  
    Started by Mindset, 03-23-2026, 11:13 AM
    0 responses
    18 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X