Use the HaasScript visual designer to create a SMA based simple trade bot

    • haasscript
    • pinescript
    • simple trade bot
    • sma indicator
    • visual editor
    • visual scripting
    • visual trade bot designer
    posted 3 years ago
    by Pshai
    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 SMA technical indicator, plotting the results on our charts, 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 text-based editor. This method vastly improves the speed and accuracy of the scripts that you are creating as you will learn through this guide.

    Getting Started

    Before we get started you will need:

    • An active simple or advanced license for HaasOnline Trade Server
    • Hardware that meets our software's minimum specifications
    • Broadband internet

    If you don't have access to one or more of the above, you can choose to test on one of our demo servers. Please remember these machines are public and you should never add any private information.

    Creating a New Script

    Visual Editor! We will be creating the same type of bot, but in a "drag & drop" environment. Let's get started by clicking the [Visual Editor] in the main menu panel.


    Yet again a new world opens in front of us. Don't be scared though! It will be fun, I promise. Here I have set the same market and interval settings as we had in the [Script Editor]. Now where is that button we create new scripts with...


    Right. Here we go. Let's click it!


    I went ahead and skipped the [New Script] window. I gave it a name and set the [Type] to [Script]. Now, like last time, first we want the historical close prices. Click on the [Commands] tab on the left hand [Menu].


    Exploring Command Blocks

    Here you will find everything you need. You can also set any command as a favorite (the star icon). These commands will be listed in the top most category [Favorites]. I went ahead and expanded the [Price Data] category. There we will find the [ClosePrices] command we were after. To create it just click it once.


    Our first block appeared, great! Now we need those SMA commands. Let's use the search field in [Commands] tab to find it faster.


    Here we go. We will be creating two of these so we click it twice. They will be created on top of each other, but thankfully we have a working mouse with a button to drag and drop them around as we like. Right?


    Managing Visual Blocks

    I added two [Number] blocks to set the [period] parameters for the SMA's. Connect the dots by clicking on the output of one and the input of the second block.


    Again, to be able to see them on our charts we will need two [Plot] blocks and two color constant blocks to define their line colors. Define the chart index and name for each [Plot] and connect our SMA outputs to them.


    Hit CTRL+R and open the chart.


    Adding Trade Logic & Backtesting

    There we go! Nice and simple, but we are again missing the trade logic. I will be re-aligning them a little and separate them to 3 sections:

    • Price data and indicator calculations
    • Plot charts
    • Trade logic


    I threw in some [Comment] blocks too to describe what each section does. Nice and clean! After everything is laid out and connected as shown, open the [Compile Log] and [Chart]. Then hit CTRL+R again and you should be seeing some results again. Awesome stuff!

    You know what to do next. Good luck!


    Video Example


    I hope this quick and simple guide gives you a better understanding of what HaasScript is capable of.

    • If you found this guide interesting, check out the guide where we recreate this strategy while using the HaasScript text-based editor
    • 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 or have comments please post them down below.

    — Pshai

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.