cristianalejandropj2275
cristianalejandropj2275's avatar

Info

Username:cristianalejandropj2275
Name:cristianalejandropj2275
Member since: 24 Apr 2022

About

None

Signature

None

Last Forum Posts

@martingale without closing previous operation:  11 Oct 2022, 06:35


hello I would like this cBot not to close the position when opening the next one, but to close all when the last position reaches take profit

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 SampleTrendRobot : Robot
    {
        [Parameter("MA Type")]
        public MovingAverageType MAType { get; set; }

        [Parameter("Source")]
        public DataSeries SourceSeries { get; set; }

        [Parameter("Stop Loss", DefaultValue = 50)]
        public int StopLoss { get; set; }

        [Parameter("Take Profit", DefaultValue = 60)]
        public int TakeProfit { get; set; }

        [Parameter("Slow Periods", DefaultValue = 8)]
        public int SlowPeriods { get; set; }

        [Parameter("Fast Periods", DefaultValue = 3)]
        public int FastPeriods { get; set; }

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

        public int RSIPeriods { get; set; }
        private RelativeStrengthIndex rsi;
        private MovingAverage slowMa;
        private MovingAverage fastMa;
        private const string label = "Trend Martangle Robot";

        protected override void OnStart()
        {
            Positions.Closed += OnPositionsClosed;
            fastMa = Indicators.MovingAverage(SourceSeries, FastPeriods, MAType);
            slowMa = Indicators.MovingAverage(SourceSeries, SlowPeriods, MAType);
            rsi = Indicators.RelativeStrengthIndex(SourceSeries, RSIPeriods);
        }

        protected override void OnTick()
        {
            var longPosition = Positions.Find(label, Symbol, TradeType.Buy);
            var shortPosition = Positions.Find(label, Symbol, TradeType.Sell);
            var currentSlowMa = slowMa.Result.Last(0);
            var currentFastMa = fastMa.Result.Last(0);
            var previousSlowMa = slowMa.Result.Last(1);
            var previousFastMa = fastMa.Result.Last(1);

            if (previousSlowMa > previousFastMa && currentSlowMa <= currentFastMa && rsi.Result.LastValue < 30 && longPosition == null)
            {
                if (shortPosition != null)
                    ClosePosition(shortPosition);
                ExecuteMarketOrder(TradeType.Buy, Symbol, Symbol.NormalizeVolume(Volume), label, StopLoss, TakeProfit);
            }
            else if (previousSlowMa < previousFastMa && currentSlowMa >= currentFastMa && rsi.Result.LastValue > 70 && shortPosition == null)
            {
                if (longPosition != null)
                    ClosePosition(longPosition);
                ExecuteMarketOrder(TradeType.Sell, Symbol, Symbol.NormalizeVolume(Volume), label, StopLoss, TakeProfit);

            }
        }

        private void OnPositionsClosed(PositionClosedEventArgs args)
        {
            var position = args.Position;
            if (position.GrossProfit < 0)
              {
                TradeType tt = TradeType.Sell;
                if(position.TradeType==TradeType.Sell) tt = TradeType.Buy;
                ExecuteMarketOrder(tt, Symbol, Symbol.NormalizeVolume(position.Volume * 1.61803), "Martingale", StopLoss, TakeProfit);
              }
             }
        }
}

@cambiar secuencia 1,2,4,8,16,32 por 1,2,3,5,8,13,21:  03 Oct 2022, 18:01


Hola alguien que quiera hacer la buena obra del día dejo este código para ser modificado en vez de la secuencia estándar de la martingala me gustaría usar una secuencia Fibonacci 1,2,3,5,8,13,21,34 no se mucho de programación por no decir nada, creo que alguien con conocimiento me podría brindar ayuda gracias de antemano 

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 SampleTrendRobot : Robot
    {
        [Parameter("MA Type")]
        public MovingAverageType MAType { get; set; }

        [Parameter("Source")]
        public DataSeries SourceSeries { get; set; }

        [Parameter("Stop Loss", DefaultValue = 50)]
        public int StopLoss { get; set; }

        [Parameter("Take Profit", DefaultValue = 60)]
        public int TakeProfit { get; set; }

        [Parameter("Slow Periods", DefaultValue = 8)]
        public int SlowPeriods { get; set; }

        [Parameter("Fast Periods", DefaultValue = 3)]
        public int FastPeriods { get; set; }

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

        public int RSIPeriods { get; set; }
        private RelativeStrengthIndex rsi;
        private MovingAverage slowMa;
        private MovingAverage fastMa;
        private const string label = "Trend Martangle Robot";

        protected override void OnStart()
        {
            Positions.Closed += OnPositionsClosed;
            fastMa = Indicators.MovingAverage(SourceSeries, FastPeriods, MAType);
            slowMa = Indicators.MovingAverage(SourceSeries, SlowPeriods, MAType);
            rsi = Indicators.RelativeStrengthIndex(SourceSeries, RSIPeriods);
        }

        protected override void OnTick()
        {
            var longPosition = Positions.Find(label, Symbol, TradeType.Buy);
            var shortPosition = Positions.Find(label, Symbol, TradeType.Sell);
            var currentSlowMa = slowMa.Result.Last(0);
            var currentFastMa = fastMa.Result.Last(0);
            var previousSlowMa = slowMa.Result.Last(1);
            var previousFastMa = fastMa.Result.Last(1);

            if (previousSlowMa > previousFastMa && currentSlowMa <= currentFastMa && rsi.Result.LastValue < 30 && longPosition == null)
            {
                if (shortPosition != null)
                    ClosePosition(shortPosition);
                ExecuteMarketOrder(TradeType.Buy, Symbol, Symbol.NormalizeVolume(Volume), label, StopLoss, TakeProfit);
            }
            else if (previousSlowMa < previousFastMa && currentSlowMa >= currentFastMa && rsi.Result.LastValue > 70 && shortPosition == null)
            {
                if (longPosition != null)
                    ClosePosition(longPosition);
                ExecuteMarketOrder(TradeType.Sell, Symbol, Symbol.NormalizeVolume(Volume), label, StopLoss, TakeProfit);

            }
        }

        private void OnPositionsClosed(PositionClosedEventArgs args)
        {
            var position = args.Position;
            if (position.GrossProfit < 0)
              {
                TradeType tt = TradeType.Sell;
                if(position.TradeType==TradeType.Sell) tt = TradeType.Buy;
                ExecuteMarketOrder(tt, Symbol, Symbol.NormalizeVolume(position.Volume * 2), "Martingale", StopLoss, TakeProfit);
              }
             }
        }
}
Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.

No uploaded.

Warning! Executing cBots downloaded from this section may result in loss of funds. Use them at your own risk.
ONBAR SELL
  7
  0
  468
free  24 Apr 2022
vende en cada vela segun su periodo de tiempo  whatsapp   3218280967 correo cristianalejandropj@gmail.com