Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Custom Tick Counter works on Historical but Fails in Realtime

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

    Custom Tick Counter works on Historical but Fails in Realtime

    Hi,
    Hoping to ask for some help please. My strategy runs on Calculate.OnEachTick, 30 Second bars as the primary dataseries, but has a secondary dataseries of ticks (AddDataSeries(BarsPeriodType.Tick, 1)). I use the following code to keep track of how many ticks were present in each 30 second bar, and store this in a new series (myTickCountSeries):

    Code:
    if (BarsInProgress == 1)
    {
    tick_countNow++; //increment the counter
    }
    if (BarsInProgress == 0)
    {
    myTickCountSeries[0] = tick_countNow-tick_countPrior;
    tick_countPrior = tick_countNow;
    }
    For historical backtests this works absolutely fine, however once I go into realtime the myTickCountSeries[0] values always equal 1 and I'm struggling to figure out why this happens in realtime, and hoping for some advice/guidance please. I was hunting around in the guides to lookup how the ticks are processed differently in realtime and historical but was struggling to find the guide (apologies - my search foo is failing me).

    Many thanks in advance

    ChainsawDR

    #2
    Hello ChainsawDR,

    You may need to do something similar to how the BuySellVolume works, that uses the first tick of each bar to do the plotting/accumulation logic. That would be similar as it uses OnMarketData to accumulate and OnBarUpdate for plotting to the primary.

    This would otherwise be a situation where you would need to use Prints to output what specifically is happening and where the 1 is coming from. Tracking that down could help to see what the solution would be.

    Comment


      #3
      Thanks Jesse. I've used prints and seeing some unexpected behavior (at least at first, as I think about it more it seems logical if I'm understanding this correctly). The attached screenshot of the print output shows the before and after of the system going from historical to realtime. I set a print statement within OnBarUpdate and you can see that when the system is processing historical data that my primary 10second Bars (BarsInProgress 0) only prints every 10 seconds, while my tick dataseries (BarsInProgress 1) prints after every tick. However once realtime begins the primary 10 second series (barsinprogress0) starts to get called after each and every tick (it switches to 0,1,0,1,0,1,0,1 etc). Not sure if I'm explaining that well.

      At a high level, would I be correct in thinking that OnBarUpdate, when processing historical data (and not using tick replay) doesn't need to bother updating the 10 sec bars after each tick and so it just processes every 10 seconds, but when in realtime mode it does need to update the primary 10 sec bar after each tick (and so an OnBarUpdate call for a tick will automatically prompt an additional OnBarUpdate call for the 10sec bar)?

      Thanks again

      ChainsawDR
      Attached Files

      Comment


        #4
        Update: Adding the logic from the BuySellVolume indicator that you recommended looks to have done the trick - thanks Jesse!

        Code:
        if (BarsInProgress == 0 && CurrentBar != activeBar)
        {
        myTickCountSeries[0] = tick_countNow-tick_countPrior;
        tick_countPrior = tick_countNow;
        activeBar = CurrentBar;

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        63 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        139 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        75 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        45 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        50 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X