Transferring

Created at 01 Aug 2020, 14:51
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!
BJ

BJORNBERNAU

Joined 21.07.2020

Transferring
01 Aug 2020, 14:51


 

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);
            }
        }
    }
}
 


@BJORNBERNAU
Replies

... Deleted by UFO ...

PanagiotisCharalampous
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

 


@PanagiotisCharalampous

BJORNBERNAU
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 


@BJORNBERNAU

PanagiotisCharalampous
03 Aug 2020, 10:09 ( Updated at: 21 Dec 2023, 09:22 )

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


@PanagiotisCharalampous

BJORNBERNAU
03 Aug 2020, 11:37 ( Updated at: 21 Dec 2023, 09:22 )

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  

 

 

 


@BJORNBERNAU

PanagiotisCharalampous
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

 


@PanagiotisCharalampous

BJORNBERNAU
03 Aug 2020, 12:16 ( Updated at: 21 Dec 2023, 09:22 )

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

BJORNBERNAU
03 Aug 2020, 12:22 ( Updated at: 21 Dec 2023, 09:22 )

INDICATOR vs ROBOT data

INDICATOR 

ROBOT - the same periods show only two signals


@BJORNBERNAU

PanagiotisCharalampous
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


@PanagiotisCharalampous

BJORNBERNAU
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 


@BJORNBERNAU

BJORNBERNAU
03 Aug 2020, 13:30

transferring signals

Also, 

it is possible to transfer a signal as 1 or 0, and then use it in a boolean expression. 

But if marketseries are used, then these are a double array. 

As such market data cannot be used in a boolean IF expression. 

How do we convert market data, so as to only represent price or index in cbot? 

Björn 


@BJORNBERNAU

PanagiotisCharalampous
03 Aug 2020, 14:19

Hi Bjorn,

Your questions are not very clear unfortunately. If you are just trying to check the DataSeries values, you can use Last() method and check if the value is NaN or not.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

BJORNBERNAU
03 Aug 2020, 15:15

IF values and Market Data in Cbot

Yes, 

this is the path I was suspecting. 

However, how do you compare a market data value, that is derived from an double array, index + value, with a NAN value? 

The market data is then composed in a way that it does not allow for boolean checks. IF statements can't be used to compare Market data with a NAN-value. 

How is the market data-value, just reduced to the value, excluding the index?  

Thank your. 

Björn 


@BJORNBERNAU

PanagiotisCharalampous
03 Aug 2020, 15:19

Hi Bjorn,

You try something like this

  if (!double.IsNaN(S2.B.Last(1)))

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

BJORNBERNAU
03 Aug 2020, 15:56

if (!double.IsNaN(S2.B.Last(1)))

This works well! 

Inspiring... 

But, 

FIRST 

where is the reference to .Last(), it is not displayed in the https://ctrader.com/api/reference/bars/last

And it doesn't work with the auto dot.notation path in C#. How is it referenced? 

 

SECOND 

I still wonder whether it is possible in any easily accessible manner to present the INDEX-array in the bot program, for referencing purposes? 

In cBOT I understand it is represented as COUNT. 

 

Thank you! 

And again, thank you for the clear cut answers! 

 

Björn Bernau


@BJORNBERNAU

PanagiotisCharalampous
03 Aug 2020, 16:09

Hi Bjorn,

1) The Last() method used in this example is this one.

2) You can use index to access indicator values from the cBot e.g. S2.B[index], but is more complicated to get the correct value than using Last() method.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous