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
How to retrieve timestamp of bar low?
Collapse
X
-
How to retrieve timestamp of bar low?
"Time[5]" returns the timestamp of the 5th bar back Close. How to retrieve the timestamp of Low[5]? Idk if there is a timestamp connected with Bar Highs and Bar Lows? What is the cleanest way to handle this? thanks!
Tags: None
-
Each and every bar on the chart has a timestamp associated with it.
To say the "timestamp of Low[5]" is technically nonsensical.
If you mean the timestamp of the lowest bar of amongst the 5 most recent
bars, that can be achieved with this code,
Code:Time[Lowest(5)]
lowest Low value within the specified Lookback period.
Code:private int Lowest(int Lookback) { double lo = Low[0]; int rc = 0; for (int BarsAgo = 1, cnt = 0; cnt < Lookback; ++cnt, ++BarsAgo) { if (Low[BarsAgo) < lo) { lo = Low[BarsAgo]; rc = BarsAgo; } } return rc; }
Last edited by bltdavid; 04-27-2021, 09:19 PM.
-
Originally posted by Kicks.Spin View Postis a timestamp connected with Bar Highs and Bar Lows? What is the cleanest way to handle this?
Good reading here.
The idea you're looking for first requires a "middle-man concept" to find
those bars with the highest highs and lowest lows. The point is: you need
some kind of algorithm to return the BarsAgo index value of said bar you're
looking for.
Why?
Because that return value is then used as the index to the Time series.
I think being more precise with describing the bars you're looking for will
help us pinpoint the right algorithm which returns the correct 'n' so that
'Time[n]' in your code gives you the Time of said bar.
Swing is one way to find values of 'n' to use with 'Time[n]'.
There are others.
Comment
-
Hello Kicks.Spin,
The Timestamps would be contained in the Time series, the Low[5] Close[5] High[5] Open[5] and Time[5] would represent the values of the same bar at 5 bars ago.
If you wanted the time for Low[5] that would be Time[5].
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Comment
-
thanks jesse & bltdavid. Time[Strength] returns the timestamp of the Close value for that bar. My hang up is that i need the timestamp at the lows. i can loop back for the bar i want as bltdavid points out. i'm not connecting the dots for how to code for time stamp of the Low itself. thanks for your patience. - Kicks.Spin
Comment
-
Hello Kicks.Spin,
If you know the BarsAgo for the Low you could use that BarsAgo for the Time series to get the time from that bar. If you are using a loop to find a low you could use whatever BarsAgo was found in the loop with Time[BarsAgo]
There is only 1 time series and that would be Time[x]
Low[5] would have a timestamp of Time[5] as an example.
I look forward to being of further assistance.
JesseNinjaTrader Customer Service
Comment
-
Originally posted by Kicks.Spin View Postthanks jesse & bltdavid. Time[Strength] returns the timestamp of the Close value for that bar. My hang up is that i need the timestamp at the lows. i can loop back for the bar i want as bltdavid points out. i'm not connecting the dots for how to code for time stamp of the Low itself. thanks for your patience. - Kicks.Spin
A 5-min bar only has one time associated with it, and that is the
time the bar closes, which is available in the Time series, and
accessed by the "BarsAgo index", which is the 'n' in 'Time[n]'.
The Low series contains the lowest value ever seen by each bar,
just think visually of a candlestick, you can visualize the Open, High,
Low, and Close values on each candlestick. Well, those 4 values
for that candlestick are available in the 4 series, et al.
But the exact time at which the high value happened, or the exact
time at which the low value happened, the exactness of that time
information is lost, because the granularity of a 5 min bar, is well
5 minutes. When you look at the value of Low[n], all you can say
is we know the "exact" time that value happened is within the last
5 minutes of Time[n] -- thus Time[n] is sort of like an approximation.
[EDIT: more 'true' time discussion]
We don't automatically know the true exact moment in time (unless
the Low and Close are the same price, which means the Low was
found when the bar closed) -- you'd have to do a lot of extra special
NinjaScript coding to record the exact times within the 5-min bar's
five minutes of construction to keep track of when the high/low value
actually occurred.
My point is, if you want to know at what intermediate time during the
life of those 5 minutes when the bar was under construction, did the
lowest value (which eventually becomes the final value that stays
in Low[n]) -- if you want the precise time this low value happened,
well, ok -- we know it happened at some point inside that 5 minute
bar, but are you wanting to know the exact time that this low value
of the bar happened? Is that what you want?
If so, that is quite possibly a foolish quest. How so?
Because let's say the lowest value recorded in the 5 min bar
was 2:14 mins into the bar. When the bar closed, armed with
knowing 134 secs into the bar, the value in Low[n] happened,
how is that useful? Not only that, how is that a trustworthy
value? You don't if the low value at 134 secs into the bar is
confirmed and never going to change until the 5 min bar's
five minutes of construction is completed. So, few people
care about the exact time at which Low[5] occurred -- most
people just use Time[5] as a proxy for everything regarding
when the OHLC values actually occurred, even though
Time[5] is really just the time at which the bar closed.
Yes, I see now what you're meaning. Time[5] is giving you
the exact time at which the value in Close[5] occurred.
There is no corresponding series is to give you the exact time
at which Low[5] occurred -- that's just not how candlesticks
work. Just use Time[5] as a proxy, isn't that good enough?
EDIT: The forum s/w does not update this post when I try
to save my edits. Very strange.Last edited by bltdavid; 04-30-2021, 09:15 AM.
Comment
-
Using my example, that's one reason why you might use a lower granularity
bar type -- such as a 1-min bar instead of the 5-min bar -- because that would
reduce the amount of time of knowing the "exact" time inside the bar the lowest
value actually occurred from "somewhere inside last 5 minutes" to "somewhere
inside last 1 minute".
If you're coding in NinjaScript, you can certainly add an additional data series,
say a 1 second series, or even 1 Tick series, and record the exact time the
highest high value and lowest low values were seen on a per primary bar
basis.Last edited by bltdavid; 04-29-2021, 11:34 AM.
Comment
-
Originally posted by bltdavid View Postyou'd have to do a lot of extra work to record the exact times
within the 5-min bar's five minutes of construction to keep track
of when the high/low occurred.
certainly extra custom coding (way beyond strategy builder),
and is certainly going to require a secondary data series of
some acceptable granularity, such as a 1-Second series,
or a 1-Tick series.
Comment
-
thank you bltdavid.
i solved this problem of swing duration by calculating it as follows
swingduration = closetocloseduration + highbartipadd - lowbartiptimesubtract.
closetocloseduration = Math.Abs((Time[CurrentBar - minbarnumber + 1] - Time[Strength + 1]).TotalSeconds)
closetocloseduration does not include duration of highbar development from open to high.
i solved that problem by calculating the duration of high bar and then estimating time of open to high as follows
higbartipadd = ( High[Strength] - Open[Strength] ) / Range()[Strength] * highbarduration.
The assumption is bar development from open to high is same as overall bar.
closetocloseduration includes extra time in bottom bar from open to low. that is not part of the swing
so i solved that problem by estimating duration of bottom bar as
lowbartiptimesubtract = ( Open[CurrentBar - minbarnumber] - Low[CurrentBar - minbarnumber] ) / Range()[CurrentBar - minbarnumber]
i spot checked the estimations on lower time frame and it is 99+%
Thanks to the senior members and moderators for helping new people along! Kicks.Spin
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by tony_28217, Today, 07:04 PM
|
0 responses
3 views
0 likes
|
Last Post
by tony_28217
Today, 07:04 PM
|
||
Started by flybuzz, Today, 10:33 AM
|
1 response
9 views
0 likes
|
Last Post
by flybuzz
Today, 06:59 PM
|
||
Started by spencerp92, 10-10-2023, 09:56 AM
|
4 responses
303 views
0 likes
|
Last Post
by flybuzz
Today, 06:45 PM
|
||
Started by samish18, Yesterday, 10:13 AM
|
1 response
25 views
0 likes
|
Last Post Today, 06:15 PM | ||
Started by Austiner87, Today, 05:02 PM
|
0 responses
5 views
0 likes
|
Last Post
by Austiner87
Today, 05:02 PM
|
Comment