Multi Timeframe Indicator Alert

Created at 03 Apr 2020, 05:40
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!
K1

K100

Joined 04.11.2018

Multi Timeframe Indicator Alert
03 Apr 2020, 05:40


Hi.

I have an indicator that draws candles (Manipulated) for me. I view the candles one timeframe, for example 15 minute chart.

However, i'd like for it to alert me if price hits a certain level on a lower timeframe, for eg a 1minute chart.

I coded it to use both timeframes however it appears the OnBar method only calls on the timeframe of the chart displayed (15m).

Is there a way around this ?

 

Thanks.

 


@K100
Replies

PanagiotisCharalampous
03 Apr 2020, 08:32

Hi K100,

You can use Bars.BarOpened event to check bar changes for bars on other timeframes.

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

K100
03 Apr 2020, 13:38

RE:

PanagiotisCharalampous said:

Hi K100,

You can use Bars.BarOpened event to check bar changes for bars on other timeframes.

Best Regards,

Panagiotis 

Join us on Telegram

 

I'm using a Dataseries, as the Bars data i am using has been manipulated, (as in i have some additional maths applied to the MarketData.GetBars) --  So i'm not sure this will work or am i misunderstanding the method ?

I've created a dataseries for the OHLC - am i able to create my own Bars data for this work ?

 


@K100

PanagiotisCharalampous
03 Apr 2020, 14:07

Hi K100,

I am not sure what do you mean. With MarketData.GetBars() you can get the bars for another timeframe. Then using Bars.BarsOpened you can subscribe to the event raised each time a new bar is added to this collection. Isn't this what you are looking for?

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

K100
03 Apr 2020, 14:30

RE:

PanagiotisCharalampous said:

Hi K100,

I am not sure what do you mean. With MarketData.GetBars() you can get the bars for another timeframe. Then using Bars.BarsOpened you can subscribe to the event raised each time a new bar is added to this collection. Isn't this what you are looking for?

Best Regards,

Panagiotis 

Join us on Telegram

The issue is that, i'm using the MarketData.GetBars() and then transforming that data - and moving it into a dataseries. So the alert i need needs to be referencing the price data from the Dataseries. I've created one Dataseries for each of the timeframes. So i need and way to subscribe to the lower timeframe dataseries for alerts while viewing the Chart in a normal 15minute timeframe...  Is that more clear ?

 


@K100

PanagiotisCharalampous
03 Apr 2020, 16:06

Hi K100,

If the bar change event of your custom data series is different than the standard timeframe, then you will need to develop this logic yourself.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

K100
04 Apr 2020, 05:51

RE:

PanagiotisCharalampous said:

Hi K100,

If the bar change event of your custom data series is different than the standard timeframe, then you will need to develop this logic yourself.

Best Regards,

Panagiotis 

Join us on Telegram

 

Would you be able to provide me some sample code on the Bars.BarOpened event , there is little documentation or discussion in the forum about it.

Maybe i can still try it ?

Many thanks for your assistance.


@K100

PanagiotisCharalampous
06 Apr 2020, 08:51

Hi K100,

See below

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        protected override void OnStart()
        {
            var bars = MarketData.GetBars(TimeFrame.Daily);
            bars.BarOpened += OnBarsBarOpened;
        }
        
        void OnBarsBarOpened(BarOpenedEventArgs obj)
        {
            Print("D1 Bar Opened");
        }
    }
}

 

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

K100
06 Apr 2020, 10:42

RE:

PanagiotisCharalampous said:

Hi K100,

See below

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        protected override void OnStart()
        {
            var bars = MarketData.GetBars(TimeFrame.Daily);
            bars.BarOpened += OnBarsBarOpened;
        }
        
        void OnBarsBarOpened(BarOpenedEventArgs obj)
        {
            Print("D1 Bar Opened");
        }
    }
}

 

Best Regards,

Panagiotis 

Join us on Telegram

 

Great ! Thanks.


@K100