Twitter Signal Service Experimentation

trend_meanreversion since: 31 Jul 2014;

  09 Nov 2020, 09:35
Twitter Signal Service Experimentation

tgjobscv said:

trend_meanreversion said:

Made a small subtle change in the alternate models ( Model_3 & Model_5 ). Included StopLoss as part of strategy. 

Performance as per change is below :

Model3 

You can make copy signal ?

Yes I am currently thinking of how to make them available to potential investors. possibly via copy signals (cCopy), leasing algorithm , or just selling signals.

trend_meanreversion since: 31 Jul 2014;

  09 Nov 2020, 15:01

First SL hit in 4 months [ such a crazy rally..very volatile  ]. Not happy as it is 1.7% hit , but let's move forward as trading is not a one-way street!

Sell Signal generated at 09/11/2020 11:58:38 UTC for UK100 at Bid/Ask Price: 6126.4 / 6127.7 [ TP: 6120.27 , SL: 6233.01 , Exit: EoD ]

tgjobscv since: 05 Dec 2018;

  09 Nov 2020, 17:14
RE: RE: RE:

trend_meanreversion said:

tgjobscv said:

trend_meanreversion said:

Made a small subtle change in the alternate models ( Model_3 & Model_5 ). Included StopLoss as part of strategy. 

Performance as per change is below :

Model3 

You can make copy signal ?

Yes I am currently thinking of how to make them available to potential investors. possibly via copy signals (cCopy), leasing algorithm , or just selling signals.

You can use naga trading platform, copyFX:

https://naga.com/register?refcode=xhfehn

 Profit for you.

trend_meanreversion since: 31 Jul 2014;

  10 Nov 2020, 00:08

After a crying hit on UK100 trade, at least US30 gave something back. ( locked in TP for US30 )

Buy Signal generated at 09/11/2020 14:50:57 UTC for US30 at Bid/Ask Price: 29602 / 29604.5 [ TP: 29634.1 , SL: 29026.93 , Exit: EoD ]

trend_meanreversion since: 31 Jul 2014;

  10 Nov 2020, 03:04

At least a positive start of today ..locked in TP !

Buy Signal generated at 10/11/2020 00:37:54 UTC for AUS200 at Bid/Ask Price: 6391.55 / 6392.35 [ TP: 6398.74 , SL: 6294.41 , Exit: EoD ]

trend_meanreversion since: 31 Jul 2014;

  10 Nov 2020, 03:21

oh..Another quick trade and locked in TP !

Buy Signal generated at 10/11/2020 01:18:15 UTC for HK50 at Bid/Ask Price: 26360.4 / 26367.6 [ TP: 26393.97 , SL: 25957.98 , Exit: EoD ]

trend_meanreversion since: 31 Jul 2014;

  11 Nov 2020, 08:48

Sorry didn't update about 2 more trades taken by bot yesterday. Both locked in TP !

Buy Signal generated at 10/11/2020 09:08:56 UTC for DE30 at Bid/Ask Price: 13063.6 / 13064.6 [ TP: 13077.66 , SL: 12783.12 , Exit: EoD ]
Buy Signal generated at 10/11/2020 14:35:44 UTC for US30 at Bid/Ask Price: 29206 / 29209.5 [ TP: 29238.71 , SL: 28626.72 , Exit: EoD ]

  

trend_meanreversion since: 31 Jul 2014;

  11 Nov 2020, 13:44

First trade of the day and locked in TP !

Buy Signal generated at 11/11/2020 07:40:10 UTC for HK50 at Bid/Ask Price: 26251.7 / 26259 [ TP: 26285.26 , SL: 25847.9 , Exit: EoD ]

tgjobscv since: 05 Dec 2018;

  11 Nov 2020, 17:26

Maybe usefull ? Tools for Signal Telegram:

