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 | ||
---|---|---|---|---|
Is it possible to have a drawing, such as a line, cycle through different colors?
by gentlebenthebear
Started by gentlebenthebear, Today, 01:30 AM
|
3 responses
14 views
0 likes
|
Last Post Today, 02:41 PM | ||
Started by PhillT, Today, 02:16 PM
|
2 responses
6 views
0 likes
|
Last Post
by PhillT
Today, 02:33 PM
|
||
Started by Kaledus, Today, 01:29 PM
|
3 responses
10 views
0 likes
|
Last Post Today, 02:24 PM | ||
Started by frankthearm, Yesterday, 09:08 AM
|
14 responses
47 views
0 likes
|
Last Post Today, 02:19 PM | ||
Started by PaulMohn, Today, 12:36 PM
|
2 responses
17 views
0 likes
|
Last Post
by PaulMohn
Today, 01:48 PM
|
Comment