Series is Above a Value

Modified on 2019/02/28 06:08 by Eugene — Categorized as: Community Indicators

SeriesIsAboveValue: Indicator Documentation

Syntax

SeriesIsAboveValue(DataSeries ds, double num, int period) SeriesIsAboveValue(DataSeries ds, double num, int period, string description)

Parameter Description

dsData series
numValue
periodPeriod for which the data series should be above the value

Description

Returns the number of consecutive bars that a DataSeries dshas been above a value num minus the Period bars.
See also:
Series Is Below a Value
Series Is Above

Example

This simple system takes long positions when the 2-period RSI has been above 95 for 5 consecutive bars, and short positions when it has been below 5 for consecutive bars, closing them after being in the market for a month.

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

namespace WealthLab.Strategies { public class MyStrategy : WealthScript { protected override void Execute() { int period = 2; DataSeries rsi = RSI.Series(Close, 2); SeriesIsAboveValue rsiAbove95 = SeriesIsAboveValue.Series( rsi, 95, 5 ); SeriesIsBelowValue rsiBelow5 = SeriesIsBelowValue.Series( rsi, 5, 5 ); ChartPane rsiPane = CreatePane(25, true, true); PlotSeries(rsiPane, rsi, Color.Black, LineStyle.Solid, 2); ChartPane cp = CreatePane(25, true, true); PlotSeries(cp, rsiAbove95, Color.Blue, LineStyle.Histogram, 2); PlotSeries(cp, rsiBelow5, Color.Red, LineStyle.Histogram, 2); for(int bar = period * 3; bar < Bars.Count; bar++) { if (IsLastPositionActive) { Position p = LastPosition; TimeSpan ts = Datebar - Datep.EntryBar; if (ts.Days > 29) ExitAtMarket(bar + 1, p, "Time-based"); } else { if (rsiAbove95bar >= 5 ) { BuyAtMarket(bar + 1); SetBackgroundColor(bar, Color.FromArgb(50, Color.Red)); } else if (rsiBelow5bar >= 5 ) { ShortAtMarket(bar + 1); SetBackgroundColor(bar, Color.FromArgb(50, Color.Blue)); } } } } } }