Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Tick Counter With Output

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

    Tick Counter With Output

    Hello. What I would like is for the native tick counter to output a signal to be used by blackbird. This signal will occur when tick counter is less than x ticks. This is my first time writing a script. I started with the NT indicator wizard and added elements from the sample bool series.

    I've read a couple forums on how to write this, and ended up here: https://ninjatrader.com/support/foru...t-plots?t=4991

    This is for NT8: When I compile it, I get the following error: tickentry already contains a definition for "entryindication" Thank you for your help. I dont know how to place the code in a zipfile so I just pasted it here. sorry for the inconvenience.

    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class TickEntry : Indicator
    {
    private Series<bool> EntryIndication;
    private double exposedVariable;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Will generate a signal for Blackbird to place a trade when current bar's tick count is less than x ticks";
    Name = "TickEntry";
    Calculate = Calculate.OnEachTick;
    CountDown = true;
    TickEntry = 100;
    IsOverlay = false;
    DisplayInDataBox = true;
    DrawOnPricePanel = false;
    DrawHorizontalGridLines = false;
    DrawVerticalGridLines = false;
    PaintPriceMarkers = false;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;


    }
    else if (State == State.Configure)
    {
    EntryIndication =new Series<bool>(this);
    }
    }

    protected override void OnBarUpdate()
    {
    double periodValue = (BarsPeriod.BarsPeriodType == BarsPeriodType.Tick) ? BarsPeriod.Value : BarsPeriod.BaseBarsPeriodValue;
    double tickCount = ShowPercent ? CountDown ? (1 - Bars.PercentComplete) * 100 : Bars.PercentComplete * 100 : CountDown ? periodValue - Bars.TickCount : Bars.TickCount;

    string tick1 = (BarsPeriod.BarsPeriodType == BarsPeriodType.Tick
    || ((BarsPeriod.BarsPeriodType == BarsPeriodType.HeikenAshi || BarsPeriod.BarsPeriodType == BarsPeriodType.Volumetric) && BarsPeriod.BaseBarsPeriodType == BarsPeriodType.Tick) ? ((CountDown
    ? NinjaTrader.Custom.Resource.TickCounterTicksRemain ing + tickCount : NinjaTrader.Custom.Resource.TickCounterTickCount + tickCount) + (ShowPercent ? "%" : ""))
    : NinjaTrader.Custom.Resource.TickCounterBarError);
    if (CurrentBar == 0)
    {
    ChkLevel = (BarsPeriod.BarsPeriodType == BarsPeriodType.HeikenAshi && BarsPeriod.BaseBarsPeriodType == BarsPeriodType.Tick) ? BarsPeriod.BaseBarsPeriodValue : BarsPeriod.Value;

    // Tick Counter is less than Tick Entry
    if (TickEntry < chklevel)
    /* This condition is considered so we set "EntryIndication" object to true */
    EntryIndication[0] = (true);
    }

    exposedVariable = Close[0];
    }

    #region Properties
    // Creating public properties that access our internal Series<bool> allows external access to this indicator's Series<bool>
    [Browsable(false)]
    [XmlIgnore]
    public Series<bool> EntryIndication
    {
    get { return EntryIndication; } // Allows our public EntryIndication Series<bool> to access and expose our interal bearIndication Series<bool>
    }

    public double ExposedVariable
    {
    // We need to call the Update() method to ensure our exposed variable is in up-to-date.
    get { Update(); return exposedVariable; }
    }
    #endregion
    }
    }

    #region NinjaScript generated code. Neither change nor remove.

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

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

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

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

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

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

    #endregion

    #2
    Hello minipax,

    Thanks for your post.

    In your script, you have a private variable called EntryIndication and a public variable called EntryIndication. Since these variables have the same name, you would need to modify one of the variables so that the name is different.

    AddPlot() would be used to add a plot to your script to act as a 'signal' when a certain condition occurs. That plot could then be referenced using the Strategy Builder or Blackbird if that is supported by Blackbird.

    I highly suggest reviewing the Indicator development tutorials in our help guide to get a solid understanding of how to develop indicators. I am linking the Indicator tutorials below.

    Indicator Tutorials: https://ninjatrader.com/support/help...indicators.htm

    Also, see this help guide page about using AddPlot(): https://ninjatrader.com/support/help...t8/addplot.htm

    If you encounter any compile errors while building your script, debugging steps would need to be taken to determine what exactly in the script is causing the error to occur.

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.
    https://ninjatrader.com/support/foru...121#post791121

    Note that in the support department at NinjaTrader it is against our policy to create, debug, or modify, code or logic for our clients. Further, we do not provide C# programming education services in our support. This is so that we can maintain a high level of service for all of our clients as well as our partners.

    Let us know if we may assist further.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      https://ninjatrader.com/support/foru...t-plots?t=4991 was the one I needed to create this type of indicator. It has both private and and public variables with the same name. I did notice that the post was from 2008, so I dont know if that post is still valid.

      Comment


        #4
        Hello minipax,

        Thanks for your note.

        We have a SampleBoolSeries reference script located in the NinjaTrader Help Guide which uses public and private variables. See the SampleBoolSeries reference sample linked below.

        SampleBoolSeries: https://ninjatrader.com/support/help...alues_that.htm

        Let us know if we may assist further.
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        61 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        39 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        21 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        23 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        51 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X