Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 r68cervera, Today, 05:29 AM
          0 responses
          2 views
          0 likes
          Last Post r68cervera  
          Started by geddyisodin, Today, 05:20 AM
          0 responses
          3 views
          0 likes
          Last Post geddyisodin  
          Started by JonesJoker, 04-22-2024, 12:23 PM
          6 responses
          34 views
          0 likes
          Last Post JonesJoker  
          Started by GussJ, 03-04-2020, 03:11 PM
          12 responses
          3,239 views
          0 likes
          Last Post Leafcutter  
          Started by AveryFlynn, Today, 04:57 AM
          0 responses
          6 views
          0 likes
          Last Post AveryFlynn  
          Working...
          X