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
Is Close[0] the current bar, or the last bar?
Collapse
X
-
Originally posted by bltdavid View Post
-
There is no NinjaTrader specific issue here.
I took the time to look more carefully at your NinjaScript output.
My opinion is that you may not be understanding your charts.
Your output looks correct.
Let me explain.
You circled output when 'BarsAgo = 0' and the Close[0] value in the output
window is printed as 13055.5. This looks viable, the chart shows the Close
of the current bar at 13055.75, so being off by 1 tick in the screenshot is most
likely a timing issue, or the additional output for this tick is obscured in the
output window.
You next circled output when 'BarsAgo = 1' and the Close[1] is 13050.00.
On the chart, I see your hand drawn blue '1' pointing to the previous bar.
But, since this is a green candlestick bar, it's Close price is at the top
of the green body, so the Close price of this candle is 13050.00.
That is correct.
At the bottom of your screenshot you hand wrote "should be 13044.75".
I believe this comment shows your confusion.
13044.75 is the price at the bottom of the green candlestick body, so that
must be the open price, not the close price.
Close[1] is 13050.00
Open[1] is 13044.75 <-- this is not the close, this is your confusion
Make sense?
Leave a comment:
-
Originally posted by bltdavid View Post
When using Calculate.OnEachTick, and processing RealTime data, your OnBarUpdate is called
for each incoming tick, and Close[0] contains the current price of the actively developing bar.
Close[1] gives you close price of the most recently closed bar.
Close[1] does not give you the close previous of the previous tick.
The code in your post isn't complete enough to understand your problem.
Please post a small working script if you need additional help.
I was using the playback connection and after restarting the NinjaTrader application seems the problem is gone! I feel sometimes when I move the playback time slider, the application doesn't work as it should! Is this a known issue?
Thank you
Leave a comment:
-
Originally posted by mahdighorbanpour View PostHi,
I am using Calculate.OnEachTick for my script, Close [0] is giving the current price which is completely correct, but Close[0] is not returning the close value of the previous bar, it's giving me the price from the previous tick!! What I am missing here? is this the desired behavior? How can I get the close of precious bar then?
for each incoming tick, and Close[0] contains the current price of the actively developing bar.
Close[1] gives you close price of the most recently closed bar.
Close[1] does not give you the close of the previous tick.
The code in your post isn't complete enough to understand your problem.
Please post a small working script if you need additional help.
Leave a comment:
-
Hi,
I am using Calculate.OnEachTick for my script, Close [0] is giving the current price which is completely correct, but Close[0] is not returning the close value of the previous bar, it's giving me the price from the previous tick!! What I am missing here? is this the desired behavior? How can I get the close of precious bar then?
here you can see my code and the script outputs:
Code:private bool HasVeryLongTail(int barsAgo) { Print("HasVeryLongTail =>" + " barsAgo = " + barsAgo + " Low[barsAgo] = " + Low[barsAgo].ToString() + " Close[barsAgo] = " + Close[barsAgo] + " GetLowCloseSpreadTicks(barsAgo)= " + GetLowCloseSpreadTicks(barsAgo).ToString() + " VeryLongSpreadTicks = " + VeryLongSpreadTicks.ToString()); return Low[barsAgo] != Close[barsAgo] && Math.Abs(GetLowCloseSpreadTicks(barsAgo)) >= VeryLongSpreadTicks; }
Leave a comment:
-
Hello timmbbo,
Thanks for your post.
The answer depends on the Calculate setting AND if you are looking at historical data OR real time (or market replay) data.
For historical data (not including market replay), when your script loads, it will process the bars in sequence from the beginning "days to load" specified in the data series of the chart. The script will be run once per bar and will perform based on that the bar index of [0] is the just closed bar. So as each bar is processed it becomes the next [0]. This is true regardless of the Calculate setting sos please keep this in mind going forward.
When the historical data has been processed and assuming you are connected to live data (or playback>MarketReplay data), the calculate setting of the script can change the bar references once it is processing the real time data as follows:
Calculate.OnBarClose, in live/replay data, [0] is the latest just closed bar, your script will run once at the end of the bar, the script does not know of the currently forming bar until it closes and the index [0] shifts to the just closed bar, the previously closed bar would now be [1]. Your code would execute exactly the same as it does historically.
Calculate.OnPriceChange, in live/replay data, Close[0] is the current price of the currently forming bar, the Close, High and Low values change as the price changes in the currently forming bar until it closes. [1] will be the just closed bar in this mode. Your script will execute on every change in price while the currently forming bar changes price which means again that Close[0], High[0] and Low[0] can change (Open[0] will not change as it is set once on the first tick).
Calculate.OnEachTick, in live/replay data, Close[0] is the current price of the currently forming bar, the Close, High and Low values change as the price changes in the currently forming bar until it closes. Note: In this mode your code will execute on each incoming tick which may be exactly the same price as the previous tick(s). Like OnPriceChange, the currently forming bar prices of Close, High, Low will change until the bar closes. The bar index of [1] is the just closed bar.
Reference: https://ninjatrader.com/support/help...?calculate.htm
- Likes 1
Leave a comment:
-
Is Close[0] the current bar, or the last bar?
Hi there,
Within OnBarUpdate, is Close[0] the current bar that's being formed, or the last completed bar? If it's the bar being formed, then the value of Close[0] would vary with each tick change, correct?
Thanks
Tags: None
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by bortz, 11-06-2023, 08:04 AM
|
47 responses
1,604 views
0 likes
|
Last Post
by aligator
Today, 07:22 PM
|
||
Started by jaybedreamin, Today, 05:56 PM
|
0 responses
8 views
0 likes
|
Last Post
by jaybedreamin
Today, 05:56 PM
|
||
Started by DJ888, 04-16-2024, 06:09 PM
|
6 responses
18 views
0 likes
|
Last Post
by DJ888
Today, 05:12 PM
|
||
Started by Jon17, Today, 04:33 PM
|
0 responses
4 views
0 likes
|
Last Post
by Jon17
Today, 04:33 PM
|
||
Started by Javierw.ok, Today, 04:12 PM
|
0 responses
13 views
0 likes
|
Last Post
by Javierw.ok
Today, 04:12 PM
|
Leave a comment: