A Python-based backtesting engine with a custom scripting system inspired by TradingView's Pine Script
Project description
FirScript
A modular scripting engine designed for algo trading. Write PineScript-like python code to define strategies, indicators, and libraries — then plug them into a clean, scriptable engine that does the orchestration for you.
💡 Why FirScript?
Building your own backtesting stack?
FirScript gives you a flexible core to run strategy and indicator code, manage dependencies, and control execution — without locking you into one opinionated interface.
- ✅ Write strategy logic as regular Python scripts
- ⚙️ Parse, register, and run strategies dynamically
- 🧹 Bring your own data, namespaces, and post-processors
- 🛠️ Easily embed into larger trading and backtesting systems or apps
- 🧪 Perfect for research, prototyping, and integration into custom trading platforms
Table of Contents
Getting Started
📦 Installation
pip install FirScript talipp pandas numpy
🚀 Quick Start
from FirScript import Engine
strategy_source = '''
def setup():
global fast_length, slow_length
fast_length = input.int("Fast MA Length", 10)
slow_length = input.int("Slow MA Length", 20)
def process():
if ta.crossover(ta.ema(data.all.close, fast_length), ta.ema(data.all.close, slow_length)):
strategy.long()
'''
data = pd.DataFrame({
'timestamp': pd.date_range('2025-01-01', periods=50),
'open': [100 + 0.5*i + random.random() for i in range(50)],
'close': [100 + 0.5*i + random.random() for i in range(50)],
'high': [100 + 0.5*i + random.random() for i in range(50)],
'low': [100 + 0.5*i + random.random() for i in range(50)],
'volume': [100 + 0.5*i + random.random() for i in range(50)]
})
engine = Engine(data, main_script_str=strategy_source)
results = engine.run()
print(results)
TADA - You just ran your first strategy!
💡 Examples
Want to see it in action? Explore these ready-to-run examples in the examples folder:
- Simple Strategy – A basic trading strategy to get you started.
- Simple Indicator – How to define and use a custom indicator.
- Simple Library – Create reusable components with a simple library.
- Importing Indicators Into Strategy – Combine indicators into your strategy logic.
- Using Libraries In Strategy – Integrate libraries directly into your strategies.
- Custom Namespace – Extend your functionality using custom namespaces.
🧠 Namespaces, Your Way
FirScript ships with default namespaces (ta, input, chart, color, data, strategy) — but you can register your own.
class MySignals:
@staticmethod
def crossover(fast, slow):
return (fast > slow) & (fast.shift() < slow.shift())
registry.register("signals", MySignals())
Now your script can do:
if signals.crossover(ema_fast, ema_slow):
strategy.long()
Check out the full implementation here.
🧹 Who is FirScript for?
- Build your own backtesting UI or cloud platform
- Dynamically load and run user-submitted strategies
- Combine with Pandas, Plotly, or any data science tool
- Use as a logic core for live or paper trading systems
🚫 What FirScript Isn't
- ❌ A charting library (use Plotly, Matplotlib, etc.)
- ❌ A full broker API or execution engine
- ❌ A replacement for full frameworks like Backtrader — FirScript is lean, modular, and pluggable
🤝 Contribute
We welcome issues, ideas, and PRs — especially if you're building on top of this engine.
📖 License
FirScript is licensed under a MIT license.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file firscript-1.0.0.tar.gz.
File metadata
- Download URL: firscript-1.0.0.tar.gz
- Upload date:
- Size: 29.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eaf131548d9540f05e5dc867cd78cd43a49553689a0c34e37f81d4b4fbab3ad3
|
|
| MD5 |
fb815dcfbdfd17a215dccb25c4d3fdc7
|
|
| BLAKE2b-256 |
76b0bb6837ffb27ced80fcad346ce073cf9a376d146787aeff697fcca272b8d2
|
File details
Details for the file firscript-1.0.0-py3-none-any.whl.
File metadata
- Download URL: firscript-1.0.0-py3-none-any.whl
- Upload date:
- Size: 21.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e4985fc1503d079cd93634b4062fef836b780c957b11b8bbaab517dd3c065b29
|
|
| MD5 |
9617acdd4c8221e88b5178e9999b01eb
|
|
| BLAKE2b-256 |
72bc8ad47f82e55e4fdf9aeb99451e7c1d518a5f058336e40aa0a3750ada1b50
|