Replies

PanagiotisCharalampous
15 Jan 2019, 17:00

Hi eliezer_barros,

I have replied to your email. You cannot use position.Close() with FxPro as it uses an older version of cTrader. You need to use ClosePosition().

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
15 Jan 2019, 09:41 ( Updated at: 21 Dec 2023, 09:21 )

Hi Benjamin,

If you check the log of your optimization, you will see the reason why this happens

This happens because you use Chart.DrawStaticText() function. Do you need this function in backtesting?

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
15 Jan 2019, 09:19

Hi bienve.pf,

I am not sure what do you mean with your question. Pip is a standard measure of change, different in each symbol but usually it is an increment/decrement of the price in the fourth decimal place for forex pairs. One pip is usually one basis point.

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
14 Jan 2019, 17:30

Hi missyeam,

I changed the code a bit. See below

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 ClickAlgoSchoolSMA : Robot
    {
        #region User defined parameters

        [Parameter("Instance Name", DefaultValue = "001")]
        public string InstanceName { get; set; }

        [Parameter("Lot Size", DefaultValue = 0.1)]
        public double LotSize { get; set; }

        [Parameter("Source SMA #1")]
        public DataSeries SourceSma1 { get; set; }

        [Parameter("Source SMA #2")]
        public DataSeries SourceSma2 { get; set; }

        [Parameter("Period SMA #1", DefaultValue = 5, MinValue = 1, MaxValue = 100)]
        public int PeriodsSma1 { get; set; }

        [Parameter("Period SMA #2", DefaultValue = 20, MinValue = 1, MaxValue = 100)]
        public int PeriodsSma2 { get; set; }

        [Parameter("Calculate OnBar", DefaultValue = false)]
        public bool CalculateOnBar { get; set; }

        #endregion

        #region Indicator declarations

        private SimpleMovingAverage _sma1 { get; set; }
        private SimpleMovingAverage _sma2 { get; set; }

        #endregion

        #region cTrader events

        double _volume;
        protected override void OnStart()
        {
            // construct the indicators
            _sma1 = Indicators.SimpleMovingAverage(SourceSma1, PeriodsSma1);
            _sma2 = Indicators.SimpleMovingAverage(SourceSma2, PeriodsSma2);
            _volume = Symbol.QuantityToVolume(LotSize);
        }


        protected override void OnTick()
        {
            if (CalculateOnBar)
            {
                return;
            }

            ManagePositions();
        }


        protected override void OnBar()
        {
            if (!CalculateOnBar)
            {
                return;
            }

            ManagePositions();
        }


        protected override void OnStop()
        {
            // unused
        }

        #endregion

        #region Position management

        private void ManagePositions()
        {
            if (_sma1.Result.LastValue > _sma2.Result.LastValue)
            {
                ClosePosition(TradeType.Sell);

                if (!IsPositionOpenByType(TradeType.Buy))
                {
                    OpenPosition(TradeType.Buy);
                }
            }


            if (_sma1.Result.LastValue < _sma2.Result.LastValue)
            {
                ClosePosition(TradeType.Buy);

                if (!IsPositionOpenByType(TradeType.Sell))
                {
                    OpenPosition(TradeType.Sell);
                }
            }
        }


        private void OpenPosition(TradeType type)
        {
            // open a new position
            ExecuteMarketOrder(type, this.Symbol, _volume, InstanceName, null, null);
        }


        private void ClosePosition(TradeType type)
        {
            var p = Positions.Find(InstanceName, this.Symbol, type);

            if (p != null)
            {
                ClosePosition(p);
                if (p.NetProfit < 0)
                {
                    _volume += 1000;
                }
                else
                {
                    _volume = Symbol.QuantityToVolume(LotSize);
                }
            }
        }

        #endregion

        #region Position Information


        private bool IsPositionOpenByType(TradeType type)
        {
            var p = Positions.FindAll(InstanceName, Symbol, type);

            if (p.Count() >= 1)
            {
                return true;
            }

            return false;
        }

        #endregion
    }
}

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
14 Jan 2019, 16:26

Hi michael00,

If your account is a demo account and if your application is working with other accounts, then make sure that your password is correct.

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
14 Jan 2019, 16:23

Hi missyeam,

Can you give me backtesting parameters and dates to check this?

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
14 Jan 2019, 15:27

Thanks missyearm,

Let me know if the below works for you

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 ClickAlgoSchoolSMA : Robot
    {
        #region User defined parameters

        [Parameter("Instance Name", DefaultValue = "001")]
        public string InstanceName { get; set; }

        [Parameter("Lot Size", DefaultValue = 0.1)]
        public double LotSize { get; set; }

        [Parameter("Source SMA #1")]
        public DataSeries SourceSma1 { get; set; }

        [Parameter("Source SMA #2")]
        public DataSeries SourceSma2 { get; set; }

        [Parameter("Period SMA #1", DefaultValue = 5, MinValue = 1, MaxValue = 100)]
        public int PeriodsSma1 { get; set; }

        [Parameter("Period SMA #2", DefaultValue = 20, MinValue = 1, MaxValue = 100)]
        public int PeriodsSma2 { get; set; }

        [Parameter("Calculate OnBar", DefaultValue = false)]
        public bool CalculateOnBar { get; set; }

        #endregion

        #region Indicator declarations

        private SimpleMovingAverage _sma1 { get; set; }
        private SimpleMovingAverage _sma2 { get; set; }

        #endregion

        #region cTrader events

        double _volume;
        protected override void OnStart()
        {
            // construct the indicators
            _sma1 = Indicators.SimpleMovingAverage(SourceSma1, PeriodsSma1);
            _sma2 = Indicators.SimpleMovingAverage(SourceSma2, PeriodsSma2);
            _volume = Symbol.QuantityToVolume(LotSize);
            Positions.Closed += Positions_Closed;
        }

        private void Positions_Closed(PositionClosedEventArgs obj)
        {
            if (obj.Position.NetProfit < 0)
                _volume += 1000;
            else
                _volume = Symbol.QuantityToVolume(LotSize);

        }

        protected override void OnTick()
        {
            if (CalculateOnBar)
            {
                return;
            }

            ManagePositions();
        }


        protected override void OnBar()
        {
            if (!CalculateOnBar)
            {
                return;
            }

            ManagePositions();
        }


        protected override void OnStop()
        {
            // unused
        }

        #endregion

        #region Position management

        private void ManagePositions()
        {
            if (_sma1.Result.LastValue > _sma2.Result.LastValue)
            {

                if (!IsPositionOpenByType(TradeType.Buy))
                {
                    OpenPosition(TradeType.Buy);
                }

                ClosePosition(TradeType.Sell);
            }


            if (_sma1.Result.LastValue < _sma2.Result.LastValue)
            {

                if (!IsPositionOpenByType(TradeType.Sell))
                {
                    OpenPosition(TradeType.Sell);
                }

                ClosePosition(TradeType.Buy);
            }
        }


        private void OpenPosition(TradeType type)
        {



            // open a new position
            ExecuteMarketOrder(type, this.Symbol, _volume, InstanceName, null, null);
        }


        private void ClosePosition(TradeType type)
        {
            var p = Positions.Find(InstanceName, this.Symbol, type);

            if (p != null)
            {
                ClosePosition(p);
            }
        }

        #endregion

        #region Position Information


        private bool IsPositionOpenByType(TradeType type)
        {
            var p = Positions.FindAll(InstanceName, Symbol, type);

            if (p.Count() >= 1)
            {
                return true;
            }

            return false;
        }

        #endregion
    }
}

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
14 Jan 2019, 14:43

Hi missyeam,

If you post your cBot code, we might be able to help you.

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
14 Jan 2019, 14:17

Hi michael00,

The host name works fine for me. What host name do you get in your FIX API form in cTrader? Are you using a demo account?

Best Regards,

 


@PanagiotisCharalampous

PanagiotisCharalampous
14 Jan 2019, 14:11

Hi Sasha,

The specific variable has nothing to do with stop outs. If you want to know the reason of position closing use obj.Reason.

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
14 Jan 2019, 12:39

Hi Ton,

There is no such feature available at the moment. However it is in our backlog therefore you should expect it in one of the future versions.

Best Regards, 

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
14 Jan 2019, 11:33

Hi Ulises,

We will be releasing a revamped help site very soon.

Best Regards,

Panagiotis

 


@PanagiotisCharalampous

PanagiotisCharalampous
14 Jan 2019, 11:28

Hi seibertm,

In principle, you can do this with cAlgo. However, you will first need to define what a pullback is for you. You should put down in detail what events consist a pullback e.g. three consecutive bars against the trend followed by two that follow the trend. After you do this, it would be easier to code your cBot. Another option is to contact a Consultant that could help you with setting your requirements and implementing your strategy.

Best Regards,

Panagiotis 


@PanagiotisCharalampous

PanagiotisCharalampous
14 Jan 2019, 11:21

Hi Glen,

Thanks for posting in our forum. At this moment there is no such feature. You can use our UserVoice forum to suggest it.

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
14 Jan 2019, 11:12

Hi montblanc,

Limit orders are copied using market orders.

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
14 Jan 2019, 11:10

Hi Sasha,

This enum indicates the way SL was triggered. Here are the enum values.

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
14 Jan 2019, 10:38

Hi seibert,

It seems there is a typo.The correct command is below

ExecuteMarketOrder(tradeType, Symbol, Volume, "SampleRSI", StopLoss, null);

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
14 Jan 2019, 10:35

Hi Piotr,

See below an example on how to do this.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;

namespace cAlgo
{
    public class General
    {
        public static int GetPosCnt(Robot robot)
        {
            int iPosCnt;
            iPosCnt = robot.Positions.Count;
            return iPosCnt;
        }

        public static double GetLastCloseValue(Robot robot)
        {          
            return robot.MarketSeries.Close.LastValue;
        }
    }
}
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 NewcBot : Robot
    {
        protected override void OnStart()
        {
            Print(General.GetPosCnt(this));
            Print(General.GetLastCloseValue(this));
        }

        protected override void OnBar()
        {
        }

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

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
14 Jan 2019, 10:26

Hi bienve.pf,

It is not possible at the moment. We will add this feature in one of the future updates.

Best Regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
11 Jan 2019, 14:07

Hi ulises.guerrero,

We are having a look at this. I will come back to you soon.

Best Regards,

Panagiotis


@PanagiotisCharalampous