Quantower
Quantower Website
  • Welcome to Quantower Help
  • 🚀Getting Started
    • What's new
    • Installation
    • First start
    • Platform update
    • Quantower Beta
    • Quantower Account
    • Quantower Licenses
    • ⚖️License Comparison
    • Backup & restore manager
    • Reset settings to default
    • Payment FAQ
    • “Coinpayments” payment
    • Binance fresh account
    • Referral Program
    • You have found a bug. What’s next?
  • ⚙️General Settings
    • Quantower Main Toolbar
    • Workspaces
    • Single Panel
    • Link panels
    • Binds
    • Group of panels
    • Templates
    • Set as Default
    • Symbols lookup
    • Table management
    • Alerts
    • General settings
    • Custom hotkeys
    • Setup Actions & Advanced filters
    • 📢Notifications center
  • 🔗Connections
    • Connections manager
    • Connection to Binance Futures
      • Errors with Binance connection
    • Connection to CQG (AMP Futures)
      • Errors with CQG
    • Connection to OANDA
    • Connection to FXCM
    • Connection to cTrader
      • How to connect to FxPro via Quantower
      • How to connect to Pepperstone via Quantower
      • How to connect to IC Markets via Quantower
    • Connection to Rithmic
      • Rithmic Issues
    • Connection to Topstep
    • Connection to Interactive Brokers
      • Errors with Interactive Brokers
    • Connection to Bybit
    • Connection to OKEx
    • Connection to MetaStock
    • Connection to IQFeed
  • 💡Analytics Panels
    • Chart
      • Chart Overview
      • Chart Types
        • Tick Bars
        • Time aggregation
        • Renko
        • Heiken Ashi
        • Kagi
        • Points & Figures
        • Range bars
        • Line break
        • Volume Bars
        • Reversal Bars
      • Chart Settings
        • View settings
        • Data Style
        • Time Scale
        • Price Scale
        • Visual Trading
          • Positions
        • Order Entry
        • Quick Ruler
        • Info Window
        • Volume Bars
        • Hotkeys
      • Chart overlays
      • Technical indicators
        • Channels
          • Range Marker
          • Donchian Channel
          • High Low Indicator
          • Round Numbers
          • Highest High
          • Lowest Low
          • Bollinger Bands
          • Bollinger Bands Flat
          • Price Channel
          • Fair Value Gap (FVG)
          • Keltner Channel
          • Moving Average Envelope
        • Moving averages
          • Demand Index
          • Exponential Moving Average
          • FYL Indicator
          • Linearly Weighted Moving Average
          • McGinley Dynamic Indicator
          • Modified Moving Average Indicator
          • Pivot Point Moving Average Indicator
          • Regression Line Indicator
          • Simple Moving Average Indicator
          • Smoothed Moving Average Indicator
          • Guppy Multiple Moving Average Indicator
          • Trend Breakout System Indicator
          • Triple Exponential Moving Average Indicator
        • Oscillators
          • Delta Divergence Reversal
          • Aroon Indicator
          • Moving Average Convergence/Divergence
          • Awesome Oscillator
          • Accelerator Oscillator
          • %R Larry Williams
          • Momentum
          • Rate of Change
          • Relative Strength Index (RSI) Indicator
          • Relative Spread Strength (RSS)
          • Balance of Power (BOP)
          • Commodity Channel Index
        • Trend
          • Bionic Candle
          • Average Directional Movement Index (ADX) Indicator
          • Ichimoku Cloud Indicator
          • Directional Movement Index (DMI) Indicator
          • ZigZag
        • Volatility
          • Average True Range
          • Standard deviation
        • Volume
          • COT High/Low
          • Depth of Bid / Ask
          • Delta Flow
          • Delta Rotation
          • Level2 indicator
          • Abnormal Volume
          • Abnormal Trades
          • Volume Impulse
      • Drawing tools
      • Volume Analysis Tools | Volume Profiles | Footprint chart | VWAP
        • Cluster chart
        • Volume profiles
        • Time statistics
        • Time histogram
        • Historical Time & Sales
      • Power Trades
      • VWAP | Volume Weighted Average Price
      • Anchored VWAP
    • Watchlist
    • Time & Sales
    • Price Statistic
    • DOM Surface
    • Option Analytics
    • TPO Profile Chart
  • 💵Trading Panels
    • Chart Trading
    • Crypto Order Entry
    • Multiple Order Entry
    • Order Entry
      • Order entry for Bybit
      • Order Entry for CQG
      • Order Types
      • Order placing strategies
        • Local SL/TP
    • DOM Trader
      • DOM Trader Settings
        • View Settings
        • DOM Trader Columns
        • Order Entry
        • VWAP Settings
        • Positions Bar
        • Hotkeys
      • DOM Trader Columns
      • How to set up Dom for scalping
    • Copy Trading
    • Market depth
    • Trading simulator
    • Market Replay
    • FX Cell
    • Backtest & Optimize
    • Strategies manager
  • 💼Portfolio Panels
    • Positions
    • Working Orders
    • Trades
    • Orders History
    • Synthetic Symbols
    • Historical Symbols
  • 📊Information Panels
    • Account performance
    • Account info
    • Crypto balances
    • Symbol Info
    • Currencies Exposure
    • Event Log
    • RSS (News panel)
    • Reports
  • 📌Miscellaneous
    • Futures Rollover
    • History Exporter
    • Symbol Mapping Manager
    • Sessions manager
    • Live Support
    • Market Heat map
    • Stat matrix
    • Exchange times
    • Quote Board
    • Browser
    • Excel and RTD function
      • Changing RTD Throttle Interval in Excel
    • Quantower Telegram Bot
    • 🎨Themes editor
  • 🤖Quantower Algo
    • Introduction
    • Install for Visual Studio 2022
    • Strategies manager
    • Backtest & Optimize
    • Debugging in VS 2022
    • Simple Indicator
    • Simple strategy
    • Input Parameters
    • Built-In indicators access
    • Custom indicators access
    • Level2 data
    • Access Volume analysis data from indicators
    • Indicator with custom painting (GDI)
    • Access Chart from indicator
    • Using markers with indicators
    • Using Clouds in Indicator
    • Adding a custom indicator to Watchlist
    • Downloading history
    • Access to trading portfolio
    • Trading operations
    • Example: Simple Moving Average
    • Access to crypto account and balances
    • Access to advanced aggregations
    • Access to symbol/account additional fields
    • Strategy runner (deprecated)
  • 💫Customization
    • Localization
  • ⁉️FAQ
    • General Errors
