Transferring

BJORNBERNAU since: 21 Jul 2020;

  01 Aug 2020, 14:51
Transferring

Hello, 

attempting to send a "one" or "zero" signal from custom indicator as a trade signal, does indeed transfer a signal to cbot, but that signal does not start the trader. 

Funnily, when setting the SIGNAL == 1, no information is available, but setting SIGNAL == 0, shows both signals "zero" and "one", but non of them liberate trading signals.

What mistakes are made by this culprit ? 

Sincerely, 

Björn Bernau 

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class aCBOTbaseBOLLINGER : Indicator
    {
        [Output("B", PlotType = PlotType.Points, LineColor = "#FFFFD700", Thickness = 4)]
        public IndicatorDataSeries B { get; set; }

        [Output("SIGNAL")]
        public int SIGNAL { get; set; }

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

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

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

        [Parameter("MAType")]
        public MovingAverageType MAType { get; set; }

        public BollingerBands boll;



        protected override void Initialize()
        {
            boll = Indicators.BollingerBands(Source, BandPeriod, Std, MAType);

        }

        public override void Calculate(int index)
        {
            var BBT = boll.Top[index];
            var HP = Bars.HighPrices[index];
            var high = HP - BBT;

            if (high > 0)
            {
                SIGNAL = 1;
                B[index] = Bars.HighPrices[index];
            }

            else
            {
                SIGNAL = 0;
            }
            SIGNAL = 0;
        }
    }
}

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

        [Parameter(DefaultValue = 100000)]
        public int Volume { get; set; }

        [Output("B")]
        public IndicatorDataSeries B { get; set; }

        [Output("SIGNAL")]
        public int SIGNAL { get; set; }

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

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

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

        [Parameter("MAType")]
        public MovingAverageType MAType { get; set; }

        private aCBOTbaseBOLLINGER S2;


        protected override void OnStart()
        {
            S2 = Indicators.GetIndicator<aCBOTbaseBOLLINGER>(Source, BandPeriod, Std, MAType);
        }

        protected override void OnBar()
        {
            if (S2.SIGNAL == 1)
            {
                Print(S2.SIGNAL, "    ", S2.B);
                ExecuteMarketOrder(TradeType.Buy, Symbol.Name, Volume, "buy1", 14, 80);
            }
        }
    }
}
 

PanagiotisCharalampous's avatar

PanagiotisCharalampous since: 13 Jan 2017;

  03 Aug 2020, 09:48

Hi Bjorn,

Try moving the print function before the if statement

            Print(S2.SIGNAL, "    ", S2.B);
            if (S2.SIGNAL == 1)
            {            
                ExecuteMarketOrder(TradeType.Buy, Symbol.Name, Volume, "buy1", 14, 80);
            }

Indicators implement a lazy loading logic, so the Calculate() function will be called only when an Output property is accessed, S2.B in this case.

Best Regards,

Panagiotis 

Join us on Telegram

Head of Community Management at cTrader

BJORNBERNAU since: 21 Jul 2020;

  03 Aug 2020, 10:04
SIGNAL from CUSTOM INDICATOR

Thanks again Panagiotis, 

sorry but this "SIGNAL" is liberating a constant "zero". It does not transfer this signal equaling "one" in any instance. 

Cordially, 

Björn 

PanagiotisCharalampous's avatar

PanagiotisCharalampous since: 13 Jan 2017;

  03 Aug 2020, 10:09

Hi Bjorn,

Also note that this line of code is meaningless so I had to comment it out

After that, the cBot places trades.

Panagiotis 

Join us on Telegram

Head of Community Management at cTrader

BJORNBERNAU since: 21 Jul 2020;

  03 Aug 2020, 11:37
ERRATIC SIGNALS

Yes - true! 

A microscopic step for mankind - a giant leap for a man. ... Thank you! 

But the signals are still erratic. See that the Signals (yellow points) are displayed clearly in the robot, but no trades are taken in several instances, e.g. count 5838, indicated by pink point. How is this? It seems, these signals are not consistently transferred after all. 

Björn  

PanagiotisCharalampous's avatar

PanagiotisCharalampous since: 13 Jan 2017;

  03 Aug 2020, 11:57

Hi Bjorn,

The cBot and indicator do exactly what you programmed them to do. You need to fix your logic. For example

 if (high > 0)
            {
                SIGNAL = 1;
                B[index] = Bars.HighPrices[index];
            }

            else
            {
                SIGNAL = 0;
            }

Here you set the B value when there is a signal but not when there isn't. Why? This will cause B having a value and displaying a point while SIGNAL is 0.

Best Regards,

Panagiotis 

Join us on Telegram

Head of Community Management at cTrader

BJORNBERNAU since: 21 Jul 2020;

  03 Aug 2020, 12:16
Zeroing out with double.NAN

Thank you! 

Incidentally, I am impressed by the diligence, speed and specifics with which you are supporting. 

This would mean, by "zeroing out B" when the SIGNAL = 0, would cancel the signal or rather - align - the indicator signal wit the trade signal, 

but e.g. a 

           double d = double.NaN;

            if (high > 0)
            {
                SIGNAL = 1;
                B[index] = Bars.HighPrices[index];
            }

            if (high <= 0)
            {
                SIGNAL = 0;
                B[index] = d;
            }

does unfortunately not change the matter. 

BJORNBERNAU since: 21 Jul 2020;

  03 Aug 2020, 12:22
INDICATOR vs ROBOT data

INDICATOR 

ROBOT - the same periods show only two signals

PanagiotisCharalampous's avatar

PanagiotisCharalampous since: 13 Jan 2017;

  03 Aug 2020, 12:24

Hi Bjorn,

Try checking the B output value instead of using the SIGNAL variable. What you are doing is not a good programming practice.

Best Regards,

Panagiotis 

Join us on Telegram

Head of Community Management at cTrader

BJORNBERNAU since: 21 Jul 2020;

  03 Aug 2020, 13:26
INDEX

Yes, thanks, 

surely I have a lot to learn. 

Another issue:

Is there a way to use INDEX in cBOT, i.e. in terms of COUNT or similar? 

OR 

is there a way to ONLY relay index count to cbot from indicator? 

Björn