Using OnBar method to set variable

Created at 01 Jul 2018, 10:51
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!
PO

pogostick

Joined 12.05.2018

Using OnBar method to set variable
01 Jul 2018, 10:51


I would like to calculate by how much a candlestick goes above or below the outer bands of the Bollingerbands indicator.

This is done on the 5 minute timeframe even though the bot is set on the 1 minute timeframe.

I am aware that the OnBar method will then calculate this variable every minute. I have included a portion of the method used to check the price against the bollinger bands.

I would like to know why the candlePipPiercedTop variable returns different values every minute when I was expecting it to remain constant for 5 consecutive minutes before changing.

 OnBar()
    {
        CheckPricePiercedBollingerBands();
    }

private string CheckPricePiercedBollingerBands()
        {
            if (MarketSeries.High.Last(1) > _bollinger5min.Top.Last(1))
            {
                double candlePiercedTop = MarketSeries.High.Last(1) - _bollinger5min.Top.Last(1);
                double candlePipPiercedTop = candleLengthPiercedTop * 10000;
                
                if (candlePipPiercedTop > 1)
                {
                    Print("candlePipPiercedTop = {0}", candlePipPiercedTop);
                    return bollingerPierced = "top";
                }
                else
                {
                    return bollingerPierced = "normal";
                }
            }

 


@pogostick
Replies

pogostick
01 Jul 2018, 11:16

No stress! Realised I was using the wrong market series. All sorted.


@pogostick

... Deleted by UFO ...