cTrader 3.6 has broken the Telegram messaging Service

Created at 29 Jan 2020, 06:12
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!
VertoTrading's avatar

VertoTrading

Joined 18.06.2018

cTrader 3.6 has broken the Telegram messaging Service
29 Jan 2020, 06:12


Hi guys,

Since the update to the latest cTdare Desktop, the cBot i am working on no longer sends messages to the group chat i have in Telegram. Before the update it worked perfectly.

I have read and gone through each step in the Telegram API documentation, to no avail. The cBot IMMEDIATELY crashes and will not proceed.

Has something changed in this latest iteration to prevent any sending of messages?


@VertoTrading
Replies

PanagiotisCharalampous
29 Jan 2020, 12:07

Hi VertoTrading,

Can you provide more information? What do you mean when you say the cBot immediately crashes? Do you get any messages in the log? Can you share the cBot code?

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

VertoTrading
29 Jan 2020, 12:22

RE:

PanagiotisCharalampous said:

Hi VertoTrading,

Can you provide more information? What do you mean when you say the cBot immediately crashes? Do you get any messages in the log? Can you share the cBot code?

Best Regards,

Panagiotis 

Join us on Telegram

 

Hey Panagiotis,

The only error is get is:

Crashed in OnStart with AggregateException: One or more errors occurred.

