Script Indicator (C#)
HTS's Script Indicator is a custom Indicator for the Trade Bot. This feature allows you to create and share your own indicators.
Check out Pshai's scripts for a set of pre-made custom indicators for use with your custom bot.
Supported license & Trade types
Settings
The Script Indicator has only one setting: the full path to the script.
Language
The scripts are C#-scripts, using the CS-Script CLR.
Interface
All indicator scripts must fully implement the IndicatorScript-interface:
Name
This property returns the name of the indicator. Haasbot will use this name for the indicator, instead of the general "Script Indicator", so it is clear for the user which script is being used.
TicksBack
With this property you can configure how much price data (Bid, Ask, High, Low, Volume) must be kept in memory by the IndicatorContext. Make sure this is big enough to have enough data to do the necessary calculations in your script, while keeping it small enough to reduce memory usage and unnecessary CPU load when doing these calculations.
Init
This method is executed after creating the script-object the first time. You can use this to do any necessary initialization. The created script-object will stay in memory and will be used until the script is recompiled. An indicator-script is recompiled when Haasbot starts and when the Script Indicator settings-window is closed.
GetResult
This method will be executed every time Haasbot checks the indicator. It should return an IndicatorResult (Stay, Buy or Sell). An IndicatorContext-object is passed, containing current price details and a reference to the IndicatorAPI, giving access to historical price data for all supported platforms and currency pairs. The default behavior of this method is to always return Stay.
GetChartLines
GetChartLines is a property defining the chart lines which will be shown on the indicator chart. This property has to return a list of ChartRecord-objects, which define the properties of one chart line. For each line in the chart, you have to define a name, on which chart it has to be shown (0 on main chart - 1,2 and 3 will create their own charts) and optionally a color. When no color is defined, Haasbot assigns a color automatically. For an example, see lines 65 to 76 in the example script.
GetChartData
This method returns the data points which have to be shown in the chart(s). It should return a list of decimal's, in the same order as the ChartRecords returned by the GetChartLines-property. The length of the list returned by the GetChartLines-property should be the same length as the list returned by GetChartData. This method is called after calling GetResult(), so if any chart data is generated in the GetResult-method, you can store it in a class member, and return it in GetChartData to be shown on the indicator chart.GetParametersThis method returns the parameters the user can configure for this script. It should return a list ScriptParameter objects. These ScriptParameter objects define for each parameter the name, current value, type and optionally some info text shown to the user. The user will be able to configure these parameters in the Haasbot user interface. The current value has to be cast into string.
SetParameters
This method is called when the script parameters are modified in the Haasbot user interface. The argument is a dictionary with the parameter names as dictionary-keys, and the parameter values as dictionary-values. The type of the values is object, so you need to cast them to the correct type (the same type as you defined in the ScriptParameter in GetParameters). When only specific values or range of values is valid for a certain parameter, you can do the checks here and revert to the previous value if an invalid value was set by the user.After SetParameters is called, the name of the script (the Name-property) is retrieved again. This way, when parameters are used in the name, the name is updated when the parameters are updated.
TA-Lib
In an indicator script you have access to TA-Lib for calculating any technical analysis indicators. All functions are static members of the static class Core in the namespace TicTacTec.TA.Library. It is not necessary to include external references to use TA-Lib, but having them allows the of your IDEs intellisense.
The PriceInstrument property in the IndicatorContext contains multiple arrays of doubles (Asks, Bids, High, Low, Volume), which can directly be used as input for the TA-Lib-functions.
Creating classes
You can define your own classes and structs in a script. You only have to make sure the class implementing the IIndicatorScript-interface is the first class in the file.
Debugging
Writing to log-file
You can write debug-info to a log file, by calling Logger.LogToFile(message) on the IndicatorContext-object. The message will be written (together with a timestamp) to a log-file. The log-file has the name of the script and is located at the Haasbot execution path.
Step-by-step debugging
Coming soon
Example script
Last updated