How to stop Buy notifications until a Sell one has been sent

Created at 14 Sep 2016, 11:32
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!
CL

clot.anthony

Joined 14.09.2016

How to stop Buy notifications until a Sell one has been sent
14 Sep 2016, 11:32


Hello everyone.

I'm trying to make my bot but I've got a problem. I've chosen to be warned by mail if a Buy/Sell signal is detected, but it doesn't stop spamming me every second until there is no more Buy or Sell signal. 

So what I want is to send the mail notification, and then put the Buy signal on pause until a Sell signal has been sent, vice versa.

Would you have a clue to this?

Thanks for helping.

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


namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC)]
    public class IchimokuUSDJPY : Robot
    {


        //Global declaration
        private IchimokuKinkoHyo i_Kijun;
        private IchimokuKinkoHyo i_SSA_Price;
        private IchimokuKinkoHyo i_SSA_Chinkou;
        private IchimokuKinkoHyo i_SSB_Price;
        private IchimokuKinkoHyo i_Chinkou;
        private IchimokuKinkoHyo i_SSB_Chinkou;
        double _Chinkou;
        double _Open_Bar;
        bool _Chinkou_Above_SSB;
        bool _Price_Above_SSA;
        bool _Price_Open_Above_Kijun;
        bool _Price_Above_SSB;
        bool _Chinkour_Above_SSA;
        bool _Buy_Signal;
        bool _Sell_Signal;

        DateTime LastTradeExecution = new DateTime(0);

        protected override void OnStart()
        {
            i_Kijun = Indicators.IchimokuKinkoHyo(9, 26, 52);
            i_SSA_Price = Indicators.IchimokuKinkoHyo(9, 26, 52);
            i_SSA_Chinkou = Indicators.IchimokuKinkoHyo(9, 26, 52);
            i_SSB_Price = Indicators.IchimokuKinkoHyo(9, 26, 52);
            i_Chinkou = Indicators.IchimokuKinkoHyo(9, 26, 52);
            i_SSB_Chinkou = Indicators.IchimokuKinkoHyo(9, 26, 52);

        }

        protected override void OnTick()
        {
            if (Trade.IsExecuting)
                return;

            //Local declaration

            //Step 1
            _Chinkou = i_Chinkou.ChikouSpan.Last(0);
            _Open_Bar = MarketSeries.Open.Last(0);

            //Step 2
            _Chinkou_Above_SSB = (_Chinkou > i_SSB_Chinkou.SenkouSpanB.Last(52));
            _Price_Above_SSA = (_Open_Bar > i_SSA_Price.SenkouSpanA.Last(26));
            _Price_Open_Above_Kijun = (_Open_Bar > i_Kijun.KijunSen.Last(0));
            _Price_Above_SSB = (_Open_Bar > i_SSB_Price.SenkouSpanB.Last(26));
            _Chinkour_Above_SSA = (_Chinkou > i_SSA_Chinkou.SenkouSpanA.Last(52));

            //Step 3
            _Buy_Signal = (_Price_Above_SSA && _Price_Above_SSB && _Chinkou_Above_SSB && _Chinkour_Above_SSA && _Price_Open_Above_Kijun);
            _Sell_Signal = (!_Price_Open_Above_Kijun && !_Price_Above_SSA && !_Price_Above_SSB && !_Chinkour_Above_SSA && !_Chinkou_Above_SSB);


            //Step 4
            if (_Buy_Signal)
                Notifications.SendEmail("clot.anthony@gmail.com", "clot.anthony@gmail.com", "Signal Buy on USDJPY H1", "Signal position");

            if (_Sell_Signal)
                Notifications.SendEmail("clot.anthony@gmail.com", "clot.anthony@gmail.com", "Signal Sell on USDJPY H1", "Signal position");

        }

 


@clot.anthony
Replies

... Deleted by UFO ...

clot.anthony
14 Sep 2016, 13:43

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


namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC)]
    public class IchimokuUSDJPY : Robot
    {


        //Global declaration
        private IchimokuKinkoHyo i_Kijun;
        private IchimokuKinkoHyo i_SSA_Price;
        private IchimokuKinkoHyo i_SSA_Chinkou;
        private IchimokuKinkoHyo i_SSB_Price;
        private IchimokuKinkoHyo i_Chinkou;
        private IchimokuKinkoHyo i_SSB_Chinkou;
        double _Chinkou;
        double _Open_Bar;
        bool _Chinkou_Above_SSB;
        bool _Price_Above_SSA;
        bool _Price_Open_Above_Kijun;
        bool _Price_Above_SSB;
        bool _Chinkour_Above_SSA;
        bool _Buy_Signal;
        bool _Sell_Signal;

        DateTime LastTradeExecution = new DateTime(0);

        protected override void OnStart()
        {
            i_Kijun = Indicators.IchimokuKinkoHyo(9, 26, 52);
            i_SSA_Price = Indicators.IchimokuKinkoHyo(9, 26, 52);
            i_SSA_Chinkou = Indicators.IchimokuKinkoHyo(9, 26, 52);
            i_SSB_Price = Indicators.IchimokuKinkoHyo(9, 26, 52);
            i_Chinkou = Indicators.IchimokuKinkoHyo(9, 26, 52);
            i_SSB_Chinkou = Indicators.IchimokuKinkoHyo(9, 26, 52);

        }

        protected override void OnTick()
        {
            if (Trade.IsExecuting)
                return;

            //Local declaration

            //Step 1
            _Chinkou = i_Chinkou.ChikouSpan.Last(0);
            _Open_Bar = MarketSeries.Open.Last(0);

            //Step 2
            _Chinkou_Above_SSB = (_Chinkou > i_SSB_Chinkou.SenkouSpanB.Last(52));
            _Price_Above_SSA = (_Open_Bar > i_SSA_Price.SenkouSpanA.Last(26));
            _Price_Open_Above_Kijun = (_Open_Bar > i_Kijun.KijunSen.Last(0));
            _Price_Above_SSB = (_Open_Bar > i_SSB_Price.SenkouSpanB.Last(26));
            _Chinkour_Above_SSA = (_Chinkou > i_SSA_Chinkou.SenkouSpanA.Last(52));

            //Step 3
            _Buy_Signal = (_Price_Above_SSA && _Price_Above_SSB && _Chinkou_Above_SSB && _Chinkour_Above_SSA && _Price_Open_Above_Kijun);
            _Sell_Signal = (!_Price_Open_Above_Kijun && !_Price_Above_SSA && !_Price_Above_SSB && !_Chinkour_Above_SSA && !_Chinkou_Above_SSB);


            //Step 4
            if (_Buy_Signal && !Buy_Signal_Send)
            {
                Buy_Signal_Send = true;
                Sell_Signal_Send = false;
                Notifications.SendEmail("@gmail.com", "@gmail.com", "Signal Buy on USDJPY H1", "Signal position");
            }
            if (_Sell_Signal && !Sell_Signal_Send)
            {
                Buy_Signal_Send = false;
                Sell_Signal_Send = true;
                Notifications.SendEmail("@gmail.com", "@gmail.com", "Signal Sell on USDJPY H1", "Signal position");
            }
        }

Thank you for your answer.

Like this? When I build the Robot it gives me an error about the context of using Buy_Signal_Send. Should I create something like variables for Buy_Signal_Send and Sell? I surely have to fill something.

Just to be sure my request is clear, is that I want an alternation of notifications between the signals, meaning I can't receive a second Buy signal before a Sell signal has been detected.

 

Thanks for your help!


@clot.anthony

... Deleted by UFO ...

... Deleted by UFO ...

clot.anthony
14 Sep 2016, 15:25

Oh my god... I searched for so long and got headache...

Your code doesn't look that complicated but even, I can't get the logic of it. You're really good, and seriously thanks for your help it works like a charm and is exactly what I wanted to do. :)

Do you have any Paypal Donation system on your website? Looked at it but didn't see.

Thanks to you I'll look at what you did and I'll add same kind of bools to be able to do my cBot working on different TF and Symbols at same time.

Thanks again, I'm really grateful. :)

Anthony


@clot.anthony