Superalgos Protocol V0.1 — the Long Version, for Beginner Traders.

Julian Molina
Oct 14 · 20 min read

A scalable framework for developing and automating your trading system.

Image © WHYFRAME, shutterstock.com

Superalgos is an open source project with the vision of developing a Collective Trading Intelligence at the service of all people.

That is our long-term vision.

Our current focus is to build and freely distribute state-of-the-art tools to create and automate trading strategies, as this is the first step in the direction of creating such intelligence.

After almost two years iterating on ideas, infrastructure and a number of web-based tools, the Superalgos Protocol emerged.

In conceptual terms, the Superalgos Protocol determines the structure in which all the information regarding a trading system is stored and — at the same time — provides a clear guidance on how traders using the various tools developed and distributed by the Superalgos Project shall create and automate their strategies.

In practical terms, the Superalgos Protocol is a file with a specific format capable of holding all the information concerning any number and variety of trading strategies. In its current early version, the protocol is simply the description of a JSON object which defines the desired automation.

The protocol allows us to standardize the way in which we describe strategies, so that the tools we develop to create or modify, visualize, backtest and deploy strategies can handle all types of strategies in a standard fashion. It also allows strategies — and even pieces of strategies — to be portable, along with many other features that will become possible in the future.

For a technical description of the Superalgos Protocol oriented to developers, please refer to the Superalgos Improvement Proposal that introduced the concept in the first place.

This article is not technical in nature and it’s mostly oriented at traders willing to dive into the Superalgos universe and start using the freely-available tools the project offers to automate your trading.

In this piece I will lay out a logical framework for developing your trading system. It is this framework that the protocol feeds from.

I will start with the basics and will dissect the logic behind trading strategies, discuss how to build them, and propose how to use them.

That said, the process and structure proposed by this framework will be further optimized by producing additional analysis on top of the basic version I will lay out here, incorporating more advanced trading concepts and tactics as we advance in our quest of building a Collective Trading Intelligence.

As the framework evolves, so will the protocol, incorporating the processes distilled in the framework. This will enable the various Superalgos tools to adopt the new standards, providing more and better features to develop more complex, robust and advanced trading systems.


The Basics

In terms of structure, you can think of a trading system as a hierarchical arrangement organizing the actionable aspects of your investment plan.

The structure would be quite large and complex if you were an Investment Bank, but can be rather simple for traders just starting out.

Simplified framework diagram

Capital

The first order of things is determining how much money you will be working with. This is your capital, and a crucial aspect to keep in mind is that there is a finite amount of capital.

You will need to manage this capital.

You will need to preserve it.

And you will aim to increase it.

Market

The market refers to the pair of assets you wish to trade with, for instance, BTC-USD, ETH-BTC, etc.

There are many reasons why you may prefer a market over others. Liquidity, volatility, likability of the underlying project… you name it.

Choosing a market is a strategic decision that you need to make, and — of course — you are free to choose more than one.

Base Asset

The third order of things is deciding what your base asset is. That is, what asset you wish to stand on when you are out of the trade, with no open positions.

For instance, let’s assume you see the outcome of your trading as your retirement bonus. You are also a crypto-believer and are long-term bullish on bitcoin. Chances are you may want to accumulate bitcoin. That is, your base asset is bitcoin.

Needless to say, you may have a valid argument for picking any other or any number of base assets.

Your Investment Plan

As you may have noticed, these three elements — capital, market and base asset — are an integral part of your investment plan.

Your plan may have any number of goals (e.g. accumulating bitcoin, diversifying on a basket of coins, annual profit targets, etc), and you may need to develop individual plans to achieve each of those goals.

This leads us to the concept of strategies.

Strategies

The framework defines a strategy as a set of actions occurring in stages, designed to achieve a specific goal within a broader plan, via executing trades.

Let’s start by dissecting this definition…

A “set of actions occurring in stages” refers to the structure of a strategy. The actions occur in stages because certain actions may be grouped, and each group of actions may be played in a specific sequence.

This concept is fundamental to the methodical aspect of the system, as it provides a framework to run every strategy with the exact same logic, which certainly contributes to developing a scalable system that may grow to any number of strategies.

Strategies are played in four stages

The second important bit in the definition of a strategy is “designed to achieve a specific goal within a broader plan”.

One specific goal.

If you attempt to achieve two different goals with a single strategy, you may run into problems. What if the two goals were antagonistic? You could argue solutions may still be found, but the strategy would certainly be more complex.

In any case, the logical thing to do is to analyze each goal separately so that you can design at least one clear, straightforward strategy for each goal.

Now, can you have more than one strategy to achieve a single goal?

Certainly! There are many roads to Rome!

In fact, the norm is to work with several strategies at the same time, as this usually leads to identifying more trading opportunities.

The set of rules and formulas comprising the strategy can be anything. They may be based on Technical Analysis, incorporate fundamentals or sentiment data or anything else you may think of.

Your strategies will be somehow related to the market that you chose to trade in, and they will have a number of characteristics which I will discuss as I move on with this analysis.

Finally, I will refer to the third section of the definition of strategy via executing trades”, which leads us to the concept of a trade.

A trade is the process that exchanges the base asset for a second asset and that — after some time — exchanges back the second asset for the base asset. The first and foremost rule of a trade is to preserve capital and its main goal is to increase it.

This means you will have rules that indicate when to sell your base asset and when to buy your base asset back.

Preserving capital is one of the key rules of becoming a successful trader, as you will probably have as many good trades as bad ones. The trick is that your good trades should end up accumulating more profits than the losses you accumulate with your bad trades.

In terms of its goal, a trade is engaged for the prospect of increasing the quantity of a given base asset.

In other words, you trade in the hope that — during the trade — the second asset will revalue against the base asset so that by the time the second asset is exchanged back for the base asset, the resulting quantity of base asset is bigger than the original.

For instance, let’s suppose your base asset is bitcoin: you may want to sell bitcoin when bitcoin price is falling in order to buy back a larger quantity at a lower price.

With all that in mind, let’s assume you have a number of strategies ready.

When do you start trading?

How do you know which strategy to use?


Stage 1: Trigger

Those two questions lead you straight into Stage 1 of your strategy and point to the first characteristic that needs to be present in it: the rules or conditions to trigger on the strategy.

The anatomy of the Trigger Stage

Triggering Strategies

I call this particular set of rules a situation, in the sense that you are trying to determine what is going on with the market and if the situation is right to use a certain strategy.

Put in other words, you define situations in which you wish to use a certain strategy and each situation is described as a set of conditions that need to be met in order for you to consider starting to use the said strategy.

When the conditions for any of the situations that would trigger a strategy are met, I call this a trigger on event, meaning the event activates the strategy.

Now, what does that actually mean?

I’m not yet discussing taking positions, so it doesn’t mean that you should buy or sell something.

A trigger on event signals an ideal time to activate the strategy and look for the opportunity of taking a position.

Now let’s assume it is the ideal time to trigger on your strategy, how do you next decide when to take a position or not?

To take a position, you will too define situations.

In this case, when the conditions that define a situation are met, this marks the take position event, that is, the moment to enter the trade.

Are you starting to see the pattern?

Your strategy is guided by predefined conditions that — when met — define situations that determine that a certain event will take place.

Now, what happens if the take position conditions are not met?

This leads us to understand that, just like you had a set of rules to determine when a situation seems appropriate, thus triggering on a specific strategy, you should also be able to analyze when the market has shifted out of those conditions — therefore cancelling the potential for taking a position — so that the strategy can eventually be triggered off.

Why is it important to trigger off a strategy?

It was established that while a strategy is on, you need to pay close attention to it and constantly evaluate the conditions for entering a trade. Triggering off the strategy allows freeing up those resources (your attention) and going back to doing something else.

Size Definition, Capital Request & Allocation

Before taking a position, it will be necessary to define the amount of base asset that you are going to risk in the trade — what I call the size of the position — which points back to one important concept I touched on before: capital.

It was established that — overall — you have a certain amount of capital to trade with and that you will need to manage. It was also established that you are most likely going to work with several strategies.

Do you see where I’m going with this?

This is when you start managing your capital.

Because you are working with several strategies, you need to decide how to allocate portions of that capital to each strategy. This is an integral part of the investment planning decisions that you will need to make, but it is out of the scope of this article.

