Welcome to NexusFi: the best trading community on the planet, with over 150,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)
Can someone help with a study that draws two white lines at the High and Low of a candle, if the next 4 candles are completely inside its range? Lines should have approx. length of 5 bars. If it's easier it can also just color the first candle or otherwise visually indicate. See image example of two white lines to indicate a small range.
Is this possible to do within SC or do I need to find someone to code this as a study? Thanks
Can you help answer these questions from other members on NexusFi?
You seem to be talking in Sierra dialect; I use NinjaTrader 8. So, could you please translate your Sierra logic code snippet to NinjaTrader 8, or in just a simple English description.
Grok is your friend.... This may indie may be backwards to your intent but you can have Grok mod it however you like.
q: hey Grok can you make an engulfing bar indicator which will draw white extension lines at the highs and lows of the engulfing bar based on how many bars you set it to look for. n=2 would would draw lines when engulfs at least 2 bars, etc. in ninjatrader 8 script.
a: Below is a NinjaTrader 8 script for an engulfing bar indicator that draws white extension lines at the highs and lows of an engulfing bar when it engulfs at least n bars, as specified by the user. The script uses the NinjaScript framework to detect bullish and bearish engulfing patterns and draw horizontal lines extending to the right.
#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
namespace NinjaTrader.NinjaScript.Indicators
{
public class EngulfingBarIndicator : Indicator
{
private int barsToEngulf;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Draws lines at highs/lows of engulfing bars based on number of bars engulfed.";
Name = "EngulfingBarIndicator";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = false;
PaintPriceMarkers = false;
barsToEngulf = 2; // Default number of bars to engulf
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < barsToEngulf) return; // Ensure enough bars are available
// Bearish engulfing: current bar's body must engulf previous bar's body
// and wicks must encompass previous bar's wicks
if (bodyHigh <= prevBodyHigh || bodyLow >= prevBodyLow ||
candleHigh < prevCandleHigh || candleLow > prevCandleLow)
{
return false;
}
}
return true;
}
#region Properties
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name = "Bars to Engulf", Description = "Number of bars the engulfing bar must engulf", Order = 1, GroupName = "Parameters")]
public int BarsToEngulf
{
get { return barsToEngulf; }
set { barsToEngulf = value; }
}
#endregion
}
}
Explanation:
Purpose: The indicator identifies bullish or bearish engulfing bars that engulf at least n previous bars (set via the BarsToEngulf parameter) and draws white horizontal lines at the high and low of the engulfing bar.
Engulfing Logic:
A bullish engulfing bar has a higher close than open, and its body (open to close) and wicks (high to low) must fully encompass the bodies and wicks of the previous n bars.
A bearish engulfing bar has a lower close than open, with the same engulfing criteria.
Drawing: Uses Draw.HorizontalLine to draw white lines at the high and low of the engulfing bar, extending to the right (default NinjaTrader behavior for horizontal lines).
Parameter: BarsToEngulf (default = 2) allows the user to specify how many bars the engulfing bar must engulf.
Safety: Checks for sufficient bars (CurrentBar < barsToEngulf) to avoid index errors.
Calculation: Runs on bar close (Calculate.OnBarClose) to ensure complete bar data.
How to Use:
In NinjaTrader 8, go to Tools > Edit NinjaScript > Indicator.
Create a new indicator and paste the above code.
Compile the script.
Add the indicator to a chart via Indicators menu.
Set the Bars to Engulf parameter (e.g., 2) in the indicator settings.
Apply the indicator to see white lines at the highs and lows of qualifying engulfing bars.
Notes:
The lines persist until manually removed or the chart is refreshed, as they are drawn with unique tags (HighLine/LowLine + CurrentBar).
Ensure the chart has enough bars to evaluate the BarsToEngulf setting.
If you want the lines to extend only a certain number of bars to the right, you’d need to modify the script to use a custom drawing tool or manage line removal, which can be added if needed.
Let me know if you need adjustments, like limiting line duration or adding visual markers!
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss