cbot renko

Created at 14 Jun 2020, 22:32
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
EM

EMILIO1.1

Joined 26.02.2020

cbot renko
14 Jun 2020, 22:32


saludos

This program opens two positions, one to buy and one to sell, and when the Stop Loss jumps, it opens two other positions, but the error is that it also opens two positions, when the Stake Stop is activated, it can be changed

 using cAlgo.API;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class HedgingWithStopLossRobot : Robot
    {
        [Parameter("Volume (Lots)", DefaultValue = 0.1)]
        public double VolumeInLots { get; set; }

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

        [Parameter("Take Profit (Pips)", DefaultValue = 40)]
        public int TakeProfitInPips { get; set; }

        protected override void OnStart()
        {
            // Abrir una posición de compra
            ExecuteMarketOrder(TradeType.Buy, Symbol, VolumeInLots, "Buy", StopLossInPips, TakeProfitInPips);

            // Abrir una posición de venta
            ExecuteMarketOrder(TradeType.Sell, Symbol, VolumeInLots, "Sell", StopLossInPips, TakeProfitInPips);

            // Suscribirse al evento Positions.Closed
            Positions.Closed += OnPositionClosed;
        }

        private void OnPositionClosed(PositionClosedEventArgs args)
        {
            // Verificar si la posición cerrada tenía activado el stop-loss
            if (args.Position.StopLoss != null && args.Position.StopLoss.Value != 0)
            {
                // Abrir dos nuevas posiciones, una de compra y otra de venta
                ExecuteMarketOrder(TradeType.Buy, Symbol, VolumeInLots, "Buy", StopLossInPips, TakeProfitInPips);
                ExecuteMarketOrder(TradeType.Sell, Symbol, VolumeInLots, "Sell", StopLossInPips, TakeProfitInPips);
            }
        }
    }
}


@EMILIO1.1