Hello,
I’m looking to display the bollinger bands of the 2H TF on a 15min chart. I was able to draft the code here below, but calculation is off a few points vs the actual values and I can’t find why. Maybe someone could see if there is an error in my code.
DEFPARAM CalculateOnLastBars = 1000
//taking the close every 2H
IF hour <> hour[1] and (hour=1 or hour = 3 or hour = 5 or hour = 7 or hour = 9 or hour = 11 or hour = 13 or hour = 15 or hour = 17 or hour = 19 or hour = 21 or hour=23) THEN
H2close = close
//taking the current price into account also
if currenttime+10000-opentime<1499 and date=today then
H2close = close
endif
BBDown = Average[160](H2Close)-2.5*std[160](H2Close)
BBUp = Average[160](H2Close)+2.5*std[160](H2Close)
RETURN BBDown,BBUp
Thank you in advance,
Because you want to make an average of a non linear data serie.
160 times the value of H2Close doesn’t mean that you are using 160 different values of it, because the data array of your H2Close is linear, it means that it follows the time passing by with the bar counts.
You could create a dummy MTF strategy and use GRAPHONPRICE to draw the 2 hour time frame Bollinger bands on a faster time frame if it is just an indicator that you want rather than a coding challenge!
Indeed Nicolas. How can I do to go through the last 160 values, and only store the 20 unique values that matters?
With a loop and some headaches, it is possible without variables arrays, but not the best solution around.
You should have a look at examples made with GRAPHONPRICE, like Vonasi said, here: GRAPHONPRICE
Thx Nicolas and Vonasi for your remarks. Graphonprice is cool but I would prefer to keep my screens light, and I usually use a small segment on the right side to display different level of price from higher TF. So I will give a try. I haven’t seen a post with the kind of loop required, so if you have an idea..
Thx you again for your remarks, after some headaches, I finally found a way to code it.
I finally found a way to code it.
Care to share it? The code might be of interest to others trying to do the same thing.