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 NullPointStrategies, Yesterday, 05:17 AM
                0 responses
                76 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                146 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                79 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                50 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                54 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X