PowerLanguage and EasyLanguage Tutorial - The Bollinger Bands

In this PowerLanguage and EasyLanguage tutorial you will learn how to build the bollinger bands indicator from scratch and how to add interesting features like the slope and the over-price signal.

What are the Bollinger Bands? They represent two standard deviations of a moving average.

So let’s start drawing a moving average:

Inputs:
BB_Length(20);

Var:
BB_Line(0);

BB_Line = Average(Close, BB_Length);

Plot1(BB_Line, “BB_Line”, Black, Default, 2);

bollinger bands first step draw moving average

Have a question? Chat with us!

Then we calculate the standard deviation of the moving average.

The standard deviation indicates how much each value moves away from the moving average.

Once calculated, we will multiply this result by a multiplier.

Inputs:
Length(20),
Molt(2);

Var:
BB_Line(0),
StDev(0),
UpperBand(0),
LowerBand(0);

BB_Line = Average(Close, Length);

StDev = StandardDev( Close, Length, 1 );

UpperBand = BB_Line + Molt * StDev ;
LowerBand = BB_Line + Molt * StDev * -1 ;

Plot1(BB_Line, “BB_Line”, Black, Default, 2);
Plot2(UpperBand, “Upper”, Blue, Default, 2);
Plot3(LowerBand, “Lower”, Blue, Default, 2);

bollinger bands standard deviation

We completed the first step of our PowerLanguage and EasyLanguage Tutorial. We have created a lean code for our Bollinger Bands.

Look carefully at the difference between our code and the classic indicator you find on your TradeStation and MultiCharts.

Put your hands in the original code may seem complicated.

You can easily modify the indicator with our short and straightforward code.

At this point we can add some interesting functions, for example, we would like to know the direction of the trend of our middle line.

 

Do you want to learn EasyLanguage & PowerLanguage for TradeStation and MultiCharts? Start here:

Bollinger Bands PowerLanguage and Learn EasyLanguage TradeStation original code

Bollinger Bands PowerLanguage and EasyLanguage Tutorial Slope Function

To avoid making the indicator code-heavy, we construct a function that calculates the direction of the trend:

Inputs:
Length(Numericsimple);

Vars:
BB_Line(0),
BB_Line2(0),
Trend(0);

BB_Line = Average(Close, Length);
BB_Line2 = Average(Close, Length*5);

If BB_Line > BB_Line2 Then
Trend = 1;

If BB_Line < BB_Line2 Then
Trend = -1;

Bollinger_Bands_Trend_Function=Trend;

In practice, we use two moving averages, one fast, and the other five times slower.

Bollinger Bands TradeStation MultiCharts EasyLanguage Indicator Slope

In this way, we will only have to enter the input of the first moving average that will be the same used to calculate the Bollinger Bands.

Let’s assume we use a classic 20-period average for the calculation of Bollinger Bands.

The function that calculates the trend will multiply the average to 20 times by five times.

Then it will compare the two averages to verify the direction of the trend. The fast moving average above the slow moving average, the trend is bullish and vice versa.

Then the function passes the value relative to the direction of the trend to the indicator:
+1 uptrend
-1 bearish trend

If Bollinger_Bands_Trend_Function(length) = 1 Then
Color1=DarkGreen;

If Bollinger_Bands_Trend_Function(Length) = -1 Then
Color1=Red;

The indicator will use this data to change the color of the moving average of our Bollinger Bands.

Bollinger Bands and RSI Strategy

Have a question? Chat with us!

Bollinger Bands Signal PowerLanguage EasyLanguage Indicator

At this point, we add another useful function to the indicator.

The Bollinger Bands are an excellent tool for measuring volatility and price excesses.

It is always interesting to know when prices break the Upper or Lower Lines because we are in the presence of price excess.

In markets, mean-reverting can generate excellent signals, as it could work using it in reverse in trend follower markets.

When the price of the previous day closes outside one of the bands, the indicator signals it by drawing a point.

However, it may be necessary to decrease the value of the standard deviation to increase the number of signals or vice versa to increase it to operate with less frequency.

It could be used to filter signals together with the relative strength index; in this case, it will be convenient to lower the Bollinger Bands’ standard deviation value.

Obviously it is possible to create an audible alarm or send a message by e-mail when this opportunity occurs.

bollinger Bands strategy setup

The code in PowerLanguage and EasyLanguage is very simple:

If Signal_Function then
Begin
If Close[1] > UpperBand Then
Plot4(High+(High*0.005), “Sell Signal”, Red, default, 5);

If Close[1] < LowerBand Then
Plot5(Low-(Low*0.005), “Buy Signal”, DarkGreen, default, 5);

End;

The important thing is to evaluate if the standard deviation used is correct for this type of signal.

Using the standard parameter of 2 standard deviations on a 20-period average should be excellent for many instruments.

However, it may be necessary to decrease the value of the standard deviation to increase the number of signals or vice versa to increase it to operate with less frequency.

It could be used to filter signals together with the relative strength index; in this case, it will be convenient to lower the Bollinger Bands’ standard deviation value.

Bollinger Bands Indicator
EasyLanguage tutorial code indicator
EasyLanguage tutorial code functions

You can find many free TradeStation EasyLanguage Tutorials and Indicators here:

TradeStation Indicators

EasyLanguage Tutorials

Have a question? Chat with us!

Do you want to learn EasyLanguage & PowerLanguage for TradeStation and MultiCharts? Start here:

Learn more about EasyLanguage Number to String:

TradeStation Link

MultiCharts Link

Leave a Reply