Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to export the amount of "ticks" in a bar in a TXT file?

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

    How to export the amount of "ticks" in a bar in a TXT file?

    I'm trying to export the amount of "ticks" in a bar with the code below.
    But, I only see the number 1 as the number of "ticks". I tried some solutions that I found here on the forum with the "Tick Replay" function enabled, but the result was the same.
    I'm using one of those CQG Demo accounts that ninjatrader provides at the beginning of the registration, is that the problem?

    Does anyone know how to count how many ticks there are in a bar?

    Thanks

    HTML Code:
    public class barcounter : Indicator
    {
    string filePath = @"C:\Intel\bar.txt";
    private List<string> bars = new List<string>();
    
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"";
    Name = "barcounter";
    Calculate = Calculate.OnEachTick;
    IsOverlay = false;
    DisplayInDataBox = false;
    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)
    {
    }
    }
    
    protected override void OnBarUpdate()
    {
    bars.Add(Time[0] + "," + Time[0].DayOfWeek + "," + Bars.TickCount.ToString());
    File.WriteAllLines(filePath, bars);
    }
    }

    #2
    Hello rafaelcoisa,

    Is this real time or historical?
    'Note: For historical usage, you must use Calculate.OnEachTick with TickReplay enabled; otherwise a value of 1 will returned.'
    https://ninjatrader.com/support/help.../tickcount.htm

    I'm printing this in real-time and I'm seeing it appears to be working.
    https://drive.google.com/file/d/1WbR...w?usp=drivesdk

    Below I am also providing a link to the streamwriter reference sample.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I'm trying to find the amount of "ticks" in historical bars.
      The code you provided worked here in real-time but not in historical bars.
      The "Tick Replay" is enabled. The problem, therefore, would be in the CQG Demo connection that does not provide the data?

      Thanks

      Comment


        #4
        Hello rafaelcoisa

        Continuum/CQG does provide historical tick data.

        Unfortunately, I am not able to reproduce.


        To confirm, if you follow the exact steps shown in the video the behavior is different?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I tested your last sample and it worked.
          my code above too.
          finally, I think my "tick replay" was not enabled.

          Thanks.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by CaptainJack, 05-29-2026, 05:09 AM
          0 responses
          245 views
          0 likes
          Last Post CaptainJack  
          Started by CaptainJack, 05-29-2026, 12:02 AM
          0 responses
          157 views
          0 likes
          Last Post CaptainJack  
          Started by charlesugo_1, 05-26-2026, 05:03 PM
          0 responses
          165 views
          1 like
          Last Post charlesugo_1  
          Started by DannyP96, 05-18-2026, 02:38 PM
          1 response
          250 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 05-11-2026, 05:56 AM
          0 responses
          201 views
          0 likes
          Last Post CarlTrading  
          Working...
          X