Skip to content

ParabolicSAR

Summary

The calculation of the Parabolic SAR Indicator.

Remarks

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.

Signature

1
public abstract interface ParabolicSAR

Namespace

cAlgo.API.Indicators

Properties

Name Description
Result { get; } Gets the resulting series of the Parabolic SAR indicator.

Examples

1
2
3
4
5
6
7
8
9
 private ParabolicSAR _parabolic;
 protected override void Initialize()
 {
     _parabolic = Indicators.ParabolicSAR(minaf, maxaf);
 }
 public override void Calculate(int index)
 {
     double parabolic = _parabolic.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
52
53
 using cAlgo.API;
 using cAlgo.API.Indicators;
 namespace cAlgo.Robots
 {
     // This sample cBot shows how to use the Parabolic SAR indicator
     [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
     public class ParabolicSARSample : Robot
     {
         private double _volumeInUnits;
         private ParabolicSAR _parabolicSAR;
         [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);
             _parabolicSAR = Indicators.ParabolicSAR(0.02, 0.2);
         }
         protected override void OnBar()
         {
             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);
             }
             else if (_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);
             }
         }
         private void ClosePositions(TradeType tradeType)
         {
             foreach (var position in BotPositions)
             {
                 if (position.TradeType != tradeType) continue;
                 ClosePosition(position);
             }
         }
     }
 }

Last update: December 8, 2022

Comments