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

Calculate High/Low of the day and the bar number

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

    Calculate High/Low of the day and the bar number

    Hello,

    I'm trying to develop a simple script, using the StreamWriter. The main objective is to have the high/low of the day and the bar number that made it.

    Example:
    I am working with a 30min candlestick RTH chart.
    For the very first candle, the price goes down. For the second bar, the price keeps going down but reverses, deploys the daily low and starts going long for the rest of the session. The daily low occurred in the second session's candle.

    I would like to have the daily low and the bar number in which it occurred. Same thing in the opposite direction, so i would need, in a 30' candlestick with the last year's trading sessions loaded:

    TRADING DAY(date) - DAILY HIGH - BAR NR(daily high) - DAILY LOW - BAR NR(daily low)

    My main problem is that i cannot understand how to work with different bars (30min candlesticks in this case) within days. If i work over a daily chart, i have no problems exporting H/L of all the bars, but when i have to work within days and the bars in these trading days, things get way more complicated.

    Any help will be appreciated.
    Thank you in advance!

    Regards,
    Diego.


    Edit: Also, i'm a new member of this forum. If this topic does not belong here or whatever, please let me know.
    Last edited by dinest93; 06-14-2024, 03:05 AM.

    #2
    Hello dinest93,

    Welcome to the NinjaTrader forums!

    First up, below is a link to the reference sample demonstrating using a C# StreamWriter.


    You can use a condition to set an int variable when a new high is made and reset this to 0 when Bars.IsFirstBarOfSession is true.

    private int highestBarThisSession;

    In OnBarUpdate():
    if (Bars.IsFirstBarOfSession)
    {
    highestBarThisSession = -1;
    }

    if (highestBarThisSession > -1 && High[0] > High[CurrentBar - highestBarThisSession])
    {
    highestBarThisSession = CurrentBar;
    }

    At the end of the session you could write the Time[CurrentBar - highestBarThisSession] and High[CurrentBar - highestBarThisSession] to file.
    A SessionIterator can be used to get the close time of the session.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you, NinjaTrader_ChelseaB.

      Today i have a little time to test this tips out. Let's see what happens.

      Regards,
      Diego

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by yertle, Today, 12:24 PM
      0 responses
      2 views
      0 likes
      Last Post yertle
      by yertle
       
      Started by reekotubbs, Yesterday, 01:09 PM
      3 responses
      26 views
      0 likes
      Last Post reekotubbs  
      Started by Blaze212, 07-07-2024, 08:58 PM
      2 responses
      18 views
      0 likes
      Last Post Blaze212  
      Started by medicmiked, Today, 11:56 AM
      0 responses
      2 views
      0 likes
      Last Post medicmiked  
      Started by miaolivi9, Today, 06:59 AM
      0 responses
      8 views
      0 likes
      Last Post miaolivi9  
      Working...
      X