CrossUnderWithin

Modified on 2013/05/11 10:17 by Eugene — Categorized as: Community Components

Syntax


public static bool CrossUnderWithin(this int bar, DataSeries Series1, DataSeries Series2, int WithinBars)

public bool CrossUnderWithin(int bar, DataSeries Series1, DataSeries Series2, int WithinBars)

Parameter Description

barBar
Series1First data series
Series2Second data series
WithinBarsWithin N bars

Description

Returns true for the specified bar if Series1 has crossed under Series2 within the specified number of WithinBars AND has not crossed above since the most-recent crossover event.

Original function created for WL4 by Robert Sucher.

Example

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 = 20; bar < Bars.Count; bar++) { if (IsLastPositionActive) { //code your exit rules here } else { if (bar.CrossUnderWithin (Close, SMA.Series(Close,20), 5)) BuyAtMarket( bar+1 ); } } } } }

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() { // create an instance of the SeriesHelper object SeriesHelper sh = new SeriesHelper(this); for(int bar = 20; bar < Bars.Count; bar++) { if (IsLastPositionActive) { //code your exit rules here } else { if (sh.CrossUnderWithin (bar, Close, SMA.Series(Close,20), 5)) ShortAtMarket( bar+1 ); } } } } }