cambiar secuencia 1,2,4,8,16,32 por 1,2,3,5,8,13,21

Created at 03 Oct 2022, 18:01
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!
CR

cristianalejandropj2275

Joined 24.04.2022

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);
              }
             }
        }
}

@cristianalejandropj2275
Replies

PanagiotisChar
04 Oct 2022, 08:01

Hi there,

It would be better to post in English. More chances to get help :)

Aieden Technologies

Need Help? Join us on Telegram

 


@PanagiotisChar