public static int GetTime(this WealthScript obj, int bar) public static int GetTime(this Bars bars, int bar) // For use when using a non-synchronized Bars objectpublic int GetTime(int bar) public int GetTime(Bars bars, int bar) // For use when using a non-synchronized Bars object
public static int AddIntegerTime(this int t, int minutes)public int AddIntegerTime( int minutes )
public static int FirstBarofDay(this WealthScript obj, int startDay)public int FirstBarofDay( int startDay )
public static int DaysInPosition(this Position p, int bar)public int DaysInPosition(int bar)
using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators;namespace WealthLab.Strategies { public class MOCStrategy : WealthScript { /* Sliders * minTradeBars are the min number of bars before the end of day that an entry is allowed */ private StrategyParameter todayCloseTime; private StrategyParameter minTradeBars; public MOCStrategy() { todayCloseTime = CreateParameter("Close Today", 1600, 1300, 1600, 300); minTradeBars = CreateParameter("Min Trade Bars", 5, 2, 10, 1); } protected override void Execute() { int todayClose = todayCloseTime.ValueInt; int minBarsInTrade = minTradeBars.ValueInt; int lastChartBar = Bars.Count - 1; int nextToLastBarTime = todayClose.AddIntegerTime( -Bars.BarInterval ); for(int bar = this.FirstBarofDay( 2 ); bar < Bars.Count - 1; bar++) { if( !IsLastPositionActive ) { if ( bar < lastChartBar - minBarsInTrade ) { BuyAtLimit(bar + 1, Bars.Low[bar] * 0.995); } } else { Position p = LastPosition; if( (bar == lastChartBar) && (this.GetTime(bar) >= nextToLastBarTime) ) { SetBarColor( bar, Color.Orange); ExitAtMarket( bar + 1, p, "Exit at open of last bar"); } else if ( (bar != lastChartBar) && Bars.IsLastBarOfDay(bar + 1) ) { SetBarColor( bar, Color.Orange); ExitAtMarket( bar + 1, p, "Exit at open of last bar"); } else { // other exit logic here } } } } } }
using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators; using Community.Components; // Intraday support functions here /*** Requires installation of Community.Components Extension from www.wealth-lab.com > Extensions ***/namespace WealthLab.Strategies { public class MOCStrategy : WealthScript { /* Sliders * minTradeBars are the min number of bars before the end of day that an entry is allowed */ private StrategyParameter todayCloseTime; private StrategyParameter minTradeBars; public MOCStrategy() { todayCloseTime = CreateParameter("Close Today", 1600, 1300, 1600, 300); minTradeBars = CreateParameter("Min Trade Bars", 5, 2, 10, 1); } protected override void Execute() { // Intraday support functions here: Utility u = new Utility( this ); int todayClose = todayCloseTime.ValueInt; int minBarsInTrade = minTradeBars.ValueInt; int lastChartBar = Bars.Count - 1; int nextToLastBarTime = u.AddIntegerTime( todayClose, -Bars.BarInterval ); for(int bar = u.FirstBarofDay( 2 ); bar < Bars.Count - 1; bar++) { if( !IsLastPositionActive ) { if ( bar < lastChartBar - minBarsInTrade ) { BuyAtLimit(bar + 1, Bars.Low[bar] * 0.995); } } else { Position p = LastPosition; if( (bar == lastChartBar) && (u.GetTime(bar) >= nextToLastBarTime) ) { SetBarColor( bar, Color.Orange); ExitAtMarket( bar + 1, p, "Exit at open of last bar"); } else if ( (bar != lastChartBar) && Bars.IsLastBarOfDay(bar + 1) ) { SetBarColor( bar, Color.Orange); ExitAtMarket( bar + 1, p, "Exit at open of last bar"); } else { // other exit logic here } } } } } }