Trade Bot Guide
Last updated
Last updated
The Trade Bot is a system which tries to make is simple to create a full bot with 3 core elements. Safeties, indicators and insurances. Each element has its own feature set and uses. The framework is build using 4 commands. TradeBotContainer, SafetyContainer, IndicatorContainer and InsuranceContainer.
The TradeBotContainer takes 3 parameter. a safetySignal, indicatorSignal and insuranceResult. The container will executed a signal based on the following steps
If safetySignal is true, DoExitPosition is executed and the rest of the steps are skipped.
if the insuraceSignal is false, the rest of the stops are skipped.
If indicatorSignal is SignalLong, DoLong is executed
If indicatorSignal is SignalShort, DoShort is executed
If IndicatorSignal is SignalExitPosition, DoExitPosition is executed.
A safety will only exit a position. It will not go from long to short or from short to long.
The SafetyContainer takes an unlimited amount of booleans as parameters. If any of the values is true, the command will also return true.
The IndicatorContainer takes an unlimited amount of signals as parameters. The return value will be an array with 3 things. All the signals in a list, the unanimous signal and the consensusSignal from all the signals.
In order to get a unanimous signal all the inputs need to be the same signal. If any of the result differs, SignalNone will be set, otherwise the unanimous signal.
With consensus signal is ruled by the majority (>50%). If we have 3 signals, 2 need to agree before the signal is valid. With 4 or 5 signals, 3 need to agree, with 6 or 7 signals, 4 need to agree and so on. If there is no majority SignalNone will be set.
The InsuranceContainer looks like the SafetyContainer but works slightly different. The container also returns true or false but will only return true when all the values are true.
Easy Safeties are command who protect your investment or deactive the bot when certain conditions are valid. It is always smart to have safeties in your script such as a StopLoss, TrailingStop or TakeProfit. All the safety commands return a boolean value. When the safety is active (for example the stop loss price has been reached) it will return true. Converioly, when the safety isnt active, it will return false.
When the safety is active it will return true, otherwise its false
Each safety has its own (required) parameters such as percentage but there always 2 default (optional) parameters. positionId and direction.
PositionId is used for more advanced scripts. Its a parameter we only have to think about when we have multiple separate position in our script. This is the case with for example the FlashCrash script. Each slot their has its own position. Script that use a Trade Bot system do not have to worry about the paramater. We can leave it open or leave set an empty string.
With the direction parameter we can restric the safety to only work when the position is a specific direction. By doing this we can for example have 2 StopLoss command. One for when we are long and one for when we are short.
The deactivate command are a way to deactive your bot or stop the backtest in your script. Once the command is executed and the condition is reached, the exection of the script will immediately stop. Much of the commands require a single parameter such as a counter or min/max value.
The Easy Indicator commands are a wrapper around the native technical analysis commands. The command take care of a couple of things
They render every input fields required.
They calculate the indicator.
They plot the indicator
They determine the signal of the indicator
If we needed to do this our own in every script it would be a lot of work and the length of our script would grow a lot. With the Easy command we just need a single command.
Each Easy Indicator command requires just 3 inputs of which only 1 is required. A chartIndex, name and interval.
This is the only required parameter. The chart index control where the indicator is drawn. We use 0 if we want the indicator on the price chart, like with an EasyBBANDS, or a positive number if we wont to draw it below the chart.
The name is the first optional parameter. If we would set a value here, the input fields generated by the command will have this as a prefix. This is only required when we are using 2 of the same commands.
The last parameter is the interval. The reason why the parameter is optional is because the default value is linked to the Main Interval setting. If the script is using multiple indicators and they are intended to run on the same interval we can leave the parameter empty. If the indicators need to run on separate intervals, we need to specific them.
In the screenshot above the EasyBBANDS run on a 5 minute interval and the EasyRSI runs on 1 minute as we selected for the Main Interval.
The output of each default Easy Indicator command is a signal enum. It will be one of the follow three values
SignalLong
SignalShort
SignalNone
SignalLong and SignalShort are pretty straight forward. SignalNone is returned when the indicators doesnt have a long or short signal. It is for example it case then the RSI is between the buy and sell level.
Custom Easy Indicators might also return SignalExitPosition.
With the output we can do several thing. We can for example pass the value on to a IndicatorContainer which gives us a final result of all the signals or we can directly execute based on a single indicator with the DoSignal command. This will execute a DoLong, DoShort or DoExitPosition
Insuraces are a way to attach conditions to your indicator signal. With for example OverComeFeeCosts we can make sure each trade is profitable after fees. Or with the StopLossCooldown we can block trades for a period after a stop loss has been executed. The Easy Insurances category is packed with such conditions for your trade bot.
When the Easy Insurance command executed they will return true of false. When has condition reached, the command will return true, as in the bot is allowed to trade, and false when the condition isnt reached.
When an insurance is blocking a trade, it will return false. When it is allowed, they return true
Most of the command require a simple parameter such as a timeout, minute or percentage value. Several commands also take a positionId. The same rules applies to this as with the Easy Indicators. If we dont have multiple bots positions in our script, we leave it empty.