How the Pembe Strategy Editor works
start programming with a simple strategy
start programming with a simple strategy
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:
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:
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.
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 SMA_10_50(backtrader.Strategy):
The first line again defines the class in the same concept as described in 'Getting Started'
def __init__(self):
The beginning of the strategy. the concept is described in this Backtrader documentary section:
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:
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: