private ZigZag zz;
private Bollinger bb;
// Long conditions
private bool longCondition1Met = false;
private bool longCondition2Met = false;
private bool longCondition3Met = false;
private bool longCondition4Met = false;
private double lastHighestZZ = double.MinValue;
// Short conditions
private bool shortCondition1Met = false;
private bool shortCondition2Met = false;
private bool shortCondition3Met = false;
private bool shortCondition4Met = false;
private double lastLowestZZ = double.MaxValue;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Indicator to detect long and short setup patterns using ZigZag and Bollinger Bands";
Name = "Bunce Indicator";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
IsSuspendedWhileInactive = true;
}
else if (State == State.DataLoaded)
{
zz = ZigZag(DeviationType.Points, 0.5, true);
bb = Bollinger(Close, 2, 14);
}
}
protected override void OnBarUpdate()
{
if(CurrentBar < 5) return;
// Get ZigZag points and their bar indices
int zzHBar0 = Math.Max(0, zz.HighBar(0, 1, 100));
int zzHBar1 = Math.Max(0, zz.HighBar(0, 2, 200));
int zzHBar2 = Math.Max(0, zz.HighBar(0, 3, 300));
int zzLBar0 = Math.Max(0, zz.LowBar(0, 1, 100));
int zzLBar1 = Math.Max(0, zz.LowBar(0, 2, 200));
int zzLBar2 = Math.Max(0, zz.LowBar(0, 3, 300));
double zzHH0 = High[zzHBar0];
double zzHH1 = High[zzHBar1];
double zzHH2 = High[zzHBar2];
double zzLL0 = Low[zzLBar0];
double zzLL1 = Low[zzLBar1];
double zzLL2 = Low[zzLBar2];
// Keep original logs
// Print("zzHH0 " + zzHH0);
// Print("zzHH1 " + zzHH1);
// Print("zzHH2 " + zzHH2);
// Print("zzLL0 " + zzLL0);
// Print("zzLL1 " + zzLL1);
// Print("zzLL2 " + zzLL2);
// Print("bbU:" + bb.Upper[0]);
// Print("bbL:" + bb.Lower[0]);
// Check LONG conditions
if (zzHH2 < zzHH1 && !longCondition1Met)
{
longCondition1Met = true;
lastHighestZZ = zzHH1;
Draw.Dot(this, "Long1_" + CurrentBar, true, zzHBar1, High[zzHBar1], Brushes.LimeGreen);
Print("Long Condition 1 Met: First higher high");
}
if (longCondition1Met && zzHH1 < zzHH0 && !longCondition2Met)
{
longCondition2Met = true;
lastHighestZZ = zzHH0;
Draw.Dot(this, "Long2_" + CurrentBar, true, zzHBar0, High[zzHBar0], Brushes.LimeGreen);
Print("Long Condition 2 Met: Second higher high");
}
if (longCondition1Met && longCondition2Met && zzHH0 > lastHighestZZ && !longCondition3Met)
{
longCondition3Met = true;
lastHighestZZ = zzHH0;
Draw.Dot(this, "Long3_" + CurrentBar, true, zzHBar0, High[zzHBar0], Brushes.LimeGreen);
Print("Long Condition 3 Met: Third higher high");
}
if (longCondition1Met && longCondition2Met && longCondition3Met && !longCondition4Met)
{
if (Low[0] <= bb.Lower[0])
{
longCondition4Met = true;
Draw.Dot(this, "Long4_" + CurrentBar, true, 0, Low[0], Brushes.LimeGreen);
Print("Long Condition 4 Met: Price touched lower BB");
}
}
// Check for long setup completion
if (longCondition1Met && longCondition2Met && longCondition3Met && longCondition4Met)
{
if (High[0] > lastHighestZZ)
{
Print("Long setup occurred!");
Draw.Dot(this, "LongSetup_" + CurrentBar, true, 0, Low[0], Brushes.LimeGreen);
// Reset long conditions
longCondition1Met = false;
longCondition2Met = false;
longCondition3Met = false;
longCondition4Met = false;
lastHighestZZ = double.MinValue;
}
}
// Check SHORT conditions
if (zzLL2 > zzLL1 && !shortCondition1Met)
{
shortCondition1Met = true;
lastLowestZZ = zzLL1;
Draw.Dot(this, "Short1_" + CurrentBar, true, zzLBar1, Low[zzLBar1], Brushes.Red);
Print("Short Condition 1 Met: First lower low");
}
if (shortCondition1Met && zzLL1 > zzLL0 && !shortCondition2Met)
{
shortCondition2Met = true;
lastLowestZZ = zzLL0;
Draw.Dot(this, "Short2_" + CurrentBar, true, zzLBar0, Low[zzLBar0], Brushes.Red);
Print("Short Condition 2 Met: Second lower low");
}
if (shortCondition1Met && shortCondition2Met && zzLL0 < lastLowestZZ && !shortCondition3Met)
{
shortCondition3Met = true;
lastLowestZZ = zzLL0;
Draw.Dot(this, "Short3_" + CurrentBar, true, zzLBar0, Low[zzLBar0], Brushes.Red);
Print("Short Condition 3 Met: Third lower low");
}
if (shortCondition1Met && shortCondition2Met && shortCondition3Met && !shortCondition4Met)
{
if (High[0] >= bb.Upper[0])
{
shortCondition4Met = true;
Draw.Dot(this, "Short4_" + CurrentBar, true, 0, High[0], Brushes.Red);
Print("Short Condition 4 Met: Price touched upper BB");
}
}
// Check for short setup completion
if (shortCondition1Met && shortCondition2Met && shortCondition3Met && shortCondition4Met)
{
if (Low[0] < lastLowestZZ)
{
Print("Short setup occurred!");
Draw.Dot(this, "ShortSetup_" + CurrentBar, true, 0, High[0], Brushes.Red);
// Reset short conditions
shortCondition1Met = false;
shortCondition2Met = false;
shortCondition3Met = false;
shortCondition4Met = false;
lastLowestZZ = double.MaxValue;
}
}
}
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Dots dont get drawn on the chart
Collapse
X
-
Dots dont get drawn on the chart
hi i made indicator based on zigzag and bollinger and wanted to show dots but they are not shown on the chart. I dont have properties for plots, are they required? I need to make sure dots are displayed in real time and in historical chart..
Code:Last edited by tkaboris; 02-11-2025, 07:19 AM.Tags: None
-
Hello tkaboris,
If you are not seeing anything you would need to first check the drawing objects dialog to see if any objects were added to the chart. If no objects were added you will need to use Print statements to debug the logic and make sure the code is being called and the values are what you wanted.
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
553 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
324 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
100 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
543 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
546 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment