NexusFi: Find Your Edge


Home Menu

 





how to code an intrabar indicator based on price offset from open that fires once/bar


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one vickisb with 2 posts (0 thanks)
    2. looks_two DavidHP with 1 posts (0 thanks)
    3. looks_3 Ozquant with 1 posts (0 thanks)
    4. looks_4 Leonardo Llaneza with 1 posts (0 thanks)
    1. trending_up 291 views
    2. thumb_up 0 thanks given
    3. group 4 followers
    1. forum 4 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 vickisb 
Sarasota FL
 
Experience: Intermediate
Platform: Ninja Trader
Trading: ES
Posts: 83 since Feb 2017
Thanks Given: 45
Thanks Received: 27

I want to perform an action (e.g., draw an arrow, play a sound or enter a trade) intrabar (only once) when price crosses X number of ticks below/above the current bar's open. How would I code that condition in an indicator or strategy?

For instance, on a UniRenko bar chart configured for a reversal bar at 30 ticks, if the bars are trending up and price pulls back 20 ticks below the open, I want to play a wav to alert me.


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Without Pulisic, USA 61.5% Live vs. Australia -- France …
Prediction Markets & Event Contracts
May 26 Deadline Dies at 7.5% as US Strikes Iran During C …
Prediction Markets & Event Contracts
Irans Answer Due Today: Peace Surges to 33.5%, Invasion …
Prediction Markets & Event Contracts
Warsh Opens Today, Hormuz June 19 -- WTI Below $80, Fran …
Prediction Markets & Event Contracts
Trump Lands in Beijing on CPI Day: Iran Peace Expires To …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Darmok and Jalad at Tanagra
1 thanks
NexusFi site changelog and issues/problem reporting
1 thanks
  #2 (permalink)
 
DavidHP's Avatar
 DavidHP 
Isla Mujeres, MX
Legendary Market Wizard
 
Experience: Advanced
Platform: NinjaTrader
Broker: Ninjatrader / Optimus Futures / AmpFutures
Trading: NQ / ES / 6E / 6B / CL
Frequency: Every few days
Duration: Minutes
Posts: 1,816 since Aug 2009
Thanks Given: 11,765
Thanks Received: 3,043


vickisb View Post
I want to perform an action (e.g., draw an arrow, play a sound or enter a trade) intrabar (only once) when price crosses X number of ticks below/above the current bar's open. How would I code that condition in an indicator or strategy?

For instance, on a UniRenko bar chart configured for a reversal bar at 30 ticks, if the bars are trending up and price pulls back 20 ticks below the open, I want to play a wav to alert me.

Can you post the code you are using?
Also, you may get better results if you post on this thread.


Rejoice in the Thunderstorms of Life . . .
Knowing it's not about Clouds or Wind. . .
But Learning to Dance in the Rain ! ! !
Follow me on X Reply With Quote
  #3 (permalink)
 vickisb 
Sarasota FL
 
Experience: Intermediate
Platform: Ninja Trader
Trading: ES
Posts: 83 since Feb 2017
Thanks Given: 45
Thanks Received: 27



DavidHP View Post
Can you post the code you are using?
Also, you may get better results if you post on this thread.

Thanks. Here's the post in the thread you suggest, with more details:


Started this thread Reply With Quote
  #4 (permalink)
Leonardo Llaneza
Miami Florida
 
Posts: 5 since Jul 2026
Thanks Given: 0
Thanks Received: 1


vickisb View Post
I want to perform an action (e.g., draw an arrow, play a sound or enter a trade) intrabar (only once) when price crosses X number of ticks below/above the current bar's open. How would I code that condition in an indicator or strategy?

For instance, on a UniRenko bar chart configured for a reversal bar at 30 ticks, if the bars are trending up and price pulls back 20 ticks below the open, I want to play a wav to alert me.

Here's a solid approach for this:
By default, NinjaScript runs on Calculate.OnBarClose, which only evaluates OnBarUpdate() once per fully closed bar — so to catch a pullback happening intrabar, you'll want Calculate.OnEachTick (or OnPriceChange) set in State.Configure instead. Otherwise you'll never see the price movement happening inside the bar.
For the "fire exactly once per bar" behavior, use a flag that resets only when the bar actually changes (not every tick), then gate your action behind that flag:
csharpprivate bool firedThisBar = false;
private int lastBar = -1;

protected override void OnBarUpdate()
{
if (CurrentBar < 1) return;

// Reset the flag exactly once when we roll onto a new bar
if (CurrentBar != lastBar)
{
firedThisBar = false;
lastBar = CurrentBar;
}

if (firedThisBar) return;

double pullbackTicks = 5; // set your desired offset
double threshold = pullbackTicks * TickSize;

if (Open[0] - Close[0] >= threshold) // pullback from open example
{
firedThisBar = true;
// your action here: Draw.ArrowDown(), PlaySound(), EnterShort(), etc.
}
}
This works the same way on UniRenko bars, since the logic is based on Open[0]/Close[0] of the current bar rather than time — just make sure your tick offset math matches your instrument's TickSize.


Reply With Quote
  #5 (permalink)
Ozquant
Brisbane Queensland Australia
 
Posts: 222 since Aug 2017
Thanks Given: 171
Thanks Received: 382

AI will likely code that up for you in a couple minutes , it's that simple most of the time especially with something this straightfoward


Reply With Quote




Last Updated on July 18, 2026


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts