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

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 tradingnasdaqprueba, Yesterday, 03:42 AM
      10 responses
      37 views
      0 likes
      Last Post tradingnasdaqprueba  
      Started by Boyarchuk, Today, 05:39 AM
      0 responses
      4 views
      0 likes
      Last Post Boyarchuk  
      Started by Orion815, 05-02-2024, 08:39 AM
      3 responses
      21 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by frenkmly, Today, 04:49 AM
      0 responses
      5 views
      0 likes
      Last Post frenkmly  
      Started by ETFVoyageur, Yesterday, 07:05 PM
      2 responses
      20 views
      0 likes
      Last Post bltdavid  
      Working...
      X