Skip to content

ChipaDevTeam/PocketPine

Repository files navigation

PocketPine

PineScript → PocketOption bot bridge. Give it a PineScript, it transpiles the strategy to Python, runs it against live PocketOption data, and trades automatically via BinaryOptionsToolsV2.

How It Works

your_strategy.pine → PineTranspiler → Python Strategy
                                            ↓
PocketOption candles ←── bo2 API ──→ Engine (indicators + signals) → Trade execution
  1. You provide a .pine file with your TradingView strategy
  2. PocketPine transpiles it to a Python strategy class (with numpy-based indicators)
  3. The engine loads historical candles, warms up indicators, then streams live data
  4. When buy/sell conditions fire, trades are executed on PocketOption

Quick Start

pip install -r requirements.txt

# Transpile a PineScript and run it as a bot
python main.py --pine strategy.pine --ssid "YOUR_SSID"

# Or run a pre-built Python strategy directly
python main.py --strategy strategies.candlestick_pattern.CandlestickPatternStrategy --ssid "YOUR_SSID"

# Just transpile (no trading) to inspect the generated Python
python main.py --transpile-only strategy.pine

Modes

1. PineScript Bot (--pine)

Transpile and run a .pine file directly. The generated Python strategy is saved as *_strategy.py so you can review and tweak it.

python main.py --pine my_strategy.pine --ssid "$SSID" --asset EURUSD_otc --timeframe 60

2. Python Strategy (--strategy)

Run a hand-written or previously generated Python strategy class.

python main.py --strategy strategies.candlestick_pattern.CandlestickPatternStrategy --ssid "$SSID"

3. Transpile Only (--transpile-only)

Convert PineScript to Python without trading — useful for reviewing and customizing.

python main.py --transpile-only my_strategy.pine > my_strategy.py

4. Webhook Mode (--webhook)

Receive TradingView webhook alerts instead of running the strategy locally.

python main.py --webhook --ssid "$SSID" --port 8080

CLI Options

Flag Default Description
--pine Path to .pine file to transpile and run
--strategy Python strategy class (module.ClassName)
--transpile-only Transpile .pine to Python and print
--webhook Run as webhook server
--ssid env POCKETPINE_SSID PocketOption session ID
--asset EURUSD_otc Trading asset
--amount 1.0 Trade amount
--duration 60 Trade duration (seconds)
--timeframe 60 Candle timeframe (seconds)
--history 200 Historical bars to load for warmup
--no-check-win false Skip waiting for trade results

Writing a Custom Strategy in Python

import numpy as np
from pocketpine import indicators as ta
from pocketpine.strategy import Strategy
from pocketpine.signal_parser import Signal, Action

class MyStrategy(Strategy):
    def setup(self):
        self.p = {"fast": 10, "slow": 30}

    def compute(self):
        close = self.bars.close
        self._fast = ta.sma(close, self.p["fast"])
        self._slow = ta.sma(close, self.p["slow"])
        self._cross_up = ta.crossover(self._fast, self._slow)
        self._cross_down = ta.crossunder(self._fast, self._slow)

    def get_signal(self):
        if len(self.bars) < 3:
            return None
        if self._cross_up[-1]:
            return Signal(Action.BUY, self.asset, self.amount, self.duration)
        if self._cross_down[-1]:
            return Signal(Action.SELL, self.asset, self.amount, self.duration)
        return None

Supported PineScript Constructs

PineScript Python
ta.sma, ta.ema, ta.rsi, ta.atr indicators.sma, .ema, .rsi, .atr
ta.crossover, ta.crossunder indicators.crossover, .crossunder
ta.highest, ta.lowest, ta.stdev indicators.highest, .lowest, .stdev
math.abs, math.max, math.min np.abs, np.maximum, np.minimum
close[1] (history operator) ta.shift(close, 1)
input.int, input.float, input.bool self.p dict
and / or / not & / | / ~ (numpy)
alertcondition(buySignal, ...) → identified as signal in get_signal()

Security

  • Never expose your SSID in code — use environment variables
  • In webhook mode, use --secret to validate incoming requests

About

PocketPine is a PineScript to PocketOption bot converter

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages