NexusFi: Find Your Edge


Home Menu

 





Need Custom Range Indicator


Discussion in Sierra Chart

Updated
      Top Posters
    1. looks_one lolu with 2 posts (0 thanks)
    2. looks_two moolob with 2 posts (0 thanks)
    3. looks_3 Sawtooth with 1 posts (0 thanks)
    4. looks_4 websouth with 1 posts (0 thanks)
    1. trending_up 248 views
    2. thumb_up 0 thanks given
    3. group 5 followers
    1. forum 6 posts
    2. attach_file 1 attachments




 
Search this Thread
  #1 (permalink)
SOAP7
Bucharest - Romania
 
Posts: 13 since Mar 2020
Thanks Given: 2
Thanks Received: 7

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


Attached Thumbnails
Click image for larger version

Name:	range exampel.jpg
Views:	12
Size:	16.0 KB
ID:	342573  
Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Building models w/Neuroshell and Adaptatrade
Platforms and Indicators
How to look up market depth?
MultiCharts
GANN THEORY DAVID BOWDEN SAFETY IN THE MARKETS
Traders Hideout
GFIs1 DAX System
Traders Hideout
NT TopStep discount?
NinjaTrader
 
  #2 (permalink)
 Sawtooth 
Prescott AZ USA
 
Experience: Advanced
Platform: SierraChart
Broker: EdgeClear, FCM:Phillip, Data:Denali, Routing:Teton
Trading: YM RTY ES NQ
Posts: 479 since Nov 2009
Thanks Given: 222
Thanks Received: 606


Quoting 
Is this possible to do within SC or do I need to find someone to code this as a study? Thanks

This would require a custom ACSIL study.


Reply With Quote
  #3 (permalink)
 
lolu's Avatar
 lolu 
Lagos, Nigeria
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader, SierraChart
Trading: Euro Currency & Oil
Frequency: Daily
Duration: Hours
Posts: 2,554 since Jun 2009
Thanks Given: 1,049
Thanks Received: 1,678



SOAP7 View Post
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

Hi,

Please, how do you use the concept in this indicator ?

lolu


Visit my NexusFi Trade Journal Reply With Quote
  #4 (permalink)
moolob
Braunschweig, Germany
 
Posts: 2 since Sep 2022
Thanks Given: 1
Thanks Received: 0

Hi, you can use the built-in Color Bar Based On Alert Condition Study to achieve this.

In the Alert Conditions Tab, enter this:

 
Code
AND(
 H > H[1],
 H > H[2],
 H > H[3],
 H > H[4],
 L < L[1],
 L < L[2],
 L < L[3],
 L < L[4]
)
Cheers!

PS: If you are interested, I can post the code for an ACSIL study to draw lines like in your example.


Reply With Quote
  #5 (permalink)
 
lolu's Avatar
 lolu 
Lagos, Nigeria
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader, SierraChart
Trading: Euro Currency & Oil
Frequency: Daily
Duration: Hours
Posts: 2,554 since Jun 2009
Thanks Given: 1,049
Thanks Received: 1,678

Thanks for your response.

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.

lolu


Visit my NexusFi Trade Journal Reply With Quote
  #6 (permalink)
moolob
Braunschweig, Germany
 
Posts: 2 since Sep 2022
Thanks Given: 1
Thanks Received: 0


lolu View Post
Thanks for your response.

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.

lolu

Sorry, I don't know how to do this in NT. You probably need to code this. The OP was asking for a Sierra Chart solution for this.


Reply With Quote
  #7 (permalink)
 
websouth's Avatar
 websouth 
Pensacola, FL
Legendary Market Wizard
 
Experience: Intermediate
Platform: graph paper
Trading: The shiny stuff
Posts: 1,221 since Jul 2009
Thanks Given: 1,118
Thanks Received: 1,340


moolob View Post
Sorry, I don't know how to do this in NT. You probably need to code this. The OP was asking for a Sierra Chart solution for this.


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

bool isBullishEngulfing = IsBullishEngulfing();
bool isBearishEngulfing = IsBearishEngulfing();

if (isBullishEngulfing || isBearishEngulfing)
{
// Draw horizontal lines at high and low of the engulfing bar
Draw.HorizontalLine(this, "HighLine" + CurrentBar, High[0], Brushes.White, DashStyleHelper.Solid, 2, false);
Draw.HorizontalLine(this, "LowLine" + CurrentBar, Low[0], Brushes.White, DashStyleHelper.Solid, 2, false);
}
}

private bool IsBullishEngulfing()
{
// Check if current bar is bullish
if (Close[0] <= Open[0]) return false;

// Check if current bar engulfs the previous n bars
double bodyHigh = Math.Max(Open[0], Close[0]);
double bodyLow = Math.Min(Open[0], Close[0]);
double candleHigh = High[0];
double candleLow = Low[0];

for (int i = 1; i <= barsToEngulf; i++)
{
if (i > CurrentBar) return false; // Not enough bars

double prevBodyHigh = Math.Max(Open[i], Close[i]);
double prevBodyLow = Math.Min(Open[i], Close[i]);
double prevCandleHigh = High[i];
double prevCandleLow = Low[i];

// Bullish 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;
}

private bool IsBearishEngulfing()
{
// Check if current bar is bearish
if (Close[0] >= Open[0]) return false;

// Check if current bar engulfs the previous n bars
double bodyHigh = Math.Max(Open[0], Close[0]);
double bodyLow = Math.Min(Open[0], Close[0]);
double candleHigh = High[0];
double candleLow = Low[0];

for (int i = 1; i <= barsToEngulf; i++)
{
if (i > CurrentBar) return false; // Not enough bars

double prevBodyHigh = Math.Max(Open[i], Close[i]);
double prevBodyLow = Math.Min(Open[i], Close[i]);
double prevCandleHigh = High[i];
double prevCandleLow = Low[i];

// 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
Visit my NexusFi Trade Journal Reply With Quote




Last Updated on April 15, 2025


© 2025 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