Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
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 memonic, Yesterday, 01:23 PM
|
2 responses
11 views
0 likes
|
Last Post
by memonic
Today, 04:26 AM
|
||
Started by merc410, Today, 03:41 AM
|
2 responses
9 views
0 likes
|
Last Post
by merc410
Today, 04:16 AM
|
||
Started by sugalt, 04-30-2024, 04:02 AM
|
2 responses
13 views
0 likes
|
Last Post
by sugalt
Today, 03:42 AM
|
||
Started by Ndakotan1313, 03-14-2024, 05:02 PM
|
2 responses
61 views
0 likes
|
Last Post
by blaise_code
Today, 03:16 AM
|
||
Started by claxxical, 05-30-2017, 12:30 PM
|
37 responses
4,461 views
0 likes
|
Last Post
by Padan
Today, 02:23 AM
|
Comment