Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Do I need to adjust order quantity when backtesting forex?

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

    Do I need to adjust order quantity when backtesting forex?

    NT 6.5 doc says

    Special Circumstances with GAIN Forex
    During a backtest, order quantity is an absolute value which is in most cases different than in a real-time brokerage account. As an example, 1 traded FX lot at a live brokerage account might be the equivalent to 100,000 of notional value (check with your broker) however, in backtest a value of 1 is a literal value of 1 and not 100,000. Thus, if you want to trade 100,000 in a backtest you need to put in a value of 100,000. Just remember that if you convert your strategy from backtest to live you will need to amend the order quantities appropriately.
    However, I just ran a strategy on $EURUSD and Sim101 (using orders with quantity 1) and the P&L gives the correct result (and so does TradesPerformance.Currency.CumProfit). So is this manual conversion (i.e. using quantity of 10,000 or 100,000 instead of 1) during backtest obsolete in NT 7?

    If I run the strategy on a currency then TradesPerformance.Currency.CumProfit and TradesPerformance.Points.CumProfit are different (Currency is correctly multiplied by 10,000 - my live account uses mini lots - however, I ran the strategy on Sim101, so how does it know?). If I run it on a stock Currency and Points have the same value (which is also correct).

    How does NT know when to scale and how much to scale (i.e. by 10,000 for mini lots or 100,000 for normal lots)? Does it get that from the account connection or instrument settings or ...?

    #2
    Nothing has changed here in NT7 that I am aware of. Scale is based off of connection and possibly how data is quoted (tenth pip, 1/2 or whole pip) set under Tools > Options.
    RayNinjaTrader Customer Service

    Comment


      #3
      I'm sorry to bring this thread back up, Ray, but I am having trouble with backtesting a Forex strategy. I have set up my strategy to multiply the order quantity by 1000, 10000 or 100000 if Historical = true. So it creates the proper order quantities for me now. But the strategy performance is all wacked out. Like profit on a single trade is in the millions for a $10,000 account.

      How can I sync up backtesting and get the profit/loss to calculate correctly? It seems like it's impossible, since you have artificially multiply your order quantities. Then I assume when you run it in realtime (I'll be using MB Trading), you have to NOT multiply order quantities so that 1 = 1 microlot, 10 = 1 minilot, 100 = 1 std. lot.

      This is really confusing and I'm hoping someone else has already figured out how to get NinjaTrader to backtest and run strategies in the Forex market.

      Thanks!
      Bryan

      Comment


        #4
        cassb,

        Please see this article: http://www.ninjatrader-support.com/H...ngFXStrategies

        When you are backtesting you would use 100,000 as the quantity for a standard lot. When on live brokerage connections, you would use whatever quantity is required by your brokerage to represent 1 standard lot.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Thanks, Josh, but I've already done that. Everything is set up according to the instructions, I think. So why is it showing millions of dollars in the performance for a $10k account??
          Attached Files

          Comment


            #6
            What is your setting in Tools>Options>Data for FX quotes?
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Josh View Post
              What is your setting in Tools>Options>Data for FX quotes?
              It's set to "Pip".

              Comment


                #8
                Can you please try with SampleMACrossOver and let me know your results then as I cannot reproduce on my end with that strategy.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Josh View Post
                  Can you please try with SampleMACrossOver and let me know your results then as I cannot reproduce on my end with that strategy.
                  OK, I opened a new EURUSD 10 min. chart, connected to Gain demo acct, and loaded up the SampleMACrossOver strategy. Since it does not have an order qty, using EnterLong() and EnterShort(), it orders a qty of "1". Apparently, "1" is a standard lot, as the Strategy Performance from a live chart appears to correctly count $10 per pip and the profit/loss amounts look good. However, if you run the same strategy in the Strategy Analyzer, the profit/loss comes out in pennies and does not match the $10/pip as the live chart Strategy Performance shows. This appears to be a bug.

                  In my strategy, I read and applied the instructions in the NT help guide, so my order quantity for historical data is 100,000 for 1 standard lot, 10,000 for 1 mini lot, 1000 for micro lots. So my strategy works in the reverse from the sample one: The strategy analyzer works OK, but the Strategy Performance on a live chart is assuming 1 lot is $10/pip.

                  Here is the code where I place the orders:

                  Code:
                              if (Historical) // if backtesting, multiply the lot number by the lot type being traded
                              {
                                  switch (lotSize)
                                  {
                                      case LotTypes.Full:
                                          OrderQty = OrderQty * 100000;
                                          break;
                                      case LotTypes.Mini:
                                          OrderQty = OrderQty * 10000;
                                          break;
                                      case LotTypes.Micro:
                                          OrderQty = OrderQty * 1000;
                                          break;
                                  }
                              }
                              
                              if (Type == "Long")
                              {
                                  Print("Placing long order " + OrderName + " for " + OrderQty + " lots");
                                  EnterLong(OrderQty, OrderName);
                              }
                              if (Type == "Short")
                              {
                                  Print("Placing short order " + OrderName + " for " + OrderQty + " lots");
                                  EnterShort(OrderQty, OrderName);
                              }

                  Comment


                    #10
                    cassb,

                    This is expected behavior. When you are backtesting in the Strategy Analyzer you have to use 100,000 for the quantity as discussed in the Help Guide article. When you are live you need to use whatever your brokerage account requires.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_Josh View Post
                      cassb,

                      This is expected behavior. When you are backtesting in the Strategy Analyzer you have to use 100,000 for the quantity as discussed in the Help Guide article. When you are live you need to use whatever your brokerage account requires.
                      A couple things come to mind then:

                      1) What is the definition of "Historical" then? It seems to mean two different things -- All bars are historical in Strategy Analyzer. But also, bars in the past on a live chart trigger the "if (Historical)" code too. So you get two different results for the same "historical" data.

                      2) How would you place an order for 1 mini lot on Gain demo? OrderQty must be an integer, so you cannot open decimal lots for mini or micro lots.

                      Thanks!
                      Bryan

                      Comment


                        #12
                        1. When running in Strategy Analyzer you need to use 100,000. When running from a chart you are connected to a brokerage account and as such you would use your brokerage settings. The brokerage settings should be used regardless if you are simply viewing the historical portion of the chart as all future live trades need to be done accordingly to the brokerage settings.

                        2. This depends on your particular GAIN account. http://www.ninjatrader.com/webnew/support_GAIN.htm

                        I suggest you contact GAIN and ask them what quantity you should be submitting for your particular account you hold with them.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_Josh View Post
                          1. When running in Strategy Analyzer you need to use 100,000. When running from a chart you are connected to a brokerage account and as such you would use your brokerage settings. The brokerage settings should be used regardless if you are simply viewing the historical portion of the chart as all future live trades need to be done accordingly to the brokerage settings.

                          2. This depends on your particular GAIN account. http://www.ninjatrader.com/webnew/support_GAIN.htm

                          I suggest you contact GAIN and ask them what quantity you should be submitting for your particular account you hold with them.

                          OK, then regarding #1 above, is there a flag or array or variable I can check in the code to know whether I'm in Stategy Analyzer or in a live account? I'm using the Historical flag, but that seems to be the same whether I'm running in Analyzer or historical bars on a live chart. I need something that will be able to distinguish between to the two.

                          Thanks!

                          Comment


                            #14
                            cassb,

                            Unfortunately there is no flag that will tell you if you are in Strategy Analyzer or live.
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              Originally posted by NinjaTrader_Josh View Post
                              cassb,

                              Unfortunately there is no flag that will tell you if you are in Strategy Analyzer or live.
                              Sounds like something for the v7.1 enhancement list then, Josh!

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              636 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              366 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              107 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              569 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              571 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X