Skip to content

Commit 139b509

Browse files
committed
feat: updated strategy format
1 parent a1a8cce commit 139b509

21 files changed

+248
-586
lines changed

README.md

-5
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,3 @@ The following is a list of demo strategies provided in this repository. The conf
4949
- `macd.yaml` MACD Crossover Trend Strategy (from the website [tutorials](https://kieran-mackle.github.io/AutoTrader/tutorials/strategy))
5050
- `ema_crossover.yaml`/`long_ema_crossover.yaml` EMA Crossover Strategy (long only example plus long/short Forex example)
5151
- `supertrend.yaml` SuperTrend Trend Detector ([AutoScan demo](https://kieran-mackle.github.io/AutoTrader/2021/09/27/developing-scanner.html))
52-
- `MTF_ema_crossover.yaml` Multiple timeframe EMA Crossover example
53-
- `rebalance.yaml` Portfolio rebalancing example
54-
55-
### Requesting a Strategy
56-
Have a strategy you would like to be automated? Request it [here](https://github.com/kieran-mackle/autotrader-demo/issues/new?assignees=&labels=&template=strategy-request.md&title=%5BSTRATEGY+REQUEST%5D).

config/MTF_ema_crossover.yaml

-15
This file was deleted.

config/ema_crossover.yaml

-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ NAME: 'EMA Crossover'
22
MODULE: 'ema_crossover'
33
CLASS: 'EMAcrossOver'
44
INTERVAL: '1h'
5-
PERIOD: 300
6-
RISK_PC: 2
7-
SIZING: 'risk'
85
PARAMETERS:
96
slow_ema: 50
107
fast_ema: 21

config/long_ema_crossover.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ NAME: 'EMA Crossover'
22
MODULE: 'long_ema_crossover'
33
CLASS: 'LongEMAcrossOver'
44
INTERVAL: '1h'
5-
PERIOD: 300
6-
RISK_PC: 90
7-
SIZING: 'risk'
8-
INCLUDE_BROKER: True
95
PARAMETERS:
106
slow_ema: 20
117
fast_ema: 10

config/macd.yaml

-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ NAME: 'MACD Trend Strategy'
22
MODULE: 'macd'
33
CLASS: 'SimpleMACD'
44
INTERVAL: '1h'
5-
PERIOD: 300
6-
RISK_PC: 1
7-
SIZING: 'risk'
85
PARAMETERS:
96
ema_period: 200
107
MACD_fast: 12

config/rebalance.yaml

-19
This file was deleted.

config/sma_momentum.yaml

-15
This file was deleted.

config/supertrend.yaml

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
NAME: 'SuperTrend Scanner'
2-
MODULE: 'alt_supertrend'
2+
MODULE: 'supertrend'
33
CLASS: 'SuperTrendScan'
44
INTERVAL: '1d'
5-
PERIOD: 200
6-
RISK_PC: 1.5
7-
SIZING: 'risk'
85
PARAMETERS:
96
ema_period: 200
107
candle_tol: 10
8+
RR: 2.0
119
WATCHLIST: ['EURUSD=X']

indiview.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1+
# """This is an example of using AutoTraders plotting module."""
12
from datetime import datetime
2-
from autotrader import AutoData, AutoPlot, indicators
3+
from autotrader import AutoTrader, AutoPlot, indicators
34

45

5-
# Instantiate GetData class
6-
get_data = AutoData(data_source="yahoo")
6+
# Instantiate AutoTrader and configure the exchange to trade on/immitate
7+
at = AutoTrader()
8+
at.configure(broker="ccxt:bybit")
79

8-
# Get price data for EUR/USD
9-
instrument = "EURUSD=X"
10-
data = get_data.fetch(
10+
# Run AutoTrader to get the broker connection(s)
11+
broker = at.run()
12+
13+
# Get candles
14+
instrument = "ETH/USDT"
15+
data = broker.get_candles(
1116
instrument=instrument,
12-
granularity="1h",
13-
start_time=datetime(2021, 1, 1),
14-
end_time=datetime(2021, 3, 1),
17+
granularity="1d",
18+
start_time=datetime(2023, 1, 1),
19+
end_time=datetime(2024, 2, 1),
1520
)
1621

1722
# Construct indicators dictionary

manual.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""Example script to use AutoTrader for manual trading via API.
2+
3+
It is recommeded that you run this in an interactive environment, such
4+
as IPython. Otherwise, you must copy and paste these commands in a
5+
Python terminal, rather than just running the script.
6+
7+
This is a good way to play around and test things before automating them
8+
in a strategy.
9+
"""
10+
11+
from autotrader import AutoTrader, Order
12+
13+
14+
# Instantiate AutoTrader and configure the exchange to trade on/immitate
15+
at = AutoTrader()
16+
at.configure(broker="ccxt:bybit")
17+
18+
# If you want to simulate trading on the exchange (but use real data from it),
19+
# configure a virtual account:
20+
at.virtual_account_config(verbosity=1, exchange="ccxt:bybit", leverage=10)
21+
22+
# Note that if you exclude the line above, you will connect to the real
23+
# exchange specified.
24+
25+
# Run AutoTrader to get the broker connection(s)
26+
broker = at.run()
27+
28+
# If you configured a virtual account above, the broker here will be an instance
29+
# of the Virtual broker. Otherwise, it will be a real exchange connection (eg.
30+
# bybit above), assuming you have provided valid keys.
31+
32+
# Now you can interact with the broker
33+
book = broker.get_orderbook("BTC/USDT:USDT")
34+
print(book.midprice)
35+
36+
# Create an order:
37+
# o = Order("MAGIC/USDT:USDT", direction=1, size=1)
38+
# broker.place_order(o)

run.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from autotrader import AutoTrader
2+
3+
# Create AutoTrader instance, configure it, and run backtest
4+
at = AutoTrader()
5+
at.configure(verbosity=1, show_plot=True, feed="yahoo")
6+
# at.add_strategy("long_ema_crossover")
7+
# at.add_strategy("ema_crossover")
8+
at.add_strategy("macd")
9+
at.backtest(start="1/6/2023", end="1/2/2024", localize_to_utc=True)
10+
at.virtual_account_config(initial_balance=1000, leverage=30)
11+
at.run()

run_scan.py

-9
This file was deleted.

runfile.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
# Create AutoTrader instance, configure it, and run backtest
44
at = AutoTrader()
55
at.configure(verbosity=1, show_plot=True, feed="yahoo")
6-
at.add_strategy("ema_crossover")
7-
at.backtest(start="1/1/2021", end="1/5/2022")
6+
at.add_strategy("sma_momentum")
7+
# at.add_strategy("ema_crossover")
8+
at.backtest(start="1/6/2023", end="1/2/2024", localize_to_utc=True)
89
at.virtual_account_config(initial_balance=1000, leverage=30)
910
at.run()

strategies/MTF_ema_crossover.py

-79
This file was deleted.

strategies/alt_supertrend.py

-92
This file was deleted.

0 commit comments

Comments
 (0)