Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to incorporate realized profits in Backtest

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

    How to incorporate realized profits in Backtest

    Hello,
    How can I make my strategy include this part of my script in backtest:


    if (Bars.FirstBarOfSession)
    {
    // Store the strategy's prior cumulated realized profit and number of trades
    priorTradesCount = Performance.RealtimeTrades.Count;
    priorTradesCumProfit = Performance.RealtimeTrades.TradesPerformance.Curre ncy.CumProfit;

    }
    /* Prevents further trading if the current session's realized profit exceeds $1000 or if realized losses exceed $1500.
    Also prevent trading if 20 trades have already been made in this session. */
    if (Performance.RealtimeTrades.TradesPerformance.Curr ency.CumProfit - priorTradesCumProfit >= 1000
    || Performance.RealtimeTrades.TradesPerformance.Curre ncy.CumProfit - priorTradesCumProfit <= -1500
    || Performance.RealtimeTrades.Count - priorTradesCount > 20)
    return;

    NB:
    I am replacing all Performance.RealtimeTrades with Performance.AllTrades.
    I am trying to reset the private double priorTradesCumProfit before the session begins.

    Regards,
    Kiriru

    #2
    Kiriru, to reset the value, you can just set the value for the performance counter to 0 when a new session starts:
    Code:
    if (Bars.FirstBarOfSession)
    {
       priorTradesCount = Performance.RealtimeTrades.Count;
       priorTradesCumProfit = Performance.RealtimeTrades.TradesPerformance.Currency.CumProfit;
       int currentSessionTrades = 0;
       double currentSessionCumProfit = 0;
    }
    AustinNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Austin View Post
      Kiriru, to reset the value, you can just set the value for the performance counter to 0 when a new session starts:
      Code:
      if (Bars.FirstBarOfSession)
      {
         priorTradesCount = Performance.RealtimeTrades.Count;
         priorTradesCumProfit = Performance.RealtimeTrades.TradesPerformance.Currency.CumProfit;
         int currentSessionTrades = 0;
         double currentSessionCumProfit = 0;
      }
      Austin,
      I'm yet to figure out what you meant by this.
      Where should I use the new int and double variables:

      int currentSessionTrades = 0;
      double currentSessionCumProfit = 0;

      NB: I have already declared:
      int priorTradesCount = 0
      double priorTradesCumProfit = 0

      under variables.
      How do I made the new variables reset my stored cumulative profit?

      Comment


        #4
        kiriu, you want to put the code Austin shared at the OnBarUpdate() start, so your variable could be reset at the begin of a new trading session.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Austin,
          Bertrand,
          The script does not reset the variables at the beginning of session.
          I have backtested with Performance.AllTrades and it won't work.
          -Kiriru

          Comment


            #6
            Kiruru,

            If you print out the counter variable to the output window does it reset or does it just continue to down upwards?

            Print(currentSessionCumProfit);

            If it continues to count upwords can you please post your section of code that is occuring in if(FirstBarOfSession).



            I look forward to assisting you further.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by ScottWalsh, Today, 06:52 PM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by ScottW, Today, 06:09 PM
            1 response
            4 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by ftsc2022, 10-25-2022, 12:03 PM
            5 responses
            256 views
            0 likes
            Last Post KeyonMatthews  
            Started by Board game geek, 10-29-2023, 12:00 PM
            14 responses
            244 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by Waxavi, 04-19-2024, 02:10 AM
            4 responses
            56 views
            0 likes
            Last Post sonia0101  
            Working...
            X