If you want to create an automated trading strategy with Bollinger Bands, but don’t know how to code, then this tutorial will save you a ton of time because you won’t have to learn a complicated and confusing programming language.

Watch the video above to see the entire process in action.

This is the easiest way build an automated trading strategy that I’ve seen in my 15+ years of running this website.  

Once you have the basic framework setup, you’re free to test different indicator setting, entry and exit ideas, very easily.

The text version is provided below if you’re at work and you don’t want your boss to hear that you’re doing trading stuff 😉

What are Bollinger Bands?

The Bollinger Band is a technical trading indicator invented by John Bollinger in the 1990s.

It consists of a moving average, combined with 2 complimentary lines, which are each typically 2 standard deviations above and below moving average.

This is what it looks like on a chart.

Bollinger Band on chart

The setting of 2 standard deviations can be changed, as can the lookback period of the moving average.

A standard deviation is statistical measurement that shows how far a value has moved away from the mean.

Therefore, the Bollinger Band is generally used as a way to show an area of the chart that price likely to stay within. In other words, it’s a regression to the mean indicator.

Since price action is likely to stay with in the upper and lower bands, there are several different trading strategies that can be created using these reference points.

This indicator is available on almost all trading and charting platforms.

How the Bollinger Band can be Used in a Trading Strategy

Like with any other indicator, there are several ways that Bollinger Bands can be used to create a trading strategy.

I’ll give you one way that it can be used, but after you read this tutorial, you’ll have the knowledge to invent your own strategies.

Start testing your own ideas because you never know…you might just come up with a new profitable way to trade with the Bollinger Band.

One of the most common ways that the Bollinger Band is used to take a trade is to buy when price touches the lower band, and sell when price touches the upper band.

Now there several different ways to handle the exit. But one way to exit is to target the central moving average.

Here’s what that looks like on a chart.

Bollinger Bands trading strategy

Now that you know the general idea of the strategy I’ll be showing you, let’s take a quick look at why you might want to create an automated strategy with this indicator.

Why Automated Trading Strategies Rock

At this point, you can probably see that there are many different settings and rules that can be used to create a trading strategy with Bollinger Bands.

If you had to test all of these ideas manually, it would take a looong ass time.

That’s where automation can speed up the process…dramatically.

Instead of taking days to test one idea, an automated backtest can give you a result in just a few minutes. 

Even if you don’t build a fully automated trading strategy, partial automation can help you quickly test different entry, exit and trade management ideas.

Now that you understand the beauty of automation, here’s how to setup your first automated Bollinger Band backtest.

The Strategy

The great thing about building a trading strategy around Bollinger Bands is that there are well-defined ways to enter and exit trades.

I’m going to be using NakedMarkets to backtest this strategy. It is the easiest and fastest way that I have found to backtest.

I like it better than Forex Tester.

To improve my odds of success, I think that it will be a good idea to enter a short trade when price closes above the upper band, or a long trade when price closes below the lower band.

Is that the best way to do it? I don’t know, but you’ll find out with me.

That’s why we backtest. 

So here’s my trading strategy: 

  1. Go short when price closes above the upper Band and close the trade when price closes below the center moving average.
  2. Go long when price closes below the lower Band and close the trade when price closes above the center moving average.

In theory, only trading a close above or below the outer bands should give me a better entry and more of a chance that price will reject that level.

But I could be wrong about that so that’s why I need to test the idea.

Start with my example, then test your own ideas.

Step 1: Create the Core Rules

Since there will be different rules for longs and shorts, I’ll have to create 2 different sets of rules.

The first thing I’m going to do is open Rule Manager in NakedMarkets.

NakedMarkets Rule Manager

Then I’m going to create a new Rule by clicking the New Rule button in the lower left corner of the screen. This also where the Save Rule button is, you’ll need that later.

New Rule button in NakedMarkets

Now I’m prompted to create a new Rule. In this case, I’m going to create a Core Rule.

NakedMarkets Core Rule

Whenever you create a new Rule, you should always name it in this format: 

