Signal on candle close and new candle start

Created at 01 Apr 2022, 13:27
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!
CS

csabz90

Joined 09.03.2022

Signal on candle close and new candle start
01 Apr 2022, 13:27


Hi All,

 

Does anyone have knowledge on how to receive signals through Open API when a candle closes and a new candle begins? For example for EURUSD M5, at 10:05:00am I would get a message to my socket saying EURUSD closed its current M5 candle for timestamp 10:00:00am and is opening a new M5 candle with timestamp 10:05:00am

As an alternative I am currently getting historical candle(s) every 5 minutes when the EURUSD trading session is active, but I feel this is inefficient and would feel better to just get the latest candle whenever I get a signal that tells me to do so. I'm aware of ProtoOASpotEvent and ProtoOASubscribeLiveTrendbarReq, but correct me if I'm wrong but that does not have the above functionality (or equivalent).

 

Thanks!


@csabz90
Replies

csabz90
01 Apr 2022, 13:44

After a bit more digging it looks like cBots have an OnBar method that does what I'm after, so I'm really just looking for the equivalent of that in Open API.


@csabz90

amusleh
04 Apr 2022, 09:44

Hi,

When you subscribe to bars by using ProtoOASubscribeLiveTrendbarReq you will receive a ProtoOASpotEvent whenever a new bar opens, the OnBar method in automate API is also called whenever a new bar opens.

So If you want to run any kind of logic on bar open you can use the ProtoOASpotEvent.

 


@amusleh

csabz90
04 Apr 2022, 13:25

RE:

amusleh said:

Hi,

When you subscribe to bars by using ProtoOASubscribeLiveTrendbarReq you will receive a ProtoOASpotEvent whenever a new bar opens, the OnBar method in automate API is also called whenever a new bar opens.

So If you want to run any kind of logic on bar open you can use the ProtoOASpotEvent.

 

Thanks, okay I'll check ProtoOASubscribeLiveTrendbarReq and ProtoOASpotEvent again and see if I'm able to get and process the event messages when new bar opens.


@csabz90

csabz90
04 Apr 2022, 23:18

RE:

amusleh said:

Hi,

When you subscribe to bars by using ProtoOASubscribeLiveTrendbarReq you will receive a ProtoOASpotEvent whenever a new bar opens, the OnBar method in automate API is also called whenever a new bar opens.

So If you want to run any kind of logic on bar open you can use the ProtoOASpotEvent.

 

I experimented with ProtoOASubscribeLiveTrendbarReq and ProtoOASpotEvent a bit. Is it correct to say it sends a message whenever there is a change in volume/bid/ask/high/low/close for a specific candle? If so, what part of such a message would signal that a new bar has been opened? After parsing, this is a message for example:

"symbolId": "1", "bid": "109701", "ask": "109701", "trendbar": [{"volume": "2", "period": "M1", "low": "109701", "deltaOpen": "0", "deltaHigh": "0", "utcTimestampInMinutes": 27485052}], "timestamp": "1649103135350"}

Would I just compare the "utcTimestampInMinutes" value to the previous one in order to be able to decide if there is a new bar? If there is no activity in the market, will I still get a ProtoOASpotEvent message as soon as a new bar opens or will I always have to wait for the first change in volume/bid/ask/etc of the candle to get a ProtoOASpotEvent?

Thank you!


@csabz90

amusleh
05 Apr 2022, 09:37

Hi,

You can use the trendbar utcTimestampInMinutes fields, if it changes then it means a new bar is opened.

If there is no activity then there will be no bars.


@amusleh

csabz90
05 Apr 2022, 10:21

RE:

amusleh said:

Hi,

You can use the trendbar utcTimestampInMinutes fields, if it changes then it means a new bar is opened.

If there is no activity then there will be no bars.

Okay got it, thanks!


@csabz90