How can I get the opening value of the 6:30am bar?
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
How do I get the value of a bar at a specific time
Collapse
X
-
thanks. i see how that works now, but i'm trying to put it all together.
in this code sample, i'd like to get the difference between the 7:30 opening bar, and the 7:36 opening bar.
the problem is that my openPrice and the thirtySixPrice is the same.
for testing, i ran a backtest on a 1 minute frequency for the previous week.
my output:Code:if (ToTime(Time[0]) >= 73600 && ToTime(Time[0]) < 73700) // ToTime(7, 30, 00)) { int barsAgoOpen = GetBar(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 7, 30, 0)); int barsAgoThirtySix = GetBar(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 7, 36, 0)); double thirtySixPrice = Open[barsAgoThirtySix]; double openPrice = Open[barsAgoOpen]; Print(Time[0].DayOfWeek+" "+openPrice+" "+thirtySixPrice); }Code:Monday 921.5 921.5 Tuesday 921 921 Wednesday 901.5 901.5 Thursday 914.5 914.5 Friday 920.25 920.25
Comment
-
you're right. my barsAgoOpen is always 0. when i increase the time window, it just prints the exact same data for the number of minutes of that window.
are there any ninjascript examples to reference? i've imported a couple from the resource link, but none do what i'm trying to accomplish.
i.e. calculate the difference between minute bars 7:30 and 7:36 and then execute a trade based on that. (obviously the logic wouldn't be that simple, but that would get me to the next step)
Comment
-
Unfortunately I'm not aware any sample more specific than this one - http://www.ninjatrader-support2.com/...ead.php?t=8600
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by cmoran13, Yesterday, 01:02 PM
|
0 responses
29 views
0 likes
|
Last Post
by cmoran13
Yesterday, 01:02 PM
|
||
|
Started by PaulMohn, 04-10-2026, 11:11 AM
|
0 responses
21 views
0 likes
|
Last Post
by PaulMohn
04-10-2026, 11:11 AM
|
||
|
Started by CarlTrading, 03-31-2026, 09:41 PM
|
1 response
160 views
1 like
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
95 views
1 like
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
148 views
2 likes
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|

Comment