Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsInProgress Issue

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

    BarsInProgress Issue

    Hello,

    I'm trying to use a multi-bar series but I keep getting the "You must use the overload that has 'BarsInProgress' parameter" error when I try to execute the code. It looks like this:

    protected override void Initialize()
    {
    CalculateOnBarClose = true;
    Add("XXX", PeriodType.Day,1);
    }

    protected override void OnBarUpdate()
    {
    // Only run on real-time data
    if (addHistoricalData==false)
    {
    if (Historical == true)
    {
    return;
    }
    }

    if (CrossBelow(XXXX, XXXX))
    {
    if (BarsSinceEntry("Trade") > XXX)
    {
    EnterLong(1, DefaultQuantity, "Long");
    }
    }

    if (BarsSinceEntry() >= XXXX)
    {
    ExitLong(1, "BarsExit", "Long");
    }
    }

    Where do I need to add the BarsInProgress? If I want the first bars object (0) as the signal but then trade the second bars object (1), what do I need to do when I'm using the BarsSinceEntry/Exit?

    Thank you,

    Regards,

    Lee

    #2
    Hello lee612801,

    Thank you for your post.

    Add if(BarsInProgress == 0) and wrap your conditions in the brackets (as seen below). For the BarsSinceEntry, you would use BarsSinceEntry(int barsInProgressIndex, string signalName, int entriesAgo) .

    For example:
    Code:
    protected override void OnBarUpdate()
    { 
    // Only run on real-time data
    if (addHistoricalData==false)
    {
    if (Historical == true)
    {
    return;
    }
    }
    
    if(BarsInProgress == 0) // check conditions on primary bar series
    {
    if (CrossBelow(XXXX, XXXX))
    {	
    if (BarsSinceEntry(0, "Trade", 0) > XXX)
    { 
    EnterLong(1, DefaultQuantity, "Long");
    }
    }
    
    if (BarsSinceEntry(0, "Trade", 0) >= XXXX)	
    {
    ExitLong(1, "BarsExit", "Long");
    }
    }
    }
    I recommend reviewing the documentation on using multiple time frames or instruments in your code at the following link: http://www.ninjatrader.com/support/h...nstruments.htm

    Please let me know if you have any questions.

    Comment


      #3
      Hi Patrick,

      Thank you for your help. I got it to work with your code but I had to remove the initial if(BarsInProgress == 0) and change the BarsSinceEntry to (BarsSinceEntry(1, "Trade", 0). Not sure exactly why this is the case, but its not working!

      Thank you so much for the prompt response and solution.

      Regards,

      Lee

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      571 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      330 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      549 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      549 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X