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

Determine if Candle Boundary is Higher Timeframe Boundary?

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

    Determine if Candle Boundary is Higher Timeframe Boundary?

    Hello all!

    I'm sure I'm overlooking something quite simple and obvious, but I'm wondering if there is an easy/elegant way to determine if a lower timeframe's candle close time is also the closing time of a specified higher timeframe's candle.

    For example, lets say I'm viewing an indicator on the m5 and the candle closes at 15:00. What I'm trying to accomplish is this:

    Code:
        if (Time[0] == IsAlsoH3CloseTime())
        {
            [COLOR="DarkGreen"]// Do Something[/COLOR]
        }
    Obviously, the "H3/m180" value could change depending on my needs. I currently have a big switch statement for the various possible close time hours for each higher timeframe, but this approach is certainly NOT elegant.

    Anyone have a better solution?

    #2
    Hello MarkWise,

    If you have a switch that would generally be the more elegant way of a branching statement instead of a bunch of if/else statements. What specifically are you trying to do, reduce the amount of syntax used?

    If you have syntax that each switch body uses that is identical to the other switch statements, likely you can replace that logic with a method. Outside of that change, there is not really much else I could suggest as you are just comparing times which == works for.

    If you can provide a more detailed sample of what you have and what you are trying to change, perhaps there would be other areas to explore with that syntax. In what has been provided I could only see that making the if statement into a method that accepts a time and returns a bool as the only reduction here.

    Please let me know if I may be of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi Jesse.

      I'm creating a candle aggregator so that when viewing a lower timeframe, I can create/aggregate candles for a higher timeframe. I need this for a strategy I'm building.

      So back to my example, if I'm viewing/running on the m5 series and I want to aggregate candles for m180 I was trying to come up with a slick way to determine when a m5 candle close time coincides with the m180 close time. I ended up with the following:

      Code:
      [FONT="Courier New"]                case 180:   // H3 
                              // 9pm UTC == 3pm MST == 5pm EST
                              inUTC = timeStamp.ToUniversalTime();
                              hour = inUTC.Hour;
      
                              switch (hour)
                              {
                                  case 0:     // 6a MST
                                      return true;
                                  case 3:     // 9a MST
                                      return true;
                                  case 6:     // 12a MST
                                      return true;
                                  case 9:     // 3a MST
                                      return true;
                                  case 12:    // 6a MST
                                      return true;
                                  case 15:    // 9a MST
                                      return true;
                                  case 18:    // 12p MST
                                      return true;
                                  case 21:    // 15p MST
                                      return true;
                                  default:
                                      return false;
                              }
      [/FONT]
      where "180" is the higher time series candle interval in minutes, and the "timeStamp" is the close time of the smaller candle.

      I also converted to UTC for timezone-agnostic behavior. Smaller timeframes are easier, since you just need to check the minute component of the time as follows:

      Code:
      [FONT="Courier New"]
                          case 15:
                              return (minute == 0 || (minute % 15) == 0);
      [/FONT]
      If you're interested, I can email you the full test indicator I'm building.


      As always, thanks for everything you do.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by PaulMohn, Today, 05:00 AM
      0 responses
      8 views
      0 likes
      Last Post PaulMohn  
      Started by ZenCortexAuCost, Today, 04:24 AM
      0 responses
      6 views
      0 likes
      Last Post ZenCortexAuCost  
      Started by ZenCortexAuCost, Today, 04:22 AM
      0 responses
      3 views
      0 likes
      Last Post ZenCortexAuCost  
      Started by SantoshXX, Today, 03:09 AM
      0 responses
      16 views
      0 likes
      Last Post SantoshXX  
      Started by DanielTynera, Today, 01:14 AM
      0 responses
      5 views
      0 likes
      Last Post DanielTynera  
      Working...
      X