How to Create a No-Code, Automated 50-200 MA Crossover Strategy

6 months ago 11
Moving average crossover trading strategy

The 50-200 Moving Average Crossover is an easy concept to build a trading strategy around because the inputs are simple and the potential optimizations are straightforward.

So it's perfect if you're just getting started with trading strategy development.

Many trading websites will give you what they say is the “best” 50-200 crossover strategy.

Interestingly, most of them don't give you any data to back up that claim.

I'm going to give you information that's much more useful.

In this tutorial, I'm going to show you how to backtest any Moving Average Crossover trading strategy on the internet to find out for yourself, if it really works or not.

Using this method will also allow you to test your own optimizations to see if you can improve on the strategy.

The best part is that you can use this method to backtest strategies very quickly because the backtests will be 100% automated.

You don't need to know how to write code to do this, it's all drag and drop.

I'll also show you some of my own backtesting results so you know good places to start with building your own strategy, and what to avoid.

Alright, let's get into it…

What is the 50-200 Moving Average Crossover Strategy?

This trading strategy is also known as a Golden Cross and Death Cross.

That's way too much drama for me, so I'm just going to call it the 50-200 Moving Average Crossover trading strategy.

As the name suggests, this strategy uses the 50 and 200 Simple Moving Averages (SMA).

Here's what that looks like on a chart.

Moving Average crossover on chart

The 50 SMA is considered the “fast” SMA because it reacts faster to price changes.

So naturally, the 200 SMA is the “slow” moving average because it takes awhile to react to price.

Basically, traders who use this method buy when the 50 crosses above the 200 and sell when the 50 crosses below the 200.

Sounds pretty easy right?

Well, not quite.

There are a few more things that have to be defined to make this a complete trading plan.

First, I'll create the trading plan, then I'll show you how to do an automated backtest of the plan, without writing a single line of code.

The 50-200 Crossover Strategy Trading Plan

Here are the rules for this plan:

Buy Buy on the close of the candle when the 50 SMA crosses above the 200 SMA Stop Loss at last swing low Risk 1% per trade Take profit at 1R (1 times risk) Sell Sell on the close of the candle when the 50 SMA crosses below the 200 SMA Stop Loss at last swing high Risk 1% per trade Take profit at 1R (1 times risk)

Remember that this is just a starting point.

Any of these settings can be changed and retested. 

So do a couple of tests with these settings, then feel free to experiment with your own settings.

Get creative.

You never know, you might just develop a super profitable moving average crossover trading strategy.

How to Build the Automated Strategy

Now let's get to work.

For this backtest, I'm going to use NakedMarkets.

It's the easiest way to build automated trading strategies with no-code.

Once you complete these initial setups, you'll be able to test all of your 50-200 moving average crossover trading strategy ideas easily.

Create the Core Rules

The first step is to create the Core Rules.

This is what will tell NakedMarkets how to identify the initial setup conditions for a trade.

You have to create one Rule for long trades and one for short trades.

This will also be true for most of the other types of Rules.

Here's how to setup your first Core Rule:

Open NakedMarkets and go to: Rules > Rule Manager Click the New Rule button in the lower left corner of the window Name the Rule in this format: [strategy name] Core [long or short] Select Core as the Rule type Click OK

Now it's time to add conditions to your new Rule.

Long Trade 

Let's setup a long trade.

To add a criteria, click the (+) symbol in the upper right corner of the screen.

From there, drag the conditions you want to use from the list on the right.

Add condition to NakedMarkets

These are the settings for each of the boxes, from left to right:

Moving average: Period (50), MA Type (SMA) Greater than Moving average: Period (200), MA Type (SMA) And Moving average: Period (50), MA Type (SMA), Previous Bar (1) Less than Moving average: Period (200), MA Type (SMA), Previous Bar (1)

The reason that I'm putting 2 moving average comparisons in there is because I want to evaluate the position of the 50 SMA relative to the 200 SMA for the current candle and the previous candle.

I want to see the previous candle have the 50 below the 200 and the current candle have the 50 above the 200.

This will give me every situation where the 50 has just crossed above the 200.

If I don't do this, I will get a signal every time the 50 closes above the 200 and that would not work.

This is what your screen should look like after you're done.

Long Core Rule

Click on the Save Rule button in the lower left corner to save your Rule.

Now I'm going to do the same thing for the short side.

Short Trade 

Here's how to setup the Core Rule for a short trade.

The easiest way to create a new Rule is to clone the long trade and just change the settings that apply to a short trade.

To clone a Rule, right-click on the long Rule in the list on the right side of the screen and select Clone Rule.

Clone NakedMarkets Rules

Then right-click the cloned Rule and rename it.

Change “long” to “short” in the name.

So in this example, the new name of your short trade will be: “MA Cross Core Short”.

Now it's time to change the settings of this Rule to look for short trades.

