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

Strategy dies when Add()ing a secondary series

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

    Strategy dies when Add()ing a secondary series

    OK, I am probably missing something really basic, but I don't know what it is.

    I made a simple strategy consisting of one Print() statement. That's it.

    When I run the strategy on the primary series, it works fine.

    When I try to Add() a secondary series, I get nothing. OnBarUpdate() doesn't appear to execute at all. Here is the code:

    Code:
    	protected override void Initialize() {
    		Add(PeriodType.Second, 20);
    		CalculateOnBarClose = true;
    	}
    
    	protected override void OnBarUpdate() {
    		Print(CurrentBar.ToString()+" "+BarsInProgress.ToString());
    	}
    What am I missing? This started out as an actual strategy with order executions but I have cut it down to this bare-bones version and it still doesn't work when I try to add a secondary series. All I get in the output window are the usual messages about disabling and then enabling the strategy.

    -Alex

    #2
    anachronist,

    The code looks OK.

    Do you get any error messages in your log tab?

    Could you possibly try using a try/catch to print to output and see if any error messages are generated?

    Adam P.NinjaTrader Customer Service

    Comment


      #3
      The log tab shows the same messages as the Output window: Disabling the strategy, then Enabling the strategy.

      I put the Print() statement inside a try...catch block and logged the result of any error. Nothing happened. No error.
      Code:
      	protected override void Initialize() {
      		Add(PeriodType.Second, 20);
      		CalculateOnBarClose = true;
      	}
      
      	protected override void OnBarUpdate() {
      		try {
      			Print(CurrentBar.ToString()+" "+BarsInProgress.ToString());
      		} catch {
      			Log("An error occurred.", LogLevel.Error);
      		}
      	}
      As I said earlier, it works fine if I comment out the Add(). Adding a series kills it.

      -Alex

      Comment


        #4
        Anachronist,

        Who is your data provider?
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Zen-fire, through Mirus Futures.
          -Alex

          Comment


            #6
            Anachronist,

            Does this not show BarsInProgress = 1 or does it not show both 1 and 0.

            You will need to ensure you have the historical data availability on the 20 second data series. I would suggest loading a chart with this data in it going back over the time period you are looking at.
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_AdamP View Post
              Does this not show BarsInProgress = 1 or does it not show both 1 and 0.
              It shows nothing at all. It gives every appearance of OnBarUpdate() not executing.
              You will need to ensure you have the historical data availability on the 20 second data series. I would suggest loading a chart with this data in it going back over the time period you are looking at.
              Yup, that was the problem. I had the wrong contract month and didn't realize it. I could blame it on my dyslexia, but in this case it seems I clicked on the wrong instrument when setting up the chart. I apologize for the bother, and thanks for the help.

              -Alex

              Comment


                #8
                Alex,

                Its no bother, we are here to help.

                Please let us know if I may assist further.
                Adam P.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Skifree, Today, 11:47 AM
                5 responses
                19 views
                0 likes
                Last Post Skifree
                by Skifree
                 
                Started by ETFVoyageur, Today, 10:34 AM
                10 responses
                23 views
                0 likes
                Last Post ETFVoyageur  
                Started by Kraken29, Today, 03:24 PM
                0 responses
                3 views
                0 likes
                Last Post Kraken29  
                Started by traderzoso, 12-27-2020, 05:19 PM
                6 responses
                229 views
                0 likes
                Last Post lekor
                by lekor
                 
                Started by ETFVoyageur, 05-18-2024, 12:45 AM
                4 responses
                27 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Working...
                X