Skip to content

Commit c7a935b

Browse files
committed
PositiveVolumeIndex
1 parent cd89769 commit c7a935b

3 files changed

Lines changed: 1738 additions & 0 deletions

File tree

Algo/Indicators/Aliases.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,4 +1414,16 @@ public class WTO : WaveTrendOscillator
14141414
/// Initializes a new instance of the <see cref="WTO"/>.
14151415
/// </summary>
14161416
public WTO() { }
1417+
}
1418+
1419+
/// <summary>
1420+
/// <see cref="PositiveVolumeIndex"/> alias.
1421+
/// </summary>
1422+
[Browsable(false)]
1423+
public class PVI : PositiveVolumeIndex
1424+
{
1425+
/// <summary>
1426+
/// Initializes a new instance of the <see cref="PVI"/>.
1427+
/// </summary>
1428+
public PVI() { }
14171429
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
namespace StockSharp.Algo.Indicators;
2+
3+
/// <summary>
4+
/// Positive Volume Index (PVI) indicator.
5+
/// </summary>
6+
[Display(
7+
ResourceType = typeof(LocalizedStrings),
8+
Name = LocalizedStrings.PVIKey,
9+
Description = LocalizedStrings.PositiveVolumeIndexKey)]
10+
[IndicatorIn(typeof(CandleIndicatorValue))]
11+
[Doc("topics/indicators/positive_volume_index.html")]
12+
public class PositiveVolumeIndex : BaseIndicator
13+
{
14+
private decimal _prevClose;
15+
private decimal _prevVolume;
16+
private decimal _pvi;
17+
18+
/// <summary>
19+
/// Initializes a new instance of the <see cref="PositiveVolumeIndex"/>.
20+
/// </summary>
21+
public PositiveVolumeIndex()
22+
{
23+
Reset();
24+
}
25+
26+
/// <inheritdoc />
27+
public override IndicatorMeasures Measure => IndicatorMeasures.Percent;
28+
29+
/// <inheritdoc />
30+
protected override IIndicatorValue OnProcess(IIndicatorValue input)
31+
{
32+
var candle = input.ToCandle();
33+
34+
var pvi = _pvi;
35+
36+
if (_prevClose != 0 && _prevVolume != 0 && candle.TotalVolume > 0)
37+
{
38+
if (candle.TotalVolume > _prevVolume)
39+
{
40+
var priceChangePercent = (candle.ClosePrice - _prevClose) / _prevClose;
41+
42+
pvi += pvi * priceChangePercent;
43+
}
44+
}
45+
46+
if (input.IsFinal)
47+
{
48+
_prevClose = candle.ClosePrice;
49+
_prevVolume = candle.TotalVolume;
50+
_pvi = pvi;
51+
52+
IsFormed = true;
53+
}
54+
55+
return new DecimalIndicatorValue(this, pvi, input.Time);
56+
}
57+
58+
/// <inheritdoc />
59+
public override void Reset()
60+
{
61+
_prevClose = 0;
62+
_prevVolume = 0;
63+
_pvi = 1000;
64+
65+
base.Reset();
66+
}
67+
}

0 commit comments

Comments
 (0)