Skip to main content

FirScript

PyPI License

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:


🧠 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.

Contributing Guide

📖 License

FirScript is licensed under a MIT license.

Metadata

Release files for firscript 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for firscript 1.0.0
File Size Uploaded
firscript-1.0.0.tar.gz 29.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for firscript 1.0.0
File Interpreter ABI Platform
firscript-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 51.1 kB

Release files / firscript-1.0.0.tar.gz

Download URL firscript-1.0.0.tar.gz
Size 29.2 kB
Tags Source
SHA-256 checksum
How to use checksums
eaf131548d9540f05e5dc867cd78cd43a49553689a0c34e37f81d4b4fbab3ad3
BLAKE2b-256 checksum
How to use checksums
76b0bb6837ffb27ced80fcad346ce073cf9a376d146787aeff697fcca272b8d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / firscript-1.0.0-py3-none-any.whl

Download URL firscript-1.0.0-py3-none-any.whl
Size 21.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e4985fc1503d079cd93634b4062fef836b780c957b11b8bbaab517dd3c065b29
BLAKE2b-256 checksum
How to use checksums
72bc8ad47f82e55e4fdf9aeb99451e7c1d518a5f058336e40aa0a3750ada1b50
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page