An Indicator from cBot?

Created at 22 Mar 2021, 18:18
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!
TE

tekASH

Joined 29.01.2014

An Indicator from cBot?
22 Mar 2021, 18:18


Guys

How to make an Alerting indicator from an existing cBot. Can you show simple way, which parts of code should be modified, entered. Take example any bot, for instance this one:

 

Making this bot's setup logic an Indicator that gives out Alert (pop-up, sound, email). I am new to coding, so have poor understanding.

Thanks in advance


@tekASH
Replies

amusleh
22 Mar 2021, 21:16

I recommend you to first learn and have some basic understanding of C# code and then try to code indicators/cBots.

The cBot link you posted is a simple cBot that uses RSI indicator for taking trading signals, you don't have to create an indicator from a cBot, usually its the opposite way.

If you don't have enough time to learn C# then you can ask one of our consultants to do it for you or post a job on jobs page.

Here is RSI indicator that sends email notification and play sound based on the cBot code:

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 RSIAlertSample : Indicator
    {
        private RelativeStrengthIndex _rsi;

        private int _lastNotifiedBarIndex;
        
        [Parameter("Source")]
        public DataSeries Source { get; set; }
 
        [Parameter("Periods", DefaultValue = 10)]
        public int Period { get; set; }

        [Parameter("Sound File Path", DefaultValue = "C:\\Windows\\Media\\notify.wav")]
        public string SoundFilePath { get; set; }

        [Parameter("Sender Email")]
        public string SenderEmail { get; set; }

        [Parameter("Receiver Email")]
        public string ReceiverEmail { get; set; }


        protected override void Initialize()
        {
            _rsi = Indicators.RelativeStrengthIndex(Source, Period);
        }

        public override void Calculate(int index)
        {
            if (!IsLastBar || _lastNotifiedBarIndex == index) return;

            _lastNotifiedBarIndex = index;
            
            if (_rsi.Result.Last(1) > 50 && _rsi.Result.Last(1) < 70 && _rsi.Result.IsRising())
            {
                Notify("RSI Buy Signal");
            }
            else if (_rsi.Result.Last(1) < 50 && _rsi.Result.Last(1) > 30 && _rsi.Result.IsFalling())
            {
                Notify("RSI Sell Signal");
            }
        }
        
        private void Notify(string message)
        {
            if (!string.IsNullOrWhiteSpace(SoundFilePath))
            {
                Notifications.PlaySound(SoundFilePath);
            }

            if (!string.IsNullOrWhiteSpace(SenderEmail) && !string.IsNullOrWhiteSpace(ReceiverEmail))
            {
                Notifications.SendEmail(SenderEmail, ReceiverEmail, "Notification", message);
            }
        }
    }
}

 


@amusleh

tekASH
22 Mar 2021, 21:23

RE:

amusleh said:

I recommend you to first learn and have some basic understanding of C# code and then try to code indicators/cBots.

The cBot link you posted is a simple cBot that uses RSI indicator for taking trading signals, you don't have to create an indicator from a cBot, usually its the opposite way.

If you don't have enough time to learn C# then you can ask one of our consultants to do it for you or post a job on jobs page.

Here is RSI indicator that sends email notification and play sound based on the cBot code:

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 RSIAlertSample : Indicator
    {
        private RelativeStrengthIndex _rsi;

        private int _lastNotifiedBarIndex;
        
        [Parameter("Source")]
        public DataSeries Source { get; set; }
 
        [Parameter("Periods", DefaultValue = 10)]
        public int Period { get; set; }

        [Parameter("Sound File Path", DefaultValue = "C:\\Windows\\Media\\notify.wav")]
        public string SoundFilePath { get; set; }

        [Parameter("Sender Email")]
        public string SenderEmail { get; set; }

        [Parameter("Receiver Email")]
        public string ReceiverEmail { get; set; }


        protected override void Initialize()
        {
            _rsi = Indicators.RelativeStrengthIndex(Source, Period);
        }

        public override void Calculate(int index)
        {
            if (!IsLastBar || _lastNotifiedBarIndex == index) return;

            _lastNotifiedBarIndex = index;
            
            if (_rsi.Result.Last(1) > 50 && _rsi.Result.Last(1) < 70 && _rsi.Result.IsRising())
            {
                Notify("RSI Buy Signal");
            }
            else if (_rsi.Result.Last(1) < 50 && _rsi.Result.Last(1) > 30 && _rsi.Result.IsFalling())
            {
                Notify("RSI Sell Signal");
            }
        }
        
        private void Notify(string message)
        {
            if (!string.IsNullOrWhiteSpace(SoundFilePath))
            {
                Notifications.PlaySound(SoundFilePath);
            }

            if (!string.IsNullOrWhiteSpace(SenderEmail) && !string.IsNullOrWhiteSpace(ReceiverEmail))
            {
                Notifications.SendEmail(SenderEmail, ReceiverEmail, "Notification", message);
            }
        }
    }
}

 

Thanks..But the thing is I have a cBot...wanna make alerting indicator from its main conditions. it is vice-versa in my case.


@tekASH

amusleh
23 Mar 2021, 13:19

Its an indicator that notifies you when the cBot entry logic happens not a cBot.


@amusleh

tekASH
23 Mar 2021, 13:26 ( Updated at: 23 Mar 2021, 13:31 )

RE:

amusleh said:

Its an indicator that notifies you when the cBot entry logic happens not a cBot.

I know but your indicator code is related to specific cBot logic. In my case, I have a cBot (not the one I posted) that want to use for making an indicator out of it. I wanna know how complicated it is to turn a cbot logic into indicator. I thought maybe it is not that difficult, that I can do it given some instructions. For instance, keep the particular conditions part of cbots code, remove entry part and other stuff, and only leave only Conditions, add alert code.


@tekASH

tekASH
23 Mar 2021, 14:08

RE:

amusleh said:

Its an indicator that notifies you when the cBot entry logic happens not a cBot.

btw, could you please add this Indicator, fields for selection of RSI levels as well as for Timeframe selection (so it considers contact of rsi levels in that particular TF only, despite chart's TF).
Also, how to configure email, sender part is unclear.

thanks in advance!


@tekASH

amusleh
23 Mar 2021, 14:16

Please hire a consultant or post a job request, I can only give you guide lines or some sample code.


@amusleh