Sansa trading system C# port. An algorithmic trading system developed using TradingMotion SDK platform http://sdk.tradingmotion.com
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Sansa
markdown_files
LICENSE
README.md
Sansa.sln

README.md

Sansa Trading Strategy

Table of Contents

Overview

Sansa is a trading algorithm written in C# using the TradingMotion SDK development tools (there is a VB.net port too).

OHLC example chart Image footnote: Example of Sansa OHLC financial chart showing some automatic trades

The strategy code is all contained in SansaStrategy.cs, including a default parameter combination.

This default parameter combination has been optimized to run over a 100' bars main chart and 120' bars secondary chart of Euro-Bund Future.

Trading a maximum of 1 contract of Euro-Bund Future, this is how performed (hypothetically) from 2001 to 2016:

Net P&L chart Image footnote: Hypothetic Net P&L chart for Sansa strategy

Anyway, go open Visual Studio, clone the project and start with the trading algo development! Sure you can do better and improve all these figures :)

Sansa Trading Rules

Sansa's trading plan is quite simple. It buys 1 contract when the weighted moving average short period of seconday chart breaks above the weighted moving average long period of main chart.

While Sansa has a position in the market, it places two exit orders. A Stop Loss order and a Take Profit.

To sum up

Sansa Trading Strategy rules:

  * Entry: Weighted moving average short period (secondary chart) breaks above the weighted moving average long period (main chart).
  * Exit: Set a fixed Stop Loss and a Take Profit (objective)
  * Filters: None

Show me the code

Here is a simplified C# source code of Sansa's OnNewBar() function. The complete code is all contained in SansaStrategy.cs along with comments and definition of parameters.

var indSlowWma = (WMAIndicator)GetIndicator("Slow WMA");
var indFastWma = (WMAIndicator)GetSecondaryChart(0).GetIndicator("Fast WMA");
            
if (GetOpenPosition() == 0)
{
    //We're flat. Check if current bar contains a golden cross
    if (indFastWma.GetWMA()[0] > indSlowWma.GetWMA()[0] && //Check if Fast weighted moving average is higher than Slow moving average in current bar
        indFastWma.GetWMA()[1] < indSlowWma.GetWMA()[1]) //Check if Fast weighted moving average was lower than Slow moving average in previous bar
    {
        //Going Long (Buying 1 Contract at Market price)
        Buy(OrderType.Market, 1, 0, "Open long position");
        log.Info("Open long position " + Bars.Bars[0].Close);
    }
}

//Place Take-Profit and Stop-Loss orders
PlaceExitOrders();
 
protected void PlaceExitOrders()
{
    if (GetOpenPosition() > 0)
    {
        var ticksTakeProfit = (int)GetInputParameter("Ticks Take-Profit");
        var ticksStopLoss = (int)GetInputParameter("Ticks Stop-Loss");

        var takeProfitLevel = GetFilledOrders()[0].FillPrice + (ticksTakeProfit * Symbol.TickSize);
        var stopLossLevel = GetFilledOrders()[0].FillPrice - (ticksStopLoss * Symbol.TickSize);

        ExitLong(OrderType.Limit, Symbol.RoundToNearestTick(takeProfitLevel), "Take Profit " + takeProfitLevel);
        ExitLong(OrderType.Stop, Symbol.RoundToNearestTick(stopLossLevel), "Stop Loss " + stopLossLevel);
    }
}

Download

First of all, make sure you have Visual Studio 2010 version (or higher). TradingMotion SDK is fully compatible with Visual Studio Express free versions.

Download the windows desktop application TradingMotionSDK Toolkit installer.

Quick Start

  • Create a free account to access TradingMotionAPI (required). It can be created from TradingMotionSDK Toolkit (the desktop application)
  • Clone the repository:
git clone https://github.com/victormartingarcia/sansa-trading-strategy-csharp
  • Open Visual Studio and load solution Sansa/Sansa.sln
  • Edit app.config file adding your TradingMotionAPI credentials on appSettings section

And you're all set!

Running the project (F5) will perform a development backtest simulation over last 6 months DAX 60' bars data.

Once it has finished, it will ask if you want to see the P&L report in TradingMotionSDK Toolkit. Pressing 'y' will load the same backtest with the desktop app, where it will show performance statistics, charts, and so on.

User Manual

More documentation in the Getting Started Guide

About iSystems

iSystems by TradingMotion is a marketplace for automated trading systems.

iSystems has partnered with 11 international brokers (and counting) that offer these trading systems to their clients (both corporate and retail) who pay for a license fee that the developer charges.

The trading systems run with live market data under a controlled environment in iSystems' datacenters.

This way the developers just need to worry about how to make their trading systems better and iSystems platform does the rest.

Visit Developers section on TradingMotion's website for more info on how to develop and offer your systems.

Disclaimer

I am R&D engineer at TradingMotion LLC, and head of TradingMotion SDK platform. Beware, the info here can be a little biased ;)