Powered by GitBook
On this page
  • What is a Strategy?
  • Basic methods
  • OnCreated
  • OnRun
  • OnStop
  • OnRemove
  • OnGetMetrics
  • Example
  1. Quantower Algo

Simple strategy

How to create you first strategy and run it the Quantower trading platform

Last updated 4 years ago

In our previous articles, we showed you how to use Quantower Algo extension and write your own indicators. Now we show you how to create you first strategy and run it the Quantower trading platform.

See examples of some strategies, integrations and indicators in our

What is a Strategy?

We use the name "Strategy" for code, that can implement absolutely any logic and can be executed in Quantower. You can use strategies for the realization of trading algorithms, a specific logic of controlling closing orders (for example Trailing stop), for arbitrage between different connections, etc. We don't have any restrictions or limitations for this, moreover, we provide you access to almost all functions from our trading core.

Quantower Algo provides you with two predefined templates of strategies. We will start from a blank template, which contains only basic functions. Use "File -> New project" in the main menu of Visual Studio to open "New project" window. Type "Strategy" and you will see special project type for blank strategy:

You will get generated code with a few empty functions:

As you can see, this blank version is not related to any trading functionality - it is a just general code-basis. It is inherited of class Strategy, by this Quantower recognize that your code is compatible and can be executed in Quantower.

