Log in to see Cloud of Tags

Wealth-Lab Wiki


public static Sum Series(WealthLab.DataSeries ds, int period)
public Sum(DataSeries ds, int period, string description)
public static double Value(int bar, DataSeries ds, int period)

Parameter Description

ds The source DataSeries
period Indicator calculation period


Returns the sum of values from the specified DataSeries over the desired period. This is not really an indicator per se, but a mathematical function used to summate values in a DataSeries. You can use this function to build your own custom indicators, like in the example shown below.

In this example, we add all the highs for twenty bars, then add all the lows for twenty bars, producing two floating point values, xUp and xDown. The two floats are subtracted and the result used to build a new series called UpMinusDown. This new indicator series behaves similar to the ATR indicator.


Sum is most useful when making your own custom indicators to integrate over a specified number of periods.


Performs the addition of the elements in a DataSeries over the period specified.

Sum = ( D1 + D2 + ... + Dn )


Sum = summation of price values
D = DataSeries to be summated, Bars.Open, Bars.Close, TrueRange.Series, SMA.Series, etc...
n = number of periods or Bars


This example trading system is based on counting the number of Up and Down days on heavy volume over the last 50 days. It buys when the count of Up days on heavy volume is 2 greater that the down days on heavy volume.

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

namespace WealthLab.Strategies { public class PriceVolumeRank : WealthScript { protected override void Execute() { DataSeries dsBVUD = new DataSeries(Bars,"BigVolumeUpDays"); DataSeries dsBVDD = new DataSeries(Bars,"BigVolumeDownDays"); SMA smaVol = SMA.Series(Volume,50); int days = 5; for(int bar = GetTradingLoopStartBar(50); bar < Bars.Count; bar++) { //A big volume up day would equal //If close is greater than yesterday and volume was 150% greater than the average volume for the last 50 days count as big up volume day.

//A big volume down day would equal //If close is less than yesterday and volume was 150% greater than the average volume for the last 50 days count as big down volume day. bool bigVol = Volume[bar] > smaVol[bar-1] * 1.5; int upDay = (Close[bar] > Close[bar-1]) && bigVol ? 1 : 0; int dnDay = (Close[bar] < Close[bar-1]) && bigVol ? 1 : 0;

//I'd like to count the number of Up days - the number of down days on heavy volume over the last 50 days. //Then the buys signal would be the count of Up days on heavy volume 2 greater that the down days on heavy volume.

dsBVUD[bar] = upDay; dsBVDD[bar] = dnDay; } dsBVUD = Sum.Series(dsBVUD,50); dsBVDD = Sum.Series(dsBVDD,50); ChartPane cpD = CreatePane( 30,true,true ); ChartPane cpU = CreatePane( 30,true,true ); PlotSeries( cpU, dsBVUD, Color.Red, WealthLab.LineStyle.Histogram, 3 ); PlotSeries( cpD, dsBVDD, Color.Blue, WealthLab.LineStyle.Histogram, 3 ); for(int bar = 1; bar < Bars.Count; bar++) { if (IsLastPositionActive) { // Exit after N days Position p = LastPosition; if ( bar+1 - p.EntryBar >= days ) SellAtMarket( bar+1, p, "Timed" ); } else { if (dsBVUD[bar] > dsBVDD[bar] * 2) { SetBackgroundColor( bar, Color.FromArgb( 30, Color.Red ) ); 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. By using this web site, you agree to the terms of this disclaimer and our Terms of Use.

ScrewTurn Wiki. Some of the icons created by FamFamFam.