Category Trend  Published on 27/10/2016

Hedging progresivo

Description

La idea inicial de este cbot es abrir ordenes opuestas con un SL definido, de manera que cuando el precio cierre una posición se abran de nuevo 2 posiciones nuevas en hedging con SL definido de nuevo y así succesivamente acumulando beneficio en las posiciones abiertas siempre y cuando el precio no gire de nuevo.

Creo que es una muy buena opción para momentos en los que hay mucha volatilidad como por ejemplo en noticias.

Como tengo unos conocimientos en programación muy limitados este cbot tiene un problema que no se resolver, si operas en otro mercado mientras esta activo y cerras alguna posición, abre de nuevo 2 posiciones. Espero que alguien pueda ayudarme a mejorar este problema.

 

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

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class sergi : Robot
    {

        [Parameter("Volume", DefaultValue = 1000)]
        public int Volume { get; set; }

        [Parameter("Stop Loss (pips)", DefaultValue = 20, MinValue = 1)]
        public int StopLossInPips { get; set; }


        protected override void OnStart()
        {

            Positions.Closed += closedposition;
            ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "Sergi", StopLossInPips, 0);
            ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "Sergi", StopLossInPips, 0);

        }

        private void closedposition(PositionClosedEventArgs arg)
        {
            var pos = arg.Position;

            if ((pos.NetProfit < 0))
                Positions.Closed -= closedposition;
            OnStart();






        }

    }
}

 


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

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class HedgingSys : Robot
    {

        [Parameter("Volume", DefaultValue = 1000)]
        public int Volume { get; set; }

        [Parameter("Stop Loss (pips)", DefaultValue = 20, MinValue = 1)]
        public int StopLossInPips { get; set; }


        protected override void OnStart()
        {

            Positions.Closed += closedposition;
            ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "Sergi", StopLossInPips, 0);
            ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "Sergi", StopLossInPips, 0);

        }

        private void closedposition(PositionClosedEventArgs arg)
        {
            var pos = arg.Position;

            if ((pos.NetProfit < 0))
                Positions.Closed -= closedposition;
            OnStart();






        }

    }
}


SE
sergiestudillo1

Joined on 11.10.2016

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Hedging Sys.algo
  • Rating: 5
  • Installs: 3470
Comments
Log in to add a comment.
ripupo88's avatar
ripupo88 · 6 years ago

Hello andrei.iuliannistor, I can help you with that "algo" if you want to. Just tell me what you want and I will make it for you. 

ripupo88's avatar
ripupo88 · 6 years ago

Que alegria encontrar algo en español aqui. Si puedes dime como te ha ido con esta estrategia por que yo tambien programé un bot similar y los resultados fueron increibles pero siempre llega un momento en el que lo pierdo todo por que el mercado empieza a rebotar una y otra ves hasta perderlo todo. pero he obtenido hasta un 400% de beneficio en un mes (Cuenta demo).

Un saludo

 

AN
andrei.iuliannistor · 6 years ago

Hello. that is not "hedging" .  open the position on the same time Buy/Sell . Someone can adjust this "algo" . To hedge need to open 1 position and after whaiting for some pips to open an oposit position on double of the first . if come back to the first point then open again another position ...... without stoploss but with take proffit 3 times of the distance betwen the position. that mean if the distance betwen buy and sell is 30 pips than take profit will be 90 pips for buy in this case and stoploss for sell will be the 120 pips . and viceversa for sell position. i need help to create something like this  Thanks !

DA
DavidBecquer · 7 years ago

Hola Sergi, si, verdaderamente es raro ver algo en castellano aquí. Suerte y probaré tu robot. Si procede te daré mis sugerencias.

Saludos.

SE
sergiestudillo1 · 7 years ago

Muchas gracias galafrin, modificaré el codigo y el lunes lo pruebo en demo, ya que en backtest no funciona porque en el cbot no se cierran posiciones en positivo si no es de forma manual.

Es una alegría ver que me contestas en español, ya que por aqui veo que hay pocos y desde luego encontrar información relacionada con los cbots si no es aquí no la hay casi en ningún otro sitio.

 

Saludos.

GA
galafrin · 7 years ago

Positions.Closed abarca todo los symboles , entonces hay que filtrar en closedPosition así:

            var pos = arg.Position;
            if ( arg.Position.SymbolCode != Symbol.Code ) return;
            if ((pos.NetProfit < 0))
                Positions.Closed -= closedposition;
            OnStart();

 

Suerte.