Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

High and Low of specific times

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

    #16
    Ugh, sorry that was stupid. I tried this now

    if (openRangeHigh == 0 && openRangeLow == 0 || ToTime(Time[0]) < ToTime(16, 0, 0));

    and it seems to be giving correct chart... Is that OK?

    Comment


      #17
      Ok, the code here plots the min and max, but it does not take into account for the first bar of the day. What do i need to change in order to capture all of the first 30 bars?

      int barsThisSession = Math.Min(Math.Max(1,Bars.BarsSinceSession),30);
      double openRangeHigh = MAX(Highs[0],30)[Math.Max(0,barsThisSession-30)];
      double openRangeLow = MIN(Lows[0],30)[Math.Max(0,barsThisSession-30)];

      if (openRangeHigh == 0 && openRangeLow == 0 || ToTime(Time[0]) < ToTime(16, 0, 0));

      Plot0.Set(openRangeHigh);
      Plot1.Set(openRangeLow);

      Comment


        #18
        Originally posted by bagzi View Post
        Ok, the code here plots the min and max, but it does not take into account for the first bar of the day. What do i need to change in order to capture all of the first 30 bars?

        int barsThisSession = Math.Min(Math.Max(1,Bars.BarsSinceSession),30);
        double openRangeHigh = MAX(Highs[0],30)[Math.Max(0,barsThisSession-30)];
        double openRangeLow = MIN(Lows[0],30)[Math.Max(0,barsThisSession-30)];

        if (openRangeHigh == 0 && openRangeLow == 0 || ToTime(Time[0]) < ToTime(16, 0, 0));

        Plot0.Set(openRangeHigh);
        Plot1.Set(openRangeLow);
        First thing to do is what I said: enclose your Plot.Set() statements in a block, so that the Time filter applies to both of them.
        Code:
         
        if (openRangeHigh == 0 && openRangeLow == 0 || ToTime(Time[0]) < ToTime(16, 0, 0))
        [COLOR=blue][B]{[/B][/COLOR]
        Plot0.Set(openRangeHigh);
        Plot1.Set(openRangeLow);
        [COLOR=blue][B]}[/B][/COLOR]
        Second thing is to ensure that it does, in fact, apply to both of them. As you had it written, it did not even apply to any of them, because you had ended your Time filter statement with a semi-colon, effectively turning it into a null statement.(Emphasis mine in red, in your original code).

        Comment


          #19
          Yes, i apologize, i am really new to writing code, i corrected it and now the chart is like below. It still does not seem correct to me, but confusingly some days are correct and some not..

          Thanks for helping me koganam. I hate to bother people like this, but i got no other options...

          Comment


            #20
            You're probably losing the first bar because on the first bar of the day, Bars.BarsThisSession is 0 (I think) and the example I gave you set it to a number between 1 and 390. That's because my program is doing many other calculations on Bars.BarsThisSession and I specifically wanted to force it to a number greater than 0 for those calculations.

            Also, my example was for an auto-trading strategy not an indicator, so it was important for me to check the current time of day because I didn't want to recalculate this variable on every tick. That's less important for you, so I would recommend only checking if openRangeHigh or openRangeLow is 0 and ignore the time.

            Comment


              #21
              Computers simply do what you tell them to do, so if your output is incorrect, then you have not given the computer the correct instructions. You may be better off using code that has already been written, rather than trying to roll your own. Until you have better skills that is.

              Here is an example of getting the opening range.



              There are quite a few other snippets and almost-complete strategies on this forum, that use an opening range, if you run a search for the phrase "opening range". Here are the immediate results of my search right now. http://www.ninjatrader.com/support/f...archid=1449220. I got 48 posts on the topic.

              Comment


                #22
                One more thing: because this code is written for a strategy, I am positive that the timeframe of the bars is always 1 minute. This code displays the highs and lows for the first 30 BARS for today. If your chart is looking at 10-minute bars, then it's looking at the first 300 minutes of the day, which is almost the entire day, and may give you the impression that it's using the highs and lows from a previous day. I have very little experience with indicators, and koganam is more knowledgeable on this subject, so if I was incorrect please correct me, koganam.

                Comment


                  #23
                  Well, eventually i also want to use it in the strategy, but was creating it as indicator to make sure it does what its suppose to.
                  If i leave the time out of it, it does not plot anything on the chart.

                  Comment


                    #24
                    Originally posted by egan857 View Post
                    One more thing: because this code is written for a strategy, I am positive that the timeframe of the bars is always 1 minute. This code displays the highs and lows for the first 30 BARS for today. If your chart is looking at 10-minute bars, then it's looking at the first 300 minutes of the day, which is almost the entire day, and may give you the impression that it's using the highs and lows from a previous day. I have very little experience with indicators, and koganam is more knowledgeable on this subject, so if I was incorrect please correct me, koganam.
                    You are quite right. Your code was written for a very specific setup and timeframe. That is why, once bagzi explained his newness at this, I figured it was better to advise to use extant code, rather than go into the explanation that you have just given.

                    Comment


                      #25
                      Ok guys, thanks a lot. I guess there is no quick solution for me, will have to investigate a bit more on this subject..

                      Comment


                        #26
                        OMG, just found this

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by sjsj2732, Yesterday, 04:31 AM
                        0 responses
                        32 views
                        0 likes
                        Last Post sjsj2732  
                        Started by NullPointStrategies, 03-13-2026, 05:17 AM
                        0 responses
                        286 views
                        0 likes
                        Last Post NullPointStrategies  
                        Started by argusthome, 03-08-2026, 10:06 AM
                        0 responses
                        283 views
                        0 likes
                        Last Post argusthome  
                        Started by NabilKhattabi, 03-06-2026, 11:18 AM
                        0 responses
                        133 views
                        1 like
                        Last Post NabilKhattabi  
                        Started by Deep42, 03-06-2026, 12:28 AM
                        0 responses
                        91 views
                        0 likes
                        Last Post Deep42
                        by Deep42
                         
                        Working...
                        X