Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy in live mode handles old data

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

    Strategy in live mode handles old data

    Hi,

    I am running a strategy, that opens based on the latest price a bracket order.

    When I start the strategy in live mode then first it loads some old data, and in the Method OnBarUpdate, when I fixate the starting price, I get some old price and the strategy doesn't work.

    To prevent that I am checking for the historical state, and only respect the price when the state is not historica.

    State != State.Historical

    This makes the strategy work fine.

    But I have than a problem with the backtest, it has only historical data I assume.

    I tried checking BarsInProgress == 0, but it didn't help.

    How is it possible to make the strategy using only latest data during live market run and all data during backtesting?

    Where do I get a log for the strategy analyzer. When I start the strategy in live mode, it trades. When I backtest it for one year with all test data available, I get an empty result with zero trades.

    Thanks and best regards
    Last edited by moneymaster; 02-12-2025, 01:53 AM.

    #2
    Hello moneymaster,

    Thank you for your post.

    You can use IsInStrategyAnalyzer to check if your script is running in the analyzer. The Strategy Analyzer only runs on historical data so your check to return when State is State.Historical will cause it not to run at all in the Strategy Analyzer.

    Code:
    //Return if we are not running this strategy from the Strategy Analyzer and State is Historical
    if(!IsInStrategyAnalyzer && State == State.Historical)
    {
    return
    }
    Please let us know if you have any further questions. ​

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    64 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    40 views
    0 likes
    Last Post PaulMohn  
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    166 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    101 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    162 views
    2 likes
    Last Post CaptainJack  
    Working...
    X