ScrewTurn

Active Trader Strategies API Community ChartStyles Community Commissions Community Components Community Indicators Knowledge Base Misc Optimizers PosSizers Providers Standard Indicators TASC Traders Tips TASCIndicators Tutorial Videos Visualizers
RSS

Navigation







Quick Search
»
Advanced Search »

PoweredBy

Syntax


public int TradingDaysBetweenDates(DateTime dt1, DateTime dt2)

Parameter Description

dt1 First date
dt2 Second date

Description

TradingDaysBetweenDates is a function created by Robert Sucher that calculates the number of trading days between two dates.

Example

In this example, TradingDaysBetweenDates calculates the number of trading days for future ex dates. When the ex-dates are found in the chart, we know that bar number directly, so the code uses that. But when the next event(s) occur in the future, it uses TradingDaysBetweenDates.


using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
using Community.Components;

namespace WealthLab.Strategies { public class MyStrategy : WealthScript { protected override void Execute() { Calculate c = new Calculate(this); ClearDebug(); FundamentalItem fi; int barsToNextEvent = -1; for(int bar = GetTradingLoopStartBar(1); bar < Bars.Count; bar++) { // Determine the number of bars until the next event try { fi = GetNextFundamentalItem(bar, Bars.Symbol, "dividend"); barsToNextEvent = fi.Bar - bar; // if fi.Bar isn't on the chart yet calculate the number of trading days if (fi.Bar == -1) { barsToNextEvent = c.TradingDaysBetweenDates(Date[bar], fi.Date); if (bar == Bars.Count - 1) DrawLabel(PricePane, "Calculated trading days to next event: " + barsToNextEvent, Color.Red); } } catch { barsToNextEvent = -1; // no future fundamental item } if (IsLastPositionActive) { Position p = LastPosition; if (barsToNextEvent == 1) // Exit on day before ex-div { SellAtClose(bar, p, "Ex-div"); } else { double Stop = p.EntryPrice * (1 - 15.00 / 100.0d); SellAtStop(bar + 1, p, Stop, "Stop Loss"); } } else { if (barsToNextEvent > - 1 && barsToNextEvent <= 8) { BuyAtMarket(bar + 1); } } } } } }

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.

Used under license from FMR Corp. Copyright 2008 FMR Corp. All rights reserved.


ScrewTurn Wiki version 3.0.2.509. Some of the icons created by FamFamFam.