Alligator


Summary

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.

Syntax

public interface Alligator

Members

NameTypeSummary
Jaws Property
Lips Property
Teeth Property

Example 1

using cAlgo.API;
using cAlgo.API.Indicators;
namespace cAlgo.Robots
{
    // This sample cBot shows how to use the Alligator indicator
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class AlligatorSample : Robot
    {
        private double _volumeInUnits;
        private Alligator _alligator;
        [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);
            _alligator = Indicators.Alligator(13, 18, 8, 5, 5, 3);
        }
        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);
            }
        }
    }
}
Reference