Developed by Welles Wilder, SAR stands for stop and reverse and is based on a concept similar to time decay, unless a security can continue to generate more profits over time, it should be liquidated. SAR trails prices as the trend extends over time, being below prices when they are increasing and above prices when they are decreasing. In this view, the indicator stops and reverses when the price trend reverses and breaks above or below the indicator. The indicator generally works well in trending markets, but not during non-trending, sideways phases. Therefore, Wilder recommended establishing the strength and direction of the trend first through the use of other indicators and then using the Parabolic SAR to trade that trend.The indicator is below prices when prices are rising and above prices when prices are falling. In this regard, the indicator stops and reverses when the price trend reverses and breaks above or below the indicator.
usingcAlgo.API;usingcAlgo.API.Indicators;namespacecAlgo.Robots{// This sample cBot shows how to use the Parabolic SAR indicator[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]publicclassParabolicSARSample:Robot{privatedouble_volumeInUnits;privateParabolicSAR_parabolicSAR;[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);_parabolicSAR=Indicators.ParabolicSAR(0.02,0.2);}protectedoverridevoidOnBar(){if(_parabolicSAR.Result.Last(1)<Bars.LowPrices.Last(1)&&_parabolicSAR.Result.Last(2)>Bars.HighPrices.Last(2)){ClosePositions(TradeType.Sell);ExecuteMarketOrder(TradeType.Buy,SymbolName,_volumeInUnits,Label,StopLossInPips,TakeProfitInPips);}elseif(_parabolicSAR.Result.Last(1)>Bars.HighPrices.Last(1)&&_parabolicSAR.Result.Last(2)<Bars.LowPrices.Last(2)){ClosePositions(TradeType.Buy);ExecuteMarketOrder(TradeType.Sell,SymbolName,_volumeInUnits,Label,StopLossInPips,TakeProfitInPips);}}privatevoidClosePositions(TradeTypetradeType){foreach(varpositioninBotPositions){if(position.TradeType!=tradeType)continue;ClosePosition(position);}}}}