#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
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.Indicators;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class MySwing5Over1Min : Strategy
{
private Swing Swing5;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Draw 5 minute Strength = 1 over a 1 Minute Chart";
Name = "MySwing5Over1Min";
Calculate = Calculate.OnBarClose;
EntriesPerDirection = 1;
IsOverlay = true;
DrawOnPricePanel = true;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToPlot = 20;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = false;
//AddPlot(Brushes.Orange, "Swing5");
}
else if (State == State.Configure)
{
AddDataSeries("", Data.BarsPeriodType.Minute, 5, Data.MarketDataType.Last);
AddPlot(new Stroke(Brushes.DarkCyan), PlotStyle.Dot, "Swing5Upper");
AddPlot(new Stroke(Brushes.Goldenrod), PlotStyle.Dot, "Swing5Lower");
}
else if (State == State.DataLoaded)
{
Swing5 = Swing(BarsArray[1], 1) ;
Plots[0].PlotStyle = PlotStyle.Dot;
Plots[1].PlotStyle = PlotStyle.Dot;
Plots[0].Brush = Brushes.Red;
Plots[1].Brush = Brushes.White;
Plots[0].DashStyleHelper = DashStyleHelper.Dot;
Plots[1].DashStyleHelper = DashStyleHelper.Dot;
Plots[0].Width = 3;
Plots[1].Width = 3;
}
}
protected override void OnBarUpdate()
{
if(CurrentBar < BarsRequiredToPlot) return;
//AddChartIndicator(Swing5);
if (BarsInProgress == 1 )
{
Swing5Upper[0] = Swing5.SwingHigh[0];
Swing5Lower[0] = Swing5.SwingLow[0];
}
if (BarsInProgress == 0)
{
Swing5Upper[0] = Swing5.SwingHigh[0];
Swing5Lower[0] = Swing5.SwingLow[0];
// if the secondary 5 minute series did not close, set the current bar's value to the previous bar's value to prevent gaps
if (!Swing5Upper.IsValidDataPoint(0))
Swing5Upper[0] = Swing5Upper[1];
if (!Swing5Lower.IsValidDataPoint(0))
Swing5Lower[0] = Swing5Lower[1];
}
//Add your custom strategy logic here.
}
#region Properties
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public Series<double> Swing5Upper
{
get { return Values[0]; }
}
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public Series<double> Swing5Lower
{
get { return Values[1]; }
}
#endregion
}
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
How to draw 5 minute swing indicator over 1 minute chart
Collapse
X
-
How to draw 5 minute swing indicator over 1 minute chart
This code does not draw anything. What's missing?
Code:Tags: None
-
Hello bobperez,
First, note the SwingHighPlot / SwingLowPlot series are what is actually being plotted on the chart with the swing indicator. The SwingHigh / SwingLow series returns the swingHighSeries and swingLowSeries.
The swing indicator changes it's historical plot values after a swing has been detected.
If you are plotting only the current bar, and you are not looping through the older bars, you wouldn't be getting any of the updated previous bar values.
You'll need the same logic the swing indicator has to loop through the previous bars and change their values. (See lines 147, 148, 161, 162, 189, 190, 203, 204)
It may be helpful to check the SwingHighBar, and if its changed, loop back through to the swing bar and set all of the plot values again.Chelsea B.NinjaTrader Customer Service
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Mindset, 04-21-2026, 06:46 AM
|
0 responses
93 views
0 likes
|
Last Post
by Mindset
04-21-2026, 06:46 AM
|
||
|
Started by M4ndoo, 04-20-2026, 05:21 PM
|
0 responses
138 views
0 likes
|
Last Post
by M4ndoo
04-20-2026, 05:21 PM
|
||
|
Started by M4ndoo, 04-19-2026, 05:54 PM
|
0 responses
68 views
0 likes
|
Last Post
by M4ndoo
04-19-2026, 05:54 PM
|
||
|
Started by cmoran13, 04-16-2026, 01:02 PM
|
0 responses
123 views
0 likes
|
Last Post
by cmoran13
04-16-2026, 01:02 PM
|
||
|
Started by PaulMohn, 04-10-2026, 11:11 AM
|
0 responses
73 views
0 likes
|
Last Post
by PaulMohn
04-10-2026, 11:11 AM
|

Comment