Category Range  Published on 20/10/2021

Hora Específica de la estrategia

Description

cBot el cual tiene la funcion de asignarle un horario de inicio y un horario de fin a la estrategia.
Este es un ejemplo ilustrativo de la aperura de New York en Horario UTC
 
 Es importante colocar el Horario UTC y si tu horario es diferente al Horario UTC tienes que adecuarlo
 
Este ejemplo es del Nasdaq en 1 minuto (1M)

 


   
   Autor: Jorge Eduardo Arteaga Galicia
   @arteagagalicia



/*cBot el cual tiene la funcion de asignarle un horario de inicio y un horario de fin a la estrategia.
 * Este es un ejemplo ilustrativo de la aperura de New York en Horario UTC
 * 
 * Es importante colocar el Horario UTC y si tu horario es diferente al Horario UTC tienes que adecuarlo
 * 
 * Este ejemplo es del Nasdaq en 1 minuto (1M)
   
   Autor: Jorge Eduardo Arteaga Galicia
   @arteagagalicia
*/

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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class cTrader_Hora_Especifica : Robot
    {
        [Parameter("Quantity (Lots)", DefaultValue = 1, MinValue = 0.01, Step = 0.01, Group = "Lotaje")]
        public double Quantity { get; set; }

        [Parameter("Hora Inicio UTC", DefaultValue = 13, Group = "Horario")]
        //Definimos la hora de inicio
        public int HoraInicio { get; set; }

        [Parameter("Hora Fin UTC", DefaultValue = 14, Group = "Horario")]
        //Definimos la hora de inicio
        public int HoraFin { get; set; }

        [Parameter("Minuto Inicio UTC", DefaultValue = 30, Group = "Horario")]
        //Definimos el minuto de inicio
        public int MinutoInicio { get; set; }

        [Parameter("Minuto Fin UTC", DefaultValue = 59, Group = "Horario")]
        //Definimos el minuto de fin
        public int MinutoFin { get; set; }

        [Parameter("Take Profit", DefaultValue = 30, Group = "Riesgo-Beneficio")]
        //Definimos el minuto de fin
        public int TP { get; set; }

        [Parameter("Stop Loss", DefaultValue = 10, Group = "Riesgo-Beneficio")]
        //Definimos el minuto de fin
        public int SL { get; set; }


        bool status = false;
        private const string label = "Hora especifica";
        protected override void OnStart()
        {
            // Put your initialization logic here
        }

        protected override void OnBar()
        {
            // Put your core logic here
            var currentHours = Server.Time.Hour;
            var currentMinutes = Server.Time.Minute;

            //Condicion para que el bot funcione en el tiempo establecido
            if (HoraInicio == HoraFin)
            {
                if (currentHours == HoraInicio && currentMinutes >= MinutoInicio)
                {

                    status = true;
                }

                else if (currentHours == HoraFin && currentMinutes <= MinutoFin && currentMinutes >= MinutoInicio)
                {
                    status = true;
                }
                else
                {
                    status = false;
                }

            }
            else
            {
                if (currentHours == HoraInicio)
                {
                    if (currentMinutes == MinutoInicio)
                    {
                        status = true;
                    }
                }
                else if (currentHours == HoraFin)
                {
                    if (currentMinutes == MinutoFin)
                    {
                        status = false;
                    }
                }
            }





            var longPosition = Positions.Find(label, SymbolName, TradeType.Buy);

            if (status == true && longPosition == null)
            {
                Print("Entramos");
                ExecuteMarketOrder(TradeType.Buy, Symbol, Quantity, label, SL, TP);
            }

        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}


jorgearteaga's avatar
jorgearteaga

Joined on 12.02.2021

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: cTrader_Hora_Especifica.algo
  • Rating: 5
  • Installs: 1364
Comments
Log in to add a comment.
GM
gmkenneyy · 2 years ago

How is this useful to anyone?

All it does is place a buy order when a new bar opens. It never places sell orders. There is no logic whatsoever to determine trend direction.

The buy order will then wait for however long it takes to hit either SL or TP.  

EM
emmasystems · 2 years ago

Any English version.

HF
hfbi037 · 2 years ago

Buen bot !!!