Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Sync Account position and equity-based position sizing does not seem to work...

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

    Sync Account position and equity-based position sizing does not seem to work...

    My NT strategy calculates the position size correctly (only in live mode, not back-testing) using this code:

    Code:
    //Calculate position size
    double equity = GetAccountValue(AccountItem.NetLiquidation);
    double qty = contractsperMillionEquity * equity / 1000000;
    EnterShort((int)qty);
    It basically takes a position proportional to the account equity.

    However, during back-tests, the account equity is returned as 0 and quantity used is 1 for all orders.

    I suspect the same thing happens when I enable a strategy with "Sync Account position = True": the startup position is derived from the historical bar signals and the account is returned as 0, therefore the position size is set to 1... Every time my strategy is enabled and a position exists, the sync just creates a position of 1 on the account. The next position taken by the code that now runs on the live account will then have the correct size (since the account value will correctly be returned on live bars).

    Is there a way to fix this behaviour (apart from setting the initial qty as a strategy parameter)?

    #2
    Jezza,

    This is expected in backtesting, as the account linked to it assumes infinite supply of money.

    You could use http://www.ninjatrader.com/support/h...ccountsize.htm

    As far as your startup position, you could have the strategy default to doing something else until you detect you are on a live bar.

    If ( Historical )
    {
    //do something
    }

    This also would help with the backtesting example.

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

    Comment


      #3
      Adam,

      Thanks for that. If I understand correctly, there is no way to have the "Synchronize position" size derived from the actual account size (ie from reading it dynamically from the live account upon strategy startup)?

      And the workaround you point to, using If ( Historical )
      would still require to read from some user-entered parameter the actual account size or position size?

      Thanks for confirming
      Jezza

      PS: I am new to NT but how do you back-test simple Money Management techniques such a Fixed Fractional if you cannot simulate an actual account equity to size your positions? Do you have to keep track of the PnL of each trade and the aggregated virtual equity?

      Comment


        #4
        Jezza,

        Backtesting is just a bit different here as it won't have access to live account values, etc. but you can track these in your strategy and use them. When a strategy goes over historical bars its essentially a backtest, and is used to calculate what state the strategy should be in at the most current bar.

        Here is a reference sample on using trade performance statistics for your order management : http://www.ninjatrader.com/support/f...ead.php?t=4084

        The Sync Account positions is a way to handle order entry on live or simulated accounts, so for example, with Sync Account Positions = true and "Wait until flat" is set in Tools > Options > NinjaScript > Strategy, it would do the following :

        When your strategy starts it will check for any active orders previously generated by the strategy on your account and cancel those first. Should the strategy be unable to cancel and receive confirmation on the cancellation of these orders within 40 seconds the strategy will not start and an alert will be issued. After the strategy is successful in cancelling any orders that required action it will check your current Account Position and compare it to a flat state. On multi-instrument strategies it will perform this check for all instruments used by the strategy.

        • If the Account Position is flat already, no reconciliatory order will be submitted. The strategy will then wait for the Strategy Position to reach a flat state as well before submitting any orders live.
        • If the Account Position is not flat, NinjaTrader will submit a market order(s) to reconcile the Account Position to a flat state. The strategy will then wait for the Strategy Position to reach a flat state before submitting live orders.

        Here is a link for understanding strategy position vs. account position.



        Here is a link to the "Sync account positions" settings descriptions.



        Essentially the strategy does this backtest on live charts since the strategy position and account position aren't intrinsically linked. The strategy syncing options are to get the account position and the strategy position to the same state as you would expect it to work, or as your strategy expects it to work.

        Please let me know if I may assist further.
        Last edited by NinjaTrader_AdamP; 06-04-2012, 02:13 PM.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Thanks Adam,
          I've been looking at these help files before but basically I just wish that the reconciliatory orders sent by the Sync Account Position could be based off the Account Equity (dynamically read from the broker) - which is not possible as I understand.

          Maybe a good feature request?

          Comment


            #6
            Jezza,

            I will suggest to development and get you a tracking ID.

            Thanks for your suggestion.
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              Jezza,

              Your suggestion has tracking ID : #654

              Thanks for your suggestion.
              Adam P.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by TheMarlin801, 10-13-2020, 01:40 AM
              21 responses
              3,915 views
              0 likes
              Last Post Bidder
              by Bidder
               
              Started by timmbbo, 07-05-2023, 10:21 PM
              3 responses
              151 views
              0 likes
              Last Post grayfrog  
              Started by Lumbeezl, 01-11-2022, 06:50 PM
              30 responses
              808 views
              1 like
              Last Post grayfrog  
              Started by xiinteractive, 04-09-2024, 08:08 AM
              3 responses
              11 views
              0 likes
              Last Post NinjaTrader_Erick  
              Started by Johnny Santiago, 10-11-2019, 09:21 AM
              95 responses
              6,194 views
              0 likes
              Last Post xiinteractive  
              Working...
              X