Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Compilation Error - Indicator TradeMarker

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

    Compilation Error - Indicator TradeMarker

    Hi,

    What i am trying to build here is a indicatior that plot a mark on the chart when a big order hits T&S.
    I am unameble to compile the code as i believe that I am missig a namespace or have it wrongly stated. I am using the using NinjaTrader.Cbi; for T&S
    Any help here is appreciated
    The type or namespace name 'TimeAndSales' could not be found (are you missing a using directive or an assembly reference?)
    The name 'TimeAndSales' does not exist in the current context
    The type or namespace name 'TimeAndSalesEventArgs' could not be found (are you missing a using directive or an assembly reference?)
    The type or namespace name 'TimeAndSalesTickType' does not exist in the namespace 'NinjaTrader.Cbi' (are you missing an assembly reference?)
    The type or namespace name 'TimeAndSalesTickType' does not exist in the namespace 'NinjaTrader.Cbi' (are you missing an assembly reference?)

    //
    // Copyright (C) 2024, NinjaTrader LLC <www.ninjatrader.com>.
    // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
    //
    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.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion

    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class BuySellVolume : Indicator
    {
    private double buys;
    private double sells;
    private int activeBar = 0;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDe scriptionBuySellVolume;
    Name = NinjaTrader.Custom.Resource.NinjaScriptIndicatorNa meBuySellVolume;
    BarsRequiredToPlot = 1;
    Calculate = Calculate.OnEachTick;
    DrawOnPricePanel = false;
    IsOverlay = false;
    DisplayInDataBox = true;

    // Plots will overlap each other no matter which one of these comes first
    // in NT8, we would add the Sells first in code and then Buys, and the "Sells" was always in front of the buys.
    AddPlot(new Stroke(Brushes.DarkCyan, 2), PlotStyle.Bar, NinjaTrader.Custom.Resource.BuySellVolumeBuys);
    AddPlot(new Stroke(Brushes.Crimson, 2), PlotStyle.Bar, NinjaTrader.Custom.Resource.BuySellVolumeSells);
    }
    else if (State == State.Historical)
    {
    if (Calculate != Calculate.OnEachTick)
    {
    Draw.TextFixed(this, "NinjaScriptInfo", string.Format(NinjaTrader.Custom.Resource.NinjaScr iptOnBarCloseError, Name), TextPosition.BottomRight);
    Log(string.Format(NinjaTrader.Custom.Resource.Ninj aScriptOnBarCloseError, Name), LogLevel.Error);
    }
    }
    }

    protected override void OnMarketData(MarketDataEventArgs e)
    {
    if(e.MarketDataType == MarketDataType.Last)
    {
    if(e.Price >= e.Ask)
    buys += (Instrument.MasterInstrument.InstrumentType == Cbi.InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume(e.Volume) : e.Volume);
    else if (e.Price <= e.Bid)
    sells += (Instrument.MasterInstrument.InstrumentType == Cbi.InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume(e.Volume) : e.Volume);
    }
    }

    protected override void OnBarUpdate()
    {
    if (CurrentBar < activeBar || CurrentBar <= BarsRequiredToPlot)
    return;

    // New Bar has been formed
    // - Assign last volume counted to the prior bar
    // - Reset volume count for new bar
    if (CurrentBar != activeBar)
    {
    Sells[1] = sells;
    Buys[1] = buys + sells;
    buys = 0;
    sells = 0;
    activeBar = CurrentBar;
    }

    Sells[0] = sells;
    Buys[0] = buys + sells;
    }

    region Properties
    [Browsable(false)]
    [XmlIgnore]
    public Series<double> Sells
    {
    get { return Values[1]; }
    }

    [Browsable(false)]
    [XmlIgnore]
    public Series<double> Buys
    {
    get { return Values[0]; }
    }
    #endregion

    }
    }

    region NinjaScript generated code. Neither change nor remove.

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
    private BuySellVolume[] cacheBuySellVolume;
    public BuySellVolume BuySellVolume()
    {
    return BuySellVolume(Input);
    }

    public BuySellVolume BuySellVolume(ISeries<double> input)
    {
    if (cacheBuySellVolume != null)
    for (int idx = 0; idx < cacheBuySellVolume.Length; idx++)
    if (cacheBuySellVolume[idx] != null && cacheBuySellVolume[idx].EqualsInput(input))
    return cacheBuySellVolume[idx];
    return CacheIndicator<BuySellVolume>(new BuySellVolume(), input, ref cacheBuySellVolume);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {
    public Indicators.BuySellVolume BuySellVolume()
    {
    return indicator.BuySellVolume(Input);
    }

    public Indicators.BuySellVolume BuySellVolume(ISeries<double> input )
    {
    return indicator.BuySellVolume(input);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
    public Indicators.BuySellVolume BuySellVolume()
    {
    return indicator.BuySellVolume(Input);
    }

    public Indicators.BuySellVolume BuySellVolume(ISeries<double> input )
    {
    return indicator.BuySellVolume(input);
    }
    }
    }

    #endregion
    ​​

    #2
    Hello jeversondg,

    Thank you for your post.

    You have posted the code for the built-in BuySellVolume indicator, which has no compile errors.

    Please provide the code for the script referenced in the compile errors.

    Comment


      #3
      Hi,

      This is the correct code TradeMarker.

      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.Data;
      using NinjaTrader.NinjaScript;
      using NinjaTrader.Core.FloatingPoint;
      using NinjaTrader.NinjaScript.DrawingTools;
      using NinjaTrader.NinjaScript;
      using NinjaTrader.Gui.Tools;
      using NinjaTrader.NinjaScript.MarketData;
      using System.Windows.Media;
      #endregion

      namespace NinjaTrader.NinjaScript.Indicators
      {
      public class TradeMarker : Indicator
      {
      [NinjaScriptProperty]
      [Range(1, double.MaxValue, ErrorMessage = "MinTradeSize must be at least 1")]
      public double MinTradeSize { get; set; }

      private TimeAndSales timeAndSales; // For Time & Sales Data

      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = "Plots dots on the chart for large buy and sell orders based on Time & Sales data";
      MinTradeSize = 50;
      }
      else if (State == State.Configure)
      {
      timeAndSales = TimeAndSales; // Connect to the NinjaTrader Time and Sales data
      timeAndSales.Update += OnTimeAndSales; // Event handler for new Time and Sales data
      }
      }

      // Event handler for new Time and Sales data
      private void OnTimeAndSales(object sender, TimeAndSalesEventArgs e)
      {
      if (e.Volume >= MinTradeSize)
      {
      if (e.TickType == TickType.Bid) // If it's a sell order
      {
      Draw.Dot(this, "SellDot" + CurrentBar + e.Time.Ticks, true, 0, e.Price, Brushes.Red); // Draw Red Dot for Sell
      }
      else if (e.TickType == TickType.Ask) // If it's a buy order
      {
      Draw.Dot(this, "BuyDot" + CurrentBar + e.Time.Ticks, true, 0, e.Price, Brushes.Green); // Draw Green Dot for Buy
      }
      }
      }

      protected override void OnBarUpdate()
      {
      }
      }
      }

      region NinjaScript generated code. Neither change nor remove.

      namespace NinjaTrader.NinjaScript.Indicators
      {
      public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
      {
      private TradeMarker[] cacheTradeMarker;
      public TradeMarker TradeMarker(double minTradeSize)
      {
      return TradeMarker(Input, minTradeSize);
      }

      public TradeMarker TradeMarker(ISeries<double> input, double minTradeSize)
      {
      if (cacheTradeMarker != null)
      for (int idx = 0; idx < cacheTradeMarker.Length; idx++)
      if (cacheTradeMarker[idx] != null && cacheTradeMarker[idx].MinTradeSize == minTradeSize && cacheTradeMarker[idx].EqualsInput(input))
      return cacheTradeMarker[idx];
      return CacheIndicator<TradeMarker>(new TradeMarker(){ MinTradeSize = minTradeSize }, input, ref cacheTradeMarker);
      }
      }
      }

      namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
      {
      public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
      {
      public Indicators.TradeMarker TradeMarker(double minTradeSize)
      {
      return indicator.TradeMarker(Input, minTradeSize);
      }

      public Indicators.TradeMarker TradeMarker(ISeries<double> input , double minTradeSize)
      {
      return indicator.TradeMarker(input, minTradeSize);
      }
      }
      }

      namespace NinjaTrader.NinjaScript.Strategies
      {
      public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
      {
      public Indicators.TradeMarker TradeMarker(double minTradeSize)
      {
      return indicator.TradeMarker(Input, minTradeSize);
      }

      public Indicators.TradeMarker TradeMarker(ISeries<double> input , double minTradeSize)
      {
      return indicator.TradeMarker(input, minTradeSize);
      }
      }
      }

      #endregion

      Comment


        #4
        Hello,

        There is no 'TimeAndSales' script or event in NinjaTrader that you can access in this way.

        Code:
        private TimeAndSales timeAndSales; // For Time & Sales Data
        
        timeAndSales = TimeAndSales; // Connect to the NinjaTrader Time and Sales data​
        ​
        If you're trying to recreate the time and sales window, we have an existing sample script.



        For realtime ask and bid updates, use OnMarketData(). This is what the sample script linked above uses.

        Comment


          #5
          Hi,

          Thanks for the reply, tweeked the code according your suggestion.Seems that is working fine. I will test it when the market is open. I added as a strategy instead of indicator.

          region Using declarations
          using System;
          using NinjaTrader.NinjaScript;
          using NinjaTrader.Data;
          using NinjaTrader.NinjaScript.Strategies;
          using System.Windows.Media; // For Brushes
          using NinjaTrader.NinjaScript.DrawingTools; // For drawing tools
          using System.ComponentModel.DataAnnotations; // Required for Display attribute

          #endregion

          namespace NinjaTrader.NinjaScript.Strategies
          {
          public class TimeSalesStyle : Strategy
          {
          private bool debugMode = false;
          private int minTradeVolume = 100; // Default minimum volume filter

          [NinjaScriptProperty]
          [Display(Name = "Enable Debug Mode", Order = 0, GroupName = "Parameters")]
          public bool DebugMode
          {
          get { return debugMode; }
          set { debugMode = value; }
          }

          [NinjaScriptProperty]
          [Display(Name = "Minimum Trade Volume", Order = 1, GroupName = "Filters")]
          public int MinTradeVolume
          {
          get { return minTradeVolume; }
          set { minTradeVolume = Math.Max(1, value); } // Ensure it's at least 1
          }

          protected override void OnStateChange()
          {
          if (State == State.SetDefaults)
          {
          Description = "Time & Sales-style indicator showing buy (yellow) and sell (blue) bullets in real time.";
          Name = "TimeSalesStyle";
          Calculate = Calculate.OnEachTick; // Process each tick
          IsOverlay = true; // Draw dots on the price chart
          }
          }

          protected override void OnMarketData(MarketDataEventArgs marketData)
          {
          // Only process trades (ignore bid/ask updates)
          if (marketData.MarketDataType != MarketDataType.Last)
          return;

          // Apply the volume filter (only show large trades)
          if (marketData.Volume < MinTradeVolume)
          return;

          // Determine trade type and plot accordingly
          if (marketData.Price >= marketData.Ask)
          {
          // Trade at ask (BUY) -> Yellow Dot
          Draw.Dot(this, $"Buy_{CurrentBar}_{marketData.Time.Ticks}", true, 0, marketData.Price, Brushes.Yellow);
          if (debugMode)
          Print($"BUY at {marketData.Price} (Volume: {marketData.Volume})");
          }
          else if (marketData.Price <= marketData.Bid)
          {
          // Trade at bid (SELL) -> Blue Dot
          Draw.Dot(this, $"Sell_{CurrentBar}_{marketData.Time.Ticks}", true, 0, marketData.Price, Brushes.Blue);
          if (debugMode)
          Print($"SELL at {marketData.Price} (Volume: {marketData.Volume})");
          }
          }
          }
          }

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          579 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          334 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          554 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          551 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X