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 get value for first bar of the trading session

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

    How to get value for first bar of the trading session

    I'm using 5 mins bar. I want to know what is the delta between the current bar close and the first bar close. I could use previous day close but it's not accurate due to gap at the open.

    In addition, I'm using this:
    double maxClose = MAX(Close, 10)[0];

    How can I use only the bars from today, not yesterday if it's early in the session like the first 15 mins of the session ? Thanks.

    #2
    Hello,

    Thanks for your note and welcome to the NinjaTrader forums!

    If you run this on the same type of chart you can count the number of bars back that would be everyday and use Open[x] in your code would be the simple way. But then you have to change this variable if you change the chart your running this on, not ideal in this case.



    Or you use FirstBarOfSession, Run a check for FirstBarOfSession, if it is the first bar of session then set a temporary variable to the Open[0] price. Then you can reference this price later in your code.

    You can also use the FirstBarOfSession to restart a counter variable to 0. Then for your maxClose variable check to see if this counter variable is equal to 10, If it is then run the MAX code. Then in each OnBarUpdate() you would iterate this counter + 1 each time or counter++.

    Theres always multiple ways to do something in coding this is simply what I may do in this situation.

    Let me know if I can be of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Gerik, Today, 09:40 AM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by RookieTrader, Today, 09:37 AM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by alifarahani, Today, 09:40 AM
    0 responses
    5 views
    0 likes
    Last Post alifarahani  
    Started by KennyK, 05-29-2017, 02:02 AM
    3 responses
    1,285 views
    0 likes
    Last Post NinjaTrader_Clayton  
    Started by AttiM, 02-14-2024, 05:20 PM
    11 responses
    186 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Working...
    X