Consecutive Days Up/Down of some percent

Modified on 2014/04/08 10:38 by Eugene — Categorized as: Community Indicators

ConsecDaysDown, ConsecDaysUp: Indicator Documentation

Syntax

Starting from version 2013.01:


DataSeries ConsecDaysDown( DataSeries ds, double pct );
DataSeries ConsecDaysUp( DataSeries ds, double pct );

Parameter Description

bars A Bars object
ds DataSeries that has declined/increased
pct Percentage decline/increase

Description

These indicators, developed by Dion Kurczek, display the number of consecutive days where prices declined (or rose) by a specified percentage or more.

Example

This example illustrates how to create a simple trading system that buys after the closing price has declined 5% or more for 2 days in a row, and shorts when the closing price has increased 5% or more for 2 days in a row. It exits after 5 days in a position at open next bar.


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 ConsecDaysDemo : WealthScript { protected override void Execute() { ConsecDaysDown cdd = ConsecDaysDown.Series( Close, 5 ); ConsecDaysUp cdu = ConsecDaysUp.Series( Close, 5 ); ChartPane mPane = CreatePane( 20, true, true ); PlotSeries( mPane, cdd, Color.Red, LineStyle.Histogram, 10 ); PlotSeries( mPane, cdu, Color.Blue, LineStyle.Histogram, 10 ); for(int bar = 1; bar < Bars.Count; bar++) { if (IsLastPositionActive) { Position p = LastPosition; if ( bar+1 - p.EntryBar >= 5 ) ExitAtMarket( bar+1, p, "Timed" ); } else { if( cdu[bar] >= 2 ) ShortAtMarket( bar+1 ); if( cdd[bar] >= 2 ) BuyAtMarket( bar+1 ); } } } } }