Skip to content

AccumulativeSwingIndex

interface cAlgo.API.Indicators

DesktopCLICloud

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

Definition

public interface AccumulativeSwingIndex

Namespace: cAlgo.API.Indicators · Group: Indicators · Implements: StandardIndicator

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.

Examples

Example 1

using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo
{
    public partial class AccumSwingIndexReferenceExample:Indicator
    {
        private AccumulativeSwingIndex _accumulativeSwingIndex;

        protected override void Initialize()
        {
            _accumulativeSwingIndex = Indicators.AccumulativeSwingIndex(LimitMove);
        }
        public override void Calculate(int index)
        {
            // Display Result of Indicator
            Result[index] = _accumulativeSwingIndex.Result[index];
        }
    }
}
import clr
clr.AddReference("cAlgo.API")

from cAlgo.API import *

class Test():
    def initialize(self):
        self.accumulativeSwingIndex = api.Indicators.AccumulativeSwingIndex(api.LimitMove)

    def calculate(self, index):
        api.Result[index] = self.accumulativeSwingIndex.Result[index]
{
  "Parameters": [
    {
      "Name": "LimitMove",
      "DisplayName": "Limit Move",
      "Type": "Integer",
      "DefaultValue": 12
    }
  ],
  "LineOutputs": [
    {
      "Name": "Result",
      "DisplayName": "Main"
    }
  ]
}

Example 2

using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Robots
{
    // This sample cBot shows how to use an Accumulative Swing Index indicator
    public partial class AccumulativeSwingIndexSample : Robot
    {
        private double _volumeInUnits;

        private AccumulativeSwingIndex _accumulativeSwingIndex;

        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);
            }
        }
    }
}
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)
{
  "AccessRights": "None",
  "TimeZone": "UTC",
  "Parameters": [
    {
      "Name": "VolumeInLots",
      "DisplayName": "Volume (Lots)",
      "Type": "Double",
      "DefaultValue": 0.01
    },
    {
      "Name": "StopLossInPips",
      "DisplayName": "Stop Loss (Pips)",
      "Type": "Double",
      "DefaultValue": 10
    },
    {
      "Name": "TakeProfitInPips",
      "DisplayName": "Take Profit (Pips)",
      "Type": "Double",
      "DefaultValue": 10
    },
    {
      "Name": "Label",
      "Type": "String",
      "DefaultValue": "Sample"
    }
  ]
}

Properties

Name Description
ResultDesktopCLICloudIndicatorDataSeries The time series of AccumulativeSwingIndex.

Inherited members

From StandardIndicator: AddToChart, Symbol, TimeFrame, Bars