Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
rectangle end time
Collapse
X
-
I was able to use the following to get rectangle start and end times. Thanks.
//set the start and end time variables for the current day
DateTime startTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 6, 45, 00);
DateTime endTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 6, 55, 00);
//get the bar number for those time variables
int startBar = GetBar(startTime);
int endBar = GetBar(endTime);
if (Time[0] >= startTime && Time[0] <= endTime)
{
DrawRectangle("tag", true, startBar, Low[LowestBar(Low, 10)], endBar, High[HighestBar(High, 10)], Color.Cyan, Color.Cyan, 1);
}
-
I apologize, there was a bug in the sample I provided. This should work.
I am going to leave the earlier, incorrect code up as it makes the meaning of the last 3 arguments clear.Code:[FONT=Courier New]public static DateTime FromTime(int time) { return new DateTime ( DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, (time % 1000000) / 10000, (time % 10000) / 100, (time % 100) / 1 ); }[/FONT]
Leave a comment:
-
That lowercase 's' should probably be uppercase.Originally posted by NinjaTrader_JessicaP View PostCode:[FONT=Courier New]public static DateTime FromTime(int time) { [/FONT][FONT=Courier New] DateTime outTime = new DateTime ( DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day ); outTime.Hour = [/FONT][FONT=Courier New][FONT=Courier New](time % 1000000) / 10000; [/FONT] outTime.Minute = [/FONT][FONT=Courier New][FONT=Courier New](time % 10000) / 100; [/FONT] outTime.[COLOR=Red][I][B]s[/B][/I][/COLOR]econd = [/FONT][FONT=Courier New][FONT=Courier New](time % 100) / 1; return outTime; [/FONT]}[/FONT]
Leave a comment:
-
We can't see your screen.Originally posted by brucelevy View Posterror says indexer date time hour minute second cannot be assigned - read only
Simple answer: your code has an error, aka, you're doing something wrong.
Want more help? Throw us a bone and post something more helpful.
Please show us your code and/or post a screenshot of your error.Last edited by bltdavid; 09-23-2016, 08:46 AM.
Leave a comment:
-
error says indexer date time hour minute second cannot be assigned - read only
Leave a comment:
-
To clarify, if you would like to convert a ToTime() compatible time into a DateTime object, you can use this static method
Code:[FONT=Courier New]public static DateTime FromTime(int time) { [/FONT][FONT=Courier New] DateTime outTime = new DateTime ( DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day ); outTime.Hour = [/FONT][FONT=Courier New][FONT=Courier New](time % 1000000) / 10000; [/FONT] outTime.Minute = [/FONT][FONT=Courier New][FONT=Courier New](time % 10000) / 100; [/FONT] outTime.second = [/FONT][FONT=Courier New][FONT=Courier New](time % 100) / 1; return outTime; [/FONT]}[/FONT]
Leave a comment:
-
rectangle end time
I want to draw a rectangle from 3am to 4am.
I am currently using the following to draw a rectangle from 3am to 20 bars forward.
if (ToTime(Time[0]) == 30000)
{
DrawRectangle("tag1"+CurrentBar, 0 ,Open[0], -20, Close[0], Color.PaleGreen);
}
I have tried this but nothing shows up on the chart...
if (ToTime(Time[0]) == 30000)
{
DrawRectangle("tag1"+CurrentBar,true, 30000 ,Open[0], 40000, Close[0], Color.PaleGreen,Color.Red,5);
}Tags: None
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by CarlTrading, 03-31-2026, 09:41 PM
|
1 response
83 views
1 like
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
45 views
0 likes
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
65 views
2 likes
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
68 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
57 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Leave a comment: