SeriesIsAboveValue: Indicator Documentation
Syntax
SeriesIsAboveValue(DataSeries ds, double num, int period)
SeriesIsAboveValue(DataSeries ds, double num, int period, string description)
Parameter Description
ds | Data series |
num | Value |
period | Period 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.
- To count the number of consecutive bars that the DataSeries has been above the value, use period = 1.
- Note! Versions prior to 2019.03 contained a bug (now fixed). Backtest results will change if upgrading to 2019.03 or higher.
- For any other period, SeriesIsAboveValue returns zero until the DataSeries has been above the value for at least period bars. After being above for period bars, SeriesIsAboveValue returns 1 and increments with each new bar that the DataSeries is above the value.
See also:
Series Is Below a Value
Series Is AboveExample
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 = Date[bar] - Date[p.EntryBar];
if (ts.Days > 29)
ExitAtMarket(bar + 1, p, "Time-based");
}
else
{
if (rsiAbove95[bar] >= 5 )
{
BuyAtMarket(bar + 1);
SetBackgroundColor(bar, Color.FromArgb(50, Color.Red));
}
else
if (rsiBelow5[bar] >= 5 )
{
ShortAtMarket(bar + 1);
SetBackgroundColor(bar, Color.FromArgb(50, Color.Blue));
}
}
}
}
}
}