Donchian Trading System

Responder
Avatar de Usuario
X-Trader
Administrador
Mensajes: 12776
Registrado: 06 Sep 2004 10:18
Contactar:

Donchian Trading System

Mensaje por X-Trader »

Venga, que no se diga todo en esta vida es Metatrader: aquí os dejo una estrategia basada en el artículo publicado por el gran Óscar Cagigas en el número de febrero de 2014 de la revista Stock & Commodities.


Saludos,
X-Trader
Adjuntos
DonchianTradingSystem.zip
(8.63 KiB) Descargado 152 veces
"Los sistemas de trading pueden funcionar en ciertas condiciones de mercado todo el tiempo, en todas las condiciones de mercado en algún momento del tiempo, pero nunca en todas las condiciones de mercado todo el tiempo."
Avatar de Usuario
X-Trader
Administrador
Mensajes: 12776
Registrado: 06 Sep 2004 10:18
Contactar:

Re: Donchian Trading System

Mensaje por X-Trader »

Vale, ya veo, parece ser que no funciona bien el código. ¿Has podido probarlo para ver qué falla?

Por otro lado, acabo de encontrar la descripción de la estrategia detallada en ThinkorSwim, cito por aquí:

Donchian

Description
The Donchian strategy is a technical indicator based on the Donchian channel, allowing for several levels of complexity. The current implementation and default values of this channel are presented by Oscar G. Cagigas in his article "The Degree of Complexity".

In order to build the Donchian channel, the system registers the highest high and the lowest low price on two periods (by default, 40 and 15). The upper band value is equal to the highest high on the shorter period if there is a simulated short position; otherwise, the highest high on the longer period is used. The lower band uses the lowest low on the shorter period if there is a simulated long position; if the position is short or absent, the lowest price on the longer period is plotted instead.

At the lowest complexity level, the strategy adds simulated orders according to the following rules:

Buy To Open. The high price is greater than the previously calculated highest high on the longer period.

Sell To Open. The low price is less than the previously calculated lowest low on the longer period.

Buy To Close. The high price is greater than the previously calculated highest high on the shorter period.

Sell To Close. The low price is less than the previously calculated lowest low on the shorter period.

To increase the complexity of the system to the medium level, you can add either a volatility filter or an ATR-based stop loss. The volatility filter affects simulated entry orders: in addition to the previously described conditions, this filter enables checking whether the previous true range was less than its average value multiplied by a factor. The stop-loss affects simulated exit orders: for Sells, it checks whether the close price is less than the entry price minus the Average True Range (ATR) multiplied by the stop factor. For Buys, it's vice versa: the high price needs to exceed the entry price by the ATR multiplied by the stop factor. In order to set the strategy to the medium level, set either the atr factor or the atr stop factor to a non-zero value. If you prefer to use the highest complexity level, make sure both parameters are non-zero.

Further Reading
1. "The Degree Of Complexity" by Oscar G. Cagigas. Technical Analysis of Stocks & Commodities, February 2014.
Saludos,
X-Trader
"Los sistemas de trading pueden funcionar en ciertas condiciones de mercado todo el tiempo, en todas las condiciones de mercado en algún momento del tiempo, pero nunca en todas las condiciones de mercado todo el tiempo."
Avatar de Usuario
X-Trader
Administrador
Mensajes: 12776
Registrado: 06 Sep 2004 10:18
Contactar:

Re: Donchian Trading System

Mensaje por X-Trader »

Vale creo que he encontrado el fallo, es por un parámetro que está mal nombrado, por error lo llama al aTRStop y luego cambia a ATRStop en algunas líneas. Lo he corregido, quedaría así:

Código: Seleccionar todo

#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    /// <summary>
    /// Based off of the TASC February 2014 article, The Degree of Complexity, written by Oscar G. Cagigas
    /// </summary>
    [Description("Based off of the TASC February 2014 article, The Degree of Complexity, written by Oscar G. Cagigas")]
    public class DonchianTradingSystem : Strategy
    {
        #region Variables
		
        //User defined inputs
        private int len1 = 40;
        private int len2 = 15;
		private int ATRStop = 4;	
		
		
		//Non UDI
		private double BuyStop;
		private double SellStop;
		private double ShortStop;
		private double CoverStop;
		private double BuyPrice;
		private double ShortPrice;
		private double CoverPrice;
		private double SellPrice;
	
        
        #endregion

        /// <summary>
        /// This method is used to configure the strategy and is called once before any strategy method is called.
        /// </summary>
        protected override void Initialize()
        {
			Add(TASCDonchian(Len1, Len2));
			
			AccountSize = 100000;
			
			EntriesPerDirection = 4;
						
            CalculateOnBarClose = true;
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
			if(CurrentBar < 40)
				return; 
			
			//BuyStop,SellStop
			BuyStop = this.TASCDonchian(Len1, Len2).LongUpper[1];
			SellStop = this.TASCDonchian(Len1, Len2).ShortLower[1];
			ShortStop = this.TASCDonchian(Len1, Len2).LongLower[1];
			CoverStop = this.TASCDonchian(Len1, Len2).ShortUpper[1];
			
			//Exit Orders
			if(Position.MarketPosition == MarketPosition.Flat)
			{
				//Order Entry
				//Long
				if(High[0] > BuyStop) 
				{					
					BuyPrice = Math.Max(BuyStop, Open[0]);
					EnterLongStop(BuyPrice, "Buy Stop");				
				}
				
				//Short
				else if(Low[0] < ShortStop)
				{
					ShortPrice = Math.Min(ShortStop, Open[0]);
					EnterShortStop(ShortPrice, "Short Stop");		
				}
			}
			
			//Sell
			if(Position.MarketPosition == MarketPosition.Long)
			{
				if(Low[0] < SellStop)
				{
					SellPrice = BuyPrice - ATR(ATRStop)[0];
					ExitLongStop(SellPrice, "Buy Stop");
				}
			}
			
			//Cover
			else if(Position.MarketPosition == MarketPosition.Short)
			{
				if(High[0] > CoverStop)
				{
					CoverPrice = ShortPrice + ATR(ATRStop)[0];
					ExitShortStop(CoverPrice, "Short Stop");
				}
			}
			
		}
		
	

        #region Properties
        [Description("")]
        [GridCategory("Parameters")]
        public int Len1
        {
            get { return len1; }
            set { len1 = Math.Max(1, value); }
        }

        [Description("")]
        [GridCategory("Parameters")]
        public int Len2
        {
            get { return len2; }
            set { len2 = Math.Max(1, value); }
        }
		
		[Description("")]
        [GridCategory("Parameters")]
        public int ATRStop
        {
            get { return ATRStop; }
            set { ATRStop = Math.Max(1, value); }
        }
        #endregion
    }
}
¿Puede alguien probarlo para confirmar que está todo ok y actualizar el código en el primer mensaje?

Saludos,
X-Trader
"Los sistemas de trading pueden funcionar en ciertas condiciones de mercado todo el tiempo, en todas las condiciones de mercado en algún momento del tiempo, pero nunca en todas las condiciones de mercado todo el tiempo."
Rango Starr
Mensajes: 3842
Registrado: 22 Dic 2014 10:49

Re: Donchian Trading System

Mensaje por Rango Starr »

.
un ciclo y otro ciclo, son un biciclo...
si añadimos otro ciclo, entonces tendremos "un triciclo"... famoso trio catalan de humor de los 90....

..y nada mas...
Si te ha gustado este hilo del Foro, ¡compártelo en redes!


Responder

Volver a “Estrategias”