Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Issue with DataSeries in Strategy

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

    Issue with DataSeries in Strategy

    Hi,
    I am using the following code within my strategy to generate a DataSeries of cumulative profit generated by my strategy in USD terms. I am trading Indirect Forex Rates (e.i. USDJPY) and I need this because the function provided by NT Performance.AllTrades.TradesPerformance.Currency.C umProfit would only return a profit in JPY, whilst I need to know my USD Cumulative Profit, that is simply the sum of the historical profit for each trade divided by the exit price at the time (please see lastProfit = new DataSeries below). This code works perfectly in my strategy, HOWEVER when using the Print fuction to return the value in the output window Print("CumProfit: "+ CumulativeLastProfit[0]); returns an incorrect value, basically it always returns the lastProfit[0], would you be able to indicate what I am doing wrong?

    Code:
     #region Variables
    private DataSeries lastProfit;
    private DataSeries CumulativeLastProfit;
    #endregion
    
    protected override void Initialize()
    {
    lastProfit = new DataSeries(this, MaximumBarsLookBack.Infinite);
    CumulativeLastProfit = new DataSeries(this, MaximumBarsLookBack.Infinite);
    }              
    
    protected override void OnBarUpdate()
    {
    lastProfit.Set(lastTrade.ProfitCurrency*lastTrade.Quantity /lastTrade.Exit.Price;
    CumulativeLastProfit.Set(CumulativeLastProfit[1] + lastProfit[0]);
                                                    
    Print("CumProfit: "+ CumulativeLastProfit[0]);
    }

    #2
    Hi sburtt, I'm a bit confused by this statement - 'This code works perfectly in my strategy, HOWEVER when using the Print fuction to return the value in the output window'

    So you mean the code works for you as expected in the script but yet the Print of individual values would not be making sense?

    Thanks

    Comment


      #3
      Originally posted by NinjaTrader_Bertrand View Post
      Hi sburtt, I'm a bit confused by this statement - 'This code works perfectly in my strategy, HOWEVER when using the Print fuction to return the value in the output window'

      So you mean the code works for you as expected in the script but yet the Print of individual values would not be making sense?

      Thanks
      I am confused too, and I can't get my head around this.. I need this script in my strategy to determine the correct position size to adopt when trading indirect forex rates. When i run the strategy apparently it works ok. If I download data in excel and double check details, it does exactly what I nedd it to do. However, as Strategy Analyser returns Profits in JPY currency when backtesting I need an algorithm to calculate the correct Profits in USD and I would like this to be displayed via Print in the output window, but when doing this, CumulativeLastProfit[0] returns incorrect values, as if it's not summing up correctly as I tell it to do in the iteration formula reported above

      Comment


        #4
        sburtt, yes the summation aspect from the snippet shared looks fine to me as well. I would suggest gradually and methodically stepping through the complete script to debug the outcomes you are seeing to better understand the event sequence that needs to happen to give you the undesired result. That can be done for example via Print commands to your output window in combination with simplifying the script / commenting to 'bare essentials' and only then starting to add complexity back in.

        Comment


          #5
          as I see it, it's the Print function that returns a funky outcome. I will try this script with a simple moving average cross over and see if the issue persists. Eventually if it does, I might send it too you to double check if I am missing out on something. Thanks

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          649 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          370 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          109 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          573 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          576 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X