Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
GetAccountValue()
Collapse
X
-
GetAccountValue()
Will GetAccountValue() (or equivalent) work in NT8 on historical bars?Tags: None
-
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.htmChelsea B.NinjaTrader Customer Service
-
Originally posted by NinjaTrader_ChelseaB View PostHello 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
Thanks!
Bryan
Comment
-
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.htmChelsea B.NinjaTrader Customer Service
Comment
-
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; }
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
Comment
-
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#post461249Chelsea B.NinjaTrader Customer Service
Comment
-
OK, whew, that's good news. I was not looking forward to editing every variable name in the program! :-)
Comment
-
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; }
'NinjaTrader.Custom.Resource' does not contain a definition for 'NinjaScriptStrategyDescriptionMyCustomStrategy'
Comment
-
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; } }
Thanks!
Bryan
Comment
-
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.NowChelsea B.NinjaTrader Customer Service
Comment
-
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
Comment
-
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.htmChelsea B.NinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_ChelseaB View PostHi 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!
Comment
-
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
-
Originally posted by NinjaTrader_ChelseaB View PostHi 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"); } }
Bryan
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 Today, 04:33 AM | ||
Started by Irukandji, Yesterday, 02:53 AM
|
2 responses
17 views
0 likes
|
Last Post
by Irukandji
Today, 03:55 AM
|
||
Started by adeelshahzad, Today, 03:54 AM
|
0 responses
3 views
0 likes
|
Last Post
by adeelshahzad
Today, 03:54 AM
|
||
Started by CortexZenUSA, Today, 12:53 AM
|
0 responses
3 views
0 likes
|
Last Post
by CortexZenUSA
Today, 12:53 AM
|
||
Started by CortexZenUSA, Today, 12:46 AM
|
0 responses
1 view
0 likes
|
Last Post
by CortexZenUSA
Today, 12:46 AM
|
Comment