MTF Bollinger Bands


Category:
0
0

Hi Pete,

How is it possible to create a Multi-time frame Bollinger bands?  That line that I have commented out is an issue. I appreciate your help!

input length = 20;
input displace = 0;
input price = close;

input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input averageType = AverageType.Simple;

input TimeFrame = AggregationPeriod.DAY;

####def sDev = stdev(data = price(period = TimeFrame)[-displace] length = length);

plot MidLine = MovingAverage(averageType, data = price[-displace], length = length);
plot LowerBand = MidLine + num_Dev_Dn * sDev;
plot UpperBand = MidLine + num_Dev_Up * sDev;

LowerBand.SetDefaultColor(GetColor(0));
MidLine.SetDefaultColor(GetColor(1));
UpperBand.SetDefaultColor(GetColor(5));

 

RESOLVED
Marked as spam
Posted by (Questions: 15, Answers: 23)
Asked on June 23, 2018 8:12 pm
522 views
0
Private answer

There is much more to it than the line you have commented out. But in order to correct that line so that is works correctly you need to use the actual close in place of the input named “price”:

def sDev = stdev(data = close(period = TimeFrame)[-displace], length = length);

Next, you need to apply the secondary aggregation period to the moving average that forms the middle line:

plot MidLine = MovingAverage(averageType, data = close(period = TimeFrame)[-displace], length = length);

After making both of these adjustments you should find that it works as expected. But it’s late. And I did not bother to fire up Thinkorswim and test it. So let me know if you still get errors and I’ll address them in the morning.

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on June 23, 2018 9:25 pm
0

Thanks Pete. I tried this, but unfortunately, it still comes up with an error on that first line that you edited.

( at June 24, 2018 12:00 pm)
0

Yes. That is because of a missing comma. I only copy and pasted your code and corrected the reference to the secondary time frame. Here it is with the comma in its proper place. I will fix this in my original answer when I get back to my computer.

def sDev = stdev(data = close(period = TimeFrame)[-displace], length = length);

( at June 24, 2018 4:57 pm)
0

Thanks Pete, that worked!

( at June 25, 2018 7:37 am)