• 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

GetBar from week open

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

    GetBar from week open

    Hi guys!

    I'd like to draw a line from (week open and month open) bar to currentBar.

    I use with this to get bars from daily open...

    barsAgoDailyOpen = CurrentBar - Bars.GetBar(new DateTime(Time[0].Year, Time[0].Month, Time[0].Day));

    How can I get from week and month open bar to now.
    Which is the easiest and simplest solution?

    many thx
    w.

    #2
    Weekly Open:

    You would need to check for the date of the current trading day. If there is a new date (first bar of new trading day) check whether it is a Monday. If it is a Monday store the value of the CurrentBar and you can use it to draw your line from the open.

    Code:
    #region Variables
    private DateTime  currentDate = Cbi.Globals.MinDate;
    private DateTime  lastDate = Cbi.Globals.MinDate;
    private int weeklyOpen = 0;
    ........
    #endregion
    
    protected override void OnBarUpdate()
    {
           currentDate = Bars.GetTradingDayFromLocal(Time[0]);
           if(currentDate > lastDate)
            { 
                 if(currentDate.DayOfWeek == DayOfWeek.Monday) 
                      weeklyOpen = CurrentBar;
                 lastDate = currentDate;
             }
    }
    For a monthly open just check whether the current date is the first business day of a month.

    The indicator is available in the downloads (search for SessionPivots V42), you can always try to copy parts of the code.
    Attached Files
    Last edited by Harry; 07-05-2013, 02:55 PM.

    Comment


      #3
      Thanks Harry!

      Its a bit confuse for me. Im newbie...
      Is there any easiest way?

      Meanwhile i try to do your way....

      Comment


        #4
        Originally posted by wokitun View Post
        Thanks Harry!

        Its a bit confuse for me. Im newbie...
        Is there any easiest way?

        Meanwhile i try to do your way....
        This is only 5 simple lines of code in OnBarUpdate() to collect the index of the bar for the weekly open. I would consider this pretty simple!

        Comment


          #5
          Ok...
          What happen if Monday is not trading day //celebrate..market close...// as a result of this not weekly open that day.
          What i find.. .If weekly first day starts at Tuesday...draw line begins from Tuesday...

          example...
          My result at Monthly open.

          barsAgo = CurrentBar - Bars.GetBar(Time[0].AddDays(-Time[0].Day));

          Not the best and properly solution...

          Or I understand something wrong?

          thx
          w.

          Comment


            #6
            Originally posted by wokitun View Post
            Ok...
            What happen if Monday is not trading day //celebrate..market close...// as a result of this not weekly open that day.
            What i find.. .If weekly first day starts at Tuesday...draw line begins from Tuesday...

            example...
            My result at Monthly open.

            barsAgo = CurrentBar - Bars.GetBar(Time[0].AddDays(-Time[0].Day));

            Not the best and properly solution...

            Or I understand something wrong?

            thx
            w.
            You are absolutely right. Easiest solution is to convert the DayOfWeek to an integer. Sunday has the value 0, Saturday has the value 6. So you could check for
            (int)Time[0].DayOfWeek to decrease. The bar where that value decreases marks the beginning of the week, whatever day of week it is.
            Last edited by Harry; 07-06-2013, 02:38 PM.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Gerik, Today, 10:58 PM
            0 responses
            1 view
            0 likes
            Last Post Gerik
            by Gerik
             
            Vps by stooby
            Started by stooby, Today, 08:32 PM
            0 responses
            11 views
            0 likes
            Last Post stooby
            by stooby
             
            Started by FaaastEddy, Today, 08:25 PM
            0 responses
            3 views
            0 likes
            Last Post FaaastEddy  
            Started by YevhenShynkarenko, Yesterday, 01:22 AM
            2 responses
            39 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by testingsarasa, 05-20-2018, 02:50 PM
            11 responses
            739 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Working...
            X