• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Automated trading in test account with FXCM - GetAccountValue method error

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

    Automated trading in test account with FXCM - GetAccountValue method error

    Hello,
    I have just moved a Forex strategy into a staging (demo) account with FXCM. The first attempted trade threw two simultaneous errors.
    1:
    'BBTF_STF_ID_TF_BBPctB/a9cc8b1fa6da489abaf0afd298bb0f8e' submitted an order that generated the following error 'UnableToSubmitOrder'. Strategy has sent cancel requests, attempted to close the position and terminated itself.

    2:
    Staging1, Order Quantity must be a multiple of 1000 affected Order: Buy 2 Stop @ 102.18

    Naturally, my method to determine lot size is different in a staging or live environment than it is during backtesting, since the live environment can look up an account value.

    Troubleshooting the second problem, it looks like the GetAccountValue(AccountItem.CashValue); method is returning zero, when it should be returning 50,000. Why would this happen?
    Secondly, this code "Instrument.MasterInstrument.PointValue" is returning 1,000. This is incorrect - a point in the USD/JPY currency pair should be either $1 or $0.1 depending on whether the automatic lot size returned from FXCM is 10,000 or 1,000. What is happening here?

    Thank you.

    #2
    Hello UglyHack,

    Thank you for your post and welcome to the NinjaTrader Support Forum!

    The Forex sizes will need to be in multiples of 1000. The CashValue is returned as 0 on historical bars, are these orders submitted or calculated from historical bars?

    The USDJPY has a point value of 1,000 and a tick size of 0.001. Is this not what you are seeing for the tick size and point value on your charts?
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      Hello PatrickH,
      Thank you for the prompt response.

      Please allow me to clarify my concern:
      According the the NT7 help manual in the Operations>Automated Trading>Running NinjaScript Strategies>Running FX Strategies area (hope that helps), special consideration needs to be paid to lot sizes when converting from a backtesting environment to a live environment.
      When running in a backtesting environment, yes, you are correct - lot sizes must be computed literally, e.g. a multiple of 1,000 units. However, when a strategy is applied to a live account, the help guide explicitly cautions that an order quantity of 1 lot should be passed as the number 1, not 1,000 or anything else.

      To quote the manual:
      "Based on the above information, if you are backtesting in the Strategy Analyzer using order quantities of 100,000 and you now wish to trade live in your brokerage account where 1 lot is equal to 100,000 MAKE SURE that you adjust your strategy's order quantity from 100,000 to 1 to ensure you are trading the correct quantity."

      So it appears that passing through a value of 1,000 would accidentally cause a position size of 1,000,000 units at a minimum, which is, shall we say, a little excessive. Should the correct lot size be automatically returned from FXCM while attempting to trade live, even in a demo account?

      As for the Cash Value component:
      I was not deliberately applying the strategy to historical bars. Unfortunately, I only put PrintWithTimeStamp(); and TraceOrder commands in place after the strategy crashed the first time. It runs on hourly bars, and I attempted to re-apply the strategy within an hour of it initially crashing. A stop entry order should have been placed, but a trade would not have triggered for five hours after that. Does that count as historical?
      Assuming a "no" to that question, what could be causing a returned value of zero balance?
      Another related observation: In the "Accounts" tab, the account in question shows a Cash Value of 50000, but null values in Buying Power, Excess Equity, Initial Margin, etc. Is that significant?

      Point Value and Tick Size:
      I did not have TickSize in my lot sizing calculation, just point value. The formula was pipsRisked * Instrument.MasterInstrument.PointValue;
      Changing this formula to the following seems to have cleared up the issue.
      pipsRisked * (TickSize * Instrument.MasterInsrument.PointValue);

      Thank you.

      Comment


        #4
        Update:
        Another trade attempted to be invoked, and this returned the proper account balance. So it looks like the current bar was being treated as historical in that context.

        I'll tinker with the OnStartup() method to see what can be done about that.

        Meanwhile, the new trade did crash the strategy for the same reason. The result of my calculation was 197 lots, which should have been converted automatically (for reasons previously mentioned) to 197,000 units of currency. FXCM uses 1,000 units of currency in a lot.

        So, the main question that remains from this thread: why is the number 197 (in this example) not being treated as 197 lots, but instead being treated as 197 units of currency?

        Apologies for the churn on this.

        Thank you for your help.

        Comment


          #5
          Hello UglyHack,

          Thank you for your response.
          To quote the manual:
          "Based on the above information, if you are backtesting in the Strategy Analyzer using order quantities of 100,000 and you now wish to trade live in your brokerage account where 1 lot is equal to 100,000 MAKE SURE that you adjust your strategy's order quantity from 100,000 to 1 to ensure you are trading the correct quantity."
          So it appears that passing through a value of 1,000 would accidentally cause a position size of 1,000,000 units at a minimum, which is, shall we say, a little excessive. Should the correct lot size be automatically returned from FXCM while attempting to trade live, even in a demo account?
          This is entirely dependent on the broker used, you actually need to contact them to understand whether 1 means 1, or 1000, or 10000, or 100000.
          Does that count as historical?
          Assuming a "no" to that question, what could be causing a returned value of zero balance?
          Another related observation: In the "Accounts" tab, the account in question shows a Cash Value of 50000, but null values in Buying Power, Excess Equity, Initial Margin, etc. Is that significant?
          From your explanation, I would say no - this is a real-time. The other account values should have no effect, but we need an execution to occur from the strategy to the account before these items would be updated at all in real-time.
          So, the main question that remains from this thread: why is the number 197 (in this example) not being treated as 197 lots, but instead being treated as 197 units of currency?
          So what order method are you using? What is the full syntax for the the method?
          Patrick H.NinjaTrader Customer Service

          Comment


            #6
            Hello Patrick,
            There was some ambiguity on FXCM's side regarding this as well, but it turns out that micro lots are now their conventional lot size. These are not automatically converted, so strategies need to pass through lot sizes in literal multiples of 1,000.

            At least, this works in a demo account. We'll see in a few months if it works the same for small live orders.

            Thanks for your help!

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by zweistein, 11-14-2017, 03:24 PM
            2 responses
            1,476 views
            0 likes
            Last Post woodie1
            by woodie1
             
            Started by Newtrader101, Today, 04:50 AM
            3 responses
            18 views
            0 likes
            Last Post NinjaTrader_ChrisL  
            Started by utilizator, Today, 06:31 AM
            3 responses
            13 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by digibob, Today, 01:13 AM
            3 responses
            14 views
            0 likes
            Last Post digibob
            by digibob
             
            Started by calebsandfort, Yesterday, 05:16 PM
            2 responses
            11 views
            0 likes
            Last Post NinjaTrader_PaulH  
            Working...
            X