CY
cysecsbin.01
Blocked user by Spotware at 11 Sep 2023, 07:13
0 follower(s) 0 following 16 subscription(s)
Replies

cysecsbin.01
09 Apr 2020, 19:53 ( Updated at: 21 Dec 2023, 09:22 )

Hi, thanks for the reply.

i missed to tell you that first and second source parameters are to be filled in with two assets name, like "GBPUSD" and "XAUUSD", the functioning version of the indicator, with the parameters set as said and with the LoadMoreHistory commented out will display like this 

Thanks in advance for any help


cysecsbin.01
06 Jan 2020, 11:17

RE:

ClickAlgo said:

Hi, C,

You just need to debug with visual studio and step through the code, you will find where the problem is easy enough. Even though cTrader has a single UI thread you should be able to use parallel programming to accomplish the task of calling the API concurrently to get the data you need, but there may be limitations with the architecture being used that could be causing your problem.

It may also be an idea to use the performance profiler to see how long the tasks are running and how much memory it is using.

https://docs.microsoft.com/en-us/visualstudio/profiling/running-profiling-tools-with-or-without-the-debugger?view=vs-2019

You could create a simple test-harness to make 10 calls to the API for the marketseries data, good luck with resolving this :-)

Hi Paul, thanks for your help, i will proceed to implement your idea and monitor the thread one by one during excecution.

Have a nice day and a happy new year

        -C


cysecsbin.01
30 Dec 2019, 19:40

RE:

PanagiotisCharalampous said:

Hi cysecsbin.01,

Can you provide us with more information to reproduce this problem i.e. cBot code, backtesting parameters and broker?

Best Regards,

Panagiotis 

Join us on Telegram

 

Good evening,

I should try to replicate the error with a different code than that i'm using now since it is part of a private project, i will try to do it in the following days.

Anyway, i have to start a managed portfolio soon, and it is quite imperative for me and my clients to do so. isn't it possible to get a general description of the error so that i can have an idea of what it is about? i know ctrader's api's methods are not thread-safe, could it be related to some kind of concurrent access problem? The bot that is causing the error loads up to 10 marketseries at a time, could it be related to the data's quantity?

Any help would be appreciated

       -C

 


cysecsbin.01
04 Sep 2019, 18:31

Cysecsbin.01 likes this element


cysecsbin.01
06 Aug 2019, 16:54 ( Updated at: 21 Dec 2023, 09:21 )

Here i'll post some screenshots of the indicated issue:

Now I'm testing a simple double rsi in the automate section, zoom level is set to 3

This is what happens if i try to zoom out:

As you can see, by zooming out i'm now not at the end of the chart anymore, and if the process is repeated: I'm now near the beginning of the chart.

Now, in this particular chart i've had several bars loaded already, but with mint-fresh charts the zooming out always triggers a reloading of the entire chart to load more bars, and thus, the resetting of the indicator being tested.

This is quite an issue since with heavy-workloads indicators it means that a lot of time goes in the waiting for the indicator to refresh at each reload.

Also, if i switch from Chart-coding area-chart, the positions of the chart will always reset, i.e. if i'm looking at Chart.LastVisibleIndex = 500 and i switch back to the code editor and then back to the chart, i'll be now looking at Chart.LastVisibleIndex = Chart.BarsTotal.

 

I hope this issue can be solved, thanks for your time

        -Cysecsbin.01


cysecsbin.01
02 Jun 2019, 19:27

RE:

usynn said:

Hi there, is it possible for us to be able to backtest/run a simulator which runs through tick data and simulates historical data as if it were happening in real time. There are many such simulators for MT4 where you can speed up and slow down the simulator. I usually use MT4 for simulator trading but I've created my own custom indicator with cAlgo and would like to sim trade in cTrader with historical data. Also, the ability to use tick-data, certain points or just every bar would be ideal.

If this concept doesn't exist within cTrader, would it be possible to be put down on the to-do's for the devs?

btw, when i mean sim trade i don't mean running a cBot but visually running through historical data as if were real-time but faster.

Many thanks

yup, i just made one, look for 'Simulator' in the cBot page


cysecsbin.01
04 Feb 2019, 15:41

the correct setting for the timeframe to apply the bot to is h1, the 'timeftrame secondario' = auxiliary timeframe from italian, should be set to h4.

however the last pic with the optimization parameters settings is correct.


cysecsbin.01
04 Feb 2019, 11:07 ( Updated at: 21 Dec 2023, 09:21 )

Thanks for your answer, i'll send the indicators' and bot's sources


using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ShutForce : Indicator
    {
        [Parameter("RSI Periods", DefaultValue = 14)]
        public int Rsi_per { get; set; }
        [Parameter("ATR Periods", DefaultValue = 14)]
        public int ATR_per { get; set; }
        [Parameter("TimeFrame")]
        public TimeFrame tf { get; set; }

        [Output("Main", Color = Colors.Black)]
        public IndicatorDataSeries Result { get; set; }

        private AverageTrueRange atr;
        private RelativeStrengthIndex rsi;
        private MarketSeries series;


        protected override void Initialize()
        {
            series = MarketData.GetSeries(tf);
            rsi = Indicators.RelativeStrengthIndex(series.Close, Rsi_per);
            atr = Indicators.AverageTrueRange(series, ATR_per, MovingAverageType.Simple);
        }

        public override void Calculate(int index)
        {
            int i = series.OpenTime.GetIndexByTime(MarketSeries.OpenTime[index]);
            if (rsi.Result[i] > rsi.Result[i - 1] && atr.Result[i] > atr.Result[i - 1])
            {
                Result[index] = 1;
                ChartObjects.DrawLine("line" + index, index, -1, index, 1, Colors.Green, 5, LineStyle.Solid);
            }
            else if (rsi.Result[i] < rsi.Result[i - 1] && atr.Result[i] > atr.Result[i - 1])
            {
                Result[index] = -1;
                ChartObjects.DrawLine("line" + index, index, -1, index, 1, Colors.Red, 5, LineStyle.Solid);
            }
            else
            {
                Result[index] = 0;
                ChartObjects.DrawLine("line" + index, index, -1, index, 1, Colors.Blue, 5, LineStyle.Solid);
            }


        }
    }
}

indicator 1


using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class TickVolume : Indicator
    {
        [Parameter(DefaultValue = false)]
        public bool Segno { get; set; }
        [Parameter(DefaultValue = 10)]
        public int Periodi { get; set; }

        [Output("Main", PlotType = PlotType.Histogram)]
        public IndicatorDataSeries Result { get; set; }
        [Output("EMA", Color = Colors.Cyan)]
        public IndicatorDataSeries EMA { get; set; }

        private ExponentialMovingAverage ema;


        protected override void Initialize()
        {
            ema = Indicators.ExponentialMovingAverage(MarketSeries.TickVolume, Periodi);
        }

        public override void Calculate(int index)
        {
            if (!Segno)
                Result[index] = MarketSeries.TickVolume[index];
            else if (Segno)
                if (Math.Max(MarketSeries.Close[index], MarketSeries.Open[index]) == MarketSeries.Close[index])
                {
                    Result[index] = MarketSeries.TickVolume[index];
                }
                else
                {
                    Result[index] = -MarketSeries.TickVolume[index];
                }
            EMA[index] = ema.Result[index];
        }
    }
}

