Skip to content

AccumulativeSwingIndex

Summary

A variation on Wilder's swing index which plots an accumulation of the swing index value of each candlestick or bar.

Remarks

The accumulative swing index is used to gain a longer-term picture than the Wilder's swing index. When the accumulative swing index is positive, the long-term trend is up. When the accumulative swing index is negative, it signals a downwards long-term trend.

Signature

1
public abstract interface AccumulativeSwingIndex

Namespace

cAlgo.API.Indicators

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
    using cAlgo.API;
    using cAlgo.API.Indicators;
    namespace cAlgo.Indicator
    {
        [Indicator]
        public class AccumSwingIndexReferenceExample:Indicator
        {
            private AccumulativeSwingIndex _accumulativeSwingIndex;
            [Parameter("Limit Move", DefaultValue = 12)]
            public int LimitMove { get; set; }
            [Output("Main")]
            public IndicatorDataSeries Result { get; set; }
            protected override void Initialize()
            {
                _accumulativeSwingIndex = Indicators.AccumulativeSwingIndex(LimitMove);
            }
            public override void Calculate(int index)
            {
              // Display Result of Indicator
                Result[index] = _accumulativeSwingIndex.Result[index];
            }
        }
    }
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
 using cAlgo.API;
 using cAlgo.API.Indicators;
 namespace cAlgo.Robots
 {
     // This sample cBot shows how to use an Accumulative Swing Index indicator
     [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
     public class AccumulativeSwingIndexSample : Robot
     {
         private double _volumeInUnits;
         private AccumulativeSwingIndex _accumulativeSwingIndex;
         [Parameter("Volume (Lots)", DefaultValue = 0.01)]
         public double VolumeInLots { get; set; }
         [Parameter("Stop Loss (Pips)", DefaultValue = 10)]
         public double StopLossInPips { get; set; }
         [Parameter("Take Profit (Pips)", DefaultValue = 10)]
         public double TakeProfitInPips { get; set; }
         [Parameter("Label", DefaultValue = "Sample")]
         public string Label { get; set; }
         public Position[] BotPositions
         {
             get
             {
                 return Positions.FindAll(Label);
             }
         }
         protected override void OnStart()
         {
             _volumeInUnits = Symbol.QuantityToVolumeInUnits(VolumeInLots);
             _accumulativeSwingIndex = Indicators.AccumulativeSwingIndex(12);
         }
         protected override void OnBar()
         {
             foreach (var position in BotPositions)
             {
                 if ((position.TradeType == TradeType.Buy && _accumulativeSwingIndex.Result.Last(1) < _accumulativeSwingIndex.Result.Last(2))
                     || (position.TradeType == TradeType.Sell && _accumulativeSwingIndex.Result.Last(1) > _accumulativeSwingIndex.Result.Last(2)))
                 {
                     ClosePosition(position);
                 }
             }
             if (_accumulativeSwingIndex.Result.Last(1) > 0 && _accumulativeSwingIndex.Result.Last(2) <= 0)
             {
                 ExecuteMarketOrder(TradeType.Buy, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
             }
             else if (_accumulativeSwingIndex.Result.Last(1) < 0 && _accumulativeSwingIndex.Result.Last(2) >= 0)
             {
                 ExecuteMarketOrder(TradeType.Sell, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
             }
         }
     }
 }

Properties

Result

Summary

The time series of AccumulativeSwingIndex.

Signature

1
public abstract IndicatorDataSeries Result {get;}

Return Value

IndicatorDataSeries

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
 //...
 private AccumulativeSwingIndex _accumulativeSwingIndex;
 //...
 [Parameter("Limit Move", DefaultValue = 12)]
 public int LimitMove { get; set; }
 //...
 protected override void OnStart()
 {
     _accumulativeSwingIndex = Indicators.AccumulativeSwingIndex(LimitMove);
 }
 protected override void OnBar()
 {
     // Print to log
     Print("The Current Accumulative Swing Index is: {0}", _accumulativeSwingIndex.Result.LastValue);
 }
 //...