Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

AddDataSeries for "intra" candle backtesting doesn't seem to work

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

    AddDataSeries for "intra" candle backtesting doesn't seem to work

    I'm trying to get the intra candle to fill during backtesting to update my stoploss, but it doesn't seem to work. I'm assuming that BarsInProgress == 2 should print, but it doesn't.

    Code:
    else if (State == State.Configure)
    {
    AddVolumetric(Instrument.FullName, BarsPeriodType.Range, Range, VolumetricDeltaType.BidAsk, 1);
    
    AddDataSeries(Instrument.FullName, BarsPeriodType.Tick, 1);
    }
    
    
    if (BarsInProgress == 2)
    {
    Print("In tick ");
    // Update Stop
    }

    #2
    Does your data provider allow tick data? For example IB and TD don't provide historical tick data.
    I build useful software systems for financial markets
    Generate automated strategies in NinjaTrader : www.stratgen.io

    Comment


      #3
      I downloaded the historical tick data and it shows the tick data in the Historical Data section.

      Comment


        #4
        Originally posted by tonystarks View Post
        I downloaded the historical tick data and it shows the tick data in the Historical Data section.
        Ok, and I'm assuming your if (BarsInProgress == 2) is in OnBarUpdate? Don't think it works in OnStateChange.
        I build useful software systems for financial markets
        Generate automated strategies in NinjaTrader : www.stratgen.io

        Comment


          #5
          Hi Tony, we also have an example of this here that you can try out.


          If this does not work, it means it's failing to grab the historical 1 tick data and we would need to look into that.

          Kind regards,
          -ChrisL

          Comment


            #6
            It seems that having AddVolumetric does not work with the second data series. Having two AddDataSeries works, but for some reason having AddVolumetric first does not show anything from the AddDataSeries below it.

            Code:
            //This namespace holds Strategies in this folder and is required. Do not change it.
            namespace NinjaTrader.NinjaScript.Strategies
            {
              public class WIP : Strategy
              {
                protected override void OnStateChange()
                {
                  if (State == State.SetDefaults)
                  {
                    Description = @"Enter the description for your new custom Strategy here.";
                    Name = "WIP";
                    Calculate = Calculate.OnEachTick;
                    EntriesPerDirection = 1;
                    EntryHandling = EntryHandling.AllEntries;
                    IsExitOnSessionCloseStrategy = true;
                    ExitOnSessionCloseSeconds = 30;
                    IsFillLimitOnTouch = false;
                    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
                    OrderFillResolution = OrderFillResolution.Standard;
                    Slippage = 0;
                    StartBehavior = StartBehavior.WaitUntilFlat;
                    TimeInForce = TimeInForce.Gtc;
                    TraceOrders = false;
                    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
                    StopTargetHandling = StopTargetHandling.PerEntryExecution;
                    BarsRequiredToTrade = 20;
                    // Disable this property for performance gains in Strategy Analyzer optimizations
                    // See the Help Guide for additional information
                    IsInstantiatedOnEachOptimizationIteration = true;
                  }
                  else if (State == State.Configure)
                  {
                    // Does not work
                    AddVolumetric(Instrument.FullName, BarsPeriodType.Range, 15, VolumetricDeltaType.BidAsk, 1);
                    AddDataSeries(Instrument.FullName, BarsPeriodType.Tick, 1);
            
                    // Works
                    //AddDataSeries(BarsPeriodType.Minute, 5);
                    //AddDataSeries(Instrument.FullName, BarsPeriodType.Tick, 100);
                  }
                }
            
                protected override void OnBarUpdate()
                {
                  if (CurrentBars[2] < BarsRequiredToTrade)
                  return;
            
                  Print(BarsInProgress);
                }
              }
            }

            Comment


              #7
              I found out that using "BarsPeriodType.Tick, 1" doesn't work. It seems that using 2 or more works "BarsPeriodType.Tick, 2".

              Comment


                #8
                Hi Tony, If you can pull up a 1 tick chart it should be working properly. If you can pull up a 2 tick chart it means you do have historical tick data with your data feed. Please test by pulling up a 1 tick chart first. Please also let me know what data feed you are using.

                Kind regards,
                -ChrisL

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Mindset, 04-21-2026, 06:46 AM
                0 responses
                93 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by M4ndoo, 04-20-2026, 05:21 PM
                0 responses
                138 views
                0 likes
                Last Post M4ndoo
                by M4ndoo
                 
                Started by M4ndoo, 04-19-2026, 05:54 PM
                0 responses
                68 views
                0 likes
                Last Post M4ndoo
                by M4ndoo
                 
                Started by cmoran13, 04-16-2026, 01:02 PM
                0 responses
                123 views
                0 likes
                Last Post cmoran13  
                Started by PaulMohn, 04-10-2026, 11:11 AM
                0 responses
                73 views
                0 likes
                Last Post PaulMohn  
                Working...
                X