Can you make an example or throw me a link which explains more?
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
can't run this Simple code-2
Collapse
X
-
I didn't quite understand your comment # 3. Don't exactly know what you mean by a large if statement.
Can you make an example or throw me a link which explains more?
-
Hi Josh,
Regarding the same old task I have been doing , The indicators I have already made are too heavy for the system and they slow down NT sigificantly. So I am trying to create these verical and horizontal line using a loop. but it seems they don't work.
In the code below I am trying to draw vertical lines every one minute starting at (1 , 30, 0) and the loop should repeat for 100 times. So what seems to be the problem? The Looping Command instructions provided by NT help guide are so brief and don't provide enough explainations.
Do I have to be a programmer to be able to use NT scripts?
protectedoverridevoid OnBarUpdate()
{
int x = 0;
(ToTime(Time[0]) == ToTime(1, 30, 0));
do
{
DrawVerticalLine("My vertical line" + CurrentBar, 0, Color.Silver, DashStyle.Dot, 2);
(ToTime(Time[0]) == (ToTime(Time[0]) + ToTime(0, 1, 0)));
}
while (x < 100);
}
Comment
-
Loops are a general programming concept. If you want more information on it you can try searching google for resources or try picking up a book on C#.
(ToTime(Time[0]) == ToTime(1, 30, 0));
Those lines of code do not make sense. == is an equality operator. If you wanted to check if the current time is equal to 1:30 AM you need to put it in an if-statement.
Josh P.NinjaTrader Customer Service
Comment
-
Ok . so the only thing you see wrong is the "if - statement" ? I fixed it but still doesn't work. Anything else wrong with it?
I have already looked up different resources to come up with the scrible below.
And gush please don't tell me I have to learn C# just to code a loop.
protectedoverridevoid OnBarUpdate()
{
int x = 0;
if (ToTime(Time[0]) == ToTime(1, 30, 0));
do
{
DrawVerticalLine("My vertical line" + CurrentBar, 0, Color.Silver, DashStyle.Dot, 2);
(ToTime(Time[0]) == (ToTime(Time[0]) + ToTime(0, 1, 0)));
}
while (x < 100);
}
Comment
-
yellowTrader,
That is just the beginning. You can't just make it an if(). You then need to tell it what you want it to do when such a condition is evaluated to true.
You have a second ToTime with == that does not make sense. You also need to increment x in your do-while loop. You are also not drawing on the correct bars for your do-while loop. You should be telling it to draw on bar x, not bar 0.Code:if (some condition) { // do something when condition is true; }
I highly suggest you try picking up an introduction to C# book of sorts first. It will provide you with a solid foundation to start off with.Josh P.NinjaTrader Customer Service
Comment
-
Hello there,
Regarding the same old issue , I need to know if the vertical lines my indicator draws can be drawn over the bars of the chart? not under.
Please run the code below and you will notice the vertical line drawn almost totally covers the the entire bar for the particular period it is drawn for. Can it be done so the chart overlays the indicator/vertical line? not the otherway around. Anotherwords can the vertical lines be drawn underneath the bars?
if (ToTime(Time[0]) == ToTime(9, 31, 0))
{
DrawVerticalLine("My vertical line" + CurrentBar, 0, Color.Silver, DashStyle.Dot, 2);
}
if (ToTime(Time[0]) == ToTime(9, 32, 0))
{
DrawVerticalLine("My vertical line" + CurrentBar, 0, Color.Silver, DashStyle.Dot, 2);
}
if (ToTime(Time[0]) == ToTime(9, 33, 0))
{
DrawVerticalLine("My vertical line" + CurrentBar, 0, Color.Silver, DashStyle.Dot, 2);
}
Comment
-
todate = sysdate
Going on the code provided by yellowTrader, it occured to me that instead of expressing each date individually for the If statement, maybe it's correct to say something like:
If(todate(date[0]) == todate(systemdate-1))
If(todate(date[0]) == todate(systemdate-2))...
And for that matter, can this be applied to time as well
if (ToTime(Time[0]) < ToTime(9, 32, 09(-1)))
Does this make any sense? The time idea is probably pushing it.
Comment
-
I have a lot of indicators in the indicator folder. How can I manage them?
Can I create subfolders inside the indicator folder? I have already tried that but it seems it doesn't work. Can anything be done?
Comment
-
In that case I need to delete all existing default indicators that are already in the indicator folder but when I delete all and restart NT I get them all back!!!
How can I get rid of them?
Comment
-
When I try to delete them via Tools > Edit... I get a message saying: " You can delete a system indicator" .
I just don't have any use for those indicators and would like to delete all of them. They are just crowding the indicator folder.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
635 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
364 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
106 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
567 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
571 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment