Sleeping indicator in the bot?

Created at 06 Mar 2019, 02:17
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!
komposter's avatar

komposter

Joined 30.12.2018

Sleeping indicator in the bot?
06 Mar 2019, 02:17


I have a simple bot using RSI indy and run it on Renko chart. Bot prints indicator values on every new bar:

    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class RenkoTest : Robot
    {
        [Parameter("RSI Price")]
        public DataSeries Source { get; set; }

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

        private RelativeStrengthIndex rsi;

        protected override void OnStart()
        {
            rsi = Indicators.RelativeStrengthIndex(Source, Periods);
        }

        protected override void OnTick()
        {
           
        }

        protected override void OnBar()
        {
            double o = MarketSeries.Open.Last(0);
            double c = MarketSeries.Close.Last(0);
            if (c > o)
                Print("Bullish bar: {0} -> {1}, signal = {2}, rsi[0] = {3}, rsi[1] = {4}", o, c, signal, rsi.Result.LastValue, rsi.Result.Last(1));
            else if (c < o)
                Print("Bearish bar: {0} -> {1}, signal = {2}, rsi[0] = {3}, rsi[1] = {4}", o, c, signal, rsi.Result.LastValue, rsi.Result.Last(1));
            else
                Print("Doj bar: {0} -> {1}, signal = {2}, rsi[0] = {3}, rsi[1] = {4}", o, c, signal, rsi.Result.LastValue, rsi.Result.Last(1));
        }

 

After few hours of correct work it starts to print the same values of indy. I catched such situation 2 times:

 

I don't any "connection lost" messages in Log too. Only trade records.

Also this time I catched "downloading update" message in the right upper corner. Maybe, it is connected to my problem.

Who can help me? What is wrong in my code?


@komposter
Replies

PanagiotisCharalampous
06 Mar 2019, 10:18

Hi Andrii,

Can you provide the full cBot code please? e.g. what is signal?

Best Regards,

Panagiotis


@PanagiotisCharalampous

komposter
06 Mar 2019, 10:43

RE:

Panagiotis Charalampous said:

Hi Andrii,

Can you provide the full cBot code please? e.g. what is signal?

Best Regards,

Panagiotis

Here is it:

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

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

        [Parameter("Lots", DefaultValue = 0.1, MinValue = 0.01, Step = 0.01)]
        public double Quantity { get; set; }

        [Parameter("SL (in renko)", DefaultValue = 2, MinValue = 1, Step = 0.1)]
        public double StopLoss { get; set; }

        [Parameter("TP (in renko)", DefaultValue = 4, MinValue = 1, Step = 0.1)]
        public double TakeProfit { get; set; }

        private RelativeStrengthIndex rsi;
        private int signal = 0;

        protected override void OnStart()
        {
            rsi = Indicators.RelativeStrengthIndex(Source, Periods);
            Print("The current symbol has pip size of: {0}, renko size = {1}", Symbol.PipSize, getRenkoSize());
        }

        protected override void OnTick()
        {
            if (signal > 0)
            {
                Close(TradeType.Sell);
                Open(TradeType.Buy);
            }
            else if (signal < 0)
            {
                Close(TradeType.Buy);
                Open(TradeType.Sell);
            }
        }

        protected override void OnBar()
        {
            CalcSignal();

            double o = MarketSeries.Open.Last(0);
            double c = MarketSeries.Close.Last(0);
            if (c > o)
                Print("Bullish bar: {0} -> {1}, signal = {2}, rsi[0] = {3}, rsi[1] = {4}", o, c, signal, rsi.Result.LastValue, rsi.Result.Last(1));
            else if (c < o)
                Print("Bearish bar: {0} -> {1}, signal = {2}, rsi[0] = {3}, rsi[1] = {4}", o, c, signal, rsi.Result.LastValue, rsi.Result.Last(1));
            else
                Print("Doj bar: {0} -> {1}, signal = {2}, rsi[0] = {3}, rsi[1] = {4}", o, c, signal, rsi.Result.LastValue, rsi.Result.Last(1));
        }

        private void CalcSignal()
        {
            signal = 0;
            if (rsi.Result.HasCrossedAbove(40, 0))
            {
                signal = 1;
                Close(TradeType.Sell);
                Open(TradeType.Buy);
            }
            else if (rsi.Result.HasCrossedBelow(60, 0))
            {
                signal = -1;
                Close(TradeType.Buy);
                Open(TradeType.Sell);
            }
        }

        private void Close(TradeType tradeType)
        {
            foreach (var position in Positions.FindAll("Renko Test", Symbol, tradeType))
                ClosePosition(position);
        }

        private void Open(TradeType tradeType)
        {
            var position = Positions.Find("Renko Test", Symbol, tradeType);
            var volumeInUnits = Symbol.QuantityToVolume(Quantity);
            var SL = Math.Round(getRenkoSize() * StopLoss, 1);
            var TP = Math.Round(getRenkoSize() * TakeProfit, 1);

            if (position == null)
                ExecuteMarketOrder(tradeType, Symbol, volumeInUnits, "Renko Test", SL, TP);
        }

        private double getRenkoSize()
        {
            return (Math.Round(Math.Abs(MarketSeries.Open.Last(1) - MarketSeries.Close.Last(1)) / Symbol.PipSize, 0));
        }
    }
}

 


@komposter

komposter
08 Mar 2019, 15:12 ( Updated at: 21 Dec 2023, 09:21 )

Bot worked without pauses ever since I wrote the post.

It printed old values of indy till 07/03 20:17 and then started to print correct values (and trade, of course):

 

First time it printed invalid value of RSI[0], but then started to work correctly.

 

Any ideas how to fix it?


@komposter

komposter
13 Mar 2019, 21:18 ( Updated at: 21 Dec 2023, 09:21 )

Again the same:

 

Any ideas?


@komposter

komposter
18 Mar 2019, 11:32

Another issue with renko chart.

I've launched cTrader, started my bot... but chart didn't draw new bars till restart!

I've recorded the video — https://youtu.be/1gD1KNniXDQ


@komposter

PanagiotisCharalampous
18 Mar 2019, 11:52

RE:

komposter said:

Another issue with renko chart.

I've launched cTrader, started my bot... but chart didn't draw new bars till restart!

I've recorded the video — https://youtu.be/1gD1KNniXDQ

Hi Andrii,

We will have a look at this. Can you reproduce this issue on Spotware cTrader Beta as well?

Best Regards,

Panagiotis


@PanagiotisCharalampous

komposter
18 Mar 2019, 11:56

RE: RE:

Panagiotis Charalampous said:

komposter said:

Another issue with renko chart.

I've launched cTrader, started my bot... but chart didn't draw new bars till restart!

I've recorded the video — https://youtu.be/1gD1KNniXDQ

Hi Andrii,

We will have a look at this. Can you reproduce this issue on Spotware cTrader Beta as well?

Best Regards,

Panagiotis

Thank you for reply!

I can't find siutable place for report on https://spotware.com/beta/

Should I register there?


@komposter

PanagiotisCharalampous
18 Mar 2019, 11:58

Hi Andrii, 

Yes you can download cTrader Beta version from https://spotware.com/beta/

Best Regards,

Panagiotis


@PanagiotisCharalampous

komposter
18 Mar 2019, 12:01

RE:

Panagiotis Charalampous said:

Hi Andrii, 

Yes you can download cTrader Beta version from https://spotware.com/beta/

Best Regards,

Panagiotis

Should I download it just to report a bug?


@komposter

PanagiotisCharalampous
18 Mar 2019, 12:05

Please download it and check if the behavior you reported is still reproduced or has been fixed. This version will be pushed to brokers soon. If the problem is fixed there, there is no reason to investigate further.


@PanagiotisCharalampous

komposter
18 Mar 2019, 12:44

RE:

Panagiotis Charalampous said:

Please download it and check if the behavior you reported is still reproduced or has been fixed. This version will be pushed to brokers soon. If the problem is fixed there, there is no reason to investigate further.

Ok, I'll try.

But this bug is floating, so I need time to catch it.


@komposter

komposter
20 Mar 2019, 20:47

The same bug in the latest beta — renko cahrt doesn't update after start: https://youtu.be/jxgssXaX1ew

I've modified bot to use 1st and 2nd bars because new renko chart draws zero bar while it formes, but first problem is frozen chart.

