Log in to see Cloud of Tags

Wealth-Lab Wiki

GetWeekNumber

RSS

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); } } } } }

Important Disclaimer: The information provided by Wealth-Lab is strictly for informational purposes and is not to be construed as advice or solicitation to buy or sell any security.  The owner of Wealth-Lab.com assumes no liability resulting from the use of the material contained herein for investment purposes. By using this web site, you agree to the terms of this disclaimer and our Terms of Use.


ScrewTurn Wiki. Some of the icons created by FamFamFam.