Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Account Size

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

    Account Size

    I am backtesting a strategy that sells out of a long stock position and immediately places a limit order to buy it back at a lower price. The order quantity is set by account size. Commisions are off.

    However, when I run the backtest, the amount of shares that are purchased is always lower than it should be. Not all of the available cash is being used. The initial market buy in uses all the cash ($100000). But, on the next limit buy, the order was placed for 65 shares ($28.80/share) less than the current account size of $101542 would suggest.

    Any suggestions on how I can make sure that my limit orders use the full account cash balance? Thanks.
    Last edited by trader789; 04-18-2010, 06:30 AM.

    #2
    trader789, could you please post the code you're using to determine the order size? It is difficult to diagnose what could be going wrong without anything to work off of.
    AustinNinjaTrader Customer Service

    Comment


      #3
      privatedouble delta = -0.100; // Default setting for Delta
      protectedoverridevoid Initialize()
      CalculateOnBarClose =
      true;
      protectedoverridevoid OnBarUpdate()
      // Condition set 1
      if (Variable2 == 0)
      EnterLong(DefaultQuantity,
      "");
      Variable2 =
      1;
      // Condition set 2
      if (ToTime(Time[0]) == ToTime(11, 0, 0)
      && Position.MarketPosition == MarketPosition.Long)
      ExitLong(
      "", "");
      Variable1 = GetCurrentBid() + Delta;
      // Condition set 3
      if (Position.MarketPosition == MarketPosition.Flat)
      EnterLongLimit(DefaultQuantity, Variable1,
      "");
      #region Properties
      [Description(
      "Price Drop")]
      [Category(
      "Parameters")]
      publicdouble Delta
      get { return delta; }
      set { delta = Math.Max(-1, value); }

      Comment


        #4
        Unfortunately, AccountSize doesn't update as trades close and the documentation is misleading in this respect (even in Version 7). See:

        Comment


          #5
          Thanks for your help.

          Comment


            #6
            I am trying to calculate the number of shares to purchase to use all of the available cash in my backtesting account including any accumulated profit/loss.

            Question 1: Why does Variable4 print out a value from Set 1, but not carry it to Set 2? It seems to be reset to zero before the second Print statement is executed.

            Question 2: How do I get Set 2 to execute the day after Set 1?

            Question 3: Do you have a sample strategy that shows how to track account size/shares using variables? Thanks.

            // Condition set 1
            if (Variable2 == 0)
            {
            EnterLong((
            int) (100000/GetCurrentAsk()), "");
            Variable2 =
            1;
            Variable4 =
            100000/GetCurrentAsk();
            Print(Variable4.ToString());
            }
            // Condition set 2
            if (Variable2 == 1
            && ToTime(Time[0]) == ToTime(11, 0, 0)
            && Position.MarketPosition == MarketPosition.Long)
            {
            Print(Variable4.ToString());
            ExitLongLimit(GetCurrentAsk(),
            "", "");
            Variable1 = GetCurrentAsk() -
            0.1;
            Variable5 = Variable4*GetCurrentAsk()/Variable1;
            }
            // Condition set 3
            if (Variable2 == 1
            && Position.MarketPosition == MarketPosition.Flat)
            {
            EnterLongLimit((
            int) (Variable5), Variable1, "");
            Variable4 = Position.Quantity;

            Comment


              #7
              trader789,

              I suggest you add a print everywhere you set a value to Variable4 so you can see where it resets. Unfortunately there is no reference sample. All you need to do is use the variables and not set values over the one you wanted. It may be easier for you to follow your code if you added more identifying messages in your Print() so you can see where exactly the print came from instead of assuming it was in Set 1 or Set 2.
              Josh P.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by fwendolynlpxz, Today, 05:19 AM
              0 responses
              3 views
              0 likes
              Last Post fwendolynlpxz  
              Started by traderqz, Yesterday, 12:06 AM
              11 responses
              28 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by PaulMohn, Today, 03:49 AM
              0 responses
              8 views
              0 likes
              Last Post PaulMohn  
              Started by inanazsocial, Today, 01:15 AM
              1 response
              10 views
              0 likes
              Last Post NinjaTrader_Jason  
              Started by rocketman7, Today, 02:12 AM
              0 responses
              11 views
              0 likes
              Last Post rocketman7  
              Working...
              X