Developed by Welles Wilder, the Swing Index compares current Open, high, Low and Close prices to find of current and previous periods to find "real" price.
usingcAlgo.API;usingcAlgo.API.Indicators;namespacecAlgo.Indicators{[Indicator]publicclassTest:Indicator{privateSwingIndex_swingIndex;[Parameter(DefaultValue = 12)]publicintLimitMoveValue{get;set;}protectedoverridevoidInitialize(){_swingIndex=Indicators.SwingIndex(LimitMoveValue);}publicoverridevoidCalculate(intindex){//Print the current value of SwingIndex to the logPrint("The current value of SwingIndex is {0}",_swingIndex.Result[index]);}}}
usingcAlgo.API;usingcAlgo.API.Indicators;namespacecAlgo.Robots{// This sample cBot shows how to use the Swing Index indicator[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]publicclassSwingIndexSample:Robot{privatedouble_volumeInUnits;privateSwingIndex_swingIndex;[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);_swingIndex=Indicators.SwingIndex(12);}protectedoverridevoidOnBar(){if(_swingIndex.Result.Last(1)>0&&_swingIndex.Result.Last(2)<=0){ClosePositions(TradeType.Sell);ExecuteMarketOrder(TradeType.Buy,SymbolName,_volumeInUnits,Label,StopLossInPips,TakeProfitInPips);}elseif(_swingIndex.Result.Last(1)<0&&_swingIndex.Result.Last(2)>=0){ClosePositions(TradeType.Buy);ExecuteMarketOrder(TradeType.Sell,SymbolName,_volumeInUnits,Label,StopLossInPips,TakeProfitInPips);}}privatevoidClosePositions(TradeTypetradeType){foreach(varpositioninBotPositions){if(position.TradeType!=tradeType)continue;ClosePosition(position);}}}}
Gets the Result Series of the Swing Index indicator.
Signature
1
publicabstractIndicatorDataSeriesResult{get;}
Return Value
IndicatorDataSeries
Examples
12345
publicoverridevoidCalculate(intindex){//Print the current value of SwingIndex to the logPrint("The current value of SwingIndex is {0}",_swingIndex.Result[index]);}