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 cmtjoancolmenero, Yesterday, 03:58 PM
              11 responses
              39 views
              0 likes
              Last Post cmtjoancolmenero  
              Started by FrazMann, Today, 11:21 AM
              0 responses
              5 views
              0 likes
              Last Post FrazMann  
              Started by geddyisodin, Yesterday, 05:20 AM
              8 responses
              52 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by DayTradingDEMON, Today, 09:28 AM
              4 responses
              26 views
              0 likes
              Last Post DayTradingDEMON  
              Started by George21, Today, 10:07 AM
              1 response
              22 views
              0 likes
              Last Post NinjaTrader_ChristopherJ  
              Working...
              X