Replies

carlosdrcunha
12 Sep 2018, 13:07

RE: RE: another question

carlosdrcunha said:

 

This is a good cBot, but why this is not giving trades?

can anyone tell me why does it not giving trades?

Thank you

 

 

 

 

 

 

 

 

Panagiotis Charalampous said:

Hi Carlos,

You can check if Positions.Count < 5 before proceeding to executing an order.

Best Regards,

Panagiotis

 

 

 

Another question, why this code is not giving trades?

 

 

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 StocMA : Robot
    {

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

        [Parameter("K_Slowing", DefaultValue = 3)]
        public int Slowing { get; set; }

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

        [Parameter("Moving_Average")]
        public DataSeries MA { get; set; }

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

        [Parameter("Trailing Stop", DefaultValue = 10)]
        public double TrailStop { get; set; }

        [Parameter("Risk", DefaultValue = 35)]
        public double Risk { get; set; }

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

        [Parameter("MA1", DefaultValue = 3)]
        public int Period { get; set; }

        [Parameter("PSar min", DefaultValue = 14)]
        public double MinA { get; set; }

        [Parameter("PSar max", DefaultValue = 14)]
        public double MaxA { get; set; }

        [Parameter("RSI", DefaultValue = 14)]
        public int RSIPeriod { get; set; }

        [Parameter("SL", DefaultValue = 14)]
        public int iSL { get; set; }

        [Parameter("TP", DefaultValue = 14)]
        public int iTP { get; set; }


        [Parameter("2nd MA", DefaultValue = 20)]
        public int a { get; set; }





        private ParabolicSAR PSar;
        private StochasticOscillator Stoch;
        private MovingAverage MA1;
        private RelativeStrengthIndex RSI;
        private MovingAverage MA2;


        private const string label = "EMA";

        private Position longPosition;
        private Position shortPosition;
        public double balance;


        protected override void OnStart()
        {
            // Put your initialization logic here
            Stoch = Indicators.StochasticOscillator(K_Period, Slowing, D_Period, MovingAverageType.Simple);
            MA1 = Indicators.SimpleMovingAverage(Stoch.PercentD, Period);
            PSar = Indicators.ParabolicSAR(MinA, MaxA);
            RSI = Indicators.RelativeStrengthIndex(Source, RSIPeriod);
            MA2 = Indicators.SimpleMovingAverage(MA1.Result, a);

            balance = Account.FreeMargin;
        }





        protected override void OnTick()
        {
            // Put your core logic here}
        }

        protected override void OnBar()
        {
            var cBotPositions = Positions.FindAll(label);

            longPosition = Positions.Find(label, Symbol, TradeType.Buy);
            shortPosition = Positions.Find(label, Symbol, TradeType.Sell);

            if (cBotPositions.Length >= 1)
                return;




            double Risk = 0.01 * balance;





            if (Stoch.PercentK.Last(0) < MA1.Result.Last(1) && Stoch.PercentK.Last(0) < 20 && longPosition == null)
            {
                CP();

                ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, label);
            }

            if (Stoch.PercentK.Last(1) > MA1.Result.Last(0) && Stoch.PercentK.Last(0) > 80 && shortPosition == null)
            {
                CP();

                ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, label);
            }
        }









        private void CP()
        {
            foreach (var Position in Positions)
            {



                ClosePosition(Position, Volume);

            }
        }
    }
}

 


@carlosdrcunha

carlosdrcunha
06 Sep 2018, 15:16

RE: another question

Panagiotis Charalampous said:

Hi Carlos,

You can check if Positions.Count < 5 before proceeding to executing an order.

Best Regards,

Panagiotis

 

 

 

Another question, why this code is not giving trades?

 

 

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 StocMA : Robot
    {

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

        [Parameter("K_Slowing", DefaultValue = 3)]
        public int Slowing { get; set; }

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

        [Parameter("Moving_Average")]
        public DataSeries MA { get; set; }

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

        [Parameter("Trailing Stop", DefaultValue = 10)]
        public double TrailStop { get; set; }

        [Parameter("Risk", DefaultValue = 35)]
        public double Risk { get; set; }

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

        [Parameter("MA1", DefaultValue = 3)]
        public int Period { get; set; }

        [Parameter("PSar min", DefaultValue = 14)]
        public double MinA { get; set; }

        [Parameter("PSar max", DefaultValue = 14)]
        public double MaxA { get; set; }

        [Parameter("RSI", DefaultValue = 14)]
        public int RSIPeriod { get; set; }

        [Parameter("SL", DefaultValue = 14)]
        public int iSL { get; set; }

        [Parameter("TP", DefaultValue = 14)]
        public int iTP { get; set; }


        [Parameter("2nd MA", DefaultValue = 20)]
        public int a { get; set; }





        private ParabolicSAR PSar;
        private StochasticOscillator Stoch;
        private MovingAverage MA1;
        private RelativeStrengthIndex RSI;
        private MovingAverage MA2;


        private const string label = "EMA";

        private Position longPosition;
        private Position shortPosition;
        public double balance;


        protected override void OnStart()
        {
            // Put your initialization logic here
            Stoch = Indicators.StochasticOscillator(K_Period, Slowing, D_Period, MovingAverageType.Simple);
            MA1 = Indicators.SimpleMovingAverage(Stoch.PercentD, Period);
            PSar = Indicators.ParabolicSAR(MinA, MaxA);
            RSI = Indicators.RelativeStrengthIndex(Source, RSIPeriod);
            MA2 = Indicators.SimpleMovingAverage(MA1.Result, a);

            balance = Account.FreeMargin;
        }





        protected override void OnTick()
        {
            // Put your core logic here}
        }

        protected override void OnBar()
        {
            var cBotPositions = Positions.FindAll(label);

            longPosition = Positions.Find(label, Symbol, TradeType.Buy);
            shortPosition = Positions.Find(label, Symbol, TradeType.Sell);

            if (cBotPositions.Length >= 1)
                return;




            double Risk = 0.01 * balance;





            if (Stoch.PercentK.Last(0) < MA1.Result.Last(1) && Stoch.PercentK.Last(0) < 20 && longPosition == null)
            {
                CP();

                ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, label);
            }

            if (Stoch.PercentK.Last(1) > MA1.Result.Last(0) && Stoch.PercentK.Last(0) > 80 && shortPosition == null)
            {
                CP();

                ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, label);
            }
        }









        private void CP()
        {
            foreach (var Position in Positions)
            {



                ClosePosition(Position, Volume);

            }
        }
    }
}


@carlosdrcunha

carlosdrcunha
06 Sep 2018, 13:25

hi again,

 

 

it was very useful

thank you very much Panagiotis,

 

Sincerly,

Carlos Cunha.


@carlosdrcunha

carlosdrcunha
06 Sep 2018, 02:03

hello again Panagiotis,

 

Problem solved, Thank you a lot,

 

can i ask you another question?

 

if now i want to allow n number of trades at the same time? like 5 trades at the same time in diferent signals? how can i code that?

 

 

Thank you,

Sincerly,

Carlos Cunha.


@carlosdrcunha

carlosdrcunha
05 Sep 2018, 23:08

hello again

Hello again Panagiotis,

 

so i did ExecuteMarketOrder(TradeType.Buy, Symbol, Volume,"string"); is this wht i should do? no other affect than the past one, can u send me the code solved? if possible?

 

 

thank you,

Carlos cunha.


@carlosdrcunha

carlosdrcunha
05 Sep 2018, 19:54

