# Superalgos // Hello World Strategy - A simple SMA50/200 Cross based strategy

By 9808us | Superalgos | 17 Feb 2021

### Superalgos Hello World Strategy

Let’s build the mother of all trading strategies The Moving Average Cross

I can’t wait any longer! Show me how to create a trading bot with Moving Average Cross between MA50 and MA200 on 4H Time Frame because I know this is all I need, make it work for me 24/7 and get rich!

Attention! This tutorial is based on Superalgos Beta 8! If you are running Beta 9 then you have to do some refactoring:
https://github.com/Superalgos/Superalgos/tree/develop#migrating-from-superalgos-beta-8

PopularSMA indicator in action

Ok it’s not true, there is some to read. Do you have coffee?

This tutorial is divided in to two parts:
PART 1 -> For who has no time and just want a quick and ready to use bot without any explanations
PART 2 -> We dig a bit on how to implement a SMA Cross with some explanations and hints (Still in progress...!)

### PART 1

TL:TR // Disclaimer: While the devs have done a fantastic job in making SA easy and fun to use, keep in mind that it’s not a toy but a powerful tool. I know that reading and studying is boring but keep in mind that here we are talking about money, make your own considerations.

https://github.com/9808us/Superalgos-Strategies

!!!!!!!!!!!!!!!! ATTENTION WARNING DANGER 😂 !!!!!!!!!!!!!!!!
This tutorial you are reading is based on Beta8 BUT
so you can safely use the latest SA version

Some users like to start from the end and asked me to make a quick handy scheme about a complete trading system with minimal fuss. So for our Hello World tutorial here you a screenshot with all the minimal formulas and conditions to use to start with your first bot. So take it, simple and quick with the bare minimal set up.

STEP 1 // Set up the Trigger Stage

If current is > and the previous is < then we defined a cross

STEP 2 // Set up the Open Stage

Strategy is Long so we use the quoted asset to buy the Base asset

STEP 3 // Set up the Manage Stage

Simple SL 3% below entry price + TP 3% above entry price

STEP 4 // Set up the Close Stage

CONDITIONS & FORMULAS USED

chart.at04hs.popularSMA.sma50 > chart.at04hs.popularSMA.sma200

chart.at04hs.popularSMA.previuos.sma50 < chart.at04hs.popularSMA.previous.sma200
(It’s a single line, no interruption!)

chart.at04hs.candle.close

N.B. Don’t forget to reference your Execution Algorithm

### ​PART 2

If you want to better understand what happens under the hood then take some time with me as I’ll go step by step in creating a strategy and making some considerations about it.

Let’s say it, Superalgos is a fantastic project
Then you hate it

When you start Superalgos for the first time, you are fascinated and stare at the monitor looking at how candles are build in the chart for the first time. I really love this moment! You click Run on the Data Task node, move to the chart space and see the magic, candles start to appear in the screen!
Your mind runs imagining what you could create with all this power available! But then you stop because you don’t understand anything. In your mind there is only one thought “I want to create my own bot!” but although it is really a breeze [I’ll show you how to do it step by step] initially we remain a little thoughtful in front of all the information and complexity we see in.

For this tutorial I assume:

• You have the latest available Superalgos version
• You are in the Getting Started Workspace
• You did the Intro Tutorial to know at least the very basic concepts

Let’s do it quick and simple and prepare the environment for our Hello World Strategy. We need two steps:

#### 1) Add Sparta Data Mine to the workspace

If you are in the Getting Started workspace, probably there is only the Master Data Mine installed, but PopularSMA indicators are under Sparta Data Mines. To add that to our workspace, locate the data mine in this subfolder:

~\Superalgos\Projects\Superalgos\Plugins\Data-Mines

Simply drag the Sparta Data Mine to Superalgos Workspace and drop it where you prefer. Later you can arrange your workspace as you prefer.

Note: The names of the Data Mines are irrelevant, think at them like folders you can name as you prefer. It’s the creator of the Data Mine that chose the name, but I admit they are amazing!

Ehy wait a minute! I can hear you asking:
“..but sir .. where or how can I find these indicators? Can I have a list please?” “Yes! Of Course!”
Here you: https://docs.superalgos.org/community-contributions.html

Superalgos Community Contributions

Here you can find useful infos about what indicators are available in Superalgos and in which Data Mines you can find them with a brief explanation and examples.

Simply expand Superalgos Project node and under Other Hierarchies you will find the option to add a Trading System. Click on it and a new empty Trading System will appear on the workspace. Name it as you prefer to easily locate it.

Superalgos Other Hierarchies // Add Trading System — Please note this is Beta8 and could be in different location in other versions

And now to speed up things let’s do a little trick! Now that you have Sparta Data Mine added to the workspace and a new Trading System, we need to make them to work. Now, if you want a super detailed in-depht view of the various references that make up the magic under the hood of Superalgos, then you can read this tuorial Superalgos // Supertrend Strategy where I explain how to install an indicator manually.

But here we use the lazy way and simply do this:

• Unistall the Market
• Install the Market

Click Uninstall Market — Wait — Click Install Market — Could have been more simple?

Don’t worry, all your data is safu! You are not going to delete anything, so don’t worry and do it! Superalgos will take care of connecting all the dots for you and in few seconds you are ready to mine some data to feed the Sparta Data Mine so it can build the PopularSMA indicator.

Zeus, Sparta and Master Data Mines at work

