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?

    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?

          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 jeronymite, 04-12-2024, 04:26 PM
            3 responses
            44 views
            0 likes
            Last Post jeronymite  
            Started by Barry Milan, Yesterday, 10:35 PM
            7 responses
            20 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by AttiM, 02-14-2024, 05:20 PM
            10 responses
            179 views
            0 likes
            Last Post jeronymite  
            Started by ghoul, Today, 06:02 PM
            0 responses
            10 views
            0 likes
            Last Post ghoul
            by ghoul
             
            Started by DanielSanMartin, Yesterday, 02:37 PM
            2 responses
            13 views
            0 likes
            Last Post DanielSanMartin  
            Working...
            X