#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 NullPointStrategies, Today, 05:17 AM
|
0 responses
41 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
124 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
64 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
41 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
46 views
0 likes
|
Last Post
|

Comment