LogoLogo
Back to HaasOnline.comSwitch to Trade Platform
3.x
3.x
  • Welcome
  • Getting Started
    • Using Local API Server
    • Authentication
    • Response
      • Error Codes
  • HaasScript
    • Using HaasScript
      • HaasScript Facts
      • Charting
      • Order Handling
      • Interval
      • Input Fields
      • Positions Handling
        • Fee correction
      • Position Information
      • Memory Management
      • Optimizations
      • Signal Handling
      • Trading
    • Script Editor
      • Syntax
      • Parameters
      • Interaction
    • Visual Editor
      • Blocks
      • Parameters
      • Flow Control
      • Interaction
    • Custom Commands
    • Tutorials
      • Trade Bot Guide
        • Creating A Trade Bot
          • Visual Editor Guide
          • Script Editor Guide
          • Custom Containers
        • Customizing Indicators
        • Customizing Safeties
        • Customizing Insurances
        • Creating Easy Indicators
      • Unmanaged Trading Guide
        • Executing Orders
        • Managing Orders
        • Managing Positions
        • Managing Wallet
      • Script Editor
        • Classes
        • MadHatter BBands
        • Percentage Price Change
      • Visual Editor
        • Importing Scripts
        • SmoothRSI
        • Scalper Bot
    • Commands
      • Array Helpers
      • Charting
      • Constants
      • Custom Commands Helpers
      • Easy Indicators
      • Easy Insurances
      • Easy Safeties
      • Equations
      • Flow Control
      • Input Fields
      • Input Settings
      • Mathematical
      • Memory Helpers
      • Miscellaneous
      • Order Handling
      • Order Information
      • Position Information
      • Position Prices
      • Price Data
      • Price Market Information
      • Profit Information
      • Settings
      • Signal Helpers
      • String Helpers
      • Technical Analysis
      • Technical Analysis Helpers
      • Time Information
      • Trade Actions (Managed)
      • Trade Actions (Unmanaged)
      • Trade Bot
      • Trade Market Information
      • Wallet
  • API Endpoints
    • Software API
    • Market Data API
    • Account Data API
    • Trade Data API
    • Advanced Order API
    • Trade Bot API
    • Custom Trade Bot API
    • ENUMS
    • Data Objects
  • Examples
    • Script Bots (C#)
      • Scalper Trade Bot
      • Flash Crash Trade Bot
    • Script Indicators (C#)
      • Indicator Script
      • Technical Analysis Library
    • Pshai Scripts (C#)
      • BBands Ext
      • BBands Ext v2
      • Chaikin A/D Line
      • Calibrator
      • Pshai's RVI
    • Scripted Driver
  • Other Resources
    • YouTube
    • Guides & Tutorials
    • Questions & Answers
    • Community Projects
  • Need Help?
    • Ask on Discord
    • Submit Support Ticket
Powered by GitBook
On this page
  • ‌Entry Logic
  • Exit Logic
  • Final Script

Was this helpful?

  1. HaasScript
  2. Tutorials
  3. Visual Editor

Scalper Bot

PreviousSmoothRSINextCommands

Last updated 5 years ago

Was this helpful?

This tutorial will create a scalper bot. The bot will enter a position based on a simple trend calculation and exit on either a stop loss or take profit.

‌Entry Logic

‌First, we need to check what current direction is of our position. We only want to do something when the bot does not have an open position. Add the GetPositionDirection command. Right-click on the output dot and add both Equals and NoPosition. Connect both GetPositionDirection and NoPosition to Equals.‌

Next step is adding the trend detection. We are going to do this by looking if the price is dropping or raising with help of the IsFalling command. Add both a ClosePrices and IsFalling command. Connect the ClosePrices to the array parameter of IsFalling. Right-click on the dot next to lookback and add an Input. We are going to make the lookback an input field so we can change it later without updating the whole script. Give the Input a name and a default value

Remeber, we want only want to continue executing if there is no position. Right-click on the IsFalling block. A context menu will show and we are going to select Toggle connector. This will give the command an additional parameter called execute. When the result of the Equals command is false the execution will stop here. When the value is true, IsFalling and other attached commands are executed.

‌IsFalling will return true of the price is dropping and false when the price is raising. We are going to split the execution flow here with the Branch command. Right-click on the IsFalling output and add it. The Branch command has 2 outputs. isTrue and isFalse. When the result of IsFalling is true (price is dropping) we are going to open a long position. Right-click on isTrue and add DoLong. Conversely, when IsFalling is false (price is raising) we are going to open a short position. Right-click on isFalse and add the DoShort command.

We have now completed the entry logic.

Exit Logic

‌The exit logic is a lot easier. We are going to make use of the build-in EasySafeties and add a StopLoss and TakeProfit. Both commands require a percentage input. Right-click on both dots and add an Input. Give them a name and default value.

Both commands will return true when their price has been breached or false when there is no position or when the price didn't breach the price yet. If one of the 2 outputs is true we are going to exit the position. Right-click on the output of TakeProfit and add an Or command. Connect the StopLoss output to the same input. Or will return true when any of the values is true.

Usually, we can only connect 1 output to an input, but when the parameter name ends with sqaured brackets [], we can connect as many as we want.

The last command we need to add is the DoExitPosition. Right-click on the Or output and select DoExitPosition. This is the final step for the scalper script.

Final Script

The script is now finished and we can run a few backtests to find the best parameters for the bot.