Code for newest cTrader:

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

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

        [Parameter("Lots", DefaultValue = 0.1, MinValue = 0.01, Step = 0.01)]
        public double Quantity { get; set; }

        [Parameter("SL (in renko)", DefaultValue = 2, MinValue = 1, Step = 0.1)]
        public double StopLoss { get; set; }

        [Parameter("TP (in renko)", DefaultValue = 4, MinValue = 1, Step = 0.1)]
        public double TakeProfit { get; set; }

        private RelativeStrengthIndex rsi;
        private int signal = 0;

        protected override void OnStart()
        {
            rsi = Indicators.RelativeStrengthIndex(Source, Periods);
            Print("The current symbol has pip size of: {0}, renko size = {1}", Symbol.PipSize, getRenkoSize());
        }

        protected override void OnTick()
        {
            if (signal > 0)
            {
                Close(TradeType.Sell);
                Open(TradeType.Buy);
            }
            else if (signal < 0)
            {
                Close(TradeType.Buy);
                Open(TradeType.Sell);
            }
        }

        protected override void OnBar()
        {
            CalcSignal();

            double o = MarketSeries.Open.Last(1);
            double c = MarketSeries.Close.Last(1);
            if (c > o)
                Print("Bullish bar: {0} -> {1}, signal = {2}, rsi[0] = {3}, rsi[1] = {4}", o, c, signal, rsi.Result.Last(1), rsi.Result.Last(2));
            else if (c < o)
                Print("Bearish bar: {0} -> {1}, signal = {2}, rsi[0] = {3}, rsi[1] = {4}", o, c, signal, rsi.Result.Last(1), rsi.Result.Last(2));
            else
                Print("Doj bar: {0} -> {1}, signal = {2}, rsi[0] = {3}, rsi[1] = {4}", o, c, signal, rsi.Result.Last(1), rsi.Result.Last(2));
        }

        private void CalcSignal()
        {
            signal = 0;
            if (rsi.Result.HasCrossedAbove(40, 1))
            {
                signal = 1;
                Close(TradeType.Sell);
                Open(TradeType.Buy);
            }
            else if (rsi.Result.HasCrossedBelow(60, 1))
            {
                signal = -1;
                Close(TradeType.Buy);
                Open(TradeType.Sell);
            }
        }

        private void Close(TradeType tradeType)
        {
            foreach (var position in Positions.FindAll("Renko Test", Symbol, tradeType))
                ClosePosition(position);
        }

        private void Open(TradeType tradeType)
        {
            var position = Positions.Find("Renko Test", Symbol, tradeType);
            var volumeInUnits = Symbol.QuantityToVolume(Quantity);
            var SL = Math.Round(getRenkoSize() * StopLoss, 1);
            var TP = Math.Round(getRenkoSize() * TakeProfit, 1);

            if (position == null)
                ExecuteMarketOrder(tradeType, Symbol, volumeInUnits, "Renko Test", SL, TP);
        }

        private double getRenkoSize()
        {
            return (Math.Round(Math.Abs(MarketSeries.Open.Last(1) - MarketSeries.Close.Last(1)) / Symbol.PipSize, 0));
        }
    }
}

 


@komposter

komposter
21 Mar 2019, 14:30 ( Updated at: 21 Dec 2023, 09:21 )

Another bug — different indicator values on the same price history:

 

 

Both RSIs based on Close prices and have period of 14


@komposter

PanagiotisCharalampous
21 Mar 2019, 14:37

Hi Andrii,

We are looking at the live renko bar issue. Regarding the RSI indicator, the two cTrader instances do not necessarily have the same price history.

Best Regards,

Panagiotis


@PanagiotisCharalampous

komposter
21 Mar 2019, 14:46 ( Updated at: 21 Dec 2023, 09:21 )

RE:

Panagiotis Charalampous said:

Regarding the RSI indicator, the two cTrader instances do not necessarily have the same price history.

It's renko!

I checked bars extremums, they are the same:

 


@komposter

komposter
21 Mar 2019, 17:38

RE:

Panagiotis Charalampous said:

Regarding the RSI indicator, the two cTrader instances do not necessarily have the same price history.

You're right, charts are different.

How to connect both terminals to one liquidity provider to have the same quotes?


@komposter

PanagiotisCharalampous
21 Mar 2019, 17:42

Hi Andrii,

This is not possible. Hopefully you should get v3.5 on ICMarkets soon and you will not need to use both versions.

Best Regards,

Panagiotis


@PanagiotisCharalampous

komposter
22 Mar 2019, 01:03

Ok.

Hope, previously described bug with frozen chart will be fixed too.


@komposter

komposter
25 Mar 2019, 09:43 ( Updated at: 21 Dec 2023, 09:21 )

I catched frozen chart again in 3.5.

It just didn't start refresh after weekends:


@komposter

komposter
25 Mar 2019, 23:17 ( Updated at: 21 Dec 2023, 09:21 )

Frozen indicator in both 3.3 and 3.5 detected again (chart continued to refresh):


@komposter

PanagiotisCharalampous
26 Mar 2019, 11:26

Hi Andrii,

We have resolved an issue with the Renko bars and we will be releasing an update soon. Let's check the indicator issue after the update as well.

Best Regards,

Panagiotis


@PanagiotisCharalampous

komposter
26 Mar 2019, 20:54

Thank you!

Problem with indicator has nothing the same with chart problem.

Waiting for upgrade.


@komposter

komposter
27 Mar 2019, 22:24 ( Updated at: 21 Dec 2023, 09:21 )