The cBot code is as follows:

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
using Telegram.Bot;
using Telegram.Bot.Args;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
using Telegram.Bot.Types.ReplyMarkups;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ALGOTRADING : Robot
    {
        #region Parameters

        #region Telegram Settings
        [Parameter("Token", DefaultValue = "Place Token Here", Group = "Telegram Settings")]
        public string TeleToken = "958414613:AAG8WdNbZjfhNxXHJ7fxiaH2nuTqhwU1Lx4";
        [Parameter("ChatID", DefaultValue = "Place ChatID Here", Group = "Telegram Settings")]
        public string TeleChatID = "590030638";
        #endregion

        #region Look at Times
        [Parameter("Hour (UTC)", Group = "Telegram Messaging Time", DefaultValue = 21)]
        public int Hours { get; set; }
        [Parameter("Minute(UTC)", Group = "Telegram Messaging Time", DefaultValue = 45)]
        public int Minutes { get; set; }

        #endregion

        #region Order Settings
        [Parameter("Take Profit", DefaultValue = 6, Group = "Order Settings")]
        public int TakeProfit { get; set; }
        [Parameter("Stop Loss", DefaultValue = 30, Group = "Order Settings")]
        public int StopLoss { get; set; }
        [Parameter("Lot Size", DefaultValue = 0.01, Group = "Order Settings", MinValue = 0.01, Step = 0.01)]
        public double LotSize { get; set; }
        #endregion

        #region Ease Of Movement Settings
        [Parameter("Period", Group = "Ease Of Movement Settings", DefaultValue = 14)]
        public int EOMPeriod { get; set; }
        [Parameter("MA Type", Group = "Ease Of Movement Settings", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType EOMType { get; set; }
        private EaseOfMovement eom;
        #endregion

        #region Chaikin Money Flow Settings
        [Parameter("Period", Group = "Chaikin Money Flow Settings", DefaultValue = 14)]
        public int CMFPeriod { get; set; }
        private ChaikinMoneyFlow cmf;
        #endregion

        #region Abolute Strength Settings
        [Parameter("Period", Group = "Abolute Strength Settings", DefaultValue = 14)]
        public int ASPeriod { get; set; }
        [Parameter("Smoothing", Group = "Abolute Strength Settings", DefaultValue = 4)]
        public int ASSmoothing { get; set; }
        [Parameter("Mode", Group = "Abolute Strength Settings", DefaultValue = 1)]
        public int ASMode { get; set; }
        private AbsoluteStrength abs;
        #endregion

        #region Force Index Settings
        public bool shape = true;
        [Parameter("Period", Group = "Force Index Settings", DefaultValue = 14)]
        public int FIPeriod { get; set; }
        private ForceIndex fi;
        #endregion

        #region SSL Settings
        [Parameter("Period", Group = "SSL Settings", DefaultValue = 14)]
        public int SSLPeriod { get; set; }
        [Parameter("Lookback", Group = "SSL Settings", DefaultValue = 1)]
        public int SSLLookback { get; set; }
        private SSL ssl;
        #endregion

        #region Heiken Ashi Settings
        [Parameter("Candle width", Group = "Heiken Ashi Settings", DefaultValue = 5)]
        public int CandleWidth { get; set; }
        [Parameter("Up color", Group = "Heiken Ashi Settings", DefaultValue = "Blue")]
        public string UpColor { get; set; }
        [Parameter("Down color", Group = "Heiken Ashi Settings", DefaultValue = "Red")]
        public string DownColor { get; set; }
        private HeikenAshi ha;
        #endregion

        #region Pips ATR Settings
        [Parameter("Atr TimeFrame", Group = "ATR Settings")]
        public TimeFrame AtrTimeFrame { get; set; }
        [Parameter("ATR Period", Group = "ATR Settings", DefaultValue = 14)]
        public int AtrPeriod { get; set; }
        [Parameter("ATR MAType", Group = "ATR Settings")]
        public MovingAverageType AtrMaType { get; set; }
        private PipsATRIndicator atrpip;

        #endregion

        #region Money Management
        [Parameter("Enabled", DefaultValue = true, Group = "Money Management")]
        public bool RiskManagement { get; set; }
        [Parameter("Risk, %", DefaultValue = 2.5, Group = "Money Management", MinValue = 0)]
        public double Risk { get; set; }
        [Parameter("Risk, $", DefaultValue = 0, Group = "Money Management", MinValue = 0)]
        public double MoneyRisk { get; set; }
        [Parameter("Fixed Balance", DefaultValue = 0, Group = "Money Management", MinValue = 0)]
        public double FixedBalance { get; set; }
        [Parameter("Use $ Instead of %", DefaultValue = false, Group = "Money Management")]
        public bool UseMoneyInsteadOfPercentage { get; set; }
        [Parameter("Use Eq Instead of Bal", DefaultValue = true, Group = "Money Management")]
        public bool UseEquityInsteadOfBalance { get; set; }
        [Parameter("Lot Digits", DefaultValue = 2, Group = "Money Management", MinValue = 0)]
        public int LotDigits { get; set; }
        #endregion

        #region Static Parameters
        public static string eom_movement;
        public static string cmf_movement;
        public static string abs_movement;
        public static string fi_movement;
        public static string ssl_movement;
        public bool _ordersactive;
        #endregion

        #endregion

        protected override void OnStart()
        {
            // Put your initialization logic here
            Timer.Start(1);
            Positions.Opened += OnPositionsOpened;
            Positions.Closed += OnPositionsClosed;
            eom = Indicators.EaseOfMovement(EOMPeriod, EOMType);
            cmf = Indicators.ChaikinMoneyFlow(CMFPeriod);
            abs = Indicators.GetIndicator<AbsoluteStrength>(ASPeriod, ASSmoothing, ASMode);
            fi = Indicators.GetIndicator<ForceIndex>(shape, FIPeriod);
            ssl = Indicators.GetIndicator<SSL>(SSLPeriod);
            ha = Indicators.GetIndicator<HeikenAshi>(CandleWidth, UpColor, DownColor);
            atrpip = Indicators.GetIndicator<PipsATRIndicator>(AtrTimeFrame, AtrPeriod, AtrMaType);
            var botClient = new TelegramBotClient(TeleToken);
            var me = botClient.GetMeAsync().Result;
            Console.WriteLine("Hello, World! I am user {me.Id} and my name is {me.FirstName}.");
        }
        protected override void OnTick()
        {

            // Put your core logic here
            if (eom.Result.IsRising())
            {
                eom_movement = "RISING";
            }
            else if (eom.Result.IsFalling())
            {
                eom_movement = "FALLING";
            }

            if (cmf.Result.IsRising())
            {
                cmf_movement = "RISING";
            }
            else if (cmf.Result.IsFalling())
            {
                cmf_movement = "FALLING";
            }

            if (abs.BullsSma.LastValue > abs.BearsSma.LastValue)
            {
                abs_movement = "Bullish";
            }
            else if (abs.BullsSma.LastValue < abs.BearsSma.LastValue)
            {
                abs_movement = "Bearish";
            }

            if (fi.FI_Line.IsRising())
            {
                fi_movement = "RISING";
            }
            else if (fi.FI_Line.IsFalling())
            {
                fi_movement = "FALLING";
            }

            if (ssl.sslUp.HasCrossedAbove(ssl.sslDown, SSLLookback) || ssl.sslUp.HasCrossedBelow(ssl.sslDown, SSLLookback))
            {
                ssl_movement = " HAS CROSSED";
            }
            else
            {
                ssl_movement = " REMAINS UNCHANGED";
            }
            Chart.DrawStaticText("Ease Of Movement", "Ease Of Movement is " + eom.Result.LastValue + " & is " + eom_movement, VerticalAlignment.Top, HorizontalAlignment.Right, Color.White);
            Chart.DrawStaticText("Chaikin Money Flow", "\nChaikin Money Flow is " + cmf.Result.LastValue + " & is " + cmf_movement, VerticalAlignment.Top, HorizontalAlignment.Right, Color.White);
            Chart.DrawStaticText("Absolute Strength", "\n\nAbsolute Strength is " + abs_movement, VerticalAlignment.Top, HorizontalAlignment.Right, Color.White);
            Chart.DrawStaticText("Force Index", "\n\n\nForce Index is " + fi.FI_Line.LastValue + " & is " + fi_movement, VerticalAlignment.Top, HorizontalAlignment.Right, Color.White);
            Chart.DrawStaticText("SSL", "\n\n\n\nSSL" + ssl_movement, VerticalAlignment.Top, HorizontalAlignment.Right, Color.White);

        }

        protected override void OnTimer()
        {
            //put Timer logic here
            var symbol = Symbol.Name;
            Chart.DrawStaticText("Time", "Time is " + Server.TimeInUtc, VerticalAlignment.Top, HorizontalAlignment.Left, Color.AliceBlue);
            var DayOfWeek = Server.TimeInUtc;
            var TimeOfDay = Server.TimeInUtc;

            if (_ordersactive == false)
            {
                if (TimeOfDay.TimeOfDay.Hours == Hours && TimeOfDay.TimeOfDay.Minutes == Minutes && TimeOfDay.TimeOfDay.Seconds == 0)
                {
                    Print("Passed Checkpoint 1");
                    if (eom.Result.LastValue > 0 && cmf.Result.LastValue > 0 && fi.FI_Line.LastValue > 0)
                    {
                        Print("BUY Passed Checkpoint 2");
                        if (ssl.sslUp.HasCrossedAbove(ssl.sslDown, SSLLookback) || ssl.sslUp.HasCrossedBelow(ssl.sslDown, SSLLookback))
                        {
                            Print("BUY Passed Checkpoint 3");
                            if (abs.BullsSma.LastValue > abs.BearsSma.LastValue)
                            {
                                Print("BUY Passed Checkpoint 4");
                                ExecuteMarketOrder(TradeType.Buy, Symbol.Name, Symbol.QuantityToVolumeInUnits(LotsOptimized()), null, (atrpip.Result.LastValue * 1.5), atrpip.Result.LastValue);
                                _ordersactive = true;
                            }
                        }
                    }
                    else if (eom.Result.LastValue < 0 && cmf.Result.LastValue < 0 && fi.FI_Line.LastValue < 0)
                    {
                        Print("SELL Passed Checkpoint 2");
                        if (ssl.sslUp.HasCrossedAbove(ssl.sslDown, SSLLookback) || ssl.sslUp.HasCrossedBelow(ssl.sslDown, SSLLookback))
                        {
                            Print("SELL Passed Checkpoint 3");
                            if (abs.BullsSma.LastValue < abs.BearsSma.LastValue)
                            {
                                Print("SELL Passed Checkpoint 4");
                                ExecuteMarketOrder(TradeType.Sell, Symbol.Name, Symbol.QuantityToVolumeInUnits(LotsOptimized()), null, (atrpip.Result.LastValue * 1.5), atrpip.Result.LastValue);
                                _ordersactive = true;
                            }
                        }
                    }
                }
            }
        }

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

        protected void OnPositionsOpened(PositionOpenedEventArgs args)
        {
            _ordersactive = true;
        }

        protected void OnPositionsClosed(PositionClosedEventArgs args)
        {
            _ordersactive = false;
        }

        #region Money Management

        double LotsOptimized()
        {
            if (!RiskManagement)
                return (LotSize);

            double Size, RiskMoney, PositionSize = 0;

            if (Account.Currency == "")
                return (0);

            if (FixedBalance > 0)
            {
                Size = FixedBalance;
            }
            else if (UseEquityInsteadOfBalance)
            {
                Size = Account.Equity;
            }
            else
            {
                Size = Account.Balance;
            }

            if (!UseMoneyInsteadOfPercentage)
                RiskMoney = Size * Risk / 100;
            else
                RiskMoney = MoneyRisk;

            double UnitCost = Symbol.PipValue;

            if ((StopLoss != 0) && (UnitCost != 0))
                PositionSize = Math.Round(Symbol.VolumeInUnitsToQuantity((int)Math.Round(RiskMoney / StopLoss / UnitCost)), LotDigits);

            //Print(PositionSize);

            if (PositionSize < Symbol.VolumeInUnitsToQuantity(Symbol.VolumeInUnitsMin))
            {
                //Print("Calculated position size (" + PositionSize + ") is less than minimum position size (" + Symbol.VolumeInUnitsToQuantity(Symbol.VolumeInUnitsMin) + "). Setting position size to minimum.");
                PositionSize = Symbol.VolumeInUnitsToQuantity(Symbol.VolumeInUnitsMin);
            }
            else if (PositionSize > Symbol.VolumeInUnitsToQuantity(Symbol.VolumeInUnitsMax))
            {
                //Print("Calculated position size (" + PositionSize + ") is greater than maximum position size (" + Symbol.VolumeInUnitsToQuantity(Symbol.VolumeInUnitsMax) + "). Setting position size to maximum.");
                PositionSize = Symbol.VolumeInUnitsToQuantity(Symbol.VolumeInUnitsMax);
            }

            double LotStep = Symbol.VolumeInUnitsToQuantity(Symbol.VolumeInUnitsStep);
            double steps = PositionSize / LotStep;
            if (Math.Floor(steps) < steps)
            {
                //Print("Calculated position size (" + PositionSize + ") uses uneven step size. Allowed step size = " + LotStep + ". Setting position size to " + (Math.Floor(steps) * LotStep) + ".");
                PositionSize = Math.Floor(steps) * LotStep;
            }

            return (PositionSize);
        }
        #endregion

    }
}

It does reference other indicators i have, however, i removed these references and it still is posing and issue.


@VertoTrading

PanagiotisCharalampous
29 Jan 2020, 13:12

Hi VertoTrading,

The exception is caused by this line of code

var me = botClient.GetMeAsync().Result;

Which version of Telegram.Bot do you use? Do you build your project using .Net 4.0 or do you use a higher version?

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

VertoTrading
29 Jan 2020, 13:42

RE:

PanagiotisCharalampous said:

Hi VertoTrading,

The exception is caused by this line of code

var me = botClient.GetMeAsync().Result;

Which version of Telegram.Bot do you use? Do you build your project using .Net 4.0 or do you use a higher version?

Best Regards,

Panagiotis 

Join us on Telegram

 

Hi Panagiotis,

Thanks for the reply. I can see that this line cases the error, however if i try to use this piece of code:

var message = botClient.SendTextMessageAsync(chatId: TeleChatID, text: "The cBot has Started.", parseMode: ParseMode.Markdown, disableNotification: false);

It does not send the message to the chat group. I have tested the Token and Chat ID to make sure they were correct in Postman and it workded there.

I am running it on .Net 4.5. Do I need to run it on 4.0?


@VertoTrading

PanagiotisCharalampous
29 Jan 2020, 14:49

Hi VertoTrading,

cTrader currently is built using .Net v4.0. If you use components that use a higher version, you might run into problems. Regarding the new line code you posted, in order to receive messages, you need to give full access rights to the cBot.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

VertoTrading
29 Jan 2020, 14:53

RE:

PanagiotisCharalampous said:

Hi VertoTrading,

cTrader currently is built using .Net v4.0. If you use components that use a higher version, you might run into problems. Regarding the new line code you posted, in order to receive messages, you need to give full access rights to the cBot.

Best Regards,

Panagiotis 

Join us on Telegram

Hey Panagiotis,

Well I'll be a monkeys uncle........ the one bit of code I overlooked............

THANKYOU!!!!!!!

Silly me haha. This thread can now be closed.


@VertoTrading