OnBar event and ticks volume

09 Feb 2019, 18:56OnBar event and ticks volume#1
erisoftdevelopposts: 6since: 09 Feb 2019

Hello Ctrader Coders

I am thinking to build a Robot that makes operation based:

0- Timeframe h1.

1- Candle close.

2- Volume of Ticks.

As Image below.

Our moderator of this forum propose this code to get the event candle event onBar. That is fine I got it.

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)]
    public class NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }
 
        protected override void OnStart()
        {
            // Put your initialization logic here
        }
 
        protected override void OnTick()
        {
            // Put your core logic here
        }
 
        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }

         protected override void OnBar()
        {
            // Ticks summarized goes here.
        }
    }
}

I have two questions.

1- OnBar event triggers when a new Bar comes to the chart or when a latest bar closes?

2-  How I can get the volume of ticks as number like the provided example of the chart(Tick Bar Up) in a proggramatic way.?

I really appreciate every help provided.

11 Feb 2019, 10:22#2
Panagiotis Charalampousposts: 2168since: 13 Jan 2017

Hi erisoftdevelop,

Thanks for posting in our forum. Regarding your questions

1) As soon as a new Bar comes to the chart.

2) You can use  MarketSeries.TickVolume. See below an example 

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()
        {
            // Put your initialization logic here
        }

        protected override void OnBar()
        {
            Print(MarketSeries.TickVolume.Last(1));
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

Best Regards,

Panagiotis


Head of Community Management at cTrader
12 Feb 2019, 17:31#3
erisoftdevelopposts: 6since: 09 Feb 2019

Thanks Panagiotis Charalampous

Can you answer me a couple of questions please:

1- How can i get the data Open, High, Low, Close,Tick Volume for the 10bars before the current bar?

2- Is there any way to get the count of the ticks realtime of the current bar?

3- How to get the data Open, High, Low, Close, Tick Volume using Date and Time(Example get the Data of the bar Yesterday 10:15am)?

 

Thanks in advance for the answers. And you do a great job.

 

Erick Alfaro

13 Feb 2019, 09:53#4
Panagiotis Charalampousposts: 2168since: 13 Jan 2017

Hi Erick,

1. Through Market Series. An example for let's say close price is MarketSeries.Close.Last(10)

2. Use MarketSeries.TickVolume.LastValue

3. An example to get the close price for 24 hours before MarketSeries.Close[MarketSeries.OpenTime.GetIndexByTime(Server.Time.AddDays(-1))];

Best Regards,

Panagiotis


Head of Community Management at cTrader