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 Access OHLC and bar time from OUTSIDE OnBarUpdate in another method

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

    How to Access OHLC and bar time from OUTSIDE OnBarUpdate in another method

    I am moving to a NT Script library of methods of my own. Once I move my methods from outside of the OnBarUpdate, I can't get CurrentBar, OHLC and bar times/dates.

    Here is what I want to do:
    1. Have multiple time frames and pass to a method OHLC and bar time for the main dataseries that I have on the chart, and for the 5 min dataseries that I am addding in the strategy?
    2. I have figured out that I need to do a private DateTimeSeries to get the bar time.... and set this in OnBarUpdate.... BUT this seems inefficient and bulky. I don't think that this is the right way to do this to pass data to a method.
    3. Please advise on the best practices way to pass OHLC and bar times (the close of the bar time) to methods outside of OnBarUpdate

    private DateTimeSeries myDateTimeSeries; // Define a DateTimeSeries variable

    protectedoverridevoid Initialize()
    {
    CalculateOnBarClose =
    true;
    EntryHandling = EntryHandling.UniqueEntries;

    Add(PeriodType.Minute, 5);

    myDateTimeSeries = new DateTimeSeries(this, MaximumBarsLookBack.Infinite);
    }

    protectedoverridevoid OnBarUpdate()
    {
    // Store the current time that we will pass in to the functions for capturing the bar times
    myDateTimeSeries.Set(Time[0]);

    mynewmethod (myDateTimeSeries, <how to pass dataseries on chart for 5 min OHLC and bar time?>, <how to pass dataseries for 5 min OHLC and bar time?>

    }



    #2
    Hello,

    Thanks for the forum post.

    Unfortunately this is past the level we are able to support for NinjaScript.

    However as a hint on what I might do is that you are correct this information is only available in OnBarUpdate(). Therefor what you would have to do is build a data pass method to pass over the data to your own class/method and pass the OHLCVT as parameters.

    -Brett

    Comment


      #3
      Hi, I was hoping for a bit more guidance.

      Some better questions:
      1. When I create a chart with say IBM data on it.
      2. Where is the OHLC data stored for the default chart? - Does this dataseries contain the bar close times/dates?
      3. When I add a second dataseries for a different time frame, how do I reference that dataseries to pass to another method?
      Both of these questions should be in your scope.

      Thanks

      Comment


        #4
        Hello,

        Sure I will answer the follow up questions.

        2) Please see the following interface for this.



        You would pass the data using this interface to your helper method.


        3) You would use the same however instead of calling your own method with just Close you would want to make sure to filter with BarsInProgress with the MTF sript so you are passing the correct data.

        You may want add a secondary parameter so that you can specify the BIP so you know what data you are recieving in your own helper method.

        -Brett

        Comment


          #5
          Hi Brett, thanks for this. I am getting it, but a couple more questions please.

          1) for the default time frame on the chart - will this work?
          2) how do I reference the same data from the 5 min time frame?
          3)do I have to do anything special for the Time? or access this like Open - using the IDataSeries ?

          Thanks

          private DateTimeSeries myDateTimeSeries; // Define a DateTimeSeries variable

          protectedoverridevoid Initialize()
          {
          CalculateOnBarClose =
          true;
          EntryHandling = EntryHandling.UniqueEntries;

          Add(PeriodType.Minute, 5);

          myDateTimeSeries = new DateTimeSeries(this, MaximumBarsLookBack.Infinite);
          }

          protectedoverridevoid OnBarUpdate()
          {
          // Store the current time that we will pass in to the functions for capturing the bar times
          myDateTimeSeries.Set(Time[0]);

          // for the default time frame on the chart - will this work?
          mynewmethod (open, high, low, close, time);


          // how do I reference the same data from the 5 min time frame?
          mynewmethod (open, high, low, close, time);

          }

          public void mynewmethod (IDataSeries O, IDataSeries H, IDataSeries L, IDataSeries C, IDataSeries T)
          {

          }

          Comment


            #6
            Hello,

            Please see my code edit below.

            protectedoverridevoid OnBarUpdate()
            {
            // Store the current time that we will pass in to the functions for capturing the bar times
            myDateTimeSeries.Set(Time[0]);

            if(BarsInProgress == 0)
            {
            // This is the primary time frame
            mynewmethod (open, high, low, close, time);

            }

            if(BarsInProgress == 1)
            {
            // This is the secondary time frame
            mynewmethod (open, high, low, close, time);
            }

            }

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by wzgy0920, 04-20-2024, 06:09 PM
            2 responses
            27 views
            0 likes
            Last Post wzgy0920  
            Started by wzgy0920, 02-22-2024, 01:11 AM
            5 responses
            32 views
            0 likes
            Last Post wzgy0920  
            Started by wzgy0920, 04-23-2024, 09:53 PM
            2 responses
            74 views
            0 likes
            Last Post wzgy0920  
            Started by Kensonprib, 04-28-2021, 10:11 AM
            5 responses
            193 views
            0 likes
            Last Post Hasadafa  
            Started by GussJ, 03-04-2020, 03:11 PM
            11 responses
            3,235 views
            0 likes
            Last Post xiinteractive  
            Working...
            X