Suffice to say that capital allocation is part of your overall capital management and diversification plan, and a subject worth of its own level in the framework which shall be developed as the Superalgos Project advances.

Notice how the Stage 1 diagram above makes a clear differentiation between Size Definition and Capital Request & Allocation.

This is because each of those concepts are completely independent of each other at a conceptual level, and because in larger organizations, different people may take responsibility over each of them or co-participate in the process.

Take Position

I explained situations with their set of conditions when discussing trigger on and trigger off events that activate and deactivate strategies.

The same concept of situations with conditions apply when you are looking to take a position.

When setting up your strategy, you will describe a number of situations, each defined by a set of rules or conditions that — when met — indicate that the moment is ripe for taking a position. I call this the take position event.

Taking a position refers to the act of entering a trade, that is, placing the orders at the exchange. These actions are actually taken in the next stage, during execution.

Quick Recap

Stage 1 is about monitoring the market and identifying when the conditions that define certain situations are met, triggering on one of your strategies.

You may see this as an early signal that tells you an opportunity may emerge soon.

The conditions that define the situation for actually taking a position may be seen as the final confirmation: the signal that determines that the time for entering a trade is as good as it gets.

I will give you a quick example…

Let’s say you are trading the BTC-USD market during the long crypto-winter. Your base asset is BTC, thus, you come up with a trend-following strategy based on the bollinger bands indicator.

Your goal is to accumulate bitcoin selling BTC as the price starts dropping and re-buying BTC at a lower price, when the price stabilizes.

One of the situations you wish to identify to trigger on the strategy is, for instance, when you detect what you may call an Incipient down-trend (or to be clear, a situation where a down-trend is developing).

How would you describe the Incipient down-trend situation with a specific set of conditions?

Well… you may come up with something like this:

Condition 1: The percentage bandwidth moving average of the bollinger bands is going down…

Condition 2: The percentage bandwidth is smaller than the previous for two consecutive periods (2 candles)…

Condition 3: The minimum candle value is less than the previous minimum for two consecutive periods…

The framework dictates that when those three conditions are met at any moment in time, the strategy is triggered on.

So you keep looking and waiting for the final confirmation to take a position that is also defined by a situation embodied by its own set of conditions. You will probably want to give the situation a significant name, such as Down-trend entry signal.

The new set of conditions may look like the following:

Condition 1: The percentage bandwidth is smaller than the previous for the third consecutive period (3 candles)…

Condition 2: The minimum candle value is less than the lower bollinger band for the last two periods (2 candles)…

That’s it! The conditions are met and you are finally ready to take the position.

So, what’s next?


Stage 2: Open

You have decided when is a good time to take a position. Good.

However, in order to complete the trade — that is, to buy back the base asset — you also need to define the rules to exit the position, or what I call the take profit and stop formulas.

The anatomy of the Open Stage

Initial Take Profit & Stop

As per the definition of a trade, the main rule is minimizing the amount of the potential loss and — if possible — the goal is completing the trade at a profit, that is, ending up with a higher amount of your base asset.

In that sense, the next step is defining two separate rule-sets for exiting the position: take profit and stop. These formulas will allow us to do just that: take the profit when the trade hits a target or stop and exit the position in case things are not going as expected.

These rule-sets are most likely expressed as mathematical formulas.

The simplest approach is fixing a constant value as a percentage of the price at the time of the take position event.

For instance, let’s say you bought at a price of 10 expecting the price to go up, and your profit target for the trade is a 20% win. Then your take profit would be at 10 + 20% = 12.

That would be a constant value for your take profit.

Then, let’s say you are willing to lose up to 2% of the capital in the trade if the market moves in the wrong direction; then your stop would be fixed at 10–2% = 9.8.

There certainly are many considerations as of how to set these two formulas, and a number of different variables like market volatility, your risk profile, quality of the signal, long-term targets and so on will be part of the criterion you will want to consider. However, such considerations are beyond the scope of this article.

That said, it is important to note that setting constant values for take profit and stop is certainly a simplistic approach, and that a lot more efficiency can be obtained with more dynamic formulas.

Such formulas may take into consideration the actual price movement, momentum and as many indicators as you may wish to factor in the analysis.

