Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Backtesting

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

    Backtesting

    Hi

    I have some problem with the backtesting.

    First of all I'm not able to deal with account size in the terms I use it.
    I can't figure out how to backtest with an initial amount for the first purchase. Then if I sell this with a profit the profit is included in my account and I am then able to buy more shares next time I buy etc. and in that way operate with compound interest.

    Furthermore I do not know how to se a graph of the cumulative profit on daily basis but only every time I sell and realize money. How do I do that?

    Do I need some add-ons or something to be able to backtest the way I need to improve my strategy?

    #2
    Hello superjma,

    It's possible but must be custom coded. You can work with trade performance class to generate PNL figures for historical, hypothetical trades and then base additional trade conditions off these values.

    There isn't a graph available until the backtest is complete but you can keep track of Unrealized PnL value on a daily basis and use it in your script as well.

    The following samples can help working with Trade Performance class as well as resetting values at the start of each day.





    There is also possibility of setting account size property for order quantity determination, although mind the "note" indicated below as it seems relevant to what you're looking to do.


    Note: This property does not update dynamically for access to updated account size values. It is dynamic for order sizing only. Should you want a dynamically updating account size you will need to track this with your own variables.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thanks

      Ok. Thanks.

      I will look into it.

      I just thought that this was basic stuff for a program like Ninja Trader.

      Comment


        #4
        I have been trying to use your links but without luck, and I do not know how to debug the code without visual studio installed.

        Can you see what I am doing wrong?

        // Condition set 1
        if (Close[0] >= SMABand(Pct, Period).Upper[0])
        {
        EnterLong(Convert.ToInt32(lastProfit / Close[0]), "");
        }

        // Condition set 2
        if (Close[0] <= SMABand(Pct, Period).Lower[0])
        {
        ExitLong("", "");

        // Check to make sure there is at least one trade in the collection
        if (Performance.LongTrades.Count > 0)
        {
        // Get the last longtrade (at index 0)
        Trade lastTrade = Performance.LongTrades[Performance.LongTrades.Count - 1];

        // Calculate the PnL for the last completed longtrade
        lastProfit = lastTrade.ProfitCurrency * lastTrade.Quantity;

        // Pring the PnL to the Output window
        Print("The last trade's profit is " + lastProfit);
        }
        }
        Attached Files
        Last edited by superjma; 05-25-2011, 03:19 PM.

        Comment


          #5
          To use those samples:
          1) Download the files.
          2) Import using File > Utilities > Import NinjaScript and select the file.
          3) View code using Tools > Edit NinjaScript > Strategy.

          What issue are you having with the code snippet posted?
          Ryan M.NinjaTrader Customer Service

          Comment


            #6
            I got it working now.
            First it didnt do what I expected.

            Now my next issue is why the Sharpe Ratio is 0.01 because it looks on the chart that the volatility in the portfolio is less than the chart.
            Attached Files

            Comment


              #7
              6 trades over 20 years, i would start with that problem first.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by tkaboris, Today, 05:13 PM
              0 responses
              2 views
              0 likes
              Last Post tkaboris  
              Started by GussJ, 03-04-2020, 03:11 PM
              16 responses
              3,281 views
              0 likes
              Last Post Leafcutter  
              Started by WHICKED, Today, 12:45 PM
              2 responses
              19 views
              0 likes
              Last Post WHICKED
              by WHICKED
               
              Started by Tim-c, Today, 02:10 PM
              1 response
              9 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by Taddypole, Today, 02:47 PM
              0 responses
              5 views
              0 likes
              Last Post Taddypole  
              Working...
              X