• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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?
      BertrandNinjaTrader Customer Service

      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...

          }
          BertrandNinjaTrader Customer Service

          Comment


            #20
            Thanks again Bertrand. I will try your suggestion

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by nepenthean, Today, 12:36 PM
            0 responses
            3 views
            0 likes
            Last Post nepenthean  
            Started by sun0781, Yesterday, 05:02 PM
            1 response
            19 views
            0 likes
            Last Post NinjaTrader_ChrisL  
            Started by Emma1, Today, 12:14 PM
            0 responses
            2 views
            0 likes
            Last Post Emma1
            by Emma1
             
            Started by Hanstanz, Today, 04:44 AM
            1 response
            17 views
            0 likes
            Last Post NinjaTrader_ChrisL  
            Started by Newtrader101, Today, 10:31 AM
            0 responses
            8 views
            0 likes
            Last Post Newtrader101  
            Working...
            X