Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi-Series using BarsInProgress doesn't working

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

    Multi-Series using BarsInProgress doesn't working

    Hello, support

    I wrote the following code:

    Code:
    protected override void OnStateChange()
    {
               ...
               ...
                else if (State == State.Configure)
                {
                    AddDataSeries(string.Format("{0}",this.Instrument), BarsPeriodType.Second, 10);
                    nGestBar++;                
                }
    }
    
    &&
    
            protected override void OnBarUpdate()
            {    
                if (CurrentBars[0] < (BarsRequiredToTrade+MaxBars))
                 return;
                Print(string.Format("BarsInProgress= {0} - Time[{0}] = {1}", BarsInProgress,Time[BarsInProgress]));
                if (BarsInProgress == nGestBar)
                {
                    Print(string.Format("Time[{0}] = {1}", nGestBar,Time[nGestBar]));
                    GestionTrade(nGestBar);
                }
    
                if (BarsInProgress != 0) 
                 return;
    My primary series is 5 min,

    The output is :

    BarsInProgress= 0 - Time[0] = 4/12/2018 01:00:00
    BarsInProgress= 0 - Time[0] = 4/12/2018 01:05:00
    BarsInProgress= 0 - Time[0] = 4/12/2018 01:10:00
    BarsInProgress= 0 - Time[0] = 4/12/2018 01:15:00
    BarsInProgress= 0 - Time[0] = 4/12/2018 01:20:00
    BarsInProgress= 0 - Time[0] = 4/12/2018 01:25:00
    BarsInProgress= 0 - Time[0] = 4/12/2018 01:30:00
    BarsInProgress= 0 - Time[0] = 4/12/2018 01:35:00
    BarsInProgress= 0 - Time[0] = 4/12/2018 01:40:00
    BarsInProgress= 0 - Time[0] = 4/12/2018 01:45:00
    BarsInProgress= 0 - Time[0] = 4/12/2018 01:50:00


    What I'm doing wrong?

    Thanks

    #2
    Hello mbcito,

    Thank you for your post.

    Your prints are exactly what I would expect to see from your code if you didn't have an additional data series.

    What are you trying to achieve here? You're returning out of OnBarUpdate if Bars in Progress doesn't equal 0, but your prints are above that, so if your additional data series is working properly I'd expect to also see prints from that, which I'm not seeing there.

    Try using this instead to add the secondary data series:

    AddDataSeries(null, BarsPeriodType.Second, 10);

    Passing it null as the instrument name will default it to the primary data series' instrument.

    Thanks in advance; I look forward to assisting you further.

    Comment


      #3
      Hello Kate,

      I am trying to execute GestionTrade (nGestBar), if: BarInProgress = nGestBar = 1 , in this case, but it not happens.


      Your prints are exactly what I would expect to see from your code if you didn't have an additional data series.
      I'm adding secondary dataseries in OnStateChange() ( see coded text in first message ).


      Thanks a lot!!!

      Best Regards
      Mariano

      Comment


        #4
        Hello Mariano,

        Thank you for your reply.

        Please try this from my initial reply, then test. Do you see the expected prints for the secondary data series?

        Originally posted by NinjaTrader_Kate View Post
        Try using this instead to add the secondary data series:

        AddDataSeries(null, BarsPeriodType.Second, 10);

        Passing it null as the instrument name will default it to the primary data series' instrument.
        Thanks in advance; I look forward to assisting you further.

        Comment


          #5
          Hello Mariano,

          Thank you for your patience.

          Were you able to resolve the issue? I believe you aren't seeing prints for the secondary series because you aren't adding it correctly. Here's a really simplified example of how I would add a secondary series of the same instrument and then have it print the time and Bars in Progress:

          Code:
              public class Example10SecSeries : Strategy
              {
                  protected override void OnStateChange()
                  {
                      if (State == State.SetDefaults)
                      {
                          Description                                    = @"Enter the description for your new custom Strategy here.";
                          Name                                        = "Example10SecSeries";
                          Calculate                                    = Calculate.OnBarClose;
                          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)
                      {
                          AddDataSeries(Data.BarsPeriodType.Second, 10);
                      }
                  }
          
                  protected override void OnBarUpdate()
                  {
                      Print(string.Format("BarsInProgress= {0} - Times[{0}][0] = {1}", BarsInProgress,Times[BarsInProgress][0]));
                  }
              }
          Give that a try - you should see prints for each bar of each series.

          Please let us know if we may be of further assistance to you.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          38 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          124 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          64 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          41 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          46 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X