Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CurrentDayOHL plotting wrong open.

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

    CurrentDayOHL plotting wrong open.

    When I write this condition statement:

    if (Times[0][0].TimeOfDay >= new TimeSpan(08, 30, 00) && Times[0][0].TimeOfDay <= new TimeSpan(17,00, 00))
    {
    RthOpen[0] = CurrentDayOHL1.CurrentOpen[0];
    RthHigh[0] = CurrentDayOHL1.CurrentHigh[0];
    RthLow[0] = CurrentDayOHL1.CurrentLow[0];
    }

    It should give me Open plot value of 0830, but it does not. It gives me the correct High and Low plot values. I did prints to better understand the behavior:

    Print(String.Format("Time[0]: {0} CurrentDayOHL1.CurrentOpen[0]: {1} CurrentDayOHL1.CurrentHigh[0]: {2}, CurrentDayOHL1.CurrentLow[0]: {3}",
    Time[0], CurrentDayOHL1.CurrentOpen[0], CurrentDayOHL1.CurrentHigh[0], CurrentDayOHL1.CurrentLow[0] ));

    But I didn't see anything out of the ordinary. Is there another check I must do in order to plot the correct open?

    Thanks.
    Attached Files

    #2
    Hello AdeptistJune,

    Thanks for your post.

    From your screenshot it appears that you are using the ETH hours of the ES 03-22.

    The indicator CurrentDayOHL will use the trading hours of the chart to determine the Current Open of the ETH session which will likely be different than the RTH session

    You could set your own time condition to pull the RTH open price value and save that in a double type variable to then plot through the RTH session.

    if (Time[0][0].TimeOfDay == new TimeSpan(08, 30, 00))
    {
    myRTHOpen = Open[0]; // save the first bars open price
    }

    RthOpen[0] = myRTHOpen; // plot the open


    Note: You may find that if the ETH Session High or Low occurs during the ETH session outside of the RTH session that they will also be incorrect during the RTH session. In this case, you may be better off following the same approach as getting the open except that you would need to track the High and Low and that would look something like this:

    if (Time[0][0].TimeOfDay == new TimeSpan(08, 30, 00))
    {
    myRTHOpen = Open[0]; // save the first bars open price
    myRTHHigh = High[0];
    myRTHLow = Low[0]
    }

    if (Times[0][0].TimeOfDay >= new TimeSpan(08, 30, 00) && Times[0][0].TimeOfDay <= new TimeSpan(17,00, 00))
    {
    RthOpen[0] =myRTHOpen[0]; // always plot this unchanging value

    if (High[0] > myRTHHigh) // c heck for new high during RTH session
    {
    myRTHHigh = High[0]; // new High
    }
    if (Low[0] < myRTHLow) // Check for new low during RTH session
    {
    myRTHLow = Low[0]; // new Low
    }

    // Plot the High and low
    RthHigh[0] = myRTHHigh;
    RtrhLow[0] = myRTHLow;
    }



    Comment


      #3
      Hello, Paul,

      I did this check to see if I would see the plot; but it doesn't show.

      if (Times[0][0].TimeOfDay == new TimeSpan(08, 30, 00))
      {
      RthOpen[0] = Open[0];
      //RthHigh[0] = CurrentDayOHL1.CurrentHigh[0];
      //RthLow[0] = CurrentDayOHL1.CurrentLow[0];
      }

      Also, I created a trading hour template with the extended trading hours.

      Comment


        #4
        Hello AdeptistJune,

        Thanks for your reply.

        Please check again my example. You changed it so that it tries to plot only once at 8:30 instead of saving the value in a double type variable called myRTHOpen and then plotting.

        You need this part RthOpen[0] = myRTHOpen; // plot the open to be under your 8:30 to 17:00 time filter

        Comment


          #5
          Hello PauH,

          I'm getting this error message: The name "myRTHOpen" does not exist in the current context

          Comment


            #6
            Hello AdeptistJune,

            Thanks for your reply.

            Correct, you would need to create/declare the double-type variable to use it.

            At the class level add private double myRTHOpen;

            To further clarify I have created an example indicator that plots the Open High Low of the current day based on a begin and end time that you input:

            myRTHOHL.zip

            Comment


              #7
              Thanks. The lesson I learned from this, is assigning and re-assigning values. I never seen this code: RTHStart = DateTime.Parse("08:30", System.Globalization.CultureInfo.InvariantCulture) ;
              RTHEnd = DateTime.Parse("17:00", System.Globalization.CultureInfo.InvariantCulture) ;

              Comment


                #8
                Now, if I will to assign those into previous values, I would use index (myRTHOpen[0][0])?

                Comment


                  #9
                  Hello AdeptistJune,

                  Thanks for your post.

                  I'm not sure what "assign those" is referring to.

                  Can you clarify?

                  Comment


                    #10
                    Know how we have the currentOHL plot values and PreviousOHLC plot values. So in order to plot the PreviousOHLC values, I would need to reference the currentOHL plot values[one day ago] instead of [one bar ago]. Will I need to use indexes, for example, myRTH[1][0]?

                    Comment


                      #11
                      Hello AdeptistJune,

                      Thanks for your reply.

                      What you could do would be to create 4 more double-type variables to hold each of the prior day values.

                      On the last bar of the RTH session (Time[0].TimeOfDay == new TimeSpan(16,59, 00)) you could store the current day Open, High, Low values and use the Close value of the last bar. On the next session, you would then plot those values.

                      You would have to add some logic so that you do not try to plot anything until those values are NOT equal to 0 as otherwise they will try to plot in your first session (at zero).

                      Comment


                        #12
                        Okay. I'm about to work on it right now

                        Comment


                          #13
                          Hello, Paul

                          This is what I came up with, but I can't get it to plot.

                          else if (State == State.DataLoaded)
                          {
                          MyRTHOHL1 = MyRTHOHL(Close, DateTime.Parse("8:31 AM"), DateTime.Parse("5:00 PM"));
                          }
                          }

                          protected override void OnBarUpdate()
                          {
                          if (BarsInProgress == 1)
                          return;

                          if (CurrentBars[0] < 1)
                          return;

                          if (Time[0].TimeOfDay == new TimeSpan(16,59, 00))
                          {
                          myPREVOpen = MyRTHOHL1.RTHOpen[0];
                          myPREVHigh = MyRTHOHL1.RTHHigh[0];
                          myPREVLow = MyRTHOHL1.RTHLow[0];
                          }
                          if (Time[0].TimeOfDay >= RTHStart.TimeOfDay && Time[0].TimeOfDay < RTHEnd.TimeOfDay)
                          {
                          PREVOpen[0] = myPREVOpen;
                          PREVHigh[0] = myPREVHigh;
                          PREVLow[0] = myPREVLow;
                          }
                          }

                          Comment


                            #14
                            Hello AdeptistJune,

                            Thanks for your post.

                            I thought you would have incorporated that into your existing indicator.

                            In the new indicator then have you created the plots PREVOpen, PREVHigh, PREVLow, and included their outputs?

                            Comment


                              #15
                              Good morning Paul,

                              Yes. I did incorporate the PREVOpen, PREVHigh, PREVLow into my existing indicator and created outputs. The prints shows: 0.

                              I'm about to look at the existing indicator and see what I did wrong.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              571 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              331 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              101 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              549 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              549 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X