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 Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          648 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          369 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          108 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          572 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          573 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X