Log in to see Cloud of Tags

Wealth-Lab Wiki

TomorrowIsLastTradingDayOfWeek

RSS

Syntax

public static bool TomorrowIsLastTradingDayOfWeek(this WealthScript obj, int bar)

public bool TomorrowIsLastTradingDayOfWeek(int bar)

Parameter Description

barCurrent bar number

Description

TomorrowIsLastTradingDayOfWeek returns true if the next trading session (with respect to bar) is the last for the week, otherwise false. You can use this function to determine if the next trading day is the last for the week in order to be alerted to exit positions before the weekend. The function accounts for weekends, U.S. market holidays, and past closures.

The function is useful primarily for EOD strategies (Daily scale) but should also work for Minute, Second, or Tick scales too.

See also: GetRemainingTradingDays, DateOfNextTradingDay

Example

The example is a duplicate of the Trading System Lab from the Nov. 2012 issue of Active Trader Magazine. It uses TomorrowIsLastTradingDayOfWeek to be alerted to exit the Position at the market close on the last trading day of the week, usually Friday.

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 WeeklyRotation : WealthScript { StrategyParameter _chaseThem; StrategyParameter _profitPct; public WeeklyRotation() { _chaseThem = CreateParameter("Chase ?", 0, 0, 1, 1); _profitPct = CreateParameter("Target", 4, 2, 6, 0.5); } protected override void Execute() { int rsiPeriod = 20; int chase = _chaseThem.ValueInt == 1 ? 1 : -1; double tgtFactor = 1 + _profitPct.Value/100d; /* if _chaseThem is 1, then the most overbought stocks are purchased */ for(int bar = rsiPeriod * 3; bar < Bars.Count; bar++) { if (IsLastPositionActive) { Position p = LastPosition; if (p.MFEAsOfBarPercent(bar) >= _profitPct.Value) SellAtMarket(bar + 1, p, "Profit"); else if (this.TomorrowIsLastTradingDayOfWeek(bar)) SellAtClose(bar + 1, p, "Friday"); } else { if (this.DateOfNextTradingDay(bar).DayOfWeek < Date[bar].DayOfWeek) { double pri = chase * RSI.Series(Close, rsiPeriod)[bar]; Position p = BuyAtMarket(bar + 1, pri.ToString("0.000")); if (p != null) p.Priority = chase * RSI.Series(Close, rsiPeriod)[bar]; } } } } } }

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, 2012.10 or later***/

namespace WealthLab.Strategies { public class WeeklyRotation : WealthScript { StrategyParameter _chaseThem; StrategyParameter _profitPct; public WeeklyRotation() { _chaseThem = CreateParameter("Chase ?", 0, 0, 1, 1); _profitPct = CreateParameter("Target", 4, 2, 6, 0.5); } protected override void Execute() { DateTimeFunctions dtf = new DateTimeFunctions(this); int rsiPeriod = 20; int chase = _chaseThem.ValueInt == 1 ? 1 : -1; double tgtFactor = 1 + _profitPct.Value/100d; /* if _chaseThem is 1, then the most overbought stocks are purchased */ for(int bar = rsiPeriod * 3; bar < Bars.Count; bar++) { if (IsLastPositionActive) { Position p = LastPosition; if (p.MFEAsOfBarPercent(bar) >= _profitPct.Value) SellAtMarket(bar + 1, p, "Profit"); else if (dtf.TomorrowIsLastTradingDayOfWeek(bar)) SellAtClose(bar + 1, p, "Friday"); } else { if (dtf.DateOfNextTradingDay(bar).DayOfWeek < Date[bar].DayOfWeek) { double pri = chase * RSI.Series(Close, rsiPeriod)[bar]; Position p = BuyAtMarket(bar + 1, pri.ToString("0.000")); if (p != null) p.Priority = chase * RSI.Series(Close, rsiPeriod)[bar]; } } } } } }

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.