Jump to content
Medved Trader Forums

First candle of the current week in an intraday chat


Recommended Posts

int FirstWeeklyCandle = -1;

public void MainCalculation()
{
    if ((int)(Timestamp.DayOfWeek) == 0) // Sunday is 0
        FirstWeeklyCandle = CandleNumber;

...

 

That would do it for futures (first day is sunday). If you want to do it for both, and you presume that there is no candle for Sunday for stocks,

int FirstWeeklyCandle = -1;
DateTime FirstWeeklyCandleDT; 

public void MainCalculation()
{
    if ((int)(Timestamp.DayOfWeek) == 0) // Sunday is 0
    {
        FirstWeeklyCandle   = CandleNumber;
        FirstWeeklyCandleDT = Timestamp.Date;
    }
    else if ((int)(Timestamp.DayOfWeek) == 1) // Monday is 1
    {
        if ((int)(FirstWeeklyCandleDT.DayOfWeek) != 0) // there isn't already a sunday FirstWeekly
        {
            FirstWeeklyCandle   = CandleNumber;
            FirstWeeklyCandleDT = Timestamp.Date;
        }
    }

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...