indicator 2


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.FullAccess)]
    public class ShutForce_Bot : Robot
    {
        [Parameter("RSI Periods", DefaultValue = 14)]
        public int Rsi_per { get; set; }
        [Parameter("ATR Periods", DefaultValue = 14)]
        public int ATR_per { get; set; }
        [Parameter("MTF RSI Periods", DefaultValue = 14)]
        public int mtf_Rsi_per { get; set; }
        [Parameter("MTF ATR Periods", DefaultValue = 14)]
        public int mtf_ATR_per { get; set; }
        [Parameter("Volume Average Periods", DefaultValue = 14)]
        public int tv_per { get; set; }
        [Parameter("SL Multiplier", DefaultValue = 1)]
        public double sl_mul { get; set; }
        [Parameter("TP to SL Ratio", DefaultValue = 1)]
        public double tp_to_sl { get; set; }
        [Parameter("Rischio %", DefaultValue = 1)]
        public double risk { get; set; }
        /*[Parameter("Trailing Start", DefaultValue = 10)]
        public double trl_start { get; set; }
        [Parameter("Trailing Step", DefaultValue = 1)]
        public double trl_step { get; set; }*/
        [Parameter("TimeFrame Secondario")]
        public TimeFrame tf { get; set; }

        private ShutForce sf, sf_mtf;
        private MarketSeries mtf_series;
        private ExponentialMovingAverage ema;
        private TickVolume tv;

        protected override void OnStart()
        {
            mtf_series = MarketData.GetSeries(tf);
            sf = Indicators.GetIndicator<ShutForce>(Rsi_per, ATR_per, TimeFrame);
            sf_mtf = Indicators.GetIndicator<ShutForce>(mtf_Rsi_per, mtf_ATR_per, tf);
            ema = Indicators.ExponentialMovingAverage(MarketSeries.Close, 200);
            tv = Indicators.GetIndicator<TickVolume>(false, tv_per);
        }
//&& MarketSeries.Close.LastValue > ema.Result.LastValue&& MarketSeries.Close.LastValue < ema.Result.LastValue
        protected override void OnBar()
        {
            CancelOrders();
            double sl = sl_mul * (MarketSeries.High.Last(1) - MarketSeries.Low.Last(1)) / Symbol.PipSize;
            double tp = sl * tp_to_sl;
            string label = MarketSeries.OpenTime.GetIndexByTime(MarketSeries.OpenTime.Last(1)).ToString();
            int index_mtf = mtf_series.OpenTime.GetIndexByTime(MarketSeries.OpenTime.Last(0));
            if (sf.Result.Last(1) == 1 && sf_mtf.Result[index_mtf - 1] == 1 && tv.Result.Last(1) > tv.EMA.Last(1))
            {
                PlaceStopOrder(TradeType.Buy, Symbol, Volume(sl), MarketSeries.High.Last(1), label, sl, tp);
            }
            else if (sf.Result.Last(1) == -1 && sf_mtf.Result[index_mtf - 1] == -1 && tv.Result.Last(1) > tv.EMA.Last(1))
            {
                PlaceStopOrder(TradeType.Sell, Symbol, Volume(sl), MarketSeries.Low.Last(1), label, sl, tp);
            }
        }

        protected override void OnTick()
        {
            //Trailing();
        }

        private void CancelOrders()
        {
            foreach (var order in PendingOrders)
            {
                CancelPendingOrder(order);
            }
        }

        private int Volume(double sl)
        {
            double _2_percent = risk * Account.Balance / 100;
            double vol = (_2_percent * Symbol.Ask) / (Symbol.PipSize * sl);
            int vol_int = 1000 * (int)Math.Round(vol / 1000, 0);
            if (vol_int < 1000)
                return 1000;
            return vol_int;
        }

        /* private void Trailing()
        {
            foreach (var pos in Positions)
            {
                if (pos.Pips > trl_start)
                    ModifyPosition(pos, pos.EntryPrice);
            }
        }*/

        protected override void OnStop()
        {
            foreach (var pos in Positions)
            {
                ClosePosition(pos);
            }
        }
    }
}

bot


these are the optimization parameters, i used grid search, tick data and a period from 21/06/2018 to 30/01/2019.

ctraders used are both spotware's open beta and fxpro's

the optimization takes a while but the issue is displayed on any positive result when transported in the backtest section.

i kindly thank you for your help, it is much appreciated.


cysecsbin.01
02 Feb 2019, 18:54

by the way, i tried the same procedure both on fxpro's ctrader and on the open beta frome spotware's site, same strange outcome