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
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 Barry Milan, Today, 10:35 PM
|
1 response
6 views
0 likes
|
Last Post Today, 10:48 PM | ||
Started by WeyldFalcon, 12-10-2020, 06:48 PM
|
14 responses
1,427 views
0 likes
|
Last Post
by Handclap0241
Today, 10:43 PM
|
||
Started by DJ888, Yesterday, 06:09 PM
|
2 responses
9 views
0 likes
|
Last Post
by DJ888
Today, 10:31 PM
|
||
Started by jeronymite, 04-12-2024, 04:26 PM
|
3 responses
40 views
0 likes
|
Last Post
by jeronymite
Today, 10:10 PM
|
||
Started by bill2023, Today, 08:51 AM
|
2 responses
16 views
0 likes
|
Last Post
by bill2023
Today, 10:10 PM
|
Comment