Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

GetAccountValue not working for some instruments?

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

    GetAccountValue not working for some instruments?

    Hey guys,

    I am using GetAccountValue() to define the cash amount for each instrument.
    The following code is working for most instruments, however, as you can see on the screenshot there are some instruments, which use the default position size of 100 contracts. Any ideas what is wrong with my code?

    Code:
        protected override void OnStartUp()             
            {
                Dquantity = (GetAccountValue(AccountItem.BuyingPower)*0.4 / 30);
                Print(Instrument.FullName+": Cash amount available for shares is"+Dquantity);
            }
    and in addition, on a daily basis:

    Code:
            protected override void OnBarUpdate()
             {
               if (Bars.FirstBarOfSession && FirstTickOfBar)
                    {
                    Print ("The date is:" + String.Format("{0:d/M/yyyy HH:mm:ss}", Time[0]) + "and now is:" + DateTime.Now.ToString());
                    Dquantity = (GetAccountValue(AccountItem.BuyingPower)*0.4 / 30);
                    Print(Instrument.FullName+": Buying-Power is "+GetAccountValue(AccountItem.BuyingPower));
                    Print(Instrument.FullName+": Cash amount available for shares is "+Dquantity);
                    }
    I am very thankful for your help!

    Best regards,
    Pascal
    Attached Files

    #2
    Hi cNuuuuuu,

    I am seeing in the following print where there are quantities of 100 for the buy limit order.

    he date is:13.1.2015 15:35:00and now is:15.01.2015 22:30:22
    AXP: Buying-Power is 0
    AXP: Cash amount available for shares is 0
    13.01.2015 15:40:00 Entered internal PlaceOrder() method at 13.01.2015 15:40:00: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=100 LimitPrice=90,80 StopPrice=0 SignalName='Long' FromEntrySignal=''
    AXP: Entry-Position is 0

    What is set in the strategy parameters for 'Set order quantity'?

    What code places the order?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hey Chelsea,
      thank you for your quick reply.

      Set order quantity is: "by strategy" as for all stratgies...
      Entry is generated with the following code.

      Code:
           //Enter Long
                      if (Position.MarketPosition == MarketPosition.Flat 
                      && entryOrder == null && CrossAbove(SMA(fast), SMA(slow), 1))
                      {                                            
                          OrderQuantity = Convert.ToInt32(Dquantity/Close[0]);    
                          entryOrder = EnterLongLimit(0, true, OrderQuantity, Close[0],"Long");
                          Print(Instrument.FullName+": Entry-Position is "+PosiQuantity);
                          barNumberOfOrder = CurrentBar;
                       }

      However, I never had problems with it before and as shown on the screenshot it is working in 20 out of 24 cases. Interestingly, it is also working the following days. Maybe because the code if (Bars.FirstBarOfSession && FirstTickOfBar) is conducted.

      I just restarted the strategy while markets are open in order to check whether it is an issue that NT can't call the BuyingPower when markets are closed. (?)

      Comment


        #4
        mmmh, problem also arises.

        Comment


          #5
          Hi cNuuuuuu,

          Add print that prints the OrderQuantity before it is used for the order call.

          OrderQuantity = Convert.ToInt32(Dquantity/Close[0]);
          Print("OrderQuantity: "+OrderQuantity);
          entryOrder = EnterLongLimit(0, true, OrderQuantity, Close[0],"Long");

          Also, have TraceOrders = true; in the Initialize() part of the code.
          Open the Output Window (Tools -> Output Window...)
          Then re-run and save the output and post this in your next post.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            okay changed the print-code as written.
            TraceOrders = true; was already set

            Just restarted the strategy few minutes ago and same Problem arises. May it be an issue that I am using acc-sync = true (historical bars)?!

            Comment


              #7
              forgot the attachments
              Attached Files

              Comment


                #8
                Hi cNuuuuuu,

                It may be that this condition is not triggering the order.

                I am not able to find OrderQuantity: in the output.

                (Also, please clear the output window before running the strategy to make the output only related to this run of the strategy. Right-click the output window -> select Clear.)

                Since the order is not being submitted from the condition you expected, the next step is to figure out what condition is triggering the order.

                I recommend you add a print to each condition that just prints out which condition is triggered.
                Like Print("Condition 1 hit");

                Then re-run and post the output.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  What do you mean that "the condition is not triggering" the order?

                  The Longsignal is definitively working and regularly triggered. I am using this sample strategy since weeks and only have a position size problem since "GetAccountValue()".

                  I further extended the print signals, to see which code block causes the print statement.
                  Interestingly, already the "OnStartUp" always shows a cash amount of 0.

                  OnStartUp: Cash amount available for shares is 0

                  So already at this point there is sth not working...
                  Attached Files

                  Comment


                    #10
                    Hi cNuuuuuu,

                    I suggested that you add a print to the code.

                    Print("OrderQuantity: "+OrderQuantity);

                    This print is not showing in the output, which means that condition is not being triggered. If that condition is not being triggered then the order is coming from another condition.


                    Did you actually add that print?
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      yeah sure:

                      Code:
                                      OrderQuantity = Convert.ToInt32(Dquantity/Close[0]);    
                                      Print(Instrument.FullName+"LongEntry: OrderQuantity: "+OrderQuantity);
                                      entryOrder = EnterLongLimit(0, true, OrderQuantity, Close[0],"Long");
                      As you can see in the output.txt, it is printed f.e. as:

                      AXP OnStartUp: Cash amount available for shares is 0
                      AXPLongEntry: OrderQuantity: 0
                      Attached Files
                      Last edited by cNuuuuuu; 01-16-2015, 02:52 PM.

                      Comment


                        #12
                        I also tested "GetAccountValue(AccountItem.CashValue)" without success.
                        Print-statement also returns 0.

                        Comment


                          #13
                          Hi cNuuuuuu,

                          I get it, the print was changed. I didn't realize that and scrolled looking for a line that starts with OrderQuantity ignoring all other lines. I see that this line 'AXPLongEntry: OrderQuantity: 0' is actually what I'm looking for.

                          Ok, well this is slightly unexpected. The value is 0, the order should be completely ignored...

                          Instead its being submitted for a quantity of 100 and the quantity overload for EnterLong() is being completely ignored.


                          Can you make a sample that demonstrates this I can test?
                          Only include the code that sets the OrderQuantity and then places the order and do not include any other code.

                          To export your script do the following:
                          1. Click File -> Utilities -> Export NinjaScript
                          2. Enter a unique name for the file in the value for 'File name:'
                          3. Select the strategy from the objects list on the left -> click the right facing arrow ">" to add the strategy to the export
                          4. Click the 'Export' button -> click 'yes' to add any referenced indicators to the export -> click OK to clear the export location message


                          By default your exported file will be in the following location:
                          • (My) Documents/NinjaTrader 7/bin/Custom/ExportNinjaScript/<export_file_name.zip>


                          Below is a link to the help guide on Exporting NinjaScripts.
                          http://www.ninjatrader.com/support/h...nt7/export.htm


                          Also, GetAccountValue() will always be 0 in historical. Did you test this in real time data?
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Hey Chelsea, I have sent you a PM with the code and some infos

                            Comment


                              #15
                              Hello cNuuuuuu,

                              Is this is a script that you would like to keep private?

                              If so, please send an email to platformsupport [at] ninjatrader [dot] com. In the email please add a link to this forum thread.

                              So far I have run the script to see if any entry orders are made. I am seeing that the order quantity is often 0, but the entry orders are being placed on my end.

                              I am running this with the Market Replay.

                              Below is a link to a video of this running.
                              http://screencast.com/t/7tLCFvEgB

                              Once you send in an email to support we can continue discussing the code.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              647 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              368 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              108 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              571 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              573 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X