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

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.
    Kate W.NinjaTrader Customer Service

    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.
        Kate W.NinjaTrader Customer Service

        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.
          Kate W.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by junkone, Today, 11:37 AM
          2 responses
          15 views
          0 likes
          Last Post junkone
          by junkone
           
          Started by frankthearm, Yesterday, 09:08 AM
          12 responses
          44 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by quantismo, 04-17-2024, 05:13 PM
          5 responses
          35 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by proptrade13, Today, 11:06 AM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by love2code2trade, 04-17-2024, 01:45 PM
          4 responses
          36 views
          0 likes
          Last Post love2code2trade  
          Working...
          X