Ok, before moving on, let’s make a quick recap:

• Superalgos is up to date
• We are using the standard Getting Started workspace
(Market Binance BTC/USDT)
• We added a new Data Mine
(and now you know how and where to find them and put them at work)
• Indicators are up to date -> You run the data mine!
• Make sure that the Trading System Reference under your Backtesting Session has a reference to the trading system you have just added (See screenshot below)
Tip: To make a reference, drag the node (click and hold left mouse button while dragging) near the Trading System and click right mouse button
• Make sure that the Trading Engine Reference under your Backtesting Session has a reference to the Low Frequency Trading Engine

Trading Engine Reference -> Make a reference to the Low Frequency Trading Engine

How to make a reference to a node

Let’s now move to the Trading System node, expand it and have look around. You should see something like this screenshot below:

Standard Trading System with its offspring nodes

To start and don’t overcomplicate things, let’s delete all the nodes we don’t need, so it’s easy to understand what we are doing. Don’t worry, we will add the deleted nodes later.

In Superalgos strategies are splitted in 4 distinct stages, you will agree that in this way we can keep things easy and mostly consistent, shaping and accustomizing our mind to work with trading systems.
Here https://docs.superalgos.org/suite-trading-systems.html you can read a lot about what is a trading system, take some time and read it as here we deal with money and even if I tend to keep things funny, loosing money because we don’t understand what we are doing is not funny at all!

What we should see now if you have deleted the unuseful nodes (for the moment!) is something like the screenshot below:

Let’s take few minutes to think here at what we are going to do.
Are you thinking?

Trigger Stage is the first stage that our trading system has to deal with.
Here we are telling the bot WHY it should open(Take) a position.

Yes it’s only in this 3 offsprings that all our trading strategy comes alive!

Let’s recap our Hello World strategy:

• Strategy is based on Moving Averages Cross
-> We need the popularSMA indicator that is under Sparta Data Mine
• We look at MA50 and MA200 cross
• Time Frame is 4H
• If MA50 > MA 200 let’s take position

What we are going to do now it’s a little trick, yes I love tricks!
I’m a lazy person and tend to find shortcuts everywhere

Look at this screenshot and follow what it suggests:

A little trick here. We demand all the hard work to a single node, the Trigger On Event

Why in the hell I’m doing this you probably are wondering!
Simple answer: To keep things easy so if there are any problems it will be pretty fast to locate the troubles and solve them.

A brief explanation: You should know that Conditions are Boolean that means that they can just have two possibles values: Yes or No that is True or False in developer language. So if we force the aswer what we do is skipping a step. We demand all the calcs to a single node that is the Trigger On Event and in case it evaluates True then the ball is given to the next node, the Open Stage.

We set (we write) “false” on the Trigger Off Event because at the moment we don’t have any reason to unlock our funds, we have only one strategy. And we want to keep things easy so if conditions are met then take position, isn’t it?
And that’s why we set (we write) “true” in the Take Position Event, so as soon as the Trigger Node Event validates “true” then we don’t think any more and take the position.

So now let’s translate the strategy into a language that is understandable by a bot … stupid bots 😂

We need to translate this:
“Look at the 4H TF chart and if the 50 periods simple moving average cross up the 200 periods simple moving averages then take a position”

In Javascript language (yes, if you didn’t notice Superlgos is made with love and JS) all we have to write is:

chart.at04hs.popularSMA.sma50 > chart.at04hs.popularSMA.sma200

That’s it! With a single line of code we are telling the bot that we want to take position every time MA50 is above MA200.

Make sure that your Trading Parameters make sense, for this tutorial I set:

• Time Range
{
“initialDatetime”: “2020–01–01”,
“finalDatetime”: “2020–12–31”
}
• Time Frame
{
“label”: “04-hs”
}

You don’t need to set anything else for the moment, you will have time later to explore the options you can set here.

How to start a backtest in Superalgos

When backtest finishes you can stop it and move to the charting space.
You should see something like this screenshot below, if not refresh F5 the browser.

All Candles Processed sounds good!

You probably would not believe it but our strategy is complete!

“What?” I can hear you say “What are you saying that strategy is complete? How could it be? It just open trades but then what?”
The answer lies in the way Superalgos deals with strategies and the fact that a complete trading system is divided in to 4 distinct stages!

What we have done here is exactly what we have written at the beginning of this tutorial, let's take position on 4H TF SMA50/200 cross.
What bot should do next is still undefined, we didn't say anything about what to once the strategy takes position. These are next steps that will be covered in another tutorial.

Now close everything, put on a pair of comfortable shoes and go out for a walk and think!

Next tutorial will dig a bit more on Trigger Stage node and the offsprings we arbitrarily set to “false” and “true” and with the next logical stage, the Open Stage! (*but has not yet been written 2021/02/01)

Disclaimer: trading is not a game. Losing money is quick and easy. I’m not giving any financial advice here. If you find any error or you think something is not right, just write me on telegram @us9808 or comment here.
##### Superalgos is the most advanced crypto trading botyou can find and it is totally free on Github

9808us

I enjoy helping people and sharing stuff I know. I'm a seeker but my dreams aren't like yours

Superalgos

FREE AND OPEN-SOURCE CRYPTO TRADING BOTS PLATFORM Sparse thoughts & tutorials Full credits to Github repository -> https://github.com/Superalgos/Superalgos

Send a \$0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.