max trades open per cbot

07 May 2019, 14:58max trades open per cbot#1
nelson.pmf.scposts: 6since: 07 Feb 2019

Hello guys.... Please, I would like to request some help for the following robot indicator. (I just want to add a simple solution ---- stop oppening positions when it reaches 20 positions opened at the total count; and automatically reopen when the total opened positions count < 20.....  thanks:))

 

using System.Linq;

using cAlgo.API;

using System.IO;

using System.Collections;

using System.Collections.Generic;

using cAlgo.API.Indicators;

using cAlgo.API.Internals;

using cAlgo.Indicators;

 

namespace cAlgo

{

    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FileSystem)]

    public class MACD : Robot

    {

 

        [Parameter("Volume", DefaultValue = 1000)]

        public int volume { get; set; }

 

        [Parameter(DefaultValue = 52, MinValue = 1)]

        public int StopLoss { get; set; }

 

        [Parameter(DefaultValue = 58, MinValue = 1)]

        public int TakeProfit { get; set; }

 

 

        [Parameter("MACD LongCycle", DefaultValue = 43, MinValue = 1)]

        public int LongCycle { get; set; }

 

        [Parameter("MACD ShortCycle", DefaultValue = 10, MinValue = 1)]

        public int ShortCycle { get; set; }

 

        [Parameter("MACD Period", DefaultValue = 10, MinValue = 1)]

        public int MACDPeriod { get; set; }

 

        private MacdCrossOver _MACD;

        protected override void OnBar()

        {

            var dailySeries = MarketData.GetSeries(TimeFrame.Daily);

 

            _MACD = Indicators.MacdCrossOver(dailySeries.Close, LongCycle, ShortCycle, MACDPeriod);

            if (_MACD.MACD.Last(1) < _MACD.Signal.Last(1) && _MACD.MACD.Last(0) > _MACD.Signal.Last(0) && _MACD.Signal.Last(0) < 0)

            {

                ExecuteMarketOrder(TradeType.Buy, Symbol, volume, "EUR/USD C", StopLoss, TakeProfit, 5);

            }

 

            if (_MACD.MACD.Last(1) > _MACD.Signal.Last(1) && _MACD.MACD.Last(0) < _MACD.Signal.Last(0) && _MACD.Signal.Last(0) > 0)

            {

                ExecuteMarketOrder(TradeType.Sell, Symbol, volume, "EUR/USD C", StopLoss, TakeProfit, 5);

            }

        }

        protected override double GetFitness(GetFitnessArgs args)

        {

            //maximize count of winning trades and minimize count of losing trades

            return args.WinningTrades / args.LosingTrades;

07 May 2019, 17:45#2
Panagiotis Charalampousposts: 2715since: 13 Jan 2017

Hi nelson.pmf.sc,

Thanks for posting in our forum. See below

protected override void OnBar()
        {
            if (Positions.Count < 20)
            {
                var dailySeries = MarketData.GetSeries(TimeFrame.Daily);

                _MACD = Indicators.MacdCrossOver(dailySeries.Close, LongCycle, ShortCycle, MACDPeriod);

                if (_MACD.MACD.Last(1) < _MACD.Signal.Last(1) && _MACD.MACD.Last(0) > _MACD.Signal.Last(0) && _MACD.Signal.Last(0) < 0)
                {
                    ExecuteMarketOrder(TradeType.Buy, Symbol, volume, "EUR/USD C", StopLoss, TakeProfit, 5);
                }

                if (_MACD.MACD.Last(1) > _MACD.Signal.Last(1) && _MACD.MACD.Last(0) < _MACD.Signal.Last(0) && _MACD.Signal.Last(0) > 0)
                {
                    ExecuteMarketOrder(TradeType.Sell, Symbol, volume, "EUR/USD C", StopLoss, TakeProfit, 5);
                }
            }
        }

Best Regards,

Panagiotis


Head of Community Management at cTrader
07 May 2019, 18:50RE:#3
nelson.pmf.scposts: 6since: 07 Feb 2019

Panagiotis Charalampous said:

Hi nelson.pmf.sc,

Thanks for posting in our forum. See below

protected override void OnBar()
        {
            if (Positions.Count < 20)
            {
                var dailySeries = MarketData.GetSeries(TimeFrame.Daily);

                _MACD = Indicators.MacdCrossOver(dailySeries.Close, LongCycle, ShortCycle, MACDPeriod);

                if (_MACD.MACD.Last(1) < _MACD.Signal.Last(1) && _MACD.MACD.Last(0) > _MACD.Signal.Last(0) && _MACD.Signal.Last(0) < 0)
                {
                    ExecuteMarketOrder(TradeType.Buy, Symbol, volume, "EUR/USD C", StopLoss, TakeProfit, 5);
                }

                if (_MACD.MACD.Last(1) > _MACD.Signal.Last(1) && _MACD.MACD.Last(0) < _MACD.Signal.Last(0) && _MACD.Signal.Last(0) > 0)
                {
                    ExecuteMarketOrder(TradeType.Sell, Symbol, volume, "EUR/USD C", StopLoss, TakeProfit, 5);
                }
            }
        }

Best Regards,

Panagiotis

Thanks a lot Panagiotis. I already tested and worked perfectly.

You´re the best <:-)

13 May 2019, 21:10RE:#4
nelson.pmf.scposts: 6since: 07 Feb 2019

Panagiotis Charalampous said:

Hi nelson.pmf.sc,

Thanks for posting in our forum. See below

protected override void OnBar()
        {
            if (Positions.Count < 20)
            {
                var dailySeries = MarketData.GetSeries(TimeFrame.Daily);

                _MACD = Indicators.MacdCrossOver(dailySeries.Close, LongCycle, ShortCycle, MACDPeriod);

                if (_MACD.MACD.Last(1) < _MACD.Signal.Last(1) && _MACD.MACD.Last(0) > _MACD.Signal.Last(0) && _MACD.Signal.Last(0) < 0)
                {
                    ExecuteMarketOrder(TradeType.Buy, Symbol, volume, "EUR/USD C", StopLoss, TakeProfit, 5);
                }

                if (_MACD.MACD.Last(1) > _MACD.Signal.Last(1) && _MACD.MACD.Last(0) < _MACD.Signal.Last(0) && _MACD.Signal.Last(0) > 0)
                {
                    ExecuteMarketOrder(TradeType.Sell, Symbol, volume, "EUR/USD C", StopLoss, TakeProfit, 5);
                }
            }
        }

Best Regards,

Panagiotis

Panagiotis... My Cbot is great but If possible, I'd like a little more help with it.

So, the question is....  by now It´s coded as below....

using System.Linq;

using cAlgo.API;

using System.IO;

using System.Collections;

using System.Collections.Generic;

using cAlgo.API.Indicators;

using cAlgo.API.Internals;

using cAlgo.Indicators;

 

namespace cAlgo

{

    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FileSystem)]

    public class MACD : Robot

    {

 

        [Parameter("Volume", DefaultValue = 1000)]

        public int volume { get; set; }

 

        [Parameter(DefaultValue = 52, MinValue = 1)]

        public int StopLoss { get; set; }

 

        [Parameter(DefaultValue = 58, MinValue = 1)]

        public int TakeProfit { get; set; }

 

 

        [Parameter("MACD LongCycle", DefaultValue = 43, MinValue = 1)]

        public int LongCycle { get; set; }

 

        [Parameter("MACD ShortCycle", DefaultValue = 10, MinValue = 1)]

        public int ShortCycle { get; set; }

 

        [Parameter("MACD Period", DefaultValue = 10, MinValue = 1)]

        public int MACDPeriod { get; set; }

 

        private MacdCrossOver _MACD;

       

protected override void OnBar()

        {

            if (Positions.Count < 20)

            {

                var dailySeries = MarketData.GetSeries(TimeFrame.Daily);

 

                _MACD = Indicators.MacdCrossOver(dailySeries.Close, LongCycle, ShortCycle, MACDPeriod);

 

                if (_MACD.MACD.Last(1) < _MACD.Signal.Last(1) && _MACD.MACD.Last(0) > _MACD.Signal.Last(0) && _MACD.Signal.Last(0) < 0)

                {

                    ExecuteMarketOrder(TradeType.Buy, Symbol, volume, "EUR/USD C", StopLoss, TakeProfit, 5);

                }

 

                if (_MACD.MACD.Last(1) > _MACD.Signal.Last(1) && _MACD.MACD.Last(0) < _MACD.Signal.Last(0) && _MACD.Signal.Last(0) > 0)

                {

                    ExecuteMarketOrder(TradeType.Sell, Symbol, volume, "EUR/USD C", StopLoss, TakeProfit, 5);

                }

            }

        }

        protected override double GetFitness(GetFitnessArgs args)

        {

            //maximize count of winning trades and minimize count of losing trades

            return args.WinningTrades / args.LosingTrades;

 

So... even  using the MACD indicator in the Daily timeframe; I would like to use the stochastic oscillator indicator(9;3;9, simple) in theHour timeframe (in order that it does not allow to open negotiations when the K line is below the level 20 of the indicator)
MIght you help me, please.

14 May 2019, 09:17#5
Panagiotis Charalampousposts: 2715since: 13 Jan 2017

Hi nelson.pmf.sc,

See below how to declare a stochastic oscillator

var _stochastic = Indicators.StochasticOscillator(9,3,9, MovingAverageType.Simple);

The parameter you need to check is

_stochastic.PercentK

Best Regards,

Panagiotis


Head of Community Management at cTrader
14 May 2019, 17:07RE:#6
nelson.pmf.scposts: 6since: 07 Feb 2019

Panagiotis Charalampous said:

Hi nelson.pmf.sc,

See below how to declare a stochastic oscillator

var _stochastic = Indicators.StochasticOscillator(9,3,9, MovingAverageType.Simple);

The parameter you need to check is

_stochastic.PercentK

Best Regards,

Panagiotis

Ok.

Thanks a lot again.

I`ll test it.

I´m just affraid if I´d achieve to put it working in the right timeframe.

Working on this now.

BEst regards

Nelson