Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

some logic not being performed during a backtest

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

    some logic not being performed during a backtest

    Click image for larger version

Name:	ninjascript loss in ticks logic questionpic.jpg
Views:	113
Size:	89.8 KB
ID:	1186338
    These lines of code are under OnBarUpdate.
    Calculate.OnEachTick

    Lines 115 & 120 are custom made calculations that are counting the amount of ticks lost that was realized on the last trade, and the output will print the correct numbers.

    Lines 130 || 137 is meant to add "LossInTicks" to the profit target on our next trade but its not preforming this logic at all and the profit target on the next trade is static.

    This logic runs correctly on a playback but does not work during a backtest, How can I solve this?

    #2
    Hello Don22Trader1,

    Thank you for your inquiry.

    What prints are seen when running this in a backtest in the Strategy Analyzer? Do you see the "Profit Target in Ticks" print at all? Does "Loss in ticks" print?

    Thanks in advance; I look forward to assisting you further.

    Comment


      #3
      Click image for larger version

Name:	output.jpg
Views:	91
Size:	23.1 KB
ID:	1186351
      Yes the prints do come out as expected
      My initial profit target is always 4 ticks, and here you can see we have accumulated a loss of 8 ticks, therefore it is correct in saying our new profit target is set at 12 ticks
      but profit is not taken at 12 ticks it is always taken at 4 ticks

      Comment


        #4
        Hello Don22Trader1,

        Thank you for your reply.

        Where is your logic for the entry in the script in relation to the shown code? Are you calling SetProfitTarget() before or after the entry? You should ensure that you're making any adjustments before the entry is made.

        If that does not resolve the issue, can you provide a simplified example strategy that illustrates the issue so we may test on our end? Any code unnecessary to reproduce should be omitted.

        Thanks in advance; I look forward to assisting you further.

        Comment


          #5
          ok so the SetProfitTarget() was before the entry method and so I moved it to after the entry method but I had the same results,

          But upon further research I found that I cannot return an account value during a back-test.
          If you review the previous picture of the code lines 115 & 120 - "LossInTicks" uses the GrossPnL of the account and if you see the output, the current Gross PnL always returns 0. therefore loss in ticks will be 0
          what can I use to replace line 108- "CurrentGrossRealizedPnL = Account.Get(AccountItem.GrossRealizedProfitLoss, Currency.UsDollar);" so i can get an updating Gross PnL during a back-test?

          Comment


            #6
            Hello Don22Trader1,

            Thank you for your reply.

            Unfortunately the Strategy Analyzer does not have an associated Account that would store that value. You could consider using SystemPerformance.AllTrades.TradesPerformance.Curr ency.CumProfit when backtesting in the Strategy Analyzer to get the current realized PnL for the Strategy itself:



            Please let us know if we may be of further assistance to you.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Today, 05:17 AM
            0 responses
            22 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            120 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            63 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            41 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            45 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X