using System;
using System.Linq;
using System.Net;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class tTelegramrepeater : Robot
    {
        [Parameter("Telegram Bot Key", DefaultValue = "__bot_key__")]
        public string BOT_API_KEY { get; set; }

        // if you know which channel you want to broadcast to, add it here
        // otherwise the bot looks at the people and channels its' interacted with and
        // sends messages to everyone
        [Parameter("ChannelId", DefaultValue = "")]
        public string ChannelId { get; set; }


        List<string> _telegramChannels = new List<string>();

        protected override void OnStart()
        {
            if (string.IsNullOrEmpty(ChannelId))
            {
                _telegramChannels = ParseChannels(GetBotUpdates());
            }
            else
            {
                _telegramChannels.Add(ChannelId);
            }



            // Subscribe to events.
            Positions.Opened += OnPositionOpened;
            Positions.Closed += OnPositionClosed;

        }

        protected override void OnTick()
        {
            // Put your core logic here

        }

        protected override void OnBar()
        {
            // Put your core logic here
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
            // Unsubscribe to events.
            Positions.Opened -= OnPositionOpened;
            Positions.Closed -= OnPositionClosed;
        }


        //  Parses messages for bot and determines which channesl are listening
        private List<string> ParseChannels(string jsonData)
        {
            var matches = new Regex("\"id\"\\:(\\d+)").Matches(jsonData);
            List<string> channels = new List<string>();
            if (matches.Count > 0)
            {
                foreach (Match m in matches)
                {
                    if (!channels.Contains(m.Groups[1].Value))
                    {
                        channels.Add(m.Groups[1].Value);
                    }
                }
            }
            foreach (var v in channels)
            {
                Print("DEBUG: Found Channel {0} ", v);
            }
            return channels;
        }

        protected int updateOffset = -1;
        private string GetBotUpdates()
        {
            Dictionary<string, string> values = new Dictionary<string, string>();
            if (updateOffset > -1)
            {
                values.Add("offset", (updateOffset++).ToString());
            }

            var jsonData = MakeTelegramRequest(BOT_API_KEY, "getUpdates", values);

            var matches = new Regex("\"message_id\"\\:(\\d+)").Matches(jsonData);
            if (matches.Count > 0)
            {
                foreach (Match m in matches)
                {
                    int msg_id = -1;
                    int.TryParse(m.Groups[1].Value, out msg_id);
                    if (msg_id > updateOffset)
                    {
                        updateOffset = msg_id;
                    }
                }
            }
            return jsonData;
        }

        private void SendMessageToAllChannels(string message)
        {
            foreach (var c in _telegramChannels)
            {
                SendMessageToChannel(c, message);
            }
        }

        private string SendMessageToChannel(string chat_id, string message)
        {
            var values = new Dictionary<string, string> 
            {
                {
                    "chat_id",
                    chat_id
                },
                {
                    "text",
                    message
                }
            };

            return MakeTelegramRequest(BOT_API_KEY, "sendMessage", values);
        }

        private string MakeTelegramRequest(string api_key, string method, Dictionary<string, string> values)
        {
            string TELEGRAM_CALL_URI = string.Format("https://api.telegram.org/bot{0}/{1}", api_key, method);

            var request = WebRequest.Create(TELEGRAM_CALL_URI);
            request.ContentType = "application/x-www-form-urlencoded";
            request.Method = "POST";

            StringBuilder data = new StringBuilder();
            foreach (var d in values)
            {
                data.Append(string.Format("{0}={1}&", d.Key, d.Value));
            }
            byte[] byteArray = Encoding.UTF8.GetBytes(data.ToString());
            request.ContentLength = byteArray.Length;

            Stream dataStream = request.GetRequestStream();

            dataStream.Write(byteArray, 0, byteArray.Length);

            dataStream.Close();

            WebResponse response = request.GetResponse();

            Print("DEBUG {0}", ((HttpWebResponse)response).StatusDescription);

            dataStream = response.GetResponseStream();

            StreamReader reader = new StreamReader(dataStream);

            string outStr = reader.ReadToEnd();

            Print("DEBUG {0}", outStr);

            reader.Close();

            return outStr;


        }

        public void OnPositionOpened(PositionOpenedEventArgs args)
        {
            ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            // If you didn't set a channel, thenfind channels by looking at the updates
            var data = string.Format("entry price: ={0} \nentry time: {1} \nsymbol: {2}\nstop loss: {3}\ntake profit: {4}", args.Position.EntryPrice, args.Position.EntryTime, args.Position.SymbolName, args.Position.StopLoss, args.Position.TakeProfit);
            Print("DEBUG", args);
            Print("DEBUG", data);
            SendMessageToAllChannels(data);
        }

        public void OnPositionClosed(PositionClosedEventArgs args)
        {
            ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            var data = string.Format("net profit: {0}", args.Position.NetProfit);
            SendMessageToAllChannels(data);
        }
    }
}

trend_meanreversion since: 31 Jul 2014;

  12 Nov 2020, 00:51
RE:

tgjobscv said:

Maybe usefull ? Tools for Signal Telegram:

