Welcome to NexusFi: the best trading community on the planet, with over 200,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- discounts are available after registering.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
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 help answer these questions from other members on NexusFi?
Hey guys, I thought many of you would enjoy and benefit from this thread. My intention is to have each poster reply and describe in as much detail as possible an indicator they want created for NinjaTrader.
The programmers on the forum (there are many), …
Rejoice in the Thunderstorms of Life . . .
Knowing it's not about Clouds or Wind. . .
But Learning to Dance in the Rain ! ! !
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?
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.