10
min

How the Pembe Strategy Editor works

start programming with a simple strategy


Getting Started



The editor is the heart of the APP. The strategies can be developed there and a backtest can be carried out directly on historical data As a basis for developing the strategies, we use the open source Python module:

  • Backtrader

All functions of backtrader can be used. Here is the link to the official backtrader documentation:

The first class is always predefined in the editor:

  • class Testclasse_uWuWYxpq(backtrader.Strategy):

This is for simplification and rapid development of the strategy. It is possible to insert its indicators directly after the class. The first line in the editor should therefore not be changed.

Example

class SMA_10_50(backtrader.Strategy):

    def __init__(self):
        ma_fast = backtrader.ind.SMA(period=10)
        ma_slow = backtrader.ind.SMA(period=50)
        self.crossover = backtrader.ind.CrossOver(ma_fast, ma_slow)

    def next(self):
        if not self.position:
            if self.crossover > 0:
                self.buy()
        elif self.crossover < 0:
            self.close()

Class

class SMA_10_50(backtrader.Strategy):

The first line again defines the class in the same concept as described in 'Getting Started'

Strategy

def __init__(self):

The beginning of the strategy. the concept is described in this Backtrader documentary section:


Indicators

ma_fast = backtrader.ind.SMA(period=10
ma_slow = backtrader.ind.SMA(period=50
self.crossover = backtrader.ind.CrossOver(ma_fast, ma_slow)

This part of the code defines the indicators used. In this example, a simple moving average is used. how the indicators work is explained in the following section:

A list of all available predefined indicators with reference can be found here:

Orders

def next(self):
    if not self.position:
        if self.crossover > 0:                  
            self.buy()              
    elif self.crossover < 0:                
        self.close()

In the last part of the strategy, the orders are defined. A detailed description of the orders can be found here:

source:

Foto from Uriel SC at Unsplash

Joshua Denefleh

CQO & Co-Founder

Strong background in financial markets, graduate from University Mannheim in B.Sc. Economics, KIT Karlsruhe University. Experience in quantitative methods, programming algo /w python