Need Help: Multi Time Frame Alert

Created at 24 Jul 2018, 09:10
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!
FL

flores.ernestoiii

Joined 24.07.2018

Need Help: Multi Time Frame Alert
24 Jul 2018, 09:10


Hi I am a newbie in coding and I was wondering if somebody can assist me with my problem. Is there any way I could create an alert for different time frames? The gist of my indicator is just to look for a certain pattern on the chart, but.. I want to be alerted on this for different timeframes. I have looked around the forums but mostly what I found was they are just displaying indicators from various timeframes. I do not want that, I just want to be alerted, should I be using the same script? Please help to give me some advise, below is a sample of my script. Thank you.

 

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 Trial : Indicator
    {

        [Parameter("Alert File", DefaultValue = "c:\\windows\\media\\Windows Hardware Insert.wav")]
        public string MediaFile { get; set; }

        [Parameter("Alert Sounds", DefaultValue = true)]
        public bool AlertNow { get; set; }

        private MarketSeries series1;
        private MarketSeries series5;


        protected override void Initialize()
        {
            series1 = MarketData.GetSeries(TimeFrame.Minute);
            series5 = MarketData.GetSeries(TimeFrame.Minute5);
        }


        public override void Calculate(int index)
        {
       
            var index1 = GetIndexByDate(series1, MarketSeries.OpenTime[index]);
            if (index1 != -1)
            {

                //just a sample
                   if 
                   {
                           if ((MarketSeries.Close[index1 - 1] <= MarketSeries.Open[index1 - 1]) & (MarketSeries.Close[index1 - 2] >= MarketSeries.Open[index1 - 2]))
                            {
                                if (AlertON)
                                {
                                    //my alert in M1 tf
                                    if (AlertNow)
                                    {
                                        Notifications.PlaySound(MediaFile);
                                    }

                                    break;
                                }
                           }
                    }
             }


            var index5 = GetIndexByDate(series5, MarketSeries.OpenTime[index]);
            if (index5 != -1)
            {

                //just a sample
                   if 
                   {
                           if ((MarketSeries.Close[index5 - 1] <= MarketSeries.Open[index5 - 1]) & (MarketSeries.Close[index5 - 2] >= MarketSeries.Open[index5 - 2]))
                            {
                                if (AlertON)
                                {
                                    //my alert in M5 tf
                                    if (AlertNow)
                                    {
                                        Notifications.PlaySound(MediaFile);
                                    }

                                    break;
                                }
                           }
                    }
             }
                    

        private int GetIndexByDate(MarketSeries series, DateTime time)
        {
            for (int i = series.Close.Count - 1; i > 0; i--)
            {
                if (time == series.OpenTime[i])
                    return i;
            }
            return -1;
        }
}
}

 


@flores.ernestoiii
Replies

PanagiotisCharalampous
24 Jul 2018, 09:29

Hi flores.ernestoiii,

Thanks for posting in our forum. My advice would be not to send alerts from within the indicator but use a cBot instead that will read your indicator's value. Then you can use several cBots, one for each timeframe of interest that will send the relevant notifications.

Best Regards,

Panagiotis


@PanagiotisCharalampous

flores.ernestoiii
24 Jul 2018, 10:34

Hi Panagiotis,

Thank you for your response, and your suggestion. Does this mean that the above script will not work? So far I am only getting the alert if I open it on the timeframe specified on the script, if not, then I do not get any alert.


@flores.ernestoiii

flores.ernestoiii
24 Jul 2018, 11:49

And also, how do I call my indicator IF it does not return any value? It just screens the chart for candle patterns/formations? Appreciate your guidance.


@flores.ernestoiii

PanagiotisCharalampous
24 Jul 2018, 11:59

Hi flores.ernestoiii,

No it will not work. Another option is to program the indicator to work for its timeframe and add the indicator on several charts with different timeframes. There is no need to code all timeframes in the indicator.

Best Regards,

Panagiotis


@PanagiotisCharalampous