public static int GetRemainingTradingDays(this DateTime DateFrom)public static int GetRemainingTradingDays(DateTime DateFrom)
using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators;namespace WealthLab.Strategies { public class EOM : WealthScript { private StrategyParameter paramNth; private StrategyParameter paramDaysR; public EOM() { paramNth = CreateParameter("Nth", 2, 1, 4, 1); paramDaysR = CreateParameter("Remaining Days", 6, 2, 8, 1); } protected override void Execute() { int remaining = 0; int newMonth = -1; int days = paramDaysR.ValueInt; int Nth = paramNth.ValueInt; for(int bar = Math.Max( days, Nth ); bar < Bars.Count; bar++) { // Month has changed if( Date[bar].Month != Date[bar-1].Month ) newMonth = bar; // Remaining days are returned by this static method remaining = Date[bar].GetRemainingTradingDays(); if (IsLastPositionActive) { if( ( newMonth > 0 ) & ( bar == newMonth + Nth - 1 ) ) SellAtMarket( bar, LastPosition ); } else { if( remaining <= days ) BuyAtMarket( bar, remaining.ToString() ); } } } } }
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 EOM : WealthScript { private StrategyParameter paramNth; private StrategyParameter paramDaysR; public EOM() { paramNth = CreateParameter("Nth", 2, 1, 4, 1); paramDaysR = CreateParameter("Remaining Days", 6, 2, 8, 1); } protected override void Execute() { int remaining = 0; int newMonth = -1; int days = paramDaysR.ValueInt; int Nth = paramNth.ValueInt; for(int bar = Math.Max( days, Nth ); bar < Bars.Count; bar++) { // Month has changed if( Date[bar].Month != Date[bar-1].Month ) newMonth = bar; // Remaining days are returned by this static method remaining = DateTimeFunctions.GetRemainingTradingDays( Date[bar] ); if (IsLastPositionActive) { if( ( newMonth > 0 ) & ( bar == newMonth + Nth - 1 ) ) SellAtMarket( bar, LastPosition ); } else { if( remaining <= days ) BuyAtMarket( bar, remaining.ToString() ); } } } } }