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 FishTrade, Today, 03:42 PM
    0 responses
    1 view
    0 likes
    Last Post FishTrade  
    Started by Richozzy38, Today, 01:06 PM
    3 responses
    14 views
    0 likes
    Last Post Richozzy38  
    Started by ttrader23, Today, 09:04 AM
    2 responses
    12 views
    0 likes
    Last Post ttrader23  
    Started by geotrades1, Today, 07:54 AM
    10 responses
    26 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by ninza33, Yesterday, 12:31 PM
    3 responses
    16 views
    0 likes
    Last Post NinjaTrader_LuisH  
    Working...
    X