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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      80 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      40 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      63 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      63 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      54 views
      0 likes
      Last Post CarlTrading  
      Working...
      X