What does this mean?
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
Error on calling 'OnBarUpdate' method for indicator ' ' on bar 0:
Collapse
X
-
kaywai,
The issue is here :
Code:private string BSTDSTLineTag1 = null; private string BSTDSTLineTag2 = null;
Those variables affect this section.
Code:if (!canceldrawtdstbuyline1) { DrawLine(BSTDSTLineTag1, true, BSTDST1bar, BSTDST1, 0, BSTDST1, Color.Green, DashStyle.Dash, 1); } if (!canceldrawtdstbuyline2) { if (BSTDST2 > BSTDST1) { DrawLine(BSTDSTLineTag2, true, BSTDST2bar, BSTDST2 ,0, BSTDST2, Color.Green, DashStyle.Dash, 1); } }
Adam P.NinjaTrader Customer Service
Comment
-
Hi Adam,
Not sure I follow you.
If you look at the code below, I have set up tags so that I can reference them, or haven't I? Please see the code in bold. If I have it all misunderstood, would you mind explaining it in layman terms.
Why do I have the tags this way? It worked well when I was drawing a rectangle in a similar manner. Hope you can assist me further.
Code:[FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff] if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] ((TDBuyExtendedSetupFX().buysetupmoveiscompleted) && (BSTDST1 == [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]))[/COLOR] { BSTDST1 = TDBuyExtendedSetupFX().hhbs; BSTDST1bar = TDBuyExtendedSetupFX().hhbsbar; Print(Time[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]); Print([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"BSTDST1 = "[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] + BSTDST1.ToString()); Print([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"BSTDST1bar = "[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] + BSTDST1bar.ToString()); BSTDSTLine1 = CurrentBar; [B]BSTDSTLineTag1 = [/B][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][B]"BSTDST1"[/B][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][B]+CurrentBar;[/B] } [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] ((TDBuyExtendedSetupFX().buysetupmoveiscompleted) && (BSTDST1 != [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])) { BSTDST2 = BSTDST1; BSTDST2bar = BSTDST1bar; BSTDST1 = TDBuyExtendedSetupFX().hhbs; BSTDST1bar = TDBuyExtendedSetupFX().hhbsbar; Print(Time[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]); Print([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"BSTDST1 = "[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] + BSTDST1.ToString()); Print([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"BSTDST1bar = "[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] + BSTDST1bar.ToString()); Print([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"BSTDST2 = "[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] + BSTDST2.ToString()); Print([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"BSTDST2bar = "[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] + BSTDST2bar.ToString()); BSTDSTLine1 = CurrentBar; [B]BSTDSTLineTag1 = [/B][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][B]"BSTDST1"[/B][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][B]+CurrentBar;[/B] BSTDSTLine2 = CurrentBar; [B]BSTDSTLineTag2 = [/B][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][B]"BSTDST2"[/B][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][B]+CurrentBar;[/B] [B]}[/B] [/SIZE][/FONT][/SIZE][/FONT]
Comment
-
kaywai,
It is possible what is occurring is that initially the tags are not set because the two conditions in your if and else-if statements aren't true for the first bar until something else is set. So it skips over them and attempts to draw a line with a null tag. I would double check your if/else, and if statement logic and see if you need to perhaps move your logic around, or set up some flag that skips over the drawing part on the first bar. E.g.
bool firstRunFlag = true;
if ( firstRunFlag == true )
{
firstRunFlag = false;
return;
}
//all your other code here
Make liberal use of Print() statements and double check all your variables are getting assigned what you think they should be assigned. Also, you can use Try/Catch blocks to catch errors and handle them more gracefully. For a helpful reference sample please see the link below.
Please let me know if I may assist further.Adam P.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by WHICKED, Today, 12:45 PM
|
2 responses
18 views
0 likes
|
Last Post
by WHICKED
Today, 03:36 PM
|
||
Started by GussJ, 03-04-2020, 03:11 PM
|
15 responses
3,276 views
0 likes
|
Last Post Today, 03:15 PM | ||
Started by Tim-c, Today, 02:10 PM
|
1 response
8 views
0 likes
|
Last Post Today, 02:52 PM | ||
Started by Taddypole, Today, 02:47 PM
|
0 responses
3 views
0 likes
|
Last Post
by Taddypole
Today, 02:47 PM
|
||
Started by chbruno, 04-24-2024, 04:10 PM
|
4 responses
51 views
0 likes
|
Last Post
by chbruno
Today, 02:38 PM
|
Comment