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

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 DJ888, 04-16-2024, 06:09 PM
            6 responses
            18 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by Jon17, Today, 04:33 PM
            0 responses
            1 view
            0 likes
            Last Post Jon17
            by Jon17
             
            Started by Javierw.ok, Today, 04:12 PM
            0 responses
            6 views
            0 likes
            Last Post Javierw.ok  
            Started by timmbbo, Today, 08:59 AM
            2 responses
            10 views
            0 likes
            Last Post bltdavid  
            Started by alifarahani, Today, 09:40 AM
            6 responses
            41 views
            0 likes
            Last Post alifarahani  
            Working...
            X