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

Checking MAX over the day session

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

    Checking MAX over the day session

    I've been using SMA, MAX, MIN, SUM to try to get a result I'm looking for. It's not working, so here's my question:

    If my formula calculates a max value of 10 for a bar (after the 8:30 day session start), is there a way to signal if I get a value >= 10 for a subsequent bar? Regardless of how many bars later the next bar that signals 10 occurs?

    In other words, is there a way to look back all the way to the opening of the day session--8:30am--to see if my current bar's value is >= the max value calculated (which happened to be 10 in my example)?

    SMA, MAX, MIN, SUM use a period that trails the market. I want that period to always go back to the start of the day session. (Or, I want that period to always go back to the same bar.)

    I hope I'm being clear.

    Is there a way to do this?

    Thank you for the help.

    #2
    Hello imalil,

    You can use a for loop from 0 to CurrentBar minus 1 to loop through all of the bars.
    Code:
    for (int index = 0; index < CurrentBar - 1; ++index)
    {
    Print(Time[index]);
    }
    You could save the bar number of the first bar of the session and then loop back to CurrentBar minus that bar number (to get a barsAgo number).

    Below is a public link to a 3rd party educational site on for loops.
    Iterate over numbers with for. Increment or decrement an index int from a start to an end value.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks for this. Couple questions:

      what state do I use this? This is all new to me.

      When you say "You could save the bar number of the first bar of the session and then loop back to CurrentBar minus that bar number (to get a barsAgo number)." This is what I want but I don't know how to do it. Could you give an example?

      Thank you.

      Comment


        #4
        imalil,

        You would use Chelsea's sample inside OnBarUpdate() and you could save the first bar of the session and convert it to a BarsAgo value by doing something similar to the following.

        Code:
        private int firstBar, barsAgoValue;
        protected override void OnBarUpdate()
        {            
            if(Bars.IsFirstBarOfSession)
                firstBar = CurrentBar;
            barsAgoValue= CurrentBar-firstBar;
        }
        You could also just use BarsSinceNewTradingDay to get the BarsAgo of the new trading day.
        Josh G.NinjaTrader Customer Service

        Comment


          #5
          Thank you, I'll work on this.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by arvidvanstaey, Today, 02:19 PM
          4 responses
          11 views
          0 likes
          Last Post arvidvanstaey  
          Started by samish18, 04-17-2024, 08:57 AM
          16 responses
          57 views
          0 likes
          Last Post samish18  
          Started by jordanq2, Today, 03:10 PM
          2 responses
          9 views
          0 likes
          Last Post jordanq2  
          Started by traderqz, Today, 12:06 AM
          10 responses
          18 views
          0 likes
          Last Post traderqz  
          Started by algospoke, 04-17-2024, 06:40 PM
          5 responses
          47 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X