Execution

If Stage 1 was mostly about monitoring the market, Stage 2 is about execution: you have identified that the moment is right to take a position, now it’s time to actually go and do it.

Why would you want to think of this as a two-stage process?

Isn’t placing an order at the exchange a pretty straightforward operation anyway?

Well… it may or may not be.

For starters, there are further decisions to be made: are you placing a market order or a limit order?

Moreover, the complexity of the execution depends on several factors, the most relevant being the size of the trade and the liquidity of the market.

Imagine placing a limit order to buy 1,000 BTC in a second-tier exchange…

The order would probably take some time to fill, get partially filled or not get filled at all, right?

Also, placing such a big order in the book may have an effect in the market and substantially affect the price, which is clearly undesirable.

Large orders need to be fragmented, sometimes even across different exchanges. Also, the position may be taken at different prices, or along a certain period of time.

It’s important to notice that the current V0.1 of the Superalgos Protocol does not manage such level of complexity at the moment of execution, but it will in the future.

For the time being, the protocol assumes your orders are rather small, in the order of magnitude that your exchange of choice can handle fine in a single order.

As you may now see, there are a number of considerations to make at the time of execution, and the task itself is quite different from monitoring the market, hence the view of the two as belonging to separate stages.


Stage 3: Manage

As hinted earlier, what you have read so far is the basis of the framework to develop your trading system.

As you may have noticed, a trading system corresponds to a lower level logic in relation to the strategic aspects of trading. The system serves to structure the processes and methods that you will use to implement your trading strategies.

What follows are a number of considerations that aim to increase the efficiency of your system.

In Stages 1 and 2, I described the fundamental components of the take position, take profit and stop events of a trade. What I haven’t covered so far are the underlying opportunities to manage the trade while you have an open position.

The term trade management implies that the rules set forth for the take profit and stop don’t actually need to be static.

I already discussed how setting the take profit and stop with dynamic formulas that take into consideration several relevant parameters such as current price or a number of indicators is preferred over the simplistic approach of setting a constant value considering the price at the take position event only.

The concept of managing the trade goes even further.

It means that the formulas to determine the take profit and stop may actually change as the trade develops.

The key point to take home is that there is a development or evolution attached to a trade. A trade is not an instantaneous event. It matures over time.

Then, how do you manage the trade?

What could possibly happen that would make you want to change your take profit and stop formulas?

How do you determine when to change them?

Well… let’s start with stating the obvious: the development of the trade is analyzed through the same lens you have been using throughout the previous steps, meaning that you keep looking at the state of the market in relation to any number of indicators you wish to analyze, in an attempt to predict what may happen next.

But, most importantly, you analyze the market in relation to your current targets embodied by the originally defined take profit and stop.

To make this clearer, let’s remember the main reason why you want to manage the trade: to optimize the outcome.

Therefore, the typical situation in which you may want to change your original take profit and stop formulas is when the trade seems to be going well in your favor. That is, the market is moving in the expected direction and you seem to be making a profit.

Does this sound counter-intuitive?

Why would you want to change anything at all if things are going according to your expectations?

First of all, as long as the position is open, you haven’t actually accrued the profits!

Even if you seem to be winning, the market may reverse before hitting the take profit and may go all the way back to your stop.

In such case, if you were playing by the book of Stage 2 (with initial take profit and stop), you would end up with a loss despite the fact that you were temporarily winning at some point in time.

Under the Stage 3 paradigm, you would be interested in moving your stop as the price moves in the expected direction in such a way that even if the market reverses before hitting the take profit, you would end up with a smaller loss, with zero loss or even with a profit, depending on how much you manage to move the stop.

A second potential scenario is that the market moves in the desired direction and does not reverse.

In such case, if you did nothing to manage the trade, you would hit the original take profit.

Good, right?

Now, what if the market keeps going way beyond the initial take profit?

Indeed, you would have missed a good opportunity to surf a big market move and make a much larger profit than originally expected.

The conclusion is that it may be in your best interest to manage both stop and take profit, moving them in the direction of the trade as the market moves, allowing some leeway for a larger profit than expected and at the same time cutting the potential for a loss.