Basic methods

Let's go deep into the code - it contains a few methods:

OnCreated

Will be called when user select required strategy from Strategy lookup. Use this method to implement logic, that needs to be executed once on creation.

OnRun

Will be called when user press Run button in Strategy Runner panel. Use this method to set initial values before running.

OnStop

Will be called when user press Stop button in Strategy Runner panel. Use this method to clear state of your strategy (if required).

OnRemove

Will be called when user close Strategy Runner Panel or select another strategy. Use this method for final clearing used resources.

OnGetMetrics

Via this method, you can display the required information in the Strategy Panel and control your strategy. For example, you can display how many quotes were processes, or how many but or sell orders were sent, etc.

You don't need to add logic to all these methods, the most often used is a pair of OnRun/OnStop methods.

The most popular case is when you use strategy to implement some trading algorithm and you need only one instrument and one account for this. For this we have a predefined template - you can use it as a basis. Use "One symbol strategy" in "New project" window:

Now we have a little more code - strategy contains Symbol and Account input variables, which we described before. It subscribes to all type of quotes for selected symbol in OnRun() method and you can receive and process them if it required by your algorithm.

Example

Let's create some trivial example and try to run it in the Quantower platform. We will talk about retrieving current trading information and trading operations in our next articles, for the current moment, we just add counters for each type of quotes and strategy metrics for displaying in Strategy Runner panel. We will add examples of logs also - you should always use them, as it can help you to understand the current strategy state or display error information. You can specify a type of log: Info, Error or Trading.

/// <summary>
/// Variables for counting quotes amount
/// </summary>
int quotesCount = 0;
int level2Count = 0;
int lastCount = 0;

/// <summary>
/// This method will be executed when strategy receive quote
/// </summary>        
private void SymbolOnNewQuote(Symbol symbol, Quote quote)
{
    // Increase quote counter
    quotesCount++;

    // An example of standard log
    Log("Quotes received", StrategyLoggingLevel.Info);
}

/// <summary>
/// This method will be executed when strategy receive level2 quote
/// </summary>        
private void SymbolOnNewLevel2(Symbol symbol, Level2Quote level2, DOMQuote dom)
{
    // Increase quote counter
    level2Count++;

    // An example of error log
    Log("Level2 received", StrategyLoggingLevel.Error);
}

/// <summary>
/// This method will be executed when strategy receive last quote
/// </summary>        
private void SymbolOnNewLast(Symbol symbol, Last last)
{
    // Increase quote counter
    lastCount++;

    // An example of trading log
    Log("Last received", StrategyLoggingLevel.Trading);
}

/// <summary>
/// Use this method to provide run time information about your strategy. You will see it in StrategyRunner panel in trading terminal
/// </summary>
protected override List<StrategyMetric> OnGetMetrics()
{
    List<StrategyMetric> result = base.OnGetMetrics();

    // Display our counters in Strategy Runner panel             
    result.Add(new StrategyMetric() { Name = "Quotes count", FormattedValue = quotesCount.ToString() });
    result.Add(new StrategyMetric() { Name = "Level2 count", FormattedValue = level2Count.ToString() });
    result.Add(new StrategyMetric() { Name = "Last count", FormattedValue = lastCount.ToString() });

    return result;
}

Build your project, and if your Quantower Algo is properly assigned to an instance of Quantower, your strategy will be automatically copied to an appropriate folder and you will see it in Strategy Lookup window:

You need to specify the required input parameters: symbol and account and then press the "Run" button. Now your strategy is running and you will see logs and metrics, that we have added:

It is a very simple example and it provides you only basic knowledge about how strategies are working in Quantower. In our further lessons, we will show you how to create real algorithms using analysis of your current trading portfolio and trading operations.

🤖
Github repository
New project window
Source code for Strategy template
New Project window and One symbol strategy template
Now your strategy is available in the Strategies Lookup
Strategy runner panel with our running strategy