Sample Breakout cBot question

Created at 29 Apr 2015, 02:43
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!
.I

.ics

Joined 10.03.2015

Sample Breakout cBot question
29 Apr 2015, 02:43


Hi all,

Having a question about some code present in Sample Breakout cBot.

In the below code we see the initialisation of bollingerBands in the OnStarrt(). In the OnBar() we request the top and bottom values of the BB.

My questions:

  • why is this initialisation of bollingerBands done in the OnStart() and not in the OnBar()?
  • is bollingerBands updated every tick even if it is defined in the OnStart()?

Thanks in advance.

        protected override void OnStart()
        {
            bollingerBands = Indicators.BollingerBands(Source, Periods, Deviations, MAType);
        }

        protected override void OnBar()
        {

            var top = bollingerBands.Top.Last(1);
            var bottom = bollingerBands.Bottom.Last(1);

            if (top - bottom <= BandHeightPips * Symbol.PipSize)
            {
                consolidation = consolidation + 1;
            }


           


@.ics
Replies

.ics
01 May 2015, 12:27

Anyone?
 


@.ics

9718853
07 May 2015, 00:41

RE:

In OnStart() the indicator is defined...

In OnBar() the last result of the indicator is used to trigger an action...

If you wanted anything to happen on tick you would have to use OnTick() 

.ics said:

Hi all,

Having a question about some code present in Sample Breakout cBot.

In the below code we see the initialisation of bollingerBands in the OnStarrt(). In the OnBar() we request the top and bottom values of the BB.

My questions:

  • why is this initialisation of bollingerBands done in the OnStart() and not in the OnBar()?
  • is bollingerBands updated every tick even if it is defined in the OnStart()?

Thanks in advance.

        protected override void OnStart()
        {
            bollingerBands = Indicators.BollingerBands(Source, Periods, Deviations, MAType);
        }

        protected override void OnBar()
        {

            var top = bollingerBands.Top.Last(1);
            var bottom = bollingerBands.Bottom.Last(1);

            if (top - bottom <= BandHeightPips * Symbol.PipSize)
            {
                consolidation = consolidation + 1;
            }


           

 


@9718853