Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

line indicator

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    line indicator

    is there a line or indicator that places line like 20 ticks under and over the current price and moves up and down dynamically?

    #2
    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

    Comment


      #3
      thanks a lot appreciate it

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      43 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      20 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      30 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      47 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      38 views
      0 likes
      Last Post CarlTrading  
      Working...
      X