This repository contains Python code implementing a Supertrend trading strategy. The Supertrend is a trend-following indicator that helps identify trend direction and potential entry and exit points in the market.
The code consists of several functions:
- fetch_asset_data: Fetches historical OHLC (Open-High-Low-Close) data for a specified asset from a cryptocurrency exchange.
- supertrend: Calculates the Supertrend indicator based on the input OHLC data and a specified ATR (Average True Range) multiplier.
- generate_signals: Generates buy/sell signals based on Supertrend values.
- create_positions: Creates buy/sell positions based on the generated signals.
- plot_data: Plots the Supertrend indicator along with buy/sell positions on a candlestick chart.
- strategy_performance: Evaluates the performance of the trading strategy, including overall profit/loss, maximum drawdown, and other metrics.
- plot_performance_curve: Plots the performance curve of the strategy against a benchmark.
- Ensure you have the necessary dependencies installed (
ccxt
,pandas
,numpy
,pandas_ta
,mplfinance
). - Replace the
symbol
,start_date
,interval
, andexchange
variables with your desired asset, start date, interval, and exchange. - Adjust the
volatility
parameter for the Supertrend calculation. - Run the script to fetch data, apply the Supertrend strategy, evaluate performance, and visualize results.
ccxt
: For fetching cryptocurrency exchange data.pandas
,numpy
: For data manipulation and analysis.pandas_ta
: For technical analysis indicators.mplfinance
: For plotting candlestick charts.matplotlib
: For additional plotting functionalities.
- This code is provided for educational purposes only. Trading involves risk, and past performance is not indicative of future results. Always perform thorough testing and analysis before implementing any trading strategy in live markets.
For any questions or inquiries, please contact: Geofrey at ntalegeofrey@gmail.com.