Category Trend  Published on 19/09/2023

Turtle Trade Channels Indicator

An update for this algorithm is currently pending moderation. Please revisit this page shortly to access the algorithm's latest version.
Description

This indicator represents a legendary trading system, which proves that great traders can be made, not born.

The Turtle Trade trend-following system stands in stark contrast to the "buy low and sell high" approach. This system was taught to a group of average and ordinary individuals, and almost everyone transformed into a profitable trader. It is based on the fundamental principles of the well-known Donchian Channels, originally developed by Richard Donchian.

The primary rule is to "Trade on a 20-day breakout and take profits when a 10-day high or low is breached."

The original system operates as follows:

Go long when the price High is equal to or above the previous 20-day highest price.
Go short when the price Low is equal to or below the previous 20-day lowest price.
Exit long positions when the price touches the exit line.
Exit short positions when the price touches the exit line.
The recommended initial stop-loss is set at ATR * 2 from the opening price.
The default system parameters are 20, 10, and 55, 20.

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Cloud("LongOpen", "LongSL", FirstColor = "Green", SecondColor = "Green", Opacity = 0.1)]
    [Cloud("ShortOpen", "ShortSL", FirstColor = "Red", SecondColor = "Red", Opacity = 0.1)]
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class mTurtleTradeChannelsIndicator : Indicator
    {
        [Parameter("Entry Bars (20)", DefaultValue = 20)]
        public int inpEntryBars { get; set; }
        [Parameter("Exit Bars (10)", DefaultValue = 10)]
        public int inpExitBars { get; set; }

        [Output("Slow HH", LineColor = "Silver", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outHHslow { get; set; }
        [Output("Slow LL", LineColor = "Silver", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outLLslow { get; set; }
        [Output("Fast HH", LineColor = "Gray", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outHHfast { get; set; }
        [Output("Fast LL", LineColor = "Gray", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outLLfast { get; set; }
        [Output("LongOpen", LineColor = "Transparent", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Solid, Thickness = 0)]
        public IndicatorDataSeries outLongOpen { get; set; }
        [Output("LongSL", LineColor = "Transparent", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Solid, Thickness = 0)]
        public IndicatorDataSeries outLongSL { get; set; }
        [Output("ShortOpen", LineColor = "Transparent", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Solid, Thickness = 0)]
        public IndicatorDataSeries outShortOpen { get; set; }
        [Output("ShortSL", LineColor = "Transparent", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Solid, Thickness = 0)]
        public IndicatorDataSeries outShortSL { get; set; }
        
        private IndicatorDataSeries _hhslow, _llslow, _hhfast, _llfast, _islong, _isshort, _longopen, _longsl, _shortopen, _shortsl;
        
        
        protected override void Initialize()
        {
            _hhslow = CreateDataSeries();
            _llslow = CreateDataSeries();
            _hhfast = CreateDataSeries();
            _llfast = CreateDataSeries();
            _islong = CreateDataSeries();
            _isshort = CreateDataSeries();
            _longopen = CreateDataSeries();
            _longsl = CreateDataSeries();
            _shortopen = CreateDataSeries();
            _shortsl = CreateDataSeries();
        }

        public override void Calculate(int i)
        {
            _hhslow[i] = i>inpEntryBars ? Bars.HighPrices.Maximum(inpEntryBars) : Bars.HighPrices[i];
            _llslow[i] = i>inpEntryBars ? Bars.LowPrices.Minimum(inpEntryBars) : Bars.LowPrices[i];
            _hhfast[i] = i>inpExitBars ? Bars.HighPrices.Maximum(inpExitBars) : Bars.HighPrices[i];
            _llfast[i] = i>inpExitBars ? Bars.LowPrices.Minimum(inpExitBars) : Bars.LowPrices[i];
            _islong[i]  = Bars.HighPrices[i] > _hhslow[i-1] || _islong[i-1] == +1 ? +1 : 0;
            _isshort[i] = Bars.LowPrices[i] < _llslow[i-1] || _isshort[i-1] == -1 ? -1 : 0;
            if(_llfast[i] < _llfast[i-1])
                _islong[i] = 0;
            if(_hhfast[i] > _hhfast[i-1])
                _isshort[i] = 0;
            _longopen[i] = _islong[i] > 0 ? _hhslow[i] : double.NaN;
            _longsl[i] = _islong[i] > 0 ? _llfast[i] : double.NaN;
            _shortopen[i] = _isshort[i] < 0 ? _llslow[i] : double.NaN;
            _shortsl[i] = _isshort[i] < 0 ? _hhfast[i] : double.NaN;
            
            outHHslow[i] = _hhslow[i];
            outLLslow[i] = _llslow[i];
            outHHfast[i] = _hhfast[i];
            outLLfast[i] = _llfast[i];
            outLongOpen[i] = _longopen[i];
            outLongSL[i] = _longsl[i];
            outShortOpen[i] = _shortopen[i];
            outShortSL[i] = _shortsl[i];
        }
    }
}



mfejza's avatar
mfejza

Joined on 25.01.2022

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: mTurtleTradeChannelsIndicator.algo
  • Rating: 5
  • Installs: 767
  • Modified: 19/09/2023 12:12
Comments
Log in to add a comment.
No comments found.