Actualidad de sistemas e indicadores para #NinjaTrader http://t.co/3eiMVMVn #NinjaTrader
¿como definir las horas de entrada y salida del sistema?
18 mensajes
• Página 2 de 2 • 1, 2
Re: ¿como definir las horas de entrada y salida del sistema?Hola Serotonina,
Si no quieres usar estructuras DateTime, una forma muy simple de hacerlo es la siguiente: Declara las siguientes variables: private int Inicio1 = 900; private int Fin1 = 1300; private int Inicio2 = 1500; private int Fin2 = 1800 Luego en OnBarUpdate () haces el siguiente ajuste ya que la función ToTime() devuelve un Integer con la siguiente estructura Hmmss : int HI1 = Inicio1 * 100; int HF1 = Fin1 * 100; int HI2 = Inicio2 * 100; int HF2 = Fin2 * 100; Ahora ya puedes usarlo como condiciones usando la siguiente sintaxis: if((ToTime(Time[0])> HI1 && ToTime(Time[0])< HF1) || (ToTime(Time[0])> HI2 && ToTime(Time[0])< HF2) && ….) Aquí está explicado: http://www.ninjatrader.com/support/help ... totime.htm Saludos,
Re: ¿como definir las horas de entrada y salida del sistema?Gracias CJS, pero debo ser más tosco de lo q creía pues he copiado lo que me indicas en el código del sistema y no consigo que defina las horas. No sé si podrías especificarlo de manera que lo pueda copiar desde aquí y pegarlo en el código de ninja. Ya te digo que en programación estoy bastante pillao y aunque me estoy comiendo tutorial tras tutorial, aún no controlo el tema.
Gracias por tu aportación. Un saludo. serotonina..-
Re: ¿como definir las horas de entrada y salida del sistema?Os dejo un ejemplo que acabo de programar... destripando el código podéis ver el funcionamiento. En el ejemplo el sistema compra en el inicio de la sesión y vende en el fin. La hora de entrada y salida se pasa por parámetros (es optimizable, vamos...).
Saludos!
Re: ¿como definir las horas de entrada y salida del sistema?Hola Chicos,
Creo que lo pongo bien y no me hace ni caso... El horario que le marco no lo respeta para nada. ¿que tengo mal? /// <summary> /// Maximos y Minimos /// </summary> [Description("Maximos y Minimos")] public class Contra : Strategy { #region Variables // Wizard generated variables private int perdida = 1; // Default setting for Perdida private int objetivo = 1; // Default setting for Objetivo private int horaInicio = 0; // Default setting for HoraInicio private int horaFin = 0; // Default setting for HoraFin private int minutoInicio = 0; // Default setting for MinutoInicio private int minutoFin = 0; // Default setting for MinutoFin // User defined variables (add any user defined variables below) int iniciosesion=0; int finsesion=0; #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() { SetProfitTarget("", CalculationMode.Ticks, Objetivo); SetStopLoss("", CalculationMode.Ticks, Perdida, false); CalculateOnBarClose = true; iniciosesion=(horaInicio*10000)+(minutoInicio*100); finsesion=(horaFin*10000)+(minutoFin*100); } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { // Condition set 1 if (Close[0] < Open[0]) { EnterLongStop(DefaultQuantity, High[0], ""); } // Condition set 2 if (Close[0] > Open[0]) { EnterShortStop(DefaultQuantity, Low[0], ""); } { if(ToTime(Time[0])==iniciosesion) EnterLong(); if(ToTime(Time[0])==finsesion) ExitLong(); } } #region Properties [Description("")] [GridCategory("Parameters")] public int Perdida { get { return perdida; } set { perdida = Math.Max(1, value); } } [Description("")] [GridCategory("Parameters")] public int Objetivo { get { return objetivo; } set { objetivo = Math.Max(1, value); } } [Description("")] [GridCategory("Parameters")] public int HoraInicio { get { return horaInicio; } set { horaInicio = Math.Max(1, value); } } [Description("")] [GridCategory("Parameters")] public int HoraFin { get { return horaFin; } set { horaFin = Math.Max(0, value); } } [Description("")] [GridCategory("Parameters")] public int MinutoInicio { get { return minutoInicio; } set { minutoInicio = Math.Max(0, value); } } [Description("")] [GridCategory("Parameters")] public int MinutoFin { get { return minutoFin; } set { minutoFin = Math.Max(0, value); } } #endregion }
Re: ¿como definir las horas de entrada y salida del sistema?Tu operativa sólo depende del horario de sesión cuando lo pides:
if(ToTime(Time[0])==iniciosesion) EnterLong(); if(ToTime(Time[0])==finsesion) ExitLong(); En el resto de condicionales entran libremente... Saludos!
Re: ¿como definir las horas de entrada y salida del sistema?buenos tardes, yo con el archivo de Traderninja he nconseguido que la operacion me entre/salga a la hora que quiero, pero cuando le pongo un bracket (entrada y stop como yo quiero) ya no me dibuja nada y se me queda sin hacer ninguna operación, alguien me podria decir a que se debe, que he hecho mal.
SISTEMA #region Variables // Wizard generated variables private int tARGET = 30; // Default setting for TARGET private int sTOP = 30; // Default setting for STOP private int horaInicio = 8; // Default setting for HORAINICIO private int minutoInicio = 55; // Default setting for MINUTOINICIO private int segundoInicio = 1; // Default setting for SEGUNDOINICIO private int horaFin = 11; // Default setting for HORAFIN private int minutoFin = 5; // Default setting for MINUTOFIN private int segundoFin = 1; // Default setting for SEGUNDOFIN int iniciosesion=0; int finsesion=0; // User defined variables (add any user defined variables below) #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() { CalculateOnBarClose = true; SetProfitTarget("", CalculationMode.Ticks, TARGET); SetStopLoss("", CalculationMode.Ticks, STOP, false); CalculateOnBarClose = true; //Calculamos las variables para que las entienda la orden "ToTime": iniciosesion=(horaInicio*10000)+(minutoInicio*100)+segundoInicio; finsesion=(horaFin*10000)+(minutoFin*100)+segundoFin; } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if((ToTime(Time[0])==iniciosesion) && Close[0] < Open[0]) {EnterLong (); } if((ToTime(Time[0])==iniciosesion) && Close[0] < Open[0]) {EnterShort ();} }
Re: ¿como definir las horas de entrada y salida del sistema?Creo que la condición de entrada debería ser:
if(ToTime(Time[0])>=iniciosesion && ToTime(Time[0])<=finsesion && Close[0] < Open[0]) {EnterLong (); } if(ToTime(Time[0])>=iniciosesion && ToTime(Time[0])<=finsesion && Close[0] < Open[0]) {EnterShort ();} Saludos!
Re: ¿como definir las horas de entrada y salida del sistema?muchas gracias, era justo eso, ya funciona como yo quiero.
un saludo crack
18 mensajes
• Página 2 de 2 • 1, 2
¿Quién está conectado?Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 0 invitados |
|
| Bridge by mehdiplugins.com |










