![]() |
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Jul 2007
Location: steamboat, co
Posts: 52
Thanks: 0
Thanked 0 times in 0 posts
|
Hello all, today I started writing a strategy (not that it matters now) to see how long a bar takes to complete. Here is the code inside OnBarUpdate:
Code:
if (FirstTickOfBar)
{
DateTime startTime = DateTime.Now;
Print("first tick of bar: " + Close[0] + " at: " + startTime);
}
if (Bars.TickCount == 17)
{
DateTime stopTime = DateTime.Now;
Print("bar ends: " + stopTime);
TimeSpan duration = stopTime - startTime;
Print("seconds:" + duration.TotalSeconds);
//Console.WriteLine("milliseconds:" + duration.TotalMilliseconds);
}
so my question is: does anyone have any suggestions for allowing me to access the variable 'startTime' from the 1st if block while in the 2nd if block? |
|
|
|
|
|
#2 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
Declare your 'startTime' variable outside of the OnBarUpdate() method. You can put it in the "Variables" region for convenience.
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Jul 2007
Location: steamboat, co
Posts: 52
Thanks: 0
Thanked 0 times in 0 posts
|
yes, i realize thats what i needed to do, but i was wondering if anyone has any phenomenal ideas to store DateTime.Now in a (single?) variable.
it can be stored as a string, but then i'll need to parse it to use it again. it could also be stored as many integers, but again, the need to parse it arises. so now i guess the question changed to: how should i declare a variable only to store DateTime.Now in it, to be retrieved later? |
|
|
|
|
|
#4 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
Curious, why would you want to store a string to only parse it again later instead of storing the actual DateTime structure itself?
If you want a string... string starStime = DateTime.Now.ToString();
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#5 | |
|
Member
Join Date: Jul 2007
Location: steamboat, co
Posts: 52
Thanks: 0
Thanked 0 times in 0 posts
|
Quote:
thanks for your patience, auspiv |
|
|
|
|
|
|
#6 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
I'm not sure what you are trying to do exactly. Please describe the context in which you will use the DateTime. You could always just pass along the DateTime object itself. Create a variable private DateTime currentTime = DateTime.Now or something like that.
You can also try using the ToTime() or ToDay() methods. They will provide you with int values representing either the time or the date.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Member
Join Date: Jul 2007
Location: steamboat, co
Posts: 52
Thanks: 0
Thanked 0 times in 0 posts
|
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Variable Stop | latkinso | General Programming | 1 | 07-09-2008 02:53 PM |
| Best variable to access to find last order entry price? | scriabinop23 | General Programming | 3 | 02-14-2008 03:04 PM |
| T&S filter(block) | zq655 | General Programming | 4 | 01-22-2008 10:47 AM |
| variable days | simone | General Programming | 1 | 08-27-2007 09:22 AM |
| Variable rounded | Richard Von | Indicator Development | 3 | 08-03-2007 06:55 AM |