GetWeekNumber

Modified on 2013/05/11 13:01 by Eugene — Categorized as: Community Components

Syntax


public static int GetWeekNumber(this Bars bars, int bar)

public int GetWeekNumber( Bars bars, int bar )

Parameter Description

barsBars object
barBar number

Description

Is there a way to know we are entering a new week?

GetWeekNumber determines the number of current week since the beginning of the year. By comparing its current bar value to the previous bar's value, this function will help find out if we're entering a new week.

Note that it will handle with Black Swan type of weeks like 09/10/2001 and 09/17/2001:

Example

Example using C# extension methods:


using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;

namespace WealthLab.Strategies { public class MyStrategy : WealthScript { protected override void Execute() { for(int bar = 1; bar < Bars.Count; bar++) { if( Bars.GetWeekNumber( bar ) > Bars.GetWeekNumber( bar-1 ) ) { // Color the background if today is the first day in a new week SetBackgroundColor(bar, Color.LightBlue); } } } } }

Legacy syntax example:


using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
using Community.Components; /*** Requires installation of Community.Components Extension from www.wealth-lab.com > Extensions ***/

namespace WealthLab.Strategies { public class MyStrategy : WealthScript { protected override void Execute() { // Create an instance of the Calculate class that contains the GetWeekNumber function // Pass it a WealthScript object Calculate calc = new Calculate( this ); for(int bar = 20; bar < Bars.Count; bar++) { if( calc.GetWeekNumber( Bars, bar ) > calc.GetWeekNumber( Bars, bar-1 ) ) { // Color the background if today is the first day in a new week SetBackgroundColor(bar, Color.LightBlue); } } } } }