public static bool TomorrowIsLastTradingDayOfWeek(this WealthScript obj, int bar)public bool TomorrowIsLastTradingDayOfWeek(int bar)
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 < Datebar.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; } } } } } }
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 < Datebar.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; } } } } } }