SUPERALGOS DATA MINING

Superalgos Dynamic Indicators for Lazy Traders

Today we will implement a Trading System using a very cool feature in Superalgos called Dynamic Indicators.

I’m pretty sure you have noticed that node called User Defined Parameters under Testing Session. Have a look at the following screenshot:

Well, this is very useful stuff as you can use this node to pass values to Dynamic Indicators!

What?!?! Ok … let’s take a breath..
I can see your eyes jumping out from your head!

Superalgos is a really nice tool. What is really special about Superalgos is that you can build your custom indicators, plot them on charts, backtest your ideas and even live trading then! Just these alone could be top features that are difficult (I would say impossible) to find in any open source free projects. But what it’s even more special is that SA is modular and can be easily modified the way you desire.

So let’s come back now to Dynamic Indicators and let me try to explain why you should definetely give it a try.

Did I say that in SA you can build your own indicators?
Well, when you develop an indicator, you are contributing to SA ecosystem. You are taking some data as an input and after some elaborations you come out with an output. It could be a SMA, or some fancy indicator like Directional Movement ecc.. Then you can plot on chart these outputs and let other indicators/bots consume these data.

All this is fantastic! But what if you just want to develop a quick indicator, or test a new fresh idea in the fastest possible way? Let’s say you come from TradingView and you already have your indicators on that platform. Then you already know the outcome and how they perform, and probably don’t need to go trhought all the little steps that will end up in creating a new indicator.

So what are your options? The answer is Dynamic Indicators!

I take Luis Molina (telegram @luis_fernando_molina, Superalgos developer) words to explain in the better way I can what this node is for:

“A dynamic indicator is an indicator you define with a formula that is going to be calculated before the execution of the a cycle of the trading bot, directly at the trading bot process. This is in contrast to regular indicators that are pre-calculated in their own task/process, as part of a data mining operation.

Dynamic Indicators are defined at the trading system level, and they are a very simple concept, just a formula that you can write, accessing from there any information on the existing data structures (tradingEngine, tradingSystem, sessionParameters, charts) and calculating anything you want with that. The results of your calculations can then be used in conditions and formulas at any point of your trading system. You might define as many Dynamic Indicators as you need.

After Dynamic Indicators are calculated, then the Trading System is run and their all calculated values are gone. When the trading bot runs again, the same process is executed, again and again.

Dynamic Indicators are also useful when you want to test new indicators ideas without having to go through the process of creating an indicator inside a Data Mine. Data Mine indicators have the advantage that they can be plotted (if you create a plotter for them) and their output can be consumed by other indicators or trading systems/strategies.”

I couldn’t find a better explanation!

So let’s dig a bit into this feature and let’s learn its usage by making a funny example. Learning by playing is the best way :-)

Let’s say there is a trader that is so unlucky that he always end up loosing. No matter what he do, it seems the universe is against him. So one day he decides to give up on price action, charting, indicators and all that stuff, and just let the fait work for him. He want to just think a number and let the trading system do the rest. Superalgos is so powerful, I’m sure it can do that!

So this is the basis of our trading system:

  • Add a new Trading System to your Workspace
  • Use User Defined Parameters to enter a number of our choice
  • Use Dynamic Indicators to write a function that will take that parameter defined in User Defined Parameter as an input
  • Formula under Dynamic Indicator will give a random output that will be used in our strategy

Obviously this is not a strategy I will run live, but it’s a funny way to show you how powerful SA is.

To start, let’s have a look at the docs about User Defined Parameters.

What we must note here is this piece of code:

sessionParameters.userDefinedParameters.config.parameterName

This is the code we need to later access our fun indicator, we just need to replace the last part “parameterName” with the name we use in our function.

And we also note that we should use parameters in this way:

{ "parameter1": "Could be a string", // Strings need quotes
"parameter2": 10 // Numbers don't need quotes
}

So let’s put all togheter and start!

A little note before moving on. In this tutorial I’m not going throught the whole process of creating a new Trading System and set it up. I assume you have a certain degree of confidence with SA and you can recreate by yourself a workspace to test this feature.

Ok, first thing first, let’s open the User Defined Node and insert this code (Have a look at the screenshot):

{ "thinkNumber": 75 }

Ok, this is the place where our unlucky trader will insert a number, a random one or a special one, it doesn’t really matter. What is important here is to note that you can define a variable giving it a name and a value (in this example the name is thinkNumber).

Now let’s write few lines of Javascript code that will be used in our function:

numberX(sessionParameters.userDefinedParameters.config.thinkNumber)function numberX(argument) {let randomX = Math.floor(Math.random() * Math.floor(argument)) + 1
let zeroOne= ( randomX & 1 ) ? 0 : 1
return zeroOne
}

Function is called numberX and as you can see it takes our thinkNumber variable (defined before) as a parameter. Function is pretty easy to read, it takes an argument and from that it extracts a random number. Then if the extracted number is even, it returns Zero (0), while if the extracted number is odd the function will return One (1).

P.S. Don’t blame at me! I know there are at least 1000 different ways of writing something similar but here I’m not teaching you how to code, I’m teaching you how to use SA, ok?

Wonderful, now we have a place where we can insert a number, and we have a function that will take that number, makes some magic and return a random Zero or One.

Now please note that to be able to access our formula results we MUST give a name to Indicator Function. This is mandatory! I call it SMART, Look below:

Ok very cool, we have just put the basis and made all the hard work!

  • We have a place where we can insert a value for a new variable
    -> User Defined Parameters
  • We have a formula that can performs some magics
    -> Formula under Dynamic Indicators
  • We can access the results of our formula
    -> With the code name “SMART” we call Indicator Function

Let’s build our Trading System. I quickly set up a Trading System with two Trading Strategy, one for opening a Long position in case the returned value of my function is Zero, and the other to open a Short position in case the returned value is One.

What we need to do now is to set up each strategy, one is the opposite of the other. Here I set up the Short strategy, I used a minimal set up to quickly test the feature and populated the Trigger Stage like in the screenshot below:

This is how I set up the Short strategy.

Trigger Stage

Trigger On Event checks our Dynamic Indicator using this syntax

dynamicIndicators.SMART == 1​

Where SMART is the code name we used before

Trigger Off Event set to false

Take Position Event set to true

Open Stage

Initial Targets -> Target Rate -> Formula

chart.at24hs.candle.close​

Target Size in Base Asset

tradingEngine.tradingCurrent.tradingEpisode.episodeBaseAsset.balance.value​​

Open Execution set up with a Market Sell Order (and its reference to the Low Frequency Trading Engine)

Manage Stage

Managed Stop Loss

tradingEngine.tradingCurrent.position.entryTargetRate.value * 1.03​

Managed Take Profit

tradingEngine.tradingCurrent.position.entryTargetRate.value * 0.97​

Close Stage

Initial Targets -> Target Rate -> Formula

tradingEngine.tradingCurrent.tradingEpisode.candle.close.value

Target Size in Base Asset

tradingEngine.tradingCurrent.strategyOpenStage.stageQuotedAsset.sizeFilled.value - tradingEngine.tradingCurrent.strategyOpenStage.stageQuotedAsset.feesPaid.value

Close Execution set up with a Market Buy Order (and its reference to the Low Frequency Trading Engine)

It’s time to test this new set up! Our strategy will handle Long and Short positions so let’s add some funds to Session Base and Quoted Assed under Trading Parameters.
My parameters are:

  • Session Base Asset { "initialBalance": 1 }​
  • Session Quoted Asset { "initialBalance": 1000 }​
  • Time Range { "initialDatetime": "1999-01-01", "finalDatetime": "2022-12-31" }​
  • Time Frame { "label": "24-hs" }​
  • User Defined Parameters { "thinkNumber": 75 }

*Note: 75 is a number I thought, you can write what you prefer. See above the part where I explained this node.

Perfect! Let’s now run our strategy as a backtest. Once done, I moved to the charting space and turned on these layers:

  • Strategies
  • Market Buy Orders
  • Market Sell Orders
  • Trading System Values
Fire up the Trading System Values info panel and check the Formula value

And that’s it, strategy is complete and we have learned how to use Dynamic Indicators!

N.B. Due to the random outcome of this indicator you will have random outcomes from backtesting this strategy -> DO NOT USE IT LIVE !!!

Now, I admit this indicator is not very useful but it’s the idea that is powerful!

For example you can easily set up SMA with custom values, or develop your own indicator without the need of going through all the steps that are required to implement a proper indicator with a plotter to see the values on the chart.

As usual I showed you the way, now it’s up to you!

I hope you enjoyed this funny tutorial to make you better feel like at home in Superalgos.

Superalgos is the most advanced crypto trading bot you can find and it is totally free on Github

Originally published at https://www.publish0x.com by me :-)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store