Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Calculate time in seconds between the close of two bars
Collapse
X
-
imported post
I added the statement below but when I do PRINT stops working (nothing prints). If I comment outthe statement you suggested PRINT works okay.
seconds = Time[0].Subtract(Time[1]).Seconds;
Print("Bar Time " + CurrentBar.ToString("00000"));
I also tried using just the PRINT statement and nothing prints.
Print(Time[0].Subtract(Time[1]).Seconds.ToString());
Comment
-
imported post
When something does not work always check the Log tab to see what errors may have been generated.
I suspect the issue is that Time[1] is throwing an exception since on the 1st bar, Time[1 bar ago] does not yet exist. Therefore, try something like:
if (CurrentBar > 0)
Print(Time[0].Subtract(Time[1]).Seconds.ToString());
Ray
RayNinjaTrader Customer Service
Comment
-
imported post
That was it. Thanks for your help.
I notice that by adding the following statement that some bars exceed 60 seconds and therefore have a value in the minutes variable. Is there a way to return the "total elapsed seconds" including minutes and seconds?
Time[0].Subtract(Time[1]).Minutes.ToString() + " " +
Comment
-
imported post
Under variables:
private DataSeries barInterval = null;
barInterval = new DataSeries(this);
barInterval.Set(CurrentBar > 0 ?(double) Time[0].Second - Time[1].Second : 0);
if (Time[0] > OrderTime.AddSeconds((int) SMA(barInterval, 5)[0])
// Do something....
RayNinjaTrader Customer Service
Comment
-
turning this into a histogram?
Originally posted by OnePutt View PostI added the statement below but when I do PRINT stops working (nothing prints). If I comment outthe statement you suggested PRINT works okay.
seconds = Time[0].Subtract(Time[1]).Seconds;
Print("Bar Time " + CurrentBar.ToString("00000"));
I also tried using just the PRINT statement and nothing prints.
Print(Time[0].Subtract(Time[1]).Seconds.ToString());
So far I have this in void Initialize()
Add(new Plot(new Pen(Color.Red, 3), PlotStyle.Bar, "seconds"));
And this in void OnBarUpdate()
Value.Set(Time[0].Subtract(Time[1]).Seconds);
It compiles ok but nothing displays on the chart.
Comment
-
I suggest you check the Control Center logs for errors when you run it. I suspect you may run into an index error outlined in this tip: http://www.ninjatrader-support.com/v...ead.php?t=3170Josh P.NinjaTrader Customer Service
Comment
-
Originally posted by Josh View PostI suggest you check the Control Center logs for errors when you run it. I suspect you may run into an index error outlined in this tip: http://www.ninjatrader-support.com/v...ead.php?t=3170
if (CurrentBar < 1)
return;
if (CurrentBar >= 1)
Value.Set(Time[0].Subtract(Time[1]).Seconds);
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by M_ichel, Today, 08:38 AM
|
0 responses
1 view
0 likes
|
Last Post
![]()
by M_ichel
Today, 08:38 AM
|
||
Started by soon123, Today, 12:18 AM
|
1 response
20 views
0 likes
|
Last Post
|
||
Started by space_trader, Today, 12:52 AM
|
1 response
20 views
0 likes
|
Last Post
|
||
Started by ybhx0315, Yesterday, 09:06 PM
|
0 responses
21 views
0 likes
|
Last Post
![]()
by ybhx0315
Yesterday, 09:06 PM
|
||
Started by parkinsonbr, Yesterday, 08:23 PM
|
1 response
10 views
0 likes
|
Last Post
|
Comment