Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Managing CashFlow in Strategy Backtest

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

    Managing CashFlow in Strategy Backtest

    Hi,

    I am making some backtest with a strategy that I've just implemented. But I am having a hard time managing the cash flow. Is there a built-in way of doing this? For example, I start my strategy with $1000,00 and I can't let my "account" became negative!!

    Thanks!

    #2
    Hello PrimoItch,

    Thank you for your post.

    When backtesting there is no means to set the values of the account. You would instead implement internal calculations in your strategy to calculate and track your own custom values for the desired account values.

    For example:

    Initial Capital = your backtest starting value.
    UnrealizedPnL = (Position.GetUnrealizedProfitLoss(PerformanceUnit. Currency, Close[0]));
    CumNetPnL = SystemPerformance.AllTrades.TradesPerformance.Curr ency.CumProfit;
    CurrentCapital = InitialCapital + UnrealizedPnL + CumNetPnL

    Then you could update these on each pass through On Bar Update and modify the logic from this example to stop the strategy after a set loss or profit amount:



    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      This works when backtesting a single instrument, but when backtesting a basket of instruments, how can you keep track of your total cumulative profit of all instruments combined? For example, in OnBarUpdate() before entering a trade, I'd like to know the current cumulative profit of all instruments at that bar.

      Comment


        #4
        Hello bkonia,

        Thank you for your reply.

        Are you talking about using the Strategy Analyzer to run backtests on an entire instrument list? This wouldn't be possible as the backtests do not run simultaneously and each run of the strategy is a separate instance of the strategy.

        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by usazencort, Today, 01:16 AM
        0 responses
        1 view
        0 likes
        Last Post usazencort  
        Started by kaywai, 09-01-2023, 08:44 PM
        5 responses
        603 views
        0 likes
        Last Post NinjaTrader_Jason  
        Started by xiinteractive, 04-09-2024, 08:08 AM
        6 responses
        22 views
        0 likes
        Last Post xiinteractive  
        Started by Pattontje, Yesterday, 02:10 PM
        2 responses
        21 views
        0 likes
        Last Post Pattontje  
        Started by flybuzz, 04-21-2024, 04:07 PM
        17 responses
        230 views
        0 likes
        Last Post TradingLoss  
        Working...
        X