This is what the short Rule looks like:

Short Core Rule

Here are the settings for each of the boxes, from left to right:

Moving average: Period (50), MA Type (SMA) Less than Moving average: Period (200), MA Type (SMA) And Moving average: Period (50), MA Type (SMA), Previous Bar (1) Greater than Moving average: Period (200), MA Type (SMA), Previous Bar (1)

Click on Save Rule in the lower left corner to save your Rule.

Great work, you just completed the hardest part of this tutorial!

There are 2 more steps that you have to complete before you can start testing this strategy, so let's keep going.

Create the Entry Rules

Now that you have the Core Rules that will identify the basic criteria of the entry, it's time to create the Entry Rule that will determine the details of each entry, such as the entry type, stop loss, risk per trade and stop loss.

To do this, go back into the Rule Manager and click the New Rule button in the lower left corner of the screen.

Again, we will start with the long Rule, then clone it to make the short Rule.

Long Rule

Name your long Rule: “MA Cross Entry Long”.

Here's what your long Entry Rule will look like:

Entry trade long

For the order type and lot size, double click on the box to change the settings.

With the other boxes, drag the appropriate Default Rule from the upper box on the right side into the stop loss and take profit boxes.

Here's how to set that up:

Instant Order: Buy Stop Loss: Last swing low Take Profit: 1R Lot Size: 1%

Click on the Save Rule button in the lower left corner to save your Rule.

Short Rule 

MA cross short entry

Now clone the long Rule and use these settings to create the short Rule:

Instant Order: Sell Stop Loss: Last swing high Take Profit: 1R Lot Size: 1%

Click on the Save Rule button in the lower left corner to save your short Rule.

Create the Setup Rules

Alright, these are the final Rules!

Don't worry, this step is super easy.

A Setup Rule basically ties everything together and monitors your chart to see if the Core Rule criteria is present.

If it is, then it executes the Entry Rule.

Long Trade 

Go back into the Rule Manager and click the New Rule button in the lower left corner of the screen.

Create a new Setup Rule, then name it: “MA Crossover Setup Long”.

Setup Rule long

First, drag the Core Rule you created from the User Rules section into the top Setup Condition box.

Under Actions, drag the Entry Rule you created into the Actions box.

Now clone this long Rule and rename it to create the short Rule.

Short Trade

Setup Rule short

Replace the Setup Condition and Action with the short trade versions of your Rules.

That's it for Setup Rules!

Run the Backtest in Visual Mode

That was pretty easy right?

Now here's the fun part, you're going to actually backtest this strategy.

You should do this step first, before using Fast Backtest because it will allow you to see any errors that you made when creating your Rules. 

Close the Rule Manager and go back to the main NakedMarkets screen.

Start a backtest by going to File > New Backtest.

New backtest

Name your backtest, then select your starting balance.

Click on Next.

Backtest 1

Select the market(s) you want to include in the test, then click on Next.

On the next screen, you can select the timezone you want to use.

I usually use the default settings, so if you aren't sure about your timezone, just use the default settings.

Click on Next.

Select timezone

Now click and drag both the long and short Setup Rules that you created onto the chart.

You'll see these Rules that you're currently using in the upper left corner of the screen.

Add setup to chart

Select the right timeframe that you want to backtest on.

The timeframe shown above is the daily chart.

Then click on the Play button in the toolbar to start the backtest.

Play button in NakedMarkets

If you setup your Rules correctly, you'll see the trades automatically execute on your chart.

Watch the trades carefully to be sure that they are executing correctly.

Now if your trades are not executing correctly, see the section below on troubleshooting.

However, if they are working, then congratulations, you have just build your own automated 50-200 Moving Average Crossover trading strategy!

Once the backtest is completed, you can see the detailed stats by doing the following:

Save the backtest by going to: File > Save Backtest Go to: Statistics > Statistics Center In Stat Center, go to: Source > Import from backtest Select the backtesting file you just saved

This will show you the stats on your backtest.

A word of caution here…

You probably won't have a super profitable strategy on the first try.

However, remember that this is a process and your results could be significantly better if you use different settings or run it on a different timeframe or market. 

You might get better results on the EURUSD 4-hour chart, or the SP&500 1-hour chart.

The return might be better if you use a different stop loss or change the moving average settings.

Again, don't get discouraged if your first test doesn't work out.

Remember that this will require some work and very rarely will even professional traders gets an awesome result on the first try. 

Therefore, be willing to experiment and treat this process like an inventor would.

Many times, inventors have to try many different prototypes before they get something that works well.

It's been said that Edison tried 10,000 ideas before he invented the light bulb.

Hopefully you won't have to try that many strategies before you find a good one, but you have to be willing to potentially stick it out for that long.

Regardless of the return on your first test, once your strategy is working in Visual Mode, now it's time to shift your backtesting into high gear.