understood, but so i tried to add the label on ExecuteMarketOrder((Tradetype.Sell,Symbol,Volume"String"); and nothing happened


@carlosdrcunha

carlosdrcunha
05 Sep 2018, 19:03

hello again

hi agan Panagiotis,

 

thank you for ur reply,

 

but if i do this code now without your the stuff i was telling u about do the same thing, buys every new candle on this code as well

 

 

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 StochasticMA1 : Robot
    {




        [Parameter("Moving_Average")]
        public DataSeries MA { get; set; }

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

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

        [Parameter("MA1", DefaultValue = 14)]
        public int Period { get; set; }



        [Parameter("SL", DefaultValue = 14)]
        public int iSL { get; set; }

        [Parameter("TP", DefaultValue = 14)]
        public int iTP { get; set; }

        private MovingAverage MA1;
        private BollingerBands BB;


        private const string label = "EMA";

        protected override void OnStart()
        {
            // Put your initialization logic here

            MA1 = Indicators.SimpleMovingAverage(MA, Period);

            BB = Indicators.BollingerBands(Source, 20, 2, MovingAverageType.Exponential);


        }

        protected override void OnTick()
        {
            // Put your core logic here}
        }

        protected override void OnBar()
        {

            if (MA1.Result.Last(0) > BB.Main.Last(0))
            {

                ExecuteMarketOrder(TradeType.Buy, Symbol, Volume);
            }
            if (MA1.Result.Last(0) < BB.Main.Last(0))
            {
                CP();
            }
            if (MA1.Result.Last(0) < BB.Main.Last(0))
            {

                ExecuteMarketOrder(TradeType.Sell, Symbol, Volume);
            }
            if (MA1.Result.Last(0) < BB.Main.Last(0))
            {
                CP();
            }

        }
        private void CP()
        {
            foreach (var Position in Positions)
            {

                if (Position.GrossProfit > 0)
                {
                    ClosePosition(Position, Volume);
                }
            }
        }


        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }


@carlosdrcunha

carlosdrcunha
05 Sep 2018, 16:24

its here

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 StochasticMA1 : Robot
    {

 


        [Parameter("Moving_Average")]
        public DataSeries MA { get; set; }

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

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

        [Parameter("MA1", DefaultValue = 14)]
        public int Period { get; set; }

 

        [Parameter("SL", DefaultValue = 14)]
        public int iSL { get; set; }

        [Parameter("TP", DefaultValue = 14)]
        public int iTP { get; set; }

 

 


  
        private MovingAverage MA1;
        private BollingerBands BB;
     

        private const string label = "EMA";

        private Position longPosition;
        private Position shortPosition;
     

 

        protected override void OnStart()
        {
            // Put your initialization logic here

            MA1 = Indicators.SimpleMovingAverage(MA, Period);

            BB = Indicators.BollingerBands(Source, 20, 2, MovingAverageType.Exponential);

 

        }

 

 

        protected override void OnTick()
        {
            // Put your core logic here}
        }

        protected override void OnBar()
        {
            var cBotPositions = Positions.FindAll(label);

            longPosition = Positions.Find(label, Symbol, TradeType.Buy);
            shortPosition = Positions.Find(label, Symbol, TradeType.Sell);

            if (cBotPositions.Length >= 1)
                return;

 

 

 

 

 

 

 

            if ( MA1.Result.Last(0) > BB.Main.Last(0) && longPosition == null)
            {

                ExecuteMarketOrder(TradeType.Buy, Symbol, Volume);
            }
            if (MA1.Result.Last(0) < BB.Main.Last(0))
            {
                CP();
            }

 

 

            if (MA1.Result.Last(0) < BB.Main.Last(0) && shortPosition == null)
            {

                ExecuteMarketOrder(TradeType.Sell, Symbol, Volume);
            }
            if (MA1.Result.Last(0) < BB.Main.Last(0))
            {
                CP();
            }

 

 


        }

 

 

 

 

        private void CP()
        {
            foreach (var Position in Positions)
            {

                if (Position.GrossProfit > 0)
                {
                    ClosePosition(Position, Volume);
                }
            }
        }


        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

 

 

 

 

 

So i want is only open one position for each signal.


@carlosdrcunha

carlosdrcunha
15 Jun 2018, 18:38

RE:

hi again,

 

 

there is no WedgeVolume custom indicator, because Wedge is my name.

 

i just created this indicator, in the indicators part, now i just want to import it to use in a cBot,

 

 

 

Thank you,

Sincerly,

Carlos Cunha.

 

 

 

 

 

 

 

Panagiotis Charalampous said:

Hi Carlos,

Please send me the indicator if possible and rename the cBot to something else. Also make sure that you reference the custom indicator.

Best Regards,

Panagiotis

 


@carlosdrcunha

carlosdrcunha
15 Jun 2018, 16:57

wedgevolume

WedgeVolume is an indicator i created, and i want to do an cBot with it.


@carlosdrcunha

carlosdrcunha
15 Jun 2018, 16:47

Hello,

 

in first i want to Thank you for ur help.

 

 

lets look at the code.

 

 

 

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 WedgeVolume : Robot
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

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


        private WedgeVolume WV;

        protected override void OnStart()
        {

            WV = Indicators.GetIndicator<WedgeVolume>(Source, Period);




            // Put your initialization logic here
        }

        protected override void OnTick()
        {
            // Put your core logic here
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

 

 

 

 

 

 

it gives me an error, wht do i need to change?

 

 

 

Thank you,

Sincerly,

 

Carlos Cunha.


@carlosdrcunha

carlosdrcunha
05 May 2018, 16:19

i need to wait for the next signal to open position and close position on the next inverse signal and open inverse position as well.

 

 

 

thank you a lot for your help.


@carlosdrcunha

carlosdrcunha
05 May 2018, 15:03

again, i just can put the MA on the Chart, the code doesnt take the values of the MA i put on the chart to DI- or DI+ or ADX, how can i get the value on the code? because source just give me Open High Close Low.

 

 

Sincerly-

Thank you.


@carlosdrcunha

carlosdrcunha
25 Apr 2018, 18:20

yes, it helped a lot, but how can i apply the indicator from the chart on the code? im just a new starter on coding, just learning.

can you give me an example?

 

thank you Panagiotis,

kind regards


@carlosdrcunha

carlosdrcunha
25 Apr 2018, 17:10

but how can i apply the ADX in the source? just appear Open, High, Close, Low, and i do not eaven know how to have that feature to apply the MA on the ADX.

 

 

thank you.

 


@carlosdrcunha

carlosdrcunha
24 Apr 2018, 22:25

RE: RE: DI- is the red line

carlosdrcunha said:

 

BTW a MA on the value on the ADX as well, not on the period, on the value given by that period, and on the Red Line as well,

 

The risk, i Want to invest 35% of the free Margin (rounded), for example.

if i have 50k, i want to invest 35%, thats 17.5k in assets.

how can i do it?

 

 

 

Thank you a lot.

 

 


@carlosdrcunha

carlosdrcunha
24 Apr 2018, 21:32

RE: DI- is the red line

​DI- is the red Line in the ADX, how can i put a MA of the red line? or for example as well, how can i put a MA on that Period u got on the ADX?

 

 

Thank you a lot.

 


@carlosdrcunha

carlosdrcunha
23 Apr 2018, 12:02

lets say this is the code

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 MAcBot : Robot
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }

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

        [Parameter("MA1", DefaultValue = 14)]
        public int Period { get; set; }

        [Parameter("MA2", DefaultValue = 10)]
        public int Period2 { get; set; }

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

        private MovingAverage firstMA1;
        private MovingAverage secondMA2;



        protected override void OnStart()
        {
            // Put your initialization logic here

            firstMA1 = Indicators.MovingAverage(Source, Period, MovingAverageType.Simple);
            secondMA2 = Indicators.MovingAverage(Source2, Period2, MovingAverageType.Simple);

        }


        protected override void OnTick()
        {
            // Put your core logic here

            var currentSlowMa = firstMA1.Result.Last(0);
            var currentFastMa = secondMA2.Result.Last(0);
            var previousSlowMa = firstMA1.Result.Last(1);
            var previousFastMa = secondMA2.Result.Last(1);



            if (previousSlowMa <previousFastMa && currentSlowMa <currentFastMa )
            {
                CP();
                ExecuteMarketOrder(TradeType.Buy, Symbol, Volume);
            }

            if (previousSlowMa > previousFastMa && currentSlowMa > currentFastMa )
            {
                CP();
                ExecuteMarketOrder(TradeType.Sell, Symbol, Volume);
            }


        }


        private void CP()
        {
            foreach (var Position in Positions)
            {
                ClosePosition(Position, Volume);
            }
        }
        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}


@carlosdrcunha