Could that be accomplished by Close[-1]? In historical tests Close[-1] gives the price of the next bar, but I suspect it may be what I'm looking for in real time.
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
last tick price?
Collapse
X
-
last tick price?
When CalculateOnBarClose is set to true, is it possible to still reference the last tick price in the code?
Could that be accomplished by Close[-1]? In historical tests Close[-1] gives the price of the next bar, but I suspect it may be what I'm looking for in real time.Tags: None
-
Hello YD777, and thank you for your question.
The situation you are in, where your strategy only needs to update on a bar close but needs access to last tick prices, is ideal for the multi time frame approach. I am including some documentation on this approach and an example. Please let us know if there are any other ways we can help.
Code:[FONT=Courier New]protected override void Initialize() { Add(PeriodType.Tick, 1); } protected override void OnBarUpdate() { // Checks to ensure all Bars objects contain enough bars before beginning if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired) { return; } if (BarsInProgress == 0) { Print("The closing price of the previous tick is " + Closes[1][1]); } }[/FONT]
Jessica P.NinjaTrader Customer Service
-
Hi Jessica, My situation is more complicated than that. It's an indicator and I don't always need last tick price, just in some conditions. I'm also trying to learn Ninjascript.
So is there a way to reference last price (regardless of if bar is still open)? And again, what does Close[-1] refer to in real time?
Comment
-
Hello YD777, and thank you for your further questions.
The short answer to both your questions, is that bars in Ninja are ordered most-recent-to-least. Close[100] means the closing price 100 bars ago, Close[0] means the current closing price.
Since you mentioned trying to learn scripting, I can provide a more complete answer.
So is there a way to reference last price (regardless of if bar is still open)?
And again, what does Close[-1] refer to in real time?
Literally speaking, you will get a compile time error if you attempt to write this into code. The explanation is a bit complex, but in the interest of completeness, variables in computer programming languages like C# are easy ways to refer to locations in your computer's memory. In older languages like C, you could actually print memory addresses from variable handles, so "Close" might be a way to refer to memory address 12345678. When we say something like Close[3] , we mean "find the memory address of Close and increase it by the storage size of 3 numbers". Building off our example, if it took 4 bytes to store a number, then this would be address 12345690. Close[-1] then, would be 1 number before close in memory (address 12345674). Memory in a programming language has to be reserved ahead of time so that nothing else can use it. If, say, Close could have 4 numbers in it, then you would only be allowed to use addresses 12345678 through 12345694 through the word "Close", and the memory located at Close[-1], 12345674, is not memory that is allowed to be used through the Close handle.
What this means is that we can not provide Close[-1], both for practical and conceptual reasons.Jessica P.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by arvidvanstaey, Today, 02:19 PM
|
0 responses
0 views
0 likes
|
Last Post Today, 02:19 PM | ||
Started by mmckinnm, Today, 01:34 PM
|
3 responses
5 views
0 likes
|
Last Post Today, 02:12 PM | ||
Started by f.saeidi, Today, 01:32 PM
|
2 responses
5 views
0 likes
|
Last Post
by f.saeidi
Today, 02:10 PM
|
||
Started by alifarahani, 04-19-2024, 09:40 AM
|
9 responses
55 views
0 likes
|
Last Post Today, 02:02 PM | ||
Started by Conceptzx, 10-11-2022, 06:38 AM
|
3 responses
60 views
0 likes
|
Last Post Today, 01:46 PM |
Comment