Remember, greed is not the point of managing the trade; the point is optimization. You need to be careful not to increase the risk as you move the take profit, and make sure you are always tightening your stop at the same time too. In fact, the best practice is to move only part of your take profit, but again, the specifics of the tactics is beyond the scope of this article.

How does all this management translate in the framework?

The management of the trade is handled in phases.

Actually, the management of take profit and stop — while correlated — is done independently of each other, therefore, each concept has its own set of phases.

Trade management involves managing the stop and take profit events in phases

Changes to take profit and stop formulas respond to the same kind of logic you used to set the original values. When a situation defined by a set of conditions is met, the event indicates that take profit or stop formulas shall be changed. At the moment those predefined conditions are met, you enter the next phase. Keep in mind that the trade is in constant development, so there may be as many phases as you deem appropriate for your particular strategy.

Chart notations indicating changes of phases on take profit (green) and stop (red). Horizontal red bars represent a dynamic stop at each candle interval while horizontal green bars represent a dynamic take profit.

The idea of having different phases comes from the notion that big market moves tend to provide clues as of what may come up next.

For instance, rallies may accelerate as more traders join the move. Recognizable patterns may emerge. Signs of exhaustion may be identified.

All of these considerations should feed the dynamic analysis performed as the trade develops, and may be contrasted with the predefined conditions that may push take profit or stop further, entering one phase after the next.


Stage 4: Close

Closing Execution

The Closing Stage has very similar implications to what I explained in the Opening Stage in regards to execution.

While it is true that the trade management process takes care of making the decisions as of when to close the position by managing the take profit and stop, the actual execution of the exit may require a number of considerations when dealing with substantial amounts of capital.

It is for that reason that I propose to understand execution as a separate stage, while it may not be required in practical terms if you are trading a small capital. If that is the case, then your trade management includes the actual execution and you don’t need to consider any other variables.

This is in fact what the current V0.1 of the protocol can handle at this point in time.

Record Keeping

While it is sometimes disregarded as a boring task, record keeping is a fundamental part of the process and should be clearly implemented in your trading system.

It doesn’t require much analysis to come to the conclusion that being able to track the results of each of your trades will become a fundamental piece of information that should help you fine tune your strategies in the future.

Remember that markets evolve and strategies perform well for limited periods of time. Therefore, you should implement a procedure that will evaluate the efficiency of your strategies over time.

The tools delivered by the Superalgos Project make sure you keep track of each of your trades, with all the basic information, such as date of opening, reasons for entering the trade (conditions met to take the position), take position price, initial and last take profit and stop, return on the trade (%), profit & loss (expressed in your base currency), duration of the trade and more.


Further Levels

So far, I covered the basic framework — what I call Level One — analyzing the four stages of a trading strategy.

The complete basic framework diagram

Needless to say, there is a lot more depth to the subject of trading systems.

I would argue that implementing the framework up to this Level One builds a a solid base for trading successfully.

That said, it is what comes after Level One what will actually put you higher in the food chain. For instance, two of the most relevant subjects that still haven’t made it to the protocol are capital allocation and risk management.

We are working on that.

In the meantime, it’s up to you to get up to speed with a solid foundation for you trading system by creating and automating your strategies using the various web-based tools the Superalgos Project makes available free of charge, embodied in the Superalgos Platform.

Paired with the Superalgos Protocol, these tools allow you to create, customize and share strategies through a graphic user interface (GUI).

You may analyze the outcome of strategies in (almost) real time through a simulation engine with historical and up-to-date market data.

Once happy with your strategies’ output in the simulation, you may deploy your strategies as fully automated bots, and trade live.


About Me

I’m a lifelong entrepreneur and co-founder of the Superalgos Project, an open source project developing and freely distributing trading tools, and building a Collective Trading Intelligence — an alternative to the reigning active investment paradigm.

You may join our Telegram and use our existing trading intelligence to trade with your own crypto assets, free of charge. You may also join the project and contribute to building our Collective Intelligence from the inside.

Superalgos

A collective trading intelligence

Julian Molina

Written by

I’m a lifelong entrepreneur and co-founder of Superalgos.org, an open-source project building a Collective Trading Intelligence.

Superalgos

A collective trading intelligence

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade