Alligator
interface cAlgo.API.Indicators
DesktopCLICloud
Legendary trader Bill Williams, an early pioneer of market psychology, developed the trend-following Alligator indicator, which follows the premise that financial markets and individual securities trend just 15% to 30% of the time while grinding through sideways ranges the other 70% to 85% of the time.
Definition
public interface Alligator
Namespace: cAlgo.API.Indicators · Group: Indicators · Implements: StandardIndicator
Examples
Example 1
var alligator = Indicators.Alligator(13, 8, 8, 5, 5, 3, MovingAverageType.WilderSmoothing);
Print("Jaws: {0}, Teeth: {1}, Lips: {2}", alligator.Jaws.Last(1), alligator.Teeth.Last(1), alligator.Lips.Last(1));
alligator = api.Indicators.Alligator(13, 8, 8, 5, 5, 3, MovingAverageType.WilderSmoothing)
api.Print(f"Jaws: {alligator.Jaws.Last(1)}, Teeth: {alligator.Teeth.Last(1)}, Lips: {alligator.Lips.Last(1)}")
Example 2
using cAlgo.API;
using cAlgo.API.Indicators;
namespace cAlgo.Robots
{
// This sample cBot shows how to use the Alligator indicator
public partial class AlligatorSample : Robot
{
private double _volumeInUnits;
private Alligator _alligator;
public Position[] BotPositions
{
get
{
return Positions.FindAll(Label);
}
}
protected override void OnStart()
{
_volumeInUnits = Symbol.QuantityToVolumeInUnits(VolumeInLots);
_alligator = Indicators.Alligator(13, 8, 8, 5, 5, 3, MovingAverageType.WilderSmoothing);
}
protected override void OnBar()
{
if (_alligator.Lips.Last(1) > _alligator.Teeth.Last(1) && _alligator.Lips.Last(2) <= _alligator.Teeth.Last(2))
{
ClosePositions(TradeType.Sell);
ExecuteMarketOrder(TradeType.Buy, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
}
else if (_alligator.Lips.Last(1) < _alligator.Teeth.Last(1) && _alligator.Lips.Last(2) >= _alligator.Teeth.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);
}
}
}
}
import clr
clr.AddReference("cAlgo.API")
# Import cAlgo API types
from cAlgo.API import *
# Import trading wrapper functions
from robot_wrapper import *
class AlligatorSample():
def on_start(self):
self.volumeInUnits = api.Symbol.QuantityToVolumeInUnits(api.VolumeInLots)
self.alligator = api.Indicators.Alligator(13, 8, 8, 5, 5, 3, MovingAverageType.WilderSmoothing)
def on_bar_closed(self):
if self.alligator.Lips.Last(0) > self.alligator.Teeth.Last(0) and self.alligator.Lips.Last(1) <= self.alligator.Teeth.Last(1):
self.close_positions(TradeType.Sell)
api.ExecuteMarketOrder(TradeType.Buy, api.SymbolName, self.volumeInUnits, api.Label, api.StopLossInPips, api.TakeProfitInPips)
elif self.alligator.Lips.Last(0) < self.alligator.Teeth.Last(0) and self.alligator.Lips.Last(1) >= self.alligator.Teeth.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)
{
"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
| Name | Description |
|---|---|
JawsDesktopCLICloudIndicatorDataSeries | The jaw is the x-period (13) smoothed moving average that is moved into the future by x (18) bars. |
LipsDesktopCLICloudIndicatorDataSeries | The lips is the x-period (5) smoothed moving average that is moved by x (3) bars into the future |
TeethDesktopCLICloudIndicatorDataSeries | The teeth is the x-period (8) smoothed moving average that is moved x (5) bars into the future. |
Inherited members
From StandardIndicator: AddToChart, Symbol, TimeFrame, Bars