Bollinger Bands Breakouts (Amibroker And Tradestation Code)

The strategy in plain English:

What happens when the price breaks out of a short-term Bollinger Band channel, but the short-term bands are smaller than the long-term bands? It shows promise in GLD (gold).

Buy and sell are done at the close.

Click here to see the original article.

Amibroker code:

AvgBBlong=BBandTop(C,100,2)-BBandBot(C,100,2);
AvgBBshort=BBandTop(C,20,2)-BBandBot(C,20,2);

Buy= Cross(Close,BBandTop(C,20,2)) AND AvgBBshort <AvgBBlong;
buyPrice=Close;
Sell= Cross(MA(C,10),Close);
sellPrice=Close ;

Tradestation code:

{
Bollinger band breakouts (Strategy 75)
What happens when the price breaks out of a short-term Bollinger Band channel, 
but the short-term bands are smaller than the long-term bands? 
It shows promise in GLD (gold).
Buy and sell are done at the close.
}

Inputs:
	BBLookbackFast(20),
	BBLookbackSlow(100),
	BBNumDevs(2),
	SellLookback(10);
	
Vars:
	AvgBBslow(0),
	AvgBBfast(0);

AvgBBslow = BollingerBand(Close, BBLookbackSlow, BBNumDevs) - BollingerBand(Close, BBLookbackSlow, -BBNumDevs);
AvgBBfast= BollingerBand(Close, BBLookbackFast, BBNumDevs) - BollingerBand(Close, BBLookbackFast, -BBNumDevs);

if Close Cross over BollingerBand(Close, BBLookbackFast, BBNumDevs) and AvgBBfast < AvgBBslow Then
	Buy this bar on close;

if Average(Close, SellLookback) Cross over Close Then
	Sell this bar on close;

Disclosure: We are not financial advisors. Please do your own due diligence and investment research or consult a financial professional. All articles are our opinions – they are not suggestions to buy or sell any securities.