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

Wanted to check multiple stocks previous bars for a specific time C# class

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

    Wanted to check multiple stocks previous bars for a specific time C# class

    Hi, Can you please let me know how I can get the candles details like high, low and volume for past 4 to 5 candles in strategy class to create my own strategy.
    Also I want to if there is any event which triggers after every minute only to check my logic.
    Also I wanted to get previous bars(including details like high, low, volume) for multiple stocks using symbol name.
    How can I write such logic in my C# strategy class.

    #2
    Hello rajeshks1988,

    Thank you for your post.

    You are able to get the High, Low, and Volume information for previous bars by using High[barsAgo], Low[barsAgo], and Volume[barsAgo]. The barsAgo value represents the number of bars ago to reference. For example, High[0] would get the value of the current bar High. High[1] would get the High value 1 bar ago. High[2] would get the High value 2 bars ago, and so on.

    See the Working with Price Series help guide documentation below for more information about getting the High, Low, and Volume of previous bars.


    To have your strategy calculate logic in 1-minute intervals, you would need to set the Primary Data Series to use a 1-minute interval and a Calculate mode of OnBarClose. This causes the OnBarUpdate() method of your strategy to calculate your logic in 1-minute intervals at the close of the bar.

    See the help guide documentation below for more information.
    OnBarUpdate() - https://ninjatrader.com/support/help...nbarupdate.htm
    Calculate - https://ninjatrader.com/support/help.../calculate.htm

    You may get information about multiple stocks by adding the instruments to your strategy using AddDataSeries() in State.Configure. AddDataSeries() adds a Bars object for developing a multi-series (multi-time frame or multi-instrument) script. The added instruments would be referred to using a BarsInProgress check. In a multi-bars script, the OnBarUpdate() method is called for each Bars object of a script. BarsInProgress allows you to check which data series is processing and separate your logic between instruments. Then, in the BarsInProgress check you could print the High, Low, and Volume information for that data series. Or, you could call something like Highs[1][0] which would get the current High value of the first added data series.

    See the help guide documentation below for more information.
    AddDataSeries() - https://ninjatrader.com/support/help...dataseries.htm
    BarsInProgress - https://ninjatrader.com/support/help...inprogress.htm
    MultiTimeframe and MultiInstruments - https://ninjatrader.com/support/help...nstruments.htm
    Accessing Price Data in a MultiBars Script - https://ninjatrader.com/support/help...arsninjascript

    Also, see the SampleMultiTimeFrame and SampleMultiInstrument scripts that come default with NinjaTrader. These scripts demonstrate how to use multiple instruments or time frames within a strategy. The scripts would be viewed in a New > NinjaScript Editor window. After opening the NinjaScript Editor, open the Strategies folder, then select the strategy to view its code.

    Please let us know if we may assist further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Hi Thanks for your quick reply.

      Comment


        #4
        Hi,
        As you said when I add new 1 min data series in 5 mins candles chart as per your comment as "To have your strategy calculate logic in 1-minute intervals, you would need to set the Primary Data Series to use a 1-minute interval and a Calculate mode of OnBarClose. This causes the OnBarUpdate() method of your strategy to calculate your logic in 1-minute intervals at the close of the bar."

        When I receive 1 min candle close signal, the candle values are also pertaining to 1 mins only which I do not want, but I would like to check 5 mins high, low values using High[0[, Low[0] but here I get values pertaining to 1 min candle.

        So I how can I get 5 mins candle details even when 1 min data series is triggered?

        Comment


          #5
          Hello rajeshks1988,

          Thank you for your note.

          To clarify, is your primary data series set to 1-minute or 5-minutes? The interval being used by the data series that your indicator/strategy is enabled on will be the strategy's primary data series. For example, if you enable your strategy on a 5-minute ES 03-21 chart, this 5-minute series will be the primary data series used by your script.

          If you would like your indicator/strategy to calculate logic in 1-minute intervals, the primary data series would need to be set to a 1-minute data series, and the indicator/strategy would need to use a Calculate mode of OnBarClose. This would mean that the logic of your script would fire on the close of the 1-minute bar. Since you have your logic calculating on the close of the 1-minute bar, the price values (OHLC) would be based on the 1-minute primary data series as well.

          To get price information for a 5-minute series, you would need to use AddDataSeries() to add a secondary 5-minute series to your script. Then, you could use Highs[1][0] and Lows[1][0] to get the current High and Low price information pertaining to the 5-minute added series.

          Please see the help guide documentation for more information.

          AddDataSeries() - https://ninjatrader.com/support/help...dataseries.htm
          Highs - https://ninjatrader.com/support/help.../nt8/highs.htm
          Lows - https://ninjatrader.com/support/helpGuides/nt8/lows.htm

          Also, please see the attached example script that demonstrates adding a 5-minute secondary series and printing the High and Low price values based on that series. To test this script, you would add the indicator to a 1-minute chart. After adding the indicator to a 1-minute series, we observe the prints in the New > NinjaScript Output window and see values printing based on the added 5-minute secondary series.

          Let us know if we may assist further.




          Attached Files
          Brandon H.NinjaTrader Customer Service

          Comment


            #6
            Ok thank you so much, but at last I am unable to get exact yesterday Open, close, low and high data using Indicator PriorDayOHLC().PriorClose[0]
            Can you please suggest how I can get accurate previous Day high/low/close/open data.
            I think especially close data is not matching rest are at least near by data.

            Comment


              #7
              Hello rajeshks1988,

              Thank you for your note.

              The Strategy Builder could be used to see how to print the Open, High, Low, and Close using the PriorDayOHLC indicator. In the Strategy Builder, navigate to the Conditions and Actions section. In the Actions section click 'add'. Select Misc > Print. Hover over the Message section and click 'set'. Select 'set' again > click Indicators > choose the Prior Day OHLC indicator. Choose the value plot you would like to see (OHLC). Click OK. Click OK again. And, click OK a third time. Next, select the 'View Code' button to see the code used to generate the Prior Day OHLC print.

              Please let us know if we may assist further.
              Brandon H.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by jclose, Today, 09:37 PM
              0 responses
              5 views
              0 likes
              Last Post jclose
              by jclose
               
              Started by WeyldFalcon, 08-07-2020, 06:13 AM
              10 responses
              1,414 views
              0 likes
              Last Post Traderontheroad  
              Started by firefoxforum12, Today, 08:53 PM
              0 responses
              11 views
              0 likes
              Last Post firefoxforum12  
              Started by stafe, Today, 08:34 PM
              0 responses
              11 views
              0 likes
              Last Post stafe
              by stafe
               
              Started by sastrades, 01-31-2024, 10:19 PM
              11 responses
              169 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Working...
              X