How to count bars using CalcBar()  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
EdL
Posts: 39
Joined: 18 Feb 2013
Has thanked: 22 times
Been thanked: 11 times

How to count bars using CalcBar()

Postby EdL » 31 Mar 2013

Hi,

I'm trying to implement a basic counter for the number of bars that I'm in a trade for.

The data originally imported into quote manager was tick data for bid and ask.
My chart is using 1hr bars with extended mode and bar magnifier switched on.

The CalcBar() method appears to be called each intra-hour-bar tick and not each 1hr bar.

Ideally I'd like to do something like:

Code: Select all

protected override void CalcBar()
{
    if (this.StrategyInfo.MarketPosition > 0)
    {
        _barCount++;
    }

    if(_barCount == x)
    {
        // exit trade or do something
    }
    ...
}

But this is called each tick and not just each hour bar, so the counter gets over-incremented.
What's the best way of actually counting the number of bars I'm in a trade using the bar resolution of the actual chart?

Many thanks,

Ed

SteveP
Posts: 1
Joined: 01 Apr 2013
Been thanked: 2 times

Re: How to count bars using CalcBar()  [SOLVED]

Postby SteveP » 01 Apr 2013

Hi Ed,

please try the following:

Code: Select all

if (Bars.Status == EBarState.Close )
{
// code here runs only on last tick of bar
}


Happy Easter
Steve
These users thanked the author SteveP for the post (total 2):
Henry MultiСhartsEdL

User avatar
Henry MultiСharts
Posts: 8503
Joined: 25 Aug 2011
Has thanked: 1213 times
Been thanked: 2731 times

Re: How to count bars using CalcBar()

Postby Henry MultiСharts » 01 Apr 2013

Hello Ed,

You can also utilize IInstrument.FullSymbolData to get the closing time of the bar.

EdL
Posts: 39
Joined: 18 Feb 2013
Has thanked: 22 times
Been thanked: 11 times

Re: How to count bars using CalcBar()

Postby EdL » 11 Apr 2013

Thanks guys, I think

Code: Select all

if (Bars.Status == EBarState.Close )
is what I'm after. I'll give that a go.

Cheers

maxzhi
Posts: 1
Joined: 10 Aug 2017

Re: How to count bars using CalcBar()

Postby maxzhi » 10 Aug 2017

Greetings,

Another question on this topic... I am new to the Multicharts.NET. I want to create a code which calculate number of Bars for each Day. Of course, this is for chats with a resolution of ticks, Ranko, Range, not for Regular Chart.
regards,

User avatar
Henry MultiСharts
Posts: 8503
Joined: 25 Aug 2011
Has thanked: 1213 times
Been thanked: 2731 times

Re: How to count bars using CalcBar()

Postby Henry MultiСharts » 22 Aug 2017

maxzhi wrote:Greetings, Another question on this topic... I am new to the Multicharts.NET. I want to create a code which calculate number of Bars for each Day. Of course, this is for chats with a resolution of ticks, Ranko, Range, not for Regular Chart.regards,
Hello maxzhi,

Please specify the exact difficulty you have.


Return to “MultiCharts .NET”