Do I need to specify a dataseries or something for this?
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
IsFirstTickOfBar
Collapse
X
-
IsFirstTickOfBar
I am trying to use IsFirstTickOfBar to reset a bool once per candle. I am also using calculate.OnPriceChange which seems to be conflicting some how as the bool is being reset on every price change not just on the first tick of each bar.
Do I need to specify a dataseries or something for this?Tags: None
-
Here are my relevant snippets of code.
Code:if (IsFirstTickOfBar) { Print("reset okToTrade to TRUE on first tick of bar"); okToTrade = true; }Code:if (!isTradeActive) { EnterLongPositionsIfAllowed(); Print("Entered Long " + Position.AveragePrice); okToTrade = false; Print("okToTrade = False"); }
I am printing Time[0] and this is on a 15m candle chart. You can see the bool is being reset every second or so.
-
Hello sofortune,
For the given example I am unsure why that may be happening, I can see on my end this works to print only on the first tick of the bar when I test this in realtime on a 10 second bar series. I get 1 print per bar.
Code:protected override void OnBarUpdate() { if(IsFirstTickOfBar) { Print("FirstTick"); } else { Print("Not first tick"); } }
Keep in mind on historical bars IsFirstTickOfBar is always true so you should initially see that every bar IsFirstTickOfBar is true, only in realtime you will see that become false when its not the first tick.
Comment
-
Hello, I found the problem is because i have thsi tick data series.
I added this because I want the entry to occur in real time, I am not actually sure if it is necessary or not to achieve that, or is Calculate.OnPriceChange adequate?Code:AddDataSeries(BarsPeriodType.Tick, 1); // Secondary series with tick bars (or any other desired granularity)
Or is there a way to specifiy the data series IsFirstTickOfBar refers to?
Comment
-
Hello sofortune,
A 1 tick bar would mean that every tick is the first tick of its bar because there is only 1 tick per bar. The concept of firs tick of bar would only apply to bars that have at least more than 1 tick.
If you are using OnPriceChange then you don't need a secondary 1 tick series, in realtime the script will work tick by tick but only process if there is a change in price.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Yesterday, 05:17 AM
|
0 responses
65 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
139 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
75 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
45 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
50 views
0 likes
|
Last Post
|

Comment