Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
CurrentBar goes negative
Collapse
X
-
CurrentBar goes negative
I have some print statements for Debugging, the output is CurrentBar, a barsAgo calculation, and a startBar for a condition. However occasionally the CurrentBar is off causing a brief misdrawing of my indicator. The CurrentBar should be 4350 NOT 869.
Tags: None
-
How are you calculating the Current Bar? I would assume that there is some logic in your code causing this to set wrong, thus throwing everything off.
-
I'm not calculating CurrentBar, I am merely referencing CurrentBar which is built into NInjatrader. Although I mispoke Current Bar is not negative but the prior bar is going from 4349 on the previous bar to 869 on the current bar which causes my calculation for barsAgo to be negative.
Comment
-
How would the current bar jump from 4349 back to 869? How are the other prints calculating the barsAgo? It's obvious the startbar is still being kept track of and is set to the correct thing. Regardless, you will need to provide the code for anyone to figure out what is potentially wrong with it.
Comment
-
Code:if (startBarShort == -1) // Determines if this is the first bar of the condition { startBarShort = CurrentBar; barsAgo = CurrentBar - startBarShort; highPrice = High[0]; lowPrice = Low[0]; Print(string.Format("Start bar set - barsAgo: {0}", barsAgo)); } else // If not first bar of the condition update the barsAgo { // Update high and low prices barsAgo = CurrentBar - startBarShort; highPrice = Math.Max(highPrice, High[0]); lowPrice = Math.Min(lowPrice, Low[0]); Print(string.Format("Continuation bar set: barsAgo: {0}", barsAgo)); Print(string.Format("Current Bar: {0}", CurrentBar)); Print(string.Format("Start Bar: {0}", startBarShort)); }
Comment
-
Ok. I don't see any reason why the CurrentBar would go backwards. Is there any other section in your code that would assign CurrentBar to something?
Comment
-
Actually it had nothing to do with startBarShort. It has to do with using the stochastics. I created a proof of concept indicator to develop code to dynamically update and draw a rectangle based on price > or < vwap. This code generated a smooth uninterrupted dynamic rectangle. when I changed the condition to use the stochastics indicator the rectangle for the most part works with intermittent hiccups to CurrentBar causing temporary disruption to the draw updates. The following fix returned it to running smooth.
FIX:Code:private double currentBar; protected override void OnBarUpdate() { currentBar = BarsArray[0].Count; // Inidcator coded below }
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
574 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
332 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 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
553 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
551 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment