Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Day of the week & Two days ago High & Low

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

    #16
    I still need some help with the code as it calculates the Monday High & Low. The issue is that as I color the bars when the Close is higher and lower, somehow some of Monday's bars are also colored. How can it be coded so only Closes above Monday's High and Closes below Monday's low are colored and not the Monday bars? For reference I included screenshots for Monday 1/5/15 and 1/12/15

    protected override void OnBarUpdate()
    {
    double PriorWkHigh = PriorWeekOHLC().PriorWeekHigh[0];
    double PriorWkLow = PriorWeekOHLC().PriorWeekLow[0];

    if(Bars.FirstBarOfSession) {
    sessionCount++;
    }
    if (sessionCount < 2)
    return;

    if(Time[0].DayOfWeek == DayOfWeek.Monday)
    {
    bar = CurrentBar;
    }

    // High and Low for Monday
    if (bar !=0 ) {
    highMON = PriorDayOHLC().PriorHigh[CurrentBar - bar];
    lowMON = PriorDayOHLC().PriorLow[CurrentBar - bar];
    }
    // High and Low for Monday
    if (bar !=0 ) {
    highMON = PriorDayOHLC().PriorHigh[CurrentBar - bar];
    lowMON = PriorDayOHLC().PriorLow[CurrentBar - bar];
    }
    if (Close[0] > highMON ) {
    if (colorBars) {
    BarColor = Color.Blue;
    }
    }
    else if (Close[0] < lowMON ) {
    if (colorBars) {
    BarColor = Color.Red;
    }
    }
    else if (colorBars) {
    BarColor = Color.DimGray;
    }
    }
    Attached Files

    Comment


      #17
      2Look4me, so you mean you would want to have Monday High / Low as the reference point and then only color the bars for Tuesday - Friday?

      Comment


        #18
        That's correct Bertrand, that's what I need. The code is right on and does what it's intended to do. I'm just lost understanding why when colors are applied to the bars, Mondays Hi/Lo are also painted.
        Thanks

        Comment


          #19
          Thanks, you just save the CurrentBar for compares the first time you would see a bar for Monday, so Monday would be included in the paint rule if your condition is satiesfied.

          You can for example only color the bars if your conditions hits on another weekend via

          if(Time[0].DayOfWeek != DayOfWeek.Monday)
          {

          // color the bars with your logic...

          }

          Comment


            #20
            Thanks again Bertrand. I will try your suggestion

            Comment

            Latest Posts

            Collapse

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