Log in to see Cloud of Tags

Wealth-Lab Wiki

Page History: DateOfNextTradingDay

Compare Page Revisions



« Older Revision - Back to Page History - Current Revision


Page Revision: 2013/05/11 10:30


Syntax

public static DateTime DateOfNextTradingDay(this WealthScript obj, int bar) public static DateTime DateOfNextTradingDay(this WealthScript obj, DateTime dt)

public DateTime DateOfNextTradingDay(int bar) public DateTime DateOfNextTradingDay(DateTime dt)


Parameter Description

barCurrent bar number
dtCurrent DateTime

Description

DateOfNextTradingDay returns the DateTime of the next trading day with respect to the bar number or date passed to the function. You can use this function to determine if the next trading day is a specific DayOfWeek (like DayOfWeek.Friday). This information can be used to trigger an Alert for a trading action on the next day, i.e., bar + 1.

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

See also: GetRemainingTradingDays, TomorrowIsLastTradingDayOfWeek

Example

In this example, the strategy simply buys on Thursdays and sells on the first trading session of the following week, usually Monday.

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 = GetTradingLoopStartBar(1); bar < Bars.Count; bar++) { if (IsLastPositionActive) { Position p = LastPosition; if (this.DateOfNextTradingDay(bar).DayOfWeek < Datebar.DayOfWeek) SellAtMarket(bar + 1, p, "It's next week!"); } else { if (this.DateOfNextTradingDay(bar).DayOfWeek == DayOfWeek.Thursday) { BuyAtMarket(bar + 1, "Buy Thurs Morning"); } } } } } }


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() { DateTimeFunctions dtf = new DateTimeFunctions(this); for(int bar = GetTradingLoopStartBar(1); bar < Bars.Count; bar++) { if (IsLastPositionActive) { Position p = LastPosition; if (dtf.DateOfNextTradingDay(bar).DayOfWeek < Datebar.DayOfWeek) SellAtMarket(bar + 1, p, "It's next week!"); } else { if (dtf.DateOfNextTradingDay(bar).DayOfWeek == DayOfWeek.Thursday) { BuyAtMarket(bar + 1, "Buy Thurs Morning"); } } } } } }

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.