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

Clarification on Accessing Forming Bar's Open Price in Multi-Timeframe Strategy

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

    Clarification on Accessing Forming Bar's Open Price in Multi-Timeframe Strategy

    Hello,

    I'm developing a strategy that involves working with two timeframes: a primary 5-minute chart and a secondary series based on 1-tick data. My intention is to analyze the behavior of the market on a tick-by-tick basis within the context of the larger 5-minute timeframe, specifically focusing on the open price of the currently forming bar in real-time.

    Given this setup, I have a question regarding the expected behavior of accessing the open price of the current, in-progress bar using the 1-tick data series. Here's the core of the issue:

    In the scenario where the main timeframe is 5 minutes and the secondary timeframe is 1 tick, when I attempt to access the open price of the current bar (which is still forming) using Opens[0][0] within the context of the tick data series, my expectation is that this would return the open price of the currently forming bar. However, I'm unclear if this is the correct expectation or if my understanding of how to access this data is incorrect.

    Could you please provide clarification on whether Opens[0][0] should indeed give me the open price of the latest, currently forming bar in the tick data series, even before the bar has completed? If not, could you advise on the correct approach to access this information in real-time, especially in a multi-timeframe setup where the finer granularity of tick data is crucial for decision-making?

    Thank you for your time and assistance. Your insights will be invaluable in ensuring the accuracy and effectiveness of my strategy.

    #2
    Hello Aviram Y,

    Thank you for your post.

    When you say you are attempting to access the open price of the current bar within the context of the tick series, are you using BarsInProgress to check which series is currently being updated in OnBarUpdate()?

    if (BarsInProgress == 0) //primary 5 min data series
    {

    }

    if (BarsInProgress == 1) //secondary
    {
    // logic that needs calculated at the frequency of 1 tick
    }



    This also depends on your Calculate setting. While OnBarUpdate() method is called for every bar update event for each Bars object added to the script, the Calculate setting determines how it is called.

    For example, if you are using Calculate.OnBarClose, AddDataSeries() will add the secondary Tick series to the script which will calculate at the close of each bar.



    Calculate.OnBarClose, in live/replay data, [0] is the latest just closed bar, your script will run once at the end of the bar, the script does not know of the currently forming bar until it closes and the index [0] shifts to the just closed bar, the previously closed bar would now be [1].​

    Please let me know if you have any further questions. ​
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      I see, firstly i do look at the BarsInProgress and call a method to check for entry signals on BarsInProgress 1, but the calculation is OnBarClose, im assuming this is why it doesn't recognize the currently forming bar when calling Opens[0][0] since it hasn't completed yet as you've mentioned.
      The biggest issue i have with Calculate.OnEachTick or OnPriceChange is that i use the OnBarClose to determine how many bars passed since i entered a limit order on the main timeframe or secondary time frames for example, or how many bars passed since i entered a position in order to advance stop loss and limit orders i connected to that position.

      if you have any suggestions regarding getting the new forming bar values (for example the ohlc values) while calling it from the secondary time frame while leaving the functionality i mentioned above intact that would be great!

      this is important because on of the entry conditions is comparing the open and close values of that bar to a support range, to see if it crossed below that specific range, and the way i do it is by using a foreach loop to get each of the drawings on the chart, then look for the specific drawings that are support ranges and determine which is the correct one to look at using various calculations such as if the open of the bar is above the lower range and the close is below it in this case.

      Comment


        #4
        Hello,

        The only way to access the currently forming bar would be to use OnPriceChange or OnEachTick as the Calculation mode.

        You can use BarsSinceEntryExecution to get the number of bars that have elapsed since the last entry.



        Here is also a sample script demonstrating running some logic once per bar and running other logic on every single tick in a strategy that uses Calculate.OnEachTick.



        Please let me know if I can assist further.
        Gaby V.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by rhyminkevin, Yesterday, 04:58 PM
        5 responses
        62 views
        0 likes
        Last Post dp8282
        by dp8282
         
        Started by realblubb, Today, 09:28 AM
        0 responses
        2 views
        0 likes
        Last Post realblubb  
        Started by AaronKoRn, Yesterday, 09:49 PM
        1 response
        18 views
        0 likes
        Last Post Rikazkhan007  
        Started by ageeholdings, Today, 07:43 AM
        0 responses
        12 views
        0 likes
        Last Post ageeholdings  
        Started by pibrew, Today, 06:37 AM
        0 responses
        4 views
        0 likes
        Last Post pibrew
        by pibrew
         
        Working...
        X