using System;
using System.Linq;
using System.Net;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class tTelegramrepeater : Robot
    {
        [Parameter("Telegram Bot Key", DefaultValue = "__bot_key__")]
        public string BOT_API_KEY { get; set; }

        // if you know which channel you want to broadcast to, add it here
        // otherwise the bot looks at the people and channels its' interacted with and
        // sends messages to everyone
        [Parameter("ChannelId", DefaultValue = "")]
        public string ChannelId { get; set; }


        List<string> _telegramChannels = new List<string>();

        protected override void OnStart()
        {
            if (string.IsNullOrEmpty(ChannelId))
            {
                _telegramChannels = ParseChannels(GetBotUpdates());
            }
            else
            {
                _telegramChannels.Add(ChannelId);
            }



            // Subscribe to events.
            Positions.Opened += OnPositionOpened;
            Positions.Closed += OnPositionClosed;

        }

        protected override void OnTick()
        {
            // Put your core logic here

        }

        protected override void OnBar()
        {
            // Put your core logic here
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
            // Unsubscribe to events.
            Positions.Opened -= OnPositionOpened;
            Positions.Closed -= OnPositionClosed;
        }


        //  Parses messages for bot and determines which channesl are listening
        private List<string> ParseChannels(string jsonData)
        {
            var matches = new Regex("\"id\"\\:(\\d+)").Matches(jsonData);
            List<string> channels = new List<string>();
            if (matches.Count > 0)
            {
                foreach (Match m in matches)
                {
                    if (!channels.Contains(m.Groups[1].Value))
                    {
                        channels.Add(m.Groups[1].Value);
                    }
                }
            }
            foreach (var v in channels)
            {
                Print("DEBUG: Found Channel {0} ", v);
            }
            return channels;
        }

        protected int updateOffset = -1;
        private string GetBotUpdates()
        {
            Dictionary<string, string> values = new Dictionary<string, string>();
            if (updateOffset > -1)
            {
                values.Add("offset", (updateOffset++).ToString());
            }

            var jsonData = MakeTelegramRequest(BOT_API_KEY, "getUpdates", values);

            var matches = new Regex("\"message_id\"\\:(\\d+)").Matches(jsonData);
            if (matches.Count > 0)
            {
                foreach (Match m in matches)
                {
                    int msg_id = -1;
                    int.TryParse(m.Groups[1].Value, out msg_id);
                    if (msg_id > updateOffset)
                    {
                        updateOffset = msg_id;
                    }
                }
            }
            return jsonData;
        }

        private void SendMessageToAllChannels(string message)
        {
            foreach (var c in _telegramChannels)
            {
                SendMessageToChannel(c, message);
            }
        }

        private string SendMessageToChannel(string chat_id, string message)
        {
            var values = new Dictionary<string, string> 
            {
                {
                    "chat_id",
                    chat_id
                },
                {
                    "text",
                    message
                }
            };

            return MakeTelegramRequest(BOT_API_KEY, "sendMessage", values);
        }

        private string MakeTelegramRequest(string api_key, string method, Dictionary<string, string> values)
        {
            string TELEGRAM_CALL_URI = string.Format("https://api.telegram.org/bot{0}/{1}", api_key, method);

            var request = WebRequest.Create(TELEGRAM_CALL_URI);
            request.ContentType = "application/x-www-form-urlencoded";
            request.Method = "POST";

            StringBuilder data = new StringBuilder();
            foreach (var d in values)
            {
                data.Append(string.Format("{0}={1}&", d.Key, d.Value));
            }
            byte[] byteArray = Encoding.UTF8.GetBytes(data.ToString());
            request.ContentLength = byteArray.Length;

            Stream dataStream = request.GetRequestStream();

            dataStream.Write(byteArray, 0, byteArray.Length);

            dataStream.Close();

            WebResponse response = request.GetResponse();

            Print("DEBUG {0}", ((HttpWebResponse)response).StatusDescription);

            dataStream = response.GetResponseStream();

            StreamReader reader = new StreamReader(dataStream);

            string outStr = reader.ReadToEnd();

            Print("DEBUG {0}", outStr);

            reader.Close();

            return outStr;


        }

        public void OnPositionOpened(PositionOpenedEventArgs args)
        {
            ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            // If you didn't set a channel, thenfind channels by looking at the updates
            var data = string.Format("entry price: ={0} \nentry time: {1} \nsymbol: {2}\nstop loss: {3}\ntake profit: {4}", args.Position.EntryPrice, args.Position.EntryTime, args.Position.SymbolName, args.Position.StopLoss, args.Position.TakeProfit);
            Print("DEBUG", args);
            Print("DEBUG", data);
            SendMessageToAllChannels(data);
        }

        public void OnPositionClosed(PositionClosedEventArgs args)
        {
            ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            var data = string.Format("net profit: {0}", args.Position.NetProfit);
            SendMessageToAllChannels(data);
        }
    }
}

 Thanks for the code for Telegram mate but it is too complicated for me :) . Btw I already got a channel where bot posts the trades. I am still thinking if I should make it public or private (premium paid service). Haven't decided on anything yet regarding commercializing my algorithm (if at all I do). So far people are enjoying it for free via Twitter :)