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);
             }
         }
     }
 }
1
2
3
4
5
6
7
8
9
 import clr
 clr.AddReference("cAlgo.API")
 from cAlgo.API import *
 class Test():    
     def initialize(self):
         # LimitMove is a parameter defined in C# file of indicator
         self.accumulativeSwingIndex = Indicators.AccumulativeSwingIndex(api.LimitMove)
     def calculate(self, index):
         api.Result[index] = self.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
 """
 VolumeInLots, StopLossInPips, TakeProfitInPips, and Label are parameters defined in C# file of cBot.
 """
 import clr
 clr.AddReference("cAlgo.API")
 # Import cAlgo API types
 from cAlgo.API import *
 # Import trading wrapper functions
 from robot_wrapper import *
 class AccumulativeSwingIndexSample():
     def on_start(self):
         self.volumeInUnits = api.Symbol.QuantityToVolumeInUnits(api.VolumeInLots)
         self.accumulativeSwingIndex = api.Indicators.AccumulativeSwingIndex(12)
     def on_bar_closed(self):
         for position in self.get_bot_positions():
             if (position.TradeType == TradeType.Buy and self.accumulativeSwingIndex.Result.Last(0) < self.accumulativeSwingIndex.Result.Last(1)) or (position.TradeType == TradeType.Sell and self.accumulativeSwingIndex.Result.Last(0) > self.accumulativeSwingIndex.Result.Last(1)):
                 api.ClosePosition(position);
         if self.accumulativeSwingIndex.Result.Last(0) > 0 and self.accumulativeSwingIndex.Result.Last(1) <= 0:
             api.ExecuteMarketOrder(TradeType.Buy, api.SymbolName, self.volumeInUnits, api.Label, api.StopLossInPips, api.TakeProfitInPips)
         elif (self.accumulativeSwingIndex.Result.Last(0) < 0 and self.accumulativeSwingIndex.Result.Last(1) >= 0):
             api.ExecuteMarketOrder(TradeType.Sell, api.SymbolName, self.volumeInUnits, api.Label, api.StopLossInPips, api.TakeProfitInPips)
     def get_bot_positions(self):
         return api.Positions.FindAll(api.Label)

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);
 }
 //...
1
2
3
4
 def on_start(self):
     self.accumulativeSwingIndex = api.Indicators.AccumulativeSwingIndex(api.LimitMove)
 def on_bar_closed(self):
     print(f"The Current Accumulative Swing Index is: {self.accumulativeSwingIndex.Result.LastValue}")