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 price range from first half hour or so of the trading day

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

    How to get price range from first half hour or so of the trading day

    Hi all,

    I want to compare prices to the opening half hour or so of the day to find out action compared to an opening range.

    What would I check for that? If I were to define an indicator's time frame for every 15 minutes I could check the high and low for the first 2 slots if I knew how to retrieve them, but the 0th slot is 'most recent'.

    Any suggestions would be appreciated.

    John

    #2
    Hello,

    You can make Time Filters using the ToTime(Time[0]) function.

    Please take a look at our reference Sample on Using a time filter to limit trading hours to help you get started:



    While this does not illustrate exactly what you wish to do, it should help you give you an idea of how you would get data from a specific time period and how to work with the Time() methods

    I would also suggest taking a look at our reference sample on Referencing the correct bar:



    Please let me know if you need further assistance.
    MatthewNinjaTrader Product Management

    Comment


      #3
      Thank you, this looks very helpful.

      Comment


        #4
        There are OpeningRange indicators available here which can use the session information and adjust to the open of each instrument.

        The best futures trading community on the planet: futures trading, market news, trading charts, trading platforms, trading strategies

        The best futures trading community on the planet: futures trading, market news, trading charts, trading platforms, trading strategies


        The indicators are available for free download, but forum membership is required. You can also send me a private message with your email, and I will then send you the indicators, as I have written them.

        Originally posted by jkmott59 View Post
        Hi all,

        I want to compare prices to the opening half hour or so of the day to find out action compared to an opening range.

        What would I check for that? If I were to define an indicator's time frame for every 15 minutes I could check the high and low for the first 2 slots if I knew how to retrieve them, but the 0th slot is 'most recent'.

        Any suggestions would be appreciated.

        John
        Attached Files
        Last edited by Harry; 04-14-2012, 08:51 AM.

        Comment


          #5
          Thanks, I found out that class variables are maintained on a per-row basis, which meant that I could use them to store a high and low. Here is the code. The value returned is 1 if the price is above the opening range, -1 if its below the opening range or 0 if its inside the opening range.

          public double LowRange = 1000000;
          public double HighRange = 0;
          /// <summary>
          /// Called on each bar update event (incoming tick)
          /// </summary>
          protected override void OnBarUpdate()
          {
          // If we are in the opening range accrue high and low
          if (InTimeRange()) {
          if (Close[0] < LowRange) LowRange = Close[0];
          if (Close[0] > HighRange) HighRange = Close[0];
          Plot0.Set(0); // by definition we are still inside the opening range
          return;
          }
          // We are out of the open
          if (Close[0] < LowRange) {
          Plot0.Set(-1);
          return;
          }
          if (Close[0] > HighRange) {
          Plot0.Set(1);
          return;
          }
          Plot0.Set(0);
          }
          // Collect times between 8:30 to 9 (Central Time)
          protected bool InTimeRange() {
          if (DateTime.Now.Hour < 8) return false;
          if (DateTime.Now.Hour > 9) return false;
          if (DateTime.Now.Hour == 8 && DateTime.Now.Minute < 30) return false;
          return true;

          }
          Last edited by jkmott59; 04-14-2012, 10:55 AM. Reason: grammer error

          Comment


            #6
            As long as you trade an exchange of your timezone that should work. If you trade an exchange outside your timezone (as I usually do) you will face the challenge that there are various daylight savings schedules, which shift the opening period back and forth during the year. In that case you need to collect the information of the correct timezone from the session template under instrument settings to allow for conversion of the exchange time into your local time, for compensating the shift introduced via the daylight savings time.

            Comment


              #7
              Thanks, that's good to remember.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by hurleydood, 09-12-2019, 10:45 AM
              14 responses
              1,096 views
              0 likes
              Last Post Board game geek  
              Started by cre8able, Yesterday, 04:16 PM
              1 response
              16 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by cre8able, Yesterday, 04:22 PM
              1 response
              14 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by stafe, 04-15-2024, 08:34 PM
              5 responses
              28 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by StrongLikeBull, Yesterday, 04:05 PM
              1 response
              12 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Working...
              X