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 Mindset, 04-21-2026, 06:46 AM
          0 responses
          57 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by M4ndoo, 04-20-2026, 05:21 PM
          0 responses
          78 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by M4ndoo, 04-19-2026, 05:54 PM
          0 responses
          39 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by cmoran13, 04-16-2026, 01:02 PM
          0 responses
          101 views
          0 likes
          Last Post cmoran13  
          Started by PaulMohn, 04-10-2026, 11:11 AM
          0 responses
          61 views
          0 likes
          Last Post PaulMohn  
          Working...
          X