How can I get that?
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
Indicator's PriorDayOHLC().PriorClose[0]
Collapse
X
-
Hello dafonseca,
Thanks for your post.
If I understand correctly, you want to obtain the value of an indicator on the last bar of the session.
Here is a code example, using the SMA indicator
if (Bars.FirstBarOfSession)
{
double yesterdaysEndingSMA = SMA[1]; // save the prior sma value on first bar of new session.
}
Paul H.NinjaTrader Customer Service
-
Hello dafonseca,
Thanks for your reply.
I apologize for not explaining the logic better.
This statement: if (Bars.FirstBarOfSession) will be true on the very first bar of the session.
This statement: double yesterdaysEndingSMA = SMA[1]; will get the previous SMA value and put it in the double variable yesterdaysEndingSMA. This was just an example indicator.
Please note that SMA[0] would be the current bar so if the current bar is the first bar of the session that would mean the the prior bar [1] is the last bar of the previous session. You could apply the logic to any indicator.Paul H.NinjaTrader Customer Service
Comment
-
I will check, But one more question:
regarding (Bars.FirstBarOfSession)
how can I be sure that (Bars.FirstBarOfSession) will consider the right value.
In case of backtesting, for instatnce, does (Bars.FirstBarOfSession) consider the first bar of each session??
supposing I am runing my strategy on a 5 days chart, will (Bars.FirstBarOfSession) updated all five days' sessions?
Comment
-
Hello dafonseca,
Thanks for your reply and great questions.
When you load an indicator or strategy (backtesting, market replay, live data) it will start at very first bar of the data series and work from left to right ending at the current bar on the chart. As it moves from the end of one session to the beginning of the next the bool FirstBarOfSession will be true for the duration of the first bar.
You can validate this yourself by adding print statements and observing the data printed in the output window, something like:
if (Bars.FirstBarOfSession)
{
Print ("FirstBarofSession: "+Time[0]); //print the date/time of the first bar of the session as it occurs
}
if you had 5 days of data, you would likely see 4 - 5 prints.Paul H.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Zeezee, Today, 12:45 PM
|
3 responses
14 views
0 likes
|
Last Post Today, 03:28 PM | ||
Started by ldanenberg, Today, 03:19 PM
|
0 responses
2 views
0 likes
|
Last Post
by ldanenberg
Today, 03:19 PM
|
||
Started by ETFVoyageur, 05-07-2024, 07:05 PM
|
9 responses
68 views
0 likes
|
Last Post
by ETFVoyageur
Today, 03:09 PM
|
||
Started by TheTradingMantis, 01-19-2023, 02:05 AM
|
42 responses
914 views
0 likes
|
Last Post Today, 02:46 PM | ||
Started by _Zero_, 04-10-2020, 03:21 PM
|
144 responses
7,896 views
6 likes
|
Last Post Today, 02:39 PM |
Comment