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

How to find out what instrument triggers the OnBarUpdate event

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

    How to find out what instrument triggers the OnBarUpdate event

    Hi,

    I'm adding 2 data series with the AddDataSeries method. The first one has hour bars. The second one has minutes bars.

    I understand the OnBarUpdate event is triggered on each bar completion of each data series (Please tell me if I'm wrong). I calculate that this event is triggered 121 times in my case since the instrument that I select in the UI has minute bars.

    I am wondering how to test if the OnBarUpdate event is triggered by the UI selected instrument (and not by the additional time series)

    Thanks

    #2
    You can use Instrument.MasterInstrument.Name to identify the instrument. Add it to an if statement, or print statement

    Print("Instrument: " + Instrument.MasterInstrument.Name);

    You can also use BarsPeriodType and BarsPeriod.Value to identify the period and period type. Use the Help on these for further info.

    Ian
    Last edited by IanC28; 01-13-2019, 02:55 PM.

    Comment


      #3
      Hello Vincere,

      OnBarUpdate will trigger for each bar for all series added to the script. The BarsInProgress value will be the index of the bar series that is currently being processed in OnBarUpdate.



      Ian is correct in that you can print the Instrument (I would suggest Instrument.FullName).


      The primary series (BarsInProgress 0) will always be the data series on the chart, or selected in the Data Series properties when adding a script to the Strategies tab of the Control Center or when backtesting.
      OnBarUpdate doesn't begin processing until all series have data.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Thanks for the quick response.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by ezrollin, 02-26-2022, 11:14 PM
        7 responses
        207 views
        0 likes
        Last Post kenz987
        by kenz987
         
        Started by rocketman7, Today, 08:34 PM
        0 responses
        4 views
        0 likes
        Last Post rocketman7  
        Started by rt61968, 02-17-2018, 05:24 PM
        3 responses
        2,736 views
        0 likes
        Last Post MasterEtrad3  
        Started by nuobo, Today, 07:43 PM
        0 responses
        5 views
        0 likes
        Last Post nuobo
        by nuobo
         
        Started by ETFVoyageur, Today, 02:04 PM
        3 responses
        23 views
        0 likes
        Last Post ETFVoyageur  
        Working...
        X