Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

backtesting forex strategy, how to set order quantity to forex lot sizes

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

    backtesting forex strategy, how to set order quantity to forex lot sizes

    I am confused by the interface. How do I tell NT that I want to trade say 2 x $10,000 mini lots or 1 x $100,000 regular lots for a particular forex currency pair I am backtesting or analyzing.

    It seems to be setup to take a number of shares or contracts, rather than forex lot size or anything related. I am probably overlooking something obvious. Could someone explain how to do this?

    Thanks.

    #2
    I have read this and it does not appear to be true.


    "Running an FX strategy in the Strategy Analyzer for a historical backtest, in real-time connected to either the Simulated Data Feed or Market Replay order quantities will always represent the total units of the base currency being traded. A lot size of one equals a base currency unit of one and DOES NOT equal a typical "standard" lot size of 100,000. Therefore, if you want to trade a standard lot you would use an order quantity of 100,000."
    This does not match up with what I see from a backtest.

    I used 2440 order quantity on a short trade where the price went from 79.39 to 78.36, total profit of 2513.20.

    This is calculated just like a normal stock: (2440*79.39)-(2440*78.36) = 2513.2

    Not like 2440 units of base currency: 2400*((79.39/78.36)-1) = 31.55

    If NT was calculating 2440 units like they say they are, as base currency, then that trade would of only showed 31.55 profit. Is there some other setting you must turn on to have NT behave like the documentation says it does? I am very confused by this program.

    Comment


      #3
      volkie,

      Lots are calculated on 100,000 units of currency. So 1 lot would be 0.1M or 100,000 for ordering through NinjaTrader. Most brokerages wouldn't support 2440 units of currency.

      A lot is 100,000, a mini-lot is 10,000, a micro-lot is 1,000, so 1,000 units would be the minimum amount you can change an order by for brokers that support micro-lots.

      What sort of issue with the performance reporting are you seeing? Could you clarify?
      Adam P.NinjaTrader Customer Service

      Comment


        #4
        I think were on different pages here. Im aware of everything you said. What I'm saying is NinjaTrader, when running a strategy in Strategy Analyzer on a Fx currency pair, isn't using the Order Quantity field as the lot size, but rather the amount of "shares." Which doesn't apply to Fx in the same manner obviously. Enter 100,000 in the Order Quantity field and it buys 100,000 "shares" at the bid price, not a 100,000 lot. You can see earlier posts where I detail a trade that clearly shows it treats the Order Quantity as share size, not lot size.

        How do I make NT behave properly when backtesting/optimizing for Forex? I want to just be able to enter 100,000 or 200,000 into the order quantity and have it work properly.

        Edit:

        The only reason I'm specifying 2440 is because I'm testing on USDJPY (price usually around ~82) and 2440*82 = ~200,000 (the lot size I want this strategy to analyze on.) Now can you tell me how to do that without using all this odd math on my end? If I don't do the math on my end to get order sizes like 2440 then none of the profits are correct, as detailed in my previous post.
        Last edited by volkie; 04-08-2012, 02:28 PM.

        Comment


          #5
          Volkie,

          All PnL would be reported in USD. Are you using the calculations based on the two pairs not possibly being USD pairs, or maybe the second currency isn't USD? I noticed you are using the USDJPY.

          Indeed, as you have noticed, NinjaTrader treats forex like a share.100,000 "shares" is 1 lot in NinjaTrader. So if you put in 100,000 for order quantity its considered as such. I believe even for USDJPY is the same but I will need to double check this.
          Adam P.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_AdamP View Post
            Volkie,
            Indeed, as you have noticed, NinjaTrader treats forex like a share.100,000 "shares" is 1 lot in NinjaTrader. So if you put in 100,000 for order quantity its considered as such. I believe even for USDJPY is the same but I will need to double check this.
            I have tried putting 100,000 in the Order Quantity for USDJPY. When I do this the cost basis is 8,200,000, not 100,000 -- easily verified by checking the optimization report and looking at an individual trade with a1% gain. NT will report something like $82,000 profit instead of $1000.

            I have taken to just putting 100,000 or whatever lot size in the Order Size field, then setting it to 'controlled by strategy' and dividing 100,000 by the last price to get the number of "shares" to buy, so that my cost basis is actually 100,000 and not 8,200,000. Still, seems there MUST be a better way I am missing.

            Comment


              #7
              volkie,

              I'll need to double check this tomorrow with our tech lead and possibly development. I'll keep this ticket open and respond after I have some more information for you tomorrow.
              Adam P.NinjaTrader Customer Service

              Comment


                #8
                volkie,

                On the EURUSD for example, if you open open a long position of one lot for EUR/USD for the ask price of 1.4000, you are purchasing 100,000 Euro while, selling 140,000 USD. This is one "Lot".

                For the USDJPY, lets say the ask price is 81.00, you would be purchasing 100,000 USD, selling 8,1000,000 Yen, I believe. So the lot size would always be 100,000 in the base currency.

                Doing some quick math here for profit / pip, lets say I buy 1 lot (which is 100,000 in NinjaTrader) of USDJPY at 81.00 and it goes up to 81.01.

                So : 0.01 (yen/dollar) profit / 81.00 (yen/dollar) * 100,000 dollars ~= 12.35 dollars profit

                All PnL in NinjaTrader is calculated in US dollars, so you may need to convert here from base currency in your calculations. I traded forex a lot before but I am a bit rusty here as I mainly do stocks now, so apologies if my arithmetic is off.

                Just doing a quick trade with the USD/JPY it looks like its around 12.30 profit / pip for a 1 lot trade (100,000 order quantity) so I believe my math is roughly correct, since the price is actually not 81.00, it was 81.28 when I bought in.

                Let me know if you have any other questions.
                Adam P.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_AdamP View Post
                  Let me know if you have any other questions.
                  I am not confused by how forex lots work, I just seem to be having an immense amount of trouble conveying my actual question: "A standard forex lot represents 100k of whatever currency your account is funded with. If your account is funded with US Dollars, a standard lot would be $100,000." My account currency is USD so it's very simple.

                  Cost basis for a forex order = Order Quantity
                  Cost basis for a non-forex order = Order Quantity * Instrument Price

                  When I put 100,000 in the Order Quantity field for a USDJPY trade in the strategy analyzer I expect my cost basis to be $100,000. With me here?

                  The problem is my cost basis is NOT $100,000 when I do this. It is calculating it like I'm placing a non-forex order. Like I'm buying 100,000 shares of some stock. It is calculating it as Order Quantity * Instrument Price instead of just Order Quantity. This leads to my cost basis being 8.2 million if I'm trying to trade a (1 lot) $100,000 of USD/JPY.

                  As a workaround, in my strategy, I take the Order Quantity I'm fed and divide by the Instrument Price, so that when NT goes ahead and treats the order like a stock order (multiplying it by the Instrument Price) it comes back out to $100,000. This is not ideal. How can I make NT treat this properly without a hack?

                  I really hope I've conveyed my actual question I don't know how else to explain it.
                  Last edited by volkie; 04-09-2012, 06:35 PM.

                  Comment


                    #10
                    volkie,

                    There seems to be some differences reading forex educational websites here in the way they describe lots. Some describe lots as "$100,000" which makes one believe its in dollars, however my understanding is that a lot is 100,000 units of the base currency. I am not sure if there exist accounts that only deal with 100,000 in USD for all lot sizes, or if these websites are mistakenly putting the "$" in front of the currency without realizing that this is the symbol for the US dollar, i.e. everything after a $ sign generally means the units are in US dollars.

                    So in other words, on the EURUSD, you are buying 100,000 Euros in exchange for
                    US dollars at the exchange rate. On the USDJPY, you are buying 100,000 USD in exchange for Yen at the exchange rate, on the CHFCAD you are buying 100,000 Swiss Francs in exchange for the Canadian Dollar at the exchange rate.

                    Here is a wikipedia article on it that mentions the lot size as calculated in base currency : http://en.wikipedia.org/wiki/Currency_pair#Trading

                    Please let me know if I may assist further.
                    Adam P.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_AdamP View Post
                      volkie,

                      There seems to be some differences reading forex educational websites here in the way they describe lots. Some describe lots as "$100,000" which makes one believe its in dollars, however my understanding is that a lot is 100,000 units of the base currency. I am not sure if there exist accounts that only deal with 100,000 in USD for all lot sizes, or if these websites are mistakenly putting the "$" in front of the currency without realizing that this is the symbol for the US dollar, i.e. everything after a $ sign generally means the units are in US dollars.

                      So in other words, on the EURUSD, you are buying 100,000 Euros in exchange for
                      US dollars at the exchange rate. On the USDJPY, you are buying 100,000 USD in exchange for Yen at the exchange rate, on the CHFCAD you are buying 100,000 Swiss Francs in exchange for the Canadian Dollar at the exchange rate.

                      Here is a wikipedia article on it that mentions the lot size as calculated in base currency : http://en.wikipedia.org/wiki/Currency_pair#Trading

                      Please let me know if I may assist further.
                      Yes I think I pasted a bad definition of what a lot is. Yes you are correct it is 100,000 units of the base currency. But in this case the base currency is USD so the problem remains valid.

                      Here's an entry from my backtest. Please do the math and tell me what's wrong with this 2 lot trade.

                      $USDJPY
                      Backtest
                      Trade: Short
                      Quantity: 200000
                      Entry Price: 80.23
                      Exit Price: 80.16
                      Profit: $13,995.00

                      Pips for USDJPY are 0.01
                      This trade was an 7 pip gain
                      So according to NT 1 pip is worth $1999.28 in this trade. Does that seem right to you?

                      Edit: My commission on the trade was $5.00 that's why the profit doesn't say a nice round $14,000.
                      Last edited by volkie; 04-10-2012, 10:49 AM.

                      Comment


                        #12
                        Hello,

                        Did currency conversion occur on this trade? To check please go to the executions tab, what is rate listed at for the trade? 1? or other?

                        -Brett

                        Comment


                          #13
                          Originally posted by NinjaTrader_Brett View Post
                          Hello,

                          Did currency conversion occur on this trade? To check please go to the executions tab, what is rate listed at for the trade? 1? or other?

                          -Brett
                          All values in the Rate column are 1.

                          Comment


                            #14
                            volkie,

                            I went and talked to development about this. This is what they said :

                            "The Strategy Analyzer wouldn't convert the currency with anything other than a value of 1 at this time. It is on our list for increased features in subsequent versions."

                            For now, using the lot sizes you mentioned would work for backtesting purposes, however once you shift to live trading either to a live account or simulated account you would want to use standard lot sizes based on 100,000.

                            This issue does not affect any live trading, nor simulated trading PnL calculations, only the Strategy Analyzer is affected.

                            Please let me know if I may assist further.
                            Adam P.NinjaTrader Customer Service

                            Comment


                              #15
                              Hi,

                              I'm curious where this topic stands in NT7. I'm using the strategy analyzer on Forex pairs, and the PNL definitely isn't correct. It appears that NT is calculating PNL as it would with a stock.

                              Is it possible now to set the exchange rate in a strategy script?

                              Thanks,
                              Michelle

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by jclose, Today, 09:37 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post jclose
                              by jclose
                               
                              Started by WeyldFalcon, 08-07-2020, 06:13 AM
                              10 responses
                              1,413 views
                              0 likes
                              Last Post Traderontheroad  
                              Started by firefoxforum12, Today, 08:53 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post firefoxforum12  
                              Started by stafe, Today, 08:34 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post stafe
                              by stafe
                               
                              Started by sastrades, 01-31-2024, 10:19 PM
                              11 responses
                              169 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Working...
                              X