Hit “Turbo Boost” and Run a Fast Backtest

Now that you're confident that everything is working correctly with your moving average crossover strategy, it's time to take your backtesting to the next level.

In this step, you're going to unleash “turbo mode” and use the Fast Backtest feature in NakedMarkets.

This will allow you to backtest multiple markets and timeframes, without having to setup each backtest individually.

To do this, go to: Tools > Fast Backtest

Then select the market(s) you want to backtest.

You can test as many as you want.

Click on Next.

Fast backtest step 1

Next, choose the timeframe(s) you want to backtest.

Again, you can select multiple timeframes.

Click on Next.

Fast backtest 2

Now select the Setup Rules that you want to backtest.

Select the moving average crossover Rules that you created above, under Setup Rules.

Click on Next.

Fast backtest step 3

Then you'll see the list of Fast Backtests that will be run.

Click on Launch to start the backtest(s).

Fast backtest 4

Once a backtest is finished, you'll see the basic statistics in this window.

There is also a link to the detailed stats in the [Load stat] link.

Load stats link

Click on the link to open Statistics Center and you'll see the complete results of each backtest.

MA cross results

As you can see, this test on the daily chart didn't work well.

But at the same time, it wasn't completely terrible either.

At least it was profitable for a period of time.

Losing 4.25% from 2006 to 2024 is also essentially breakeven.

So this strategy could be improved by using different settings in the strategy.

Again, this is a process and don't get discouraged by poor results on your first tries. 

Troubleshooting Your Rules

Even with a simple trading strategy like this, it's possible to make mistakes in the Rule creation process.

This is especially true when cloning Rules.

I actually made couple of mistakes when creating this tutorial.

So if your strategy isn't working as you expected, don't worry.

Just go back through the steps above and double check your Rules.

The most common mistakes are:

Not changing the greater-than or less-than criteria. Having the wrong trade direction (buy or sell) Using the wrong settings for an indicator

If you cannot see the error by just looking at the Rules, then there are 2 more things you can to do troubleshoot your strategy.

First, in your Setup Rules, change the Action to Pause Backtest, instead of using the Entry Rule as the Action.

This will take the Entry Rule out of the equation and allow you to only focus on the Core Rule.

Right-click on your chart and select: Detach all Rules.

Then drag your new Setup Rules onto your chart and run the backtest again in Visual Mode.

Every time the trade sets up, the chart will stop.

This will allow you to double check the logic of the Rule.

If your Core Rule is working correctly, then the mistake should be in your Entry Rule.

To test this, simply use the Entry Rule by itself by dragging the Rule from the list on the left of the screen onto the chart.

Add Entry Rule to chart

You can do this at any time, you don't necessarily have to wait for your entry criteria to be met.

This will open a trade and allow you to see if your Entry Rule is working as expected.

These methods will allow you to debug your trading strategy.

Stay calm and go through your Rules step-by-step.

If you cannot find the problem, head over to the NakedMarkets Forum and ask for help.

Potential Improvements

If you didn't get the results you were looking for in your backtests, here are a few ideas on how you can potentially improve your results:

Change the period of the moving averages Use different types of moving averages, like an exponential moving average Test different timeframes Adjust the settings on the last swing high/low indicator Test different markets Use a different stop loss level Use a different take profit level Trail your stop loss Risk more per trade Risk less per trade Add another indicator to create a second entry criteria Use a strategy across multiple timeframes or markets at the same time to potentially increase profits and diversify risk

But don't stop there, what else can YOU think of?

Backtesting Results

All of this is great in theory, but how well does this strategy actually work?

That's what you're going to find out in the following links.

I'm going to backtest different ideas around this trading strategy, starting with the method described above.

The version above will be version 1 and I'll create a new version every time I make a change to the original strategy.

Rules for new versions will be available via the links below.

As I do new backtests I'll add them to the appropriate pages.

You'll see all of the stats for each backtest.

Even if a backtest doesn't do incredibly well, it can give you a starting point for creating a strategy of your own.

These tests also show you what to avoid and will save you time in the testing process.

Here are the versions that I've currently tested:

Version 1 (listed above)

Conclusion

So that's an easy way to do a fully automated backtest of the 50-200 Moving Average Crossover strategy.

This is a great method to build a trading strategy around because it's so simple and provides many opportunties for optimization.

But remember that you must backtest every trading strategy yourself.

You cannot rely on my results or the results of anyone else.

To develop real confidence in a strategy, you must see hundreds or even thousands of trades, and test many different ideas.

Luckily, NakedMarkets speeds up this process dramatically.

I've given you the template…now get to work.

You can get a discount and some fantastic bonuses for NakedMarkets here.

If I missed something in this tutorial, let me know here.

 

The post How to Create a No-Code, Automated 50-200 MA Crossover Strategy appeared first on Trading Heroes.

Read Entire Article