I've got an update for both platforms today and already catched frozen indicator in 3.5:


@komposter

PanagiotisCharalampous
28 Mar 2019, 09:35

Hi Andrii,

I have been running this since yesterday but I still cannot catch it. Can you please send me an email at community@spotware.com so that we can coordinate this investigation further?

Best Regards,

Panagiotis


@PanagiotisCharalampous

komposter
28 Mar 2019, 09:39

RE:

Panagiotis Charalampous said:

Hi Andrii,

I have been running this since yesterday but I still cannot catch it. Can you please send me an email at community@spotware.com so that we can coordinate this investigation further?

Best Regards,

Panagiotis

Done


@komposter

DonaldD
11 Oct 2019, 12:47

Hi Spotware,

It seems that this issue still occurs. Any idea when this can be fixed?


@DonaldD

nawab.islam
11 Nov 2019, 08:48 ( Updated at: 21 Dec 2023, 09:21 )

The Issue Still Exists. The Bot stops trading because the Data in the chart Gets Stuck.

As shown below you can see the Moving Average difference for 200 MA and 400 MA Indicator is stuck from 21:59:00. Moreover the Bar 11837 should be Bar 11838 at 22:05:00 Hours but its gone back to 7093 Bars. The same incident happend in all the open instances. This graph is for NZDCAD 1 Minute Chart. The issue gets resolved when we restart the BOT.

 

 

Similar issue with another Instance NZDUSD. Same time same issue. If it problem with BOT Coding then it will not create problem with all instance at the same time.

 

USDCAD Same Problem

 

Please resolve this ASAP or else we will be forced to use other platforms.

 

One more update. USDJPY pair didnt get stuck. Please take a look at the log for the same time. At 22:05:00 the bar changed. But this time it increased unlike the other pairs. The MA Difference didnt get stuck. And the BOT is still working perfect for this Instance.


@nawab.islam

PanagiotisCharalampous
11 Nov 2019, 09:36

Hi all,

This should have been solved in the latest update we released for Spotware cTrader Beta. Can you please also check and let us know if you face any issues?

Best Regards,

Panagiotis


@PanagiotisCharalampous

komposter
11 Nov 2019, 11:21

RE:

Panagiotis Charalampous said:

Hi all,

This should have been solved in the latest update we released for Spotware cTrader Beta. Can you please also check and let us know if you face any issues?

Best Regards,

Panagiotis

How can I check version number?

What version contains this fix?


@komposter

PanagiotisCharalampous
11 Nov 2019, 11:27

Hi Andrii,

At the moment only Spotware cTrader Beta contains the fix. Your cTrader should be automatically updated.

Best Regards,

Panagiotis


@PanagiotisCharalampous

komposter
11 Nov 2019, 11:28

RE:

Panagiotis Charalampous said:

Hi Andrii,

At the moment only Spotware cTrader Beta contains the fix. Your cTrader should be automatically updated.

Best Regards,

Panagiotis

I've started my Bot. Will let you know how it goes soon.


@komposter

PanagiotisCharalampous
13 Nov 2019, 11:51

Hi Andrii,

We have released the update on all brokers. You can test on your broker as well if you wish.

Best Regards,

Panagiotis


@PanagiotisCharalampous

komposter
13 Nov 2019, 12:02

RE:

Panagiotis Charalampous said:

Hi Andrii,

We have released the update on all brokers. You can test on your broker as well if you wish.

Best Regards,

Panagiotis

Testing on Spotware cTrader Beta since yesterday, so far so good.


@komposter

nawab.islam
18 Nov 2019, 14:21

RE:

Panagiotis Charalampous said:

Hi all,

This should have been solved in the latest update we released for Spotware cTrader Beta. Can you please also check and let us know if you face any issues?

Best Regards,

Panagiotis

Dear Panagiotis Charalampous,

I have tested in the Spotware cTrader (Public beta) 3.6 for more than a week. Its working perfect. It is not halting any more. I was waiting for exact same time it occured last week i.e UTC 9.55 AM. Working as expected.

FXPro broker will update this beta relaeas as well ? Or we need to wait for their update ?


@nawab.islam

PanagiotisCharalampous
18 Nov 2019, 14:31

Hi nawab.islam,

All brokers have now updated to 3.6.

Best Regards,

Panagiotis


@PanagiotisCharalampous

komposter
19 Nov 2019, 09:52

I had no errors since start. It seems, bug is fixed.

Thank you.

 

Are you going to add backtesting on Renko-charts?


@komposter

PanagiotisCharalampous
19 Nov 2019, 10:13

Hi Andrii,

We will but we do not have an ETA for this yet.

Best Regards,

Panagiotis


@PanagiotisCharalampous