Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

GetAccountValue()

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

    GetAccountValue()

    Will GetAccountValue() (or equivalent) work in NT8 on historical bars?
    cassb
    NinjaTrader Ecosystem Vendor - Logical Forex

    #2
    Hello cassb,

    GetAccountValue() has been replaced with Account.Get(AccountItem, Currency). This method does work historically, however, historical trades do not affect the account balance.

    Below is a link to the help guide on Account.Get().
    http://ninjatrader.com/support/helpG.../en-us/get.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello cassb,

      GetAccountValue() has been replaced with Account.Get(AccountItem, Currency). This method does work historically, however, historical trades do not affect the account balance.

      Below is a link to the help guide on Account.Get().
      http://ninjatrader.com/support/helpG.../en-us/get.htm
      Thank you, Chelsea, that is good news. I am getting ready to begin converting my NT7 strategies to NT8. Is there a best practices or user guide document on how to do this?

      Thanks!
      Bryan
      cassb
      NinjaTrader Ecosystem Vendor - Logical Forex

      Comment


        #4
        Hi cassb,

        While there isn't a guide for converting, there is the code breaking changes which list the items that have changed from nt7 to nt8.
        http://ninjatrader.com/support/helpG...ng_changes.htm

        Also, the educational resources may be helpful.
        http://ninjatrader.com/support/helpG..._resources.htm
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi again, I hope it's OK to reuse this thread for other NT7 -> NT8 conversion questions.

          I'm sorry, but I am not a C# expert, so excuse my ignorance. I see in your sample strategies that you now use the property declaration of a variable as the actual variable you define and use:

          Code:
                  protected override void OnStateChange()
                  {
                      if (State == State.SetDefaults)
                      {
                          Description    = NinjaTrader.Custom.Resource.NinjaScriptStrategyDescriptionSampleMACrossOver;
                           Name        = NinjaTrader.Custom.Resource.NinjaScriptStrategyNameSampleMACrossOver;
                          Fast        = 10;
                          Slow        = 25;
                          // This strategy has been designed to take advantage of performance gains in Strategy Analyzer optimizations
                          // See the Help Guide for additional information
                          IsInstantiatedOnEachOptimizationIteration = false;
                      }
          
                  [Range(1, int.MaxValue), NinjaScriptProperty]
                  [Display(ResourceType = typeof(Custom.Resource), Name = "Fast", GroupName = "NinjaScriptStrategyParameters", Order = 0)]
                  public int Fast
                  { get; set; }
          
                  [Range(1, int.MaxValue), NinjaScriptProperty]
                  [Display(ResourceType = typeof(Custom.Resource), Name = "Slow", GroupName = "NinjaScriptStrategyParameters", Order = 1)]
                  public int Slow
                  { get; set; }
          Is this just a coding style, or has something changed to require this in NT8? The NT7 version of this code is:

          Code:
                  #region Variables
                  private int        fast    = 10;
                  private int        slow    = 25;
                  #endregion
          
                  [Description("Period for fast MA")]
                  [GridCategory("Parameters")]
                  public int Fast
                  {
                      get { return fast; }
                      set { fast = Math.Max(1, value); }
                  }
          
                  [Description("Period for slow MA")]
                  [GridCategory("Parameters")]
                  public int Slow
                  {
                      get { return slow; }
                      set { slow = Math.Max(1, value); }
                  }

          If the NT8 version of this code is required now, I have a lot of editing to do because I have a lot of properties. Or can I just keep the NT7 style of variable definition and compile it as-is in NT8?

          Thanks!
          Bryan
          cassb
          NinjaTrader Ecosystem Vendor - Logical Forex

          Comment


            #6
            Hi cassb,

            This is a coding style change that is now possible with NT8. A private variable is no longer required and the public variable gets and sets itself. The older style of NT7 still works fine in NT8 where the private variable is returned and set.

            Sometimes you may find a need to use the NT7 way in NT8 and use a private variable.
            As an example when re-using brushes its necessary to use a private variable.
            http://ninjatrader.com/support/forum...249#post461249
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              OK, whew, that's good news. I was not looking forward to editing every variable name in the program! :-)
              cassb
              NinjaTrader Ecosystem Vendor - Logical Forex

              Comment


                #8
                Another NT8 question. In the SampleATMStrategy, there is this code in OnStateChange():

                Code:
                            if (State == State.SetDefaults)
                            {
                                Description    = NinjaTrader.Custom.Resource.NinjaScriptStrategyDescriptionSampleATMStrategy;
                                Name        = NinjaTrader.Custom.Resource.NinjaScriptStrategyNameSampleATMStrategy;
                                // This strategy has been designed to take advantage of performance gains in Strategy Analyzer optimizations
                                // See the Help Guide for additional information
                                IsInstantiatedOnEachOptimizationIteration = false;
                            }
                What are the variables Description and Name, and where are they defined? I tried the same code in my strategy, but I get a compile error:

                'NinjaTrader.Custom.Resource' does not contain a definition for 'NinjaScriptStrategyDescriptionMyCustomStrategy'
                cassb
                NinjaTrader Ecosystem Vendor - Logical Forex

                Comment


                  #9
                  I have another conversion question. This code gets the time of day from the chart:

                  Code:
                          // Returns the 'chart' time when called.
                          private DateTime Now
                          {
                              get
                              {
                                  DateTime now = (Bars.IsInReplayMode ? NinjaTrader.Cbi.Connection.PlaybackConnection.Now: NinjaTrader.Core.Globals.Now);
                                  if (now.Millisecond > 0)
                                      now = Cbi.Globals.MinDate.AddSeconds((long) System.Math.Floor(now.Subtract(Cbi.Globals.MinDate).TotalSeconds));
                                  return now;
                              }
                          }
                  But there is no Cbi.Globals any more. Has the MinDate.AddSeconds() function moved to a different hierarchy?

                  Thanks!
                  Bryan
                  cassb
                  NinjaTrader Ecosystem Vendor - Logical Forex

                  Comment


                    #10
                    Hello cassb,

                    Thank you for your note.

                    The Name is the name of the script as this appears in the Indicator or Strategy window.
                    The Description is the description you will see on the lower left of the window when the Indicator or Strategy is selected from the list.

                    The Description and Name are not required to be set, but you should set these.

                    The SampleAtmStrategy and all of the other default NinjaTrader scripts use a resource dictionary so that the names, descriptions, labels, etc.. can be translated into other languages. This is what is being set with 'NinjaTrader.Custom.Resource.NinjaScriptStrategyDe scriptionSampleATMStrategy;'.

                    You don't have to do that in your script.

                    For an understanding of a basic setup of a NinjaScript Strategy, I would recommend you make a script with the wizard (add a few inputs) and take a look at the code that is automatically generated.


                    For replay time in NT8:
                    Cbi.Connection.PlaybackConnection.Now

                    For current time in NT8:
                    NinjaTrader.Core.Globals.Now
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Did I find a bug in NT8? I am running Market Replay with my strategy, and I have a line of code that checks Bars.IsInReplayMode, and it's false. It's that line of code in my previous note:

                      DateTime now = (Bars.IsInReplayMode ? NinjaTrader.Cbi.Connection.PlaybackConnection.Now: NinjaTrader.Core.Globals.Now);


                      Shouldn't it be true when I am running Market Replay?

                      Bryan
                      cassb
                      NinjaTrader Ecosystem Vendor - Logical Forex

                      Comment


                        #12
                        Hi Bryan,

                        I've not seen that Bars.IsReplayMode and I'm not sure how it works.

                        However, if you want to know if replay is being played back use: Bars.IsTickReplay.
                        http://ninjatrader.com/support/helpG...tickreplay.htm
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_ChelseaB View Post
                          Hi Bryan,

                          I've not seen that Bars.IsReplayMode and I'm not sure how it works.

                          However, if you want to know if replay is being played back use: Bars.IsTickReplay.
                          http://ninjatrader.com/support/helpG...tickreplay.htm

                          Thank you, but Bars.IsTickReplay returns False also, when running Playback mode. Is there's a function or method or property I can use to tell when my strategy is running in Playback versus Realtime?

                          Thanks!
                          cassb
                          NinjaTrader Ecosystem Vendor - Logical Forex

                          Comment


                            #14
                            Hi Bryan,

                            Thanks for your patience with this.

                            I gave this a quick test and realized I was also confused about this.
                            The Bars.IsTickReplay is letting you know whether or not tick replay is enabled.

                            For identifying the playback connection this can be done with the OnConnectionStatusUpdate() method.

                            http://ninjatrader.com/support/helpG...atusupdate.htm

                            Code:
                            protected override void OnConnectionStatusUpdate(ConnectionStatusEventArgs connectionStatusUpdate)
                            {
                            	connectionName = connectionStatusUpdate.Connection.Options.Name;
                            
                            	Print("connectionStatusUpdate: " + connectionStatusUpdate.Connection.Options.Name);
                            
                            	if (connectionStatusUpdate.Connection.Options.Name == "Playback Connection")
                            	{
                            		Print("Is Playback Connection");
                            	}
                            }
                            Last edited by NinjaTrader_ChelseaB; 05-31-2016, 03:15 PM.
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Originally posted by NinjaTrader_ChelseaB View Post
                              Hi Bryan,

                              Thanks for your patience with this.

                              I gave this a quick test and realized I was also confused about this.
                              The Bars.IsTickReplay is letting you know whether or not tick replay is enabled.

                              For identifying the playback connection this can be done with the OnConnectionStatusUpdate() method.



                              Code:
                              protected override void OnConnectionStatusUpdate(ConnectionStatusEventArgs connectionStatusUpdate)
                              {
                                  connectionName = connectionStatusUpdate.Connection.Options.Name;
                              
                                  Print("connectionStatusUpdate: " + connectionStatusUpdate.Connection.Options.Name);
                              
                                  if (connectionStatusUpdate.Connection.Options.Name == "Playback Connection")
                                  {
                                      Print("Is Playback Connection");
                                  }
                              }
                              OK thank you, that works! :-) This is a design change from NT7, because Bars.IsInReplayMode in NT7 would return True if you were running in Market Replay. Apparently that is no longer true.

                              Bryan
                              cassb
                              NinjaTrader Ecosystem Vendor - Logical Forex

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by sidlercom80, 10-28-2023, 08:49 AM
                              171 responses
                              2,274 views
                              0 likes
                              Last Post QuantKey_Bruce  
                              Started by Irukandji, Yesterday, 02:53 AM
                              2 responses
                              17 views
                              0 likes
                              Last Post Irukandji  
                              Started by adeelshahzad, Today, 03:54 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post adeelshahzad  
                              Started by CortexZenUSA, Today, 12:53 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post CortexZenUSA  
                              Started by CortexZenUSA, Today, 12:46 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post CortexZenUSA  
                              Working...
                              X