Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
line indicator
Collapse
X
-
I was able to get ChatGPT4 to whip this up real quick, I attached some photos of actual usage and here is the code...
region Using declarations
using System;
using System.ComponentModel;
using System.Windows.Media;
using NinjaTrader.Gui.Tools;
using NinjaTrader.NinjaScript;
using NinjaTrader.NinjaScript.Strategies;
using NinjaTrader.NinjaScript.Indicators;
using NinjaTrader.Data;
#endregion
// This namespace holds indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
public class PriceChannel : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = "Price channel with lines 20 ticks above and below the last traded price";
Name = "PriceChannel";
IsOverlay = true;
IsSuspendedWhileInactive = true;
AddPlot(Brushes.Orange, "UpperChannel");
AddPlot(Brushes.Blue, "LowerChannel");
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < 1) return; // Make sure we have at least one bar worth of data.
double tickSize = Instrument.MasterInstrument.TickSize;
double upperBound = Closes[0][0] + 20 * tickSize; // 20 ticks above the last close price
double lowerBound = Closes[0][0] - 20 * tickSize; // 20 ticks below the last close price
Values[0][0] = upperBound;
Values[1][0] = lowerBound;
}
}
}
region NinjaScript generated code. Neither change nor remove.
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private PriceChannel[] cachePriceChannel;
public PriceChannel PriceChannel()
{
return PriceChannel(Input);
}
public PriceChannel PriceChannel(ISeries<double> input)
{
if (cachePriceChannel != null)
for (int idx = 0; idx < cachePriceChannel.Length; idx++)
if (cachePriceChannel[idx] != null && cachePriceChannel[idx].EqualsInput(input))
return cachePriceChannel[idx];
return CacheIndicator<PriceChannel>(new PriceChannel(), input, ref cachePriceChannel);
}
}
}
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.PriceChannel PriceChannel()
{
return indicator.PriceChannel(Input);
}
public Indicators.PriceChannel PriceChannel(ISeries<double> input )
{
return indicator.PriceChannel(input);
}
}
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.PriceChannel PriceChannel()
{
return indicator.PriceChannel(Input);
}
public Indicators.PriceChannel PriceChannel(ISeries<double> input )
{
return indicator.PriceChannel(input);
}
}
}
#endregion
2 Photos
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
596 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
343 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
103 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
556 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
554 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment