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.
usingcAlgo.API;usingcAlgo.API.Indicators;namespacecAlgo.Indicator{[Indicator]publicclassAccumSwingIndexReferenceExample:Indicator{privateAccumulativeSwingIndex_accumulativeSwingIndex;[Parameter("Limit Move", DefaultValue = 12)]publicintLimitMove{get;set;}[Output("Main")]publicIndicatorDataSeriesResult{get;set;}protectedoverridevoidInitialize(){_accumulativeSwingIndex=Indicators.AccumulativeSwingIndex(LimitMove);}publicoverridevoidCalculate(intindex){// Display Result of IndicatorResult[index]=_accumulativeSwingIndex.Result[index];}}}
usingcAlgo.API;usingcAlgo.API.Indicators;namespacecAlgo.Robots{// This sample cBot shows how to use an Accumulative Swing Index indicator[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]publicclassAccumulativeSwingIndexSample:Robot{privatedouble_volumeInUnits;privateAccumulativeSwingIndex_accumulativeSwingIndex;[Parameter("Volume (Lots)", DefaultValue = 0.01)]publicdoubleVolumeInLots{get;set;}[Parameter("Stop Loss (Pips)", DefaultValue = 10)]publicdoubleStopLossInPips{get;set;}[Parameter("Take Profit (Pips)", DefaultValue = 10)]publicdoubleTakeProfitInPips{get;set;}[Parameter("Label", DefaultValue = "Sample")]publicstringLabel{get;set;}publicPosition[]BotPositions{get{returnPositions.FindAll(Label);}}protectedoverridevoidOnStart(){_volumeInUnits=Symbol.QuantityToVolumeInUnits(VolumeInLots);_accumulativeSwingIndex=Indicators.AccumulativeSwingIndex(12);}protectedoverridevoidOnBar(){foreach(varpositioninBotPositions){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);}elseif(_accumulativeSwingIndex.Result.Last(1)<0&&_accumulativeSwingIndex.Result.Last(2)>=0){ExecuteMarketOrder(TradeType.Sell,SymbolName,_volumeInUnits,Label,StopLossInPips,TakeProfitInPips);}}}}
//...privateAccumulativeSwingIndex_accumulativeSwingIndex;//...[Parameter("Limit Move", DefaultValue = 12)]publicintLimitMove{get;set;}//...protectedoverridevoidOnStart(){_accumulativeSwingIndex=Indicators.AccumulativeSwingIndex(LimitMove);}protectedoverridevoidOnBar(){// Print to logPrint("The Current Accumulative Swing Index is: {0}",_accumulativeSwingIndex.Result.LastValue);}//...