BarOpened Event

Created at 04 Jan 2021, 08:52
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!
GE

gennimatas

Joined 19.09.2018

BarOpened Event
04 Jan 2021, 08:52


BarOpened event is firing on ticks.

Following snippet produces this log:


04/01/2021 09:50:42.390 | 2021-01-04 08:50:41 >Bars_BarOpened  EURGBP 2021-01-04 06:00:00 1162 Hour 
04/01/2021 09:50:34.765 | 2021-01-04 08:50:33 >Bars_BarOpened  EURGBP 2021-01-04 06:00:00 1162 Hour 
04/01/2021 09:50:32.828 | 2021-01-04 08:50:31 >Bars_BarOpened  EURGBP 2021-01-04 06:00:00 1162 Hour 
04/01/2021 09:50:27.265 | 2021-01-04 08:50:26 >Bars_BarOpened  EURGBP 2021-01-04 06:00:00 1162 Hour 
04/01/2021 09:50:25.187 | 2021-01-04 08:50:24 >Bars_BarOpened  EURGBP 2021-01-04 06:00:00 1162 Hour 
04/01/2021 09:50:18.578 | 2021-01-04 08:50:17 >Bars_BarOpened  EURGBP 2021-01-04 06:00:00 1162 Hour 
04/01/2021 09:50:11.203 | 2021-01-04 08:50:10 >Bars_BarOpened  EURGBP 2021-01-04 06:00:00 1162 Hour 
04/01/2021 09:50:05.859 | 2021-01-04 08:50:04 >Bars_BarOpened  EURGBP 2021-01-04 06:00:00 1162 Hour 
04/01/2021 09:50:04.031 | 2021-01-04 08:50:02 >Bars_BarOpened  EURGBP 2021-01-04 06:00:00 1162 Hour 
 


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

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class TestBarOpened : Indicator
    {

        protected override void Initialize()
        {
            Chart.Bars.BarOpened += Bars_BarOpened;
        }

        private void Bars_BarOpened(BarOpenedEventArgs obj)
        {
            Print(DateTime.Now + " >Bars_BarOpened " + " " + obj.Bars.SymbolName + " " + obj.Bars.LastBar.OpenTime + " " + Bars.OpenTimes.GetIndexByExactTime(obj.Bars.LastBar.OpenTime) + " " + obj.Bars.TimeFrame + " ");
        }

        public override void Calculate(int index)
        {

        }

    }
}

 


@gennimatas
Replies

PanagiotisCharalampous
04 Jan 2021, 09:59

Hi Takis,

It is a known issue and will be fixed in an upcoming release.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

Shares4us
04 Jan 2021, 11:13

RE:

You can use workaround like:


int PrevIndex=-1;
public override void Calculate(int index)
{
    if(PrevIndex!=index)
    {
        // do your barstuff here;
        PrevIndex=index;
    }
}

 


@Shares4us

gennimatas
04 Jan 2021, 16:37

RE:

PanagiotisCharalampous said:

Hi Takis,

It is a known issue and will be fixed in an upcoming release.

Best Regards,

Panagiotis 

Join us on Telegram

Thanks Panagiotis


@gennimatas

gennimatas
04 Jan 2021, 16:41

RE: RE:

Shares4us said:

You can use workaround like:


int PrevIndex=-1;
public override void Calculate(int index)
{
    if(PrevIndex!=index)
    {
        // do your barstuff here;
        PrevIndex=index;
    }
}

 

Thanx

I fixed in place and it seems it works.

Don't know why but it does. LOL

if (DateTime.UtcNow.Subtract(obj.Bars.LastBar.OpenTime).TotalSeconds < 0)

DoSomething()

 


@gennimatas