Log in to see Cloud of Tags

**Main Page**- Category List
- Knowledge Base
- Traders Tips
- Indicator documentation
- Addin examples

Log in to search

```
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)
```

ds |
The source DataSeries |

period |
Indicator calculation period |

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 = ( D1 + D2 + ... + Dn )

where,

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

```
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);
}
}
}
}
}
}