---
id: "T:cAlgo.API.Indicators.ParabolicSAR"
kind: "interface"
namespace: "cAlgo.API.Indicators"
url: "https://help.ctrader.com/ctrader-algo/references/Indicators/ParabolicSAR/"
---

> Documentation index for agents: https://help.ctrader.com/ctrader-algo/llms.txt · machine index: https://help.ctrader.com/ctrader-algo/api.json

# ParabolicSAR (interface)

The calculation of the Parabolic SAR Indicator.

Environments: Desktop supported · CLI supported · Cloud supported.

## Definition

```csharp
public interface ParabolicSAR
```

## 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.

## Examples

C#:

```csharp
private ParabolicSAR _parabolic;
protected override void Initialize()
{
    _parabolic = Indicators.ParabolicSAR(0.02, 0.2);
}
public override void Calculate(int index)
{
    double parabolic = _parabolic.Result[index];
}
```

Python:

```python
import clr
clr.AddReference("cAlgo.API")

from cAlgo.API import *

class Test():
    def initialize(self):
        # 0.02 is the minimum and 0.2 the maximum acceleration factor
        self.parabolicSar = api.Indicators.ParabolicSAR(0.02, 0.2)

    def calculate(self, index):
        parabolic = self.parabolicSar.Result[index]
```

C#:

```csharp
using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Robots
{
    // This sample cBot shows how to use the Parabolic SAR indicator
    public partial class ParabolicSARSample : Robot
    {
        private double _volumeInUnits;

        private ParabolicSAR _parabolicSAR;

        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);
            }
        }
    }
}
```

Python:

```python
import clr

clr.AddReference("cAlgo.API")

# Import cAlgo API types
from cAlgo.API import *

# Import trading wrapper functions
from robot_wrapper import *

class ParabolicSARSample():
    def on_start(self):
        self.volumeInUnits = api.Symbol.QuantityToVolumeInUnits(api.VolumeInLots)
        self.parabolicSAR = api.Indicators.ParabolicSAR(0.02, 0.2)

    def on_bar_closed(self):
        if self.parabolicSAR.Result.Last(0) < api.Bars.LowPrices.Last(0) and self.parabolicSAR.Result.Last(1) > api.Bars.HighPrices.Last(1):
            self.close_positions(TradeType.Sell)
            api.ExecuteMarketOrder(TradeType.Buy, api.SymbolName, self.volumeInUnits, api.Label, api.StopLossInPips, api.TakeProfitInPips)
        elif self.parabolicSAR.Result.Last(0) > api.Bars.HighPrices.Last(0) and self.parabolicSAR.Result.Last(1) < api.Bars.LowPrices.Last(1):
            self.close_positions(TradeType.Buy)
            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)

    def close_positions(self, tradeType):
        for position in self.get_bot_positions():
            if position.TradeType != tradeType:
                continue
            api.ClosePosition(position)
```

config.json:

```json
{
  "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

- `IndicatorDataSeries Result {get;}` — Gets the resulting series of the Parabolic SAR indicator. [details](https://help.ctrader.com/ctrader-algo/references/Indicators/ParabolicSAR/Result/index.md)

## Inherited members

- `ChartIndicator AddToChart()` (from StandardIndicator) [details](https://help.ctrader.com/ctrader-algo/references/General/StandardIndicator/AddToChart/index.md)
- `Symbol Symbol {get;}` (from StandardIndicator) [details](https://help.ctrader.com/ctrader-algo/references/General/StandardIndicator/Symbol/index.md)
- `TimeFrame TimeFrame {get;}` (from StandardIndicator) [details](https://help.ctrader.com/ctrader-algo/references/General/StandardIndicator/TimeFrame/index.md)
- `Bars Bars {get;}` (from StandardIndicator) [details](https://help.ctrader.com/ctrader-algo/references/General/StandardIndicator/Bars/index.md)

