I am trying to put a time limit on the code to draw a text but it is not working and I cant figure out what am I doing wrong... all I want is when the time is between the time variables, to draw Trading... and if not write no trading or something like that... here is the code I am using.
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
draw a text on the chart based on time
Collapse
X
-
draw a text on the chart based on time
hello
I am trying to put a time limit on the code to draw a text but it is not working and I cant figure out what am I doing wrong... all I want is when the time is between the time variables, to draw Trading... and if not write no trading or something like that... here is the code I am using.
Tags: None
-
I forgot to attach the document.
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 0)
return;
// Set 1
if ((((Times[0][0].TimeOfDay > Start_Time.TimeOfDay)
&& (Times[0][0].TimeOfDay < End_Time.TimeOfDay))
||
((Times[0][0].TimeOfDay > Start_Time2.TimeOfDay)
&& (Times[0][0].TimeOfDay < End_Time2.TimeOfDay)))
&& Position.MarketPosition == MarketPosition.Flat
)
{
IsTradingTime = false;
}
// Set 2
if ((((Times[0][0].TimeOfDay > Start_Time.TimeOfDay)
&& (Times[0][0].TimeOfDay < End_Time.TimeOfDay))
||
((Times[0][0].TimeOfDay > Start_Time2.TimeOfDay)
&& (Times[0][0].TimeOfDay < End_Time2.TimeOfDay)))
&& Position.MarketPosition == MarketPosition.Flat
)
{
IsTradingTime = true;
}
// Set 3
if (IsTradingTime == true)
{
Draw.TextFixed(this, @"Test Fixed text_1", trading, TextPosition.TopRight);
}
// Set 4
if (IsTradingTime == false)
{
Draw.TextFixed(this, @"Test Fixed text_1", @"no trading", TextPosition.TopRight);
}
}
}
}
-
Hello babouin77,
Thank you for your inquiry.
It looks like your conditions in Set 1 and Set 2 are the same, which would cause IsTradingTime to always be set to true if it's between one of those two time periods, so you'd always see it print true unless you're in a trade during one of the two time periods, in which case it would print false. It looks like your strategy was created with the Strategy Builder, is that correct? If you've unlocked that code you could simply do something like this:
if (((Times[0][0].TimeOfDay > Start_Time.TimeOfDay)
&& (Times[0][0].TimeOfDay < End_Time.TimeOfDay))
||
((Times[0][0].TimeOfDay > Start_Time2.TimeOfDay)
&& (Times[0][0].TimeOfDay < End_Time2.TimeOfDay)))
{
IsTradingTime = true;
}
else {
IsTradingTime = false;
}
// Set 3
if (IsTradingTime == true)
{
Draw.TextFixed(this, @"Test Fixed text_1", "trading", TextPosition.TopRight);
}
// Set 4
if (IsTradingTime == false)
{
Draw.TextFixed(this, @"Test Fixed text_1", @"no trading", TextPosition.TopRight);
}
If you're just wanting that to print based on whether it's between those two times, I wouldn't suggest checking the position, otherwise it'll print "no trading" when in a position during that time frame.
Now if it's still locked in the Strategy Builder this gets trickier, because you can't really do an else in the Builder. What you could do is in set 1, don't put any conditions, but have it automatically set the IsTradingTime bool to false, and then leave your conditions in set 2 to set IsTradingTime to true. This way, it's false unless you're within those hours and you get the same effect as above.
Please let us know if we may be of further assistance to you.Kate W.NinjaTrader Customer Service
- Likes 1
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Aviram Y, Today, 05:29 AM
|
0 responses
1 view
0 likes
|
Last Post
by Aviram Y
Today, 05:29 AM
|
||
Started by quantismo, 04-17-2024, 05:13 PM
|
3 responses
25 views
0 likes
|
Last Post Today, 05:23 AM | ||
Started by ScottWalsh, 04-16-2024, 04:29 PM
|
7 responses
34 views
0 likes
|
Last Post Today, 05:15 AM | ||
Started by cls71, Today, 04:45 AM
|
0 responses
6 views
0 likes
|
Last Post
by cls71
Today, 04:45 AM
|
||
Started by mjairg, 07-20-2023, 11:57 PM
|
3 responses
216 views
1 like
|
Last Post
by PaulMohn
Today, 04:22 AM
|
Comment