Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Position Sizing - Help with Performance.AllTrades.TradesPerformance.Currency

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

    Position Sizing - Help with Performance.AllTrades.TradesPerformance.Currency

    Hi Guys,

    I need some help.

    I am trying to build a strategy to trade Forex that takes into account Position Sizing. More specifically my objective is to have the strategy determine the size of my position based on a fixed % of my account I am willing to risk on each trade. First of all we must distinguish between Direct Rates (e.i. EURUSD, AUDUSD, NZDUSD) and Indirect Rates (USDJPY, USDCAD). For direct rates coding the strategy is simple, however I am encountering problems in coding the strategy for the case of the Indirect Rates.

    1.
    I need somebody to explain me how the following script works(Performance.AllTrades.TradesPerformance.Currency.C umProfit) or basically from where does it take data? Is this the same data I can see in the Execution/Trades tab when running a strategy in the StrategyAnalyser?

    2.
    In my strategy I would need Performance.AllTrades.TradesPerformance.Currency.C umProfit to be divided by the SpotRate at the moment of the exit, basically Close[0] at the time the trade occured. This is necessary as the Profit for each trade reported by NT is not in USD terms but in Foreign Currency terms for IndirectRates (e.i. when trading USDJPY the Performance.AllTrades.TradesPerformance.Currency.C umProfit will be expressed in JPY terms, whilst I need to report this back in USD). Could somebody please tell me if this is possible, and if yes what script should I use?

    Thanks, sburtt

    #2
    Originally posted by sburtt View Post
    Hi Guys,

    1.
    I need somebody to explain me how the following script works(Performance.AllTrades.TradesPerformance.Currency.C umProfit) or basically from where does it take data? Is this the same data I can see in the Execution/Trades tab when running a strategy in the StrategyAnalyser?
    Yes, this information is pulled directly from the database. Note that this can contain both real-time and historical (synthetic) executions. Since you're using AllTrades, it will use both historical executions, and executions that occurred on the real-time stream. If you'd only like real-time executions that actually occurred on your account, you'd want to use the Performance.RealTime method.


    Originally posted by sburtt View Post
    2.
    In my strategy I would need Performance.AllTrades.TradesPerformance.Currency.C umProfit to be divided by the SpotRate at the moment of the exit, basically Close[0] at the time the trade occured. This is necessary as the Profit for each trade reported by NT is not in USD terms but in Foreign Currency terms for IndirectRates (e.i. when trading USDJPY the Performance.AllTrades.TradesPerformance.Currency.C umProfit will be expressed in JPY terms, whilst I need to report this back in USD).
    Your understanding is only true when backtesting or if you do not have the USDJPY cross pair streaming on real-time trades. For real-time trades, we will use the real-time Close[0] price at the time of execution to convert back to USD.

    Originally posted by sburtt View Post

    Could somebody please tell me if this is possible, and if yes what script should I use?
    It would be possible to implement your own method of taking the closing price to determine the USD results for non-usd pairs, however I'm not aware of a script that already does this There is not a supported method to override historical collection of trade performance to reflect this information at this time, however you can use that collection to calculate the performance values vs the close price as you're hoping.



    This is a limitation we are looking to improve on in the next major release.
    Last edited by NinjaTrader_Matthew; 07-19-2013, 07:49 AM.
    MatthewNinjaTrader Product Management

    Comment


      #3
      I would also like to mention that forex brokers use two methods for determine the conversion rate: either the real-time price, or the last settlement price.

      You may find it easier in your backtesting process to just just the last settlement which is the simply the closing price of the last daily bar. This should reduce the number of calculation in your logic and should give you a relative conversion rate for backtesting purposes.
      MatthewNinjaTrader Product Management

      Comment


        #4
        Originally posted by NinjaTrader_Matthew View Post
        It would be possible to implement your own method of taking the closing price to determine the USD results for non-usd pairs, however I'm not aware of a script that already does this There is not a supported method to override historical collection of trade performance to reflect this information at this time, however you can use that collection to calculate the performance values vs the close price as you're hoping.

        This is a limitation we are looking to improve on in the next major release.
        Matt, thanks for your reply. At this stage I need this for back-testing purpose, to test the robustness of my strategy.

        1. do you have any idea when the next major release is scheduled for?
        2. Am I right when I say that the "Performance.AllTrades.TradesPerformance.Currency. C umProfit" script would print the Cumulative Profit? If this is the case this wouldn't work, as I would need to convert each single trade profit from JPY to USD by dividing the JPY Profit by the Close of the bar at the time of the trade and sum this to my Capital. Are you aware of a script that allows to view the Profit per single trade, and ideally the entry and exit price of the trade? Basically I need to figure out the correct script to go and pick these details from the database. Thanks again

        Comment


          #5
          Hello,

          We do not have an ETA on the date of the next major release.

          Correct, the Cumulative Profit would get you a running total. You can use the Trade object to get the information from the most recent trade to perform your calculation:



          I do not know any scripts that will do this already.
          MatthewNinjaTrader Product Management

          Comment


            #6
            Originally posted by NinjaTrader_Matthew View Post
            Hello,

            We do not have an ETA on the date of the next major release.

            Correct, the Cumulative Profit would get you a running total. You can use the Trade object to get the information from the most recent trade to perform your calculation:



            I do not know any scripts that will do this already.
            Am i right in saying that this complicates things quite a lot, meaning that it's hard to have a standard template to adapt to different strategies. Having to look into the IExecution field this will need to be customized for each single strategy.

            Comment


              #7
              Originally posted by NinjaTrader_Matthew View Post
              Hello,

              We do not have an ETA on the date of the next major release.

              Correct, the Cumulative Profit would get you a running total. You can use the Trade object to get the information from the most recent trade to perform your calculation:



              I do not know any scripts that will do this already.
              Hi Matt,
              I would need some help. In my strategy I need to create a DataSeries object to store values. I’ve defined a variable “lastProfit” to hold the DataSeries object and created a new DataSeries in the Initialize() method. Finally in the OnBarUpdate() method I’ve defined how to define the value to be stored in the DataSeries (please see code below).

              What I would need to know is what function to use to obtain the cumulative sum of the values stored in the DataSeries, basically I want my strategy to return the cumulative sum of the lastProfit DataSeries. Please help
              Code:
              {
                          [Description("")]
                          public class ABC : Strategy
                          {
                                      #region Variables
              		private DataSeries lastProfit;
                                      #endregion
              
                                      protected override void Initialize()
                                      {
              			lastProfit = new DataSeries(this, MaximumBarsLookBack.Infinite);
                                      }
              
                                      protected override void OnBarUpdate()
                                      {
                                                  if (...)
                                                  {
                                                       	lastProfit.Set(lastTrade.ProfitCurrency * lastTrade.Quantity / lastTrade.Exit);
              			else
              				lastProfit.Set(0);
              }
              }
              }

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              648 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              369 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
              575 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X