Sirwin
Sirwin
Dynamic Indicators Explained

Superalgos // Dynamic Indicators for Lazy Traders

By 9808us | Superalgos | 27 Mar 2021


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:

User Defined Parameters

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 any 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:

  • I use User Defined Parameters to enter a number 
  • I use Dynamic Indicators to write a function that will take the number of the previous point as an input
  • Formula under Dynamic Indicator will give a random output

Obviously this is not a strategy I will go running 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

94db902eac5f05ecf70ccae94a5af896eabd9985edc310ce830d5e21d79654d8.png

What we must note here is this piece of code:

sessionParameters.userDefinedParameters.config.parameterName

This is the code we need to later acces our funny indicator, we just need to replace the last part "parameterName" with the name we use for our function.

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

{
"parameter1": "Could be a string",
"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
}

User Defined Parameters // Think A Number!

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, give 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, while if the extracted number is odd function will return One.

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 magics and return Zero or One.

Go to Trading System and insert the previous code as in the following screenshot:

5eed424e64656e751bbd8b2ff54b19415e1d58a022e36a513af165e5a8066fec.png

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

I called the indicator SMART. Isn't it a funny name?

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 -> The code name we have given to Indicator Function

Let's build our Trading System. As you can see in the screenshot above, 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:

e2364e96c21420cb3577ac74b3a50d8480fa12938d09f8169c1d0baaad59abac.png

This is how I set up the 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.at01hs.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)

For your convenience I prepared a download with both Long and Short strategies: Dynamic Indicators Trading System

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": "2021-01-01",
        "finalDatetime": "2099-12-31"
    }​
  • Time Frame
    {
        "label": "01-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

Wow! It works!

fff7a02141443832dedc7635dd578eaa9746b03cfd4c74bd863dabdff432742d.png

Zoom the chart and turn on TP and SL layers

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

Now, I admit this indycator is very unuseful but it's the idea that is powerful. You can easily set up SMA with custom values, or develop your own indicator without the need of going thruoght all the steps that are required to implement a proper indicator.

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

See you on the next tutorial and have a nice day

P.S. If you want to ask me to cover particular aspects of this amazing Superalgos project, write me in Telegram @us9808 or comment below.

 

I hope you enjoyed this funny tutorial to make you better feel like at home in Superalgos
Don't forget to tip me, it's free!

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

 

 

How do you rate this article?

3


9808us
9808us

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


Superalgos
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.