Visual Scripting to use Bollinger Bands and exit on Trailing Stop with Arm

    • bollinger bands
    • haasbot
    • trailing stop loss
    • visual editor
    • visual scripting
    • visual trade bots
    posted 4 years ago
    by evergreen
    Tutorial Featured Image


    In this quick and simple guide we will be going through the steps of using HaasScript and our visual designer to generate signals with the Bollinger Bands technical indicator, trigger trailing stop loss actions once a defined variable is met, and backtesting the script to see how it performs with historical price data.

    The visual designer allows us to drag-and-drop hundreds of built-in blocks to perform the desired logic, instead of using a test-based editor. This method vastly improves the speed and accuracy of the scripts that you are creating as you will learn through this guide.

    Creating the Strategy

    We start by creating a new script with the trade bot template, creating a unique name, and adding a description (optional).

    The first thing we need to do is to add the "Trailing Arm Stop Loss" visual block to the canvas. You can find the entire list of visual block commands in the left-hand menu.

    After we've selected our safety that we want to use, we can begin building out our strategy using the Trailing Stop with Arm safety. To do this we need to add a couple input blocks to feed the trailing arm stop loss. We need to set the trailing stop % and the trailing stop arm %. This safety starts trailing when the price changed at least the ARM percentage, in this case 1%. The trailing distance can be seen below as the Trailing Stop (%) and in this case set to 0.2%.

    In this example we want to split our execution flow and we do this by using the branch block. Using the branch block we split the flow into two parts, the first is when the stop loss is active and the second one for when its not active.

    Now that we've got our branch block in place it's time to add some actions. If the logic is determined to be true, then we want to call "DoExitPosition" when the stop loss is triggered. If the signal generated was false, then we can choose to do an entirely separate set of instructions.

    Now we need to determine which position we are in and we do this with the "GetPositionDirection", "NoPosition", and the equals logic block. We only want to do stuff when there's no position detected.

    When the stop loss isn't active and we don't have a position, we let the Bollinger Bands technical indicator decide what we should do. This can be long or short, but only when the two conditions are true. In this particular strategy we only exit on the stop loss.

    Time to backtest and see the fruits of your labor. Make sure to check your scripts general settings in the left-hand menu. Check to see that your exchange, pair, intervals, etc all have been selected. Save your script and start a backtest (CTRL+R).

    Video Example


    We hope this quick and simple guide gives you a better understanding of what HaasScript combined with HaasOnline Trade Server is capable of.

    • If you found this guide interesting, check out the guide where we recreate other strategies using the HaasScript visual designer
    • For the complete list of built-in commands and documentation of all our features, check out our HaasScript documentation
    • You can use HaasScript to recreate other popular strategies and indicators from languages such as PineScript

    If you enjoyed this guide, want to give feedback, or have comments please post them down below.

    — Evergreen

Be the first to comment

The community content is generated by people from the community and is actively moderated. However, we do not endorse or claim to maintain any user generated content, links, tutorials, guides, projects, or questions that may appear in community sections.