Create a Trading System with Overbasic

A Trading System is an algorithm that produces buy/sell signals based on specific defined rules.

With Overbasic programming language you can create Trading Systems to attach to your charts and view buy/sell signals generated. Using Tester application you can also backtest trading systems and check their past results. Once created and compiled, trading systems can also be used within indicators or other trading systems.

Trading Systems in Overcharts ONLY provide signals. Automated trading is currently NOT supported. It will be in the future.

Create a New Trading System #

Before starting the development of a trading system, we recommend you carefully read the Overbasic language syntax documentation, keywords and available built-in functions.

To create a new trading system:

  1. Access Developer (the Overcharts development app):
    • from Overcharts main window > Tools menu > Developer
    • or from Workspace window > Tools menu > Developer
  2. Create the trading system from:
    • File menu > New > Trading System – Overbasic
    • or press New button on the top toolbar
    • or from Trading Systems Tab > press ‘+‘ button on the left vertical toolbar
  3. Define trading-system name. The name must comply with the following rules::
    • can consist of letters (both Uppercase and lowercase) or numbers
    • cannot contain spaces. The only separator character allowed is underscore: “_
    • cannot contain special characters such as !”£$%&/()=?^|
    • cannot contain special letters (typical of some languages)
    • cannot be a number or start with a number
  4. Press OK to confirm the name and create the trading-system.

Once the trading system has been created, the editor is automatically opened.

Afterwards, you will be able to access the editor to edit the trading-system from trading-system list on the left:

  • by double clicking the trading-system name
  • or by pressing the corresponding Open button next to the trading-system name
  • or by right clicking the trading-system name > Edit

Trading-System Modules #

A trading system consists of the following modules:

  • Common Module: contains PROPERTYs, INFO, OPTIONs and variable declarations common to all modules.
  • Long Entry: contains all rules for entering the LONG position.
  • Long Extension: contains all rules for extending a LONG position by x quantities.
  • Long Exit: contains all rules for exiting a LONG position.
  • Short Entry: contains all rules for entering the SHORT position.
  • Short Extension: contains all rules for extending a SHORT position by x quantities.
  • Short Exit: contains all rules for exiting a SHORT position.

No module is mandatory. Based on the logic of your trading system, you will activate the modules that interest you. For example, if your trading system provides only LONG signals, you will deactivate (using the respective check-boxes) the modules relating to SHORT positions.

Common Module #

Common Module is a special module containing only declarations of PROPERTYs, OPTIONs and variables accessible and modifiable by all the other modules. It is especially useful to declare variables in the Common Module to share information between modules.

Everything declared within Common Module is accessible and usable from any other module.

Running logic #

Trading-system modules are run according to the current position (OUT, LONG, SHORT). If a module is disabled, it simply will not run.

The following describes how a trading system works:

  1. Initially, trading system is OUT (no open positions).
  2. Long-Entry module runs. If a long signal is generated, trading-system moves to the next bar and goes to step 5.
  3. Short-Entry module runs. If a short signal is generated, trading-system moves to the next bar and goes to step 6.
  4. Trading-system moves to the next bar and goes back to step 2.
  5. Trading-system is in LONG position:
    • Long-Exit module runs. If the exit signal is generated, trading-system moves to the next bar and goes to step 1.
    • Short-Entry module runs. If a short signal is generated, trading-system moves to the next bar and goes to step 6.
    • Long-Extension module runs.
    • Trading-system moves to the next bar and goes back to step 5.
  6. Trading-system is in SHORT position:
    • Short-Exit module runs. If the exit signal is generated, trading-system moves to the next bar and goes to step 1.
    • Long-Entry module runs. If a long signal is generated, trading-system moves to the next bar and goes to step 5.
    • Short-Extension module runs.
    • Trading-system moves to the next bar and goes back to step 6.

MAIN Function #

The main component of each module (the only really mandatory one) is the Main function, i.e. the function that contains rules for generating the signal. The result returned by Main function MUST be boolean (True or False). If True, signal is generated.

In the example below, main function generates the signal (returning True) only when current close is greater than previous one. Quantity keyword (optional) defines the signal quantity.

Function Main()
    If (Close > Close(-1)) Then
        Quantity 1
        Return True
    EndIf
    
    Return False
EndFunction

Signal Quantity and Price #

Quantity:
You can define the signal quantity using Quantity keyword. If the quantity is not defined within the script:

  • it is calculated automatically based on available capital and trading-system parameters (defined when adding the trading system to a chart, or during the backtest configuration) in Long-Entry, Long-Extension, Short-Entry, and Short-Extension modules.
  • it is equal to the posizion total quantity in Long-Exit and Short-Exit modules.

Using Quantity in Long-Exit or Short-Exit modules, you can also exit the position in multiple steps.

Price:
You can define the signal execution price (which is equivalent to the limit price of an order) using Price keyword. If the price is not defined within the script, the signal is executed at the market price (in real time) or at the Open or Close price of current or next bar according to trading-system settings (in backtesting).

Option #

An Option is a special numeric property with a specific validity range. The difference with the other PROPERTYs is that it can be optimized during the trading-system backtesting (procedure performed by Tester application). In other words, backtesting will automatically test all the values that an Option can assume (from minimum to maximum by adding the step value to each new test), trying to identify the Option value that produces best results in the trading system.

For more information on syntax and usage refer to the Option page.

Trading System description #

You can define a description for the Trading System using INFO keyword within Common Module. Description will be shown, for example, in the available trading-systems window.

Example:

Info "My first trading system"

Compile/build the Trading System #

To use the trading-system in Overcharts, you MUST compile it. Compiling a trading-system means transforming the source code into a ‘something’ that the program understands.

In Developer, you can build a single trading-system in one of the following ways:

  • by pressing Compile button on toolbar inside the Editor window
  • or by pressing ‘Compile’ icon (gear) next to trading-system name in the list. The icon is ONLY visible if the trading-system needs to be compiled.

You can massively compile multiple trading-systems, in one of the following ways:

  • Developer main window > Compile menu > Select which items to compile
  • Developer main window > press Compile button on main toolbar > Select which items to compile
  • Trading-system list > press Compile button on toolbar above the list > Select which items to compile

Using the Trading-System in an external script #

My.Trading_System.Private category contains all trading-system functions.

To use a trading-system within the script of an indicator or another trading-system:

  1. Create and Compile the trading-system
  2. Use the trading-system function in the external script. You can find the trading-system function in My.Trading_System.Private category. Function has the same name as the trading-system. If present, it is also necessary to set trading-system OPTIONs and PROPERTYs by passing them as arguments to the function.
  3. (optional) In the function you can also define some trading-system parameters, such as Slippage, Simulation Account etc.

Example:

In the example below, MyFirstStopAndReverse function represents a previously created and compiled trading-system. Arguments 10 and 5 are the values of OPTIONs and/or PROPERTYs defined in the trading-system script.

Function Main()
    Return MyFirstStopAndReverse(10, 5)
EndFunction

Note: Usually, you can use the trading-system function directly without specifying the full path: ‘My. Trading_System. Private. MyFirstStopAndReverse(10, 5)‘. You need to specify the full path only if exists another function with the same name as the trading-system.