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!
See more
See less

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 memonic, Yesterday, 01:23 PM
      2 responses
      11 views
      0 likes
      Last Post memonic
      by memonic
       
      Started by merc410, Today, 03:41 AM
      2 responses
      9 views
      0 likes
      Last Post merc410
      by merc410
       
      Started by sugalt, 04-30-2024, 04:02 AM
      2 responses
      13 views
      0 likes
      Last Post sugalt
      by sugalt
       
      Started by Ndakotan1313, 03-14-2024, 05:02 PM
      2 responses
      61 views
      0 likes
      Last Post blaise_code  
      Started by claxxical, 05-30-2017, 12:30 PM
      37 responses
      4,461 views
      0 likes
      Last Post Padan
      by Padan
       
      Working...
      X