[Trading System Name] [Rule Type] [Long or Short]

  • Listing the trading system name first will group all of the Rules for the same system together.
  • Since you cannot have Rules with the same name, including the Rule type will prevent that from happening.
  • Finally, you want to have long/short at the end so it’s easy to change after you clone a Rule. More on that in a minute.

So for this backtest, I’m going to name my first Core Rule: BB Stretch Core Long.

This Rule will look for the case where price closes below the lower Band.

Here’s what this Core Rule looks like.

Create Core Rule in NakedMarkets
Click to see bigger image in new tab

In this Core Rule, I’m looking for price to close below the lower Bollinger Band and I only want to take one trade at a time. This will prevent overloading on trades when there are multiple signals in a row. 

To set up the above, do the following:

  1. Click the Add Criteria (+) button twice to add 2 more criteria. You should now have 4 primary boxes and 3 operator boxes. Click the Remove Criteria (-) button to remove criteria.
  2. In the first box, click and drag Price Value > Close into the box.
  3. Next, drag Operators > Less Than into the box.
  4. Then drag Indicators > Bollinger Bands into the 3rd box. Keep all of the default settings, but select Down Band under Selected Value.
  5. Drag Operators > And into the 4th box.
  6. Almost done…then drag Account Information > Open Trades Count into box number 5.
  7. Drag Operators > Equal into the 6th box.
  8. Drag Price Value > Input into the last box. Set the number to zero.
  9. Finally, click the Save button in the lower left corner of the window.

Next, duplicate the Rule to create the short Rule. Right-click on the Rule and select Clone Rule.

This makes it really easy to create a Rule for the opposite side of the trade.

Clone NakedMarkets Rules

Then right-click the new Rule and select Rename Rule.

Rename the rule to BB Stretch Core Short.

Double click on the new Rule to edit it.

Change the settings to the following:

  1. Change the first operator to Greater Than.
  2. Double click the Indicator Value and change the Down Band to Up Band under Selected Value.
  3. Click the Save button in the lower left corner of the window.

Here’s what it will look like.

NakedMarkets Core Rule

That’s it.

Now you have 2 Rules that will check for the entry criteria.

Let’s move on to the Exit Rules.

Step 2: Define Exit Rules

Next, you have to define how the strategy will exit trades.

In this example, I’m going to close a trade when it closes on the opposite side of the central moving average.

My initial reasoning for doing this is that I feel that price is very likely to cross the moving average easily and thus close at a quick profit.

Exiting the trade on a close would also theoretically provide more profit compared to exiting the trade on a touch of the moving average.

Again, you can easily change this exit to test out different ideas that you have. 

So follow the instructions above to create a new Rule, but this time create an Exit Rule.

Here’s what the Rule looks like.

Name it: BB Stretch Exit Long. 

Exit Rule in NakedMarkets

To create this Rule do the following:

  1. Add a criteria in the Exit Condition section by clicking the Add Criteria (+) button in the upper right corner of the screen.
  2. In the first box, click and drag Price Value > Close into the box.
  3. Next, drag Operators > Greater Than into the second box.
  4. Then drag Indicators > Bollinger Bands into the 3rd box. Keep all of the default settings, but select MA under Selected Value. Make sure that the rest of your Bollinger Band settings are the same across all your Rules.
  5. Under Actions, drop Actions > Close Order in the box.

Then clone the Rule and rename it to: BB Stretch Exit Short.

The only thing you have to change in the cloned Rule is Greater Than to Less Than.

NakedMarkets Short Rule

Step 3: Create the Entry Rules

Alright, now you’re going to create an Entry Rule that will utilize the Exit Rule you just created.

Make a new Entry Rule and name it: BB Stretch Entry Long. 

Long Rule in NakedMarkets

Here’s how you set this up:

  1. In the top box, double click the box and change the order type to Instant Buy.
  2. In the left box, drag and drop Price Value > Last Swing Low into the box.
  3. Change the Lot Size to 1 static lot. You can also choose to use a percent risk lot sizing.
  4. Drag and drop the BB Stretch Exit Long Rule into the Exit Rule box.
  5. Click the Save button.

