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