Then clone and rename this Rule to create the short.

Short Rule

Just change the following:

  1. Order type Sell.
  2. Stop loss to Price Value > Last Swing High.
  3. Exit Rule to BB Stretch Exit Short.
  4. Click the Save button and you’re done!

Step 4: Create the Setup Rules

Now I’m going tie all of the Rules together by putting them into a Setup Rule.

This is the Rule that I’m going to add to the chart. It will check the chart on every candle and see if the criteria for the Entry and Exit Rules are met and execute trades accordingly.

Create a new Setup Rule and name it: BB Stretch Setup Long.

Then add the following:

  1. BB Stretch Core Long Rule in the top box.
  2. BB Stretch Entry Long Rule in the bottom box.

Setup Rule Long

Click Save on this Rule.

Then clone and rename the Rule and add the appropriate short Rules.

Bollinger Band setup short

Step 5: Test Your Rule

Now you’re ready to see this all in action!

Open a new backtest and drag and drop both the Long and Short Setup Rules onto the chart.

After you’re done, you’ll see the attached Rules are in the upper left corner of the chart.

Active Rules on chart

The click Play on your chart and the backtest will move forward and execute trades.

Check Your Stats

At the end of a backtest, save the backtest by going to File > Save Backtest.

Then go to Statistics > Stat Center in the menu.

In Stat Center, go to: Source > Import From Backtest.

Import backtest

Open the backtest file you just saved and you’ll be able to see a complete analysis of your backtesting session.

Backtesting results

The results of this test on the Weekly chart was decent, but it has to be tested on more markets and timeframes.

Even if you get a negative result, don’t quit just yet. The strategy might work much better in another market or timeframe.

Also try new indicator settings, exits and entries to optimize the trading strategy.

Speed Up Testing by Using Fast Backtest

Once your Rules are working as you expected, you can hit the “turbo boost button” by using Fast Backtest.

This is a fully automated process that runs without a chart display.

Go to Tools > Fast Backtest in the menu.

Fast backtest

On the first screen, check the markets that you want to backtest and hit the Next button.

If you haven’t downloaded historical data for all the markets, be sure to exit Fast Backtest and download the data in Tools > Data Center.

Fast Backtest screen 1

Select the timeframe(s) that you want to test and click the Next button.

If you want do a very quick test for the first time, select the Weekly (W1) timeframe.

Backtest timeframes

Then select the 2 Setup Rules you created for this tutorial and click Next.

The final screen will show you which markets, timeframes and Setup Rules will be tested.

Click the Launch button to start the backtest.

Once the backtest finishes, you’ll see the basic stats on this screen.

To see detailed statistics on your backtest, click the [Load Stat] link.

Load Fast Backtest stats

Fast Backtest will allow you to backtest multiple markets and timeframes at the same time.

Setup the backtest then go get some dinner.

When you get back, it should be finished.


There can be times when you make a mistake when setting up your Rules, especially when you clone Rules.

I’ve done it many times and it’s nothing to worry about.

The easiest way to troubleshoot your Rules is to test them individually.

You can do this by creating a new Setup Rule. 

Then drag and drop the Rule you want to test into the criteria box. It doesn’t have to be a Core Rule, it can be an Exit Rule or Setup Rule also.

Set the Action to Actions > Pause Backtest.

Test rule

Save the Rule, then drag it onto your chart before your backtest.

Hit the Play button and the chart will pause every time the criteria is met on your chart.

This will allow you to see what each individual Rule is doing and diagnose errors.

Once you see what the issue is, go back into Rule Manager and change the settings.


Now you know how to create a fully automated Bollinger Bands trading strategy that you can use to test different ideas and settings.

It does take a bit of time to setup the Rules.

But once you have them setup, you can test different ideas very quickly, so it’s well worth the time to create them.

I’m sure you’ll agree this is much faster than learning a programming language.

This is a tool that I wish was available when I first started back in 2007. 

If you want to get a discount on NakedMarkets, go here.


Leave a Reply

Your email address will not be published. Required fields are marked *