Immediate priorities
- Fix position sizing to calculate BTC quantity correctly.
- Add stop loss and take profit to every trade.
- Implement daily loss limits and trade frequency caps.
- Add EMA buffer and trend strength confirmation.
Supertrend Strategy
Pine Script v4 | Binance BTC/USDT | Report generated December 2024
Overview
Priority actions, guardrails, and validation gates.
Roadmap
Six phased path from critical fixes to full automation.
Position sizing, risk controls, parameter alignment.
Completed2 to 3 years data, parameter tuning, realistic costs.
CurrentLive data, real time signals, no real money.
NextAPI integration, order execution, monitoring.
NextMicro positions, 10 to 20% capital, monitor closely.
NextScale to full capital, continuous monitoring.
NextStep 2 - Backtesting & optimization
~5 months
Goal: Make the strategy functionally correct and safe to test.
Deliverable: Updated Pine Script with all critical fixes implemented.
Goal: Validate strategy performance and optimize parameters.
Success criteria: Sharpe ratio above 1.0, max drawdown under 25%, profit factor above 1.3.
Deliverable: Comprehensive backtest report with optimized parameters.
Goal: Test strategy in real time without risking capital.
Success criteria: 2 to 3 months of profitable paper trading, performance within 80% of backtest.
Deliverable: Paper trading journal with all trades documented and analyzed.
Goal: Create autonomous system for order execution.
Technical stack options:
Core components to build:
Security considerations:
Deliverable: Fully functional trading bot tested on testnet.
Goal: Validate bot in production with minimal risk.
What to watch for:
Success criteria: 2 months profitable, max drawdown under 15%, no critical bugs.
Deliverable: Proven bot operation with real money, full trade log analysis.
Goal: Scale to full intended capital with confidence.
Ongoing maintenance:
When to pause or stop:
Total: ~6 months minimum from current broken state to full autonomous trading.
Findings
These blockers must be resolved before any live testing.
The strategy calculates position size in contracts without accounting for BTC price, which leads to zero or incorrect positions.
floor(0.46) = 0 contracts, no position is entered.
Why it fails: The formula divides USD risk by USD distance, giving a ratio instead of BTC quantity. It must convert to actual BTC units.
No safety mechanisms are protecting capital today:
$230 max loss with 20 max contracts creates dangerous misalignment:
The strategy instantly flips long and short on every signal, causing:
Fixes
Implementation-level changes to make the strategy safe to test.
Replace the broken contract calculation with proper BTC quantity calculation.
// Option A: Risk percentage of equity
risk_percent = input(2.0, title="Risk % Per Trade") / 100
equity = strategy.equity
risk_amount = equity * risk_percent
// Calculate USD position size based on risk
position_size_usd = risk_amount / risk_per_unit_long
// Convert to BTC quantity
btc_qty = position_size_usd / close
strategy.entry("Long", strategy.long, qty=btc_qty)
// Option B: Fixed USD notional
usd_position_size = input(1000, title="Position Size USD")
btc_qty = usd_position_size / close
strategy.entry("Long", strategy.long, qty=btc_qty)
Protect every trade with proper risk management.
// Stop loss at Supertrend line
stop_loss_long = up
stop_loss_short = dn
// Take profit at 2:1 risk reward ratio
risk_long = close - stop_loss_long
take_profit_long = close + (risk_long * 2.0)
risk_short = stop_loss_short - close
take_profit_short = close - (risk_short * 2.0)
// Apply to entry orders
strategy.entry("Long", strategy.long, qty=btc_qty)
strategy.exit("Exit Long", "Long",
stop=stop_loss_long, limit=take_profit_long)
Prevent catastrophic losing streaks.
// Track daily P and L
max_daily_loss = input(500, title="Max Daily Loss USD")
var float daily_pnl = 0.0
var int current_day = dayofmonth
// Reset at start of new day
if (dayofmonth != current_day)
daily_pnl := 0.0
current_day := dayofmonth
// Update with closed trade results
if (strategy.closedtrades > 0)
last_trade = strategy.closedtrades.profit(strategy.closedtrades - 1)
daily_pnl := daily_pnl + last_trade
// Block new trades if limit hit
allow_trades = daily_pnl > -max_daily_loss
if (longCondition and allow_trades)
strategy.entry("Long", strategy.long, qty=btc_qty)
Prevent overtrading in choppy conditions.
// Minimum bars between trades
min_bars_between = input(10, title="Min Bars Between Trades")
var int last_trade_bar = 0
can_trade = bar_index - last_trade_bar >= min_bars_between
if (longCondition and can_trade)
strategy.entry("Long", strategy.long, qty=btc_qty)
last_trade_bar := bar_index
// Maximum trades per day
var int trades_today = 0
var int last_day = 0
if (dayofmonth != last_day)
trades_today := 0
last_day := dayofmonth
max_daily_trades = input(5, title="Max Trades Per Day")
if (longCondition and trades_today < max_daily_trades)
strategy.entry("Long", strategy.long, qty=btc_qty)
trades_today := trades_today + 1
Add buffer zone to reduce whipsaws around the 200 EMA.
// Create buffer zone around EMA
ema_buffer_percent = input(0.5, title="EMA Buffer %") / 100
ema_upper = ema200 * (1 + ema_buffer_percent)
ema_lower = ema200 * (1 - ema_buffer_percent)
// Stricter entry conditions
longCondition = crossover(close, dn) and close > ema_upper
shortCondition = crossunder(close, up) and close < ema_lower
// Optional: Add trend strength confirmation
ema_slope = ema200 - ema200[10]
strong_uptrend = ema_slope > 0
strong_downtrend = ema_slope < 0
longCondition = longCondition and strong_uptrend
shortCondition = shortCondition and strong_downtrend
Strategy
How the system operates and when it performs best.
This is a trend following reversal system that aims to stay in the market at all times, flipping between long and short positions based on Supertrend crossovers filtered by the 200 EMA.
Long entry: Price crosses above lower Supertrend band and price is above 200 EMA.
Short entry: Price crosses below upper Supertrend band and price is below 200 EMA.
Thrives in:
Struggles in:
Binance BTC/USDT futures:
Risk
Operational, market, and behavioral risks to plan for.
The current implementation has fundamental flaws that could result in:
Backtested does not equal real trading: Parameters optimized for past data often fail forward. Markets change, volatility regimes shift, and correlation structures break down.
60 to 70% chop time: Most markets spend the majority of time ranging or consolidating. Trend following strategies make money 30 to 40% of the time and bleed slowly the rest.
Psychological warfare: Following a system through a 30% drawdown requires discipline most traders do not have. Many abandon strategies right before they become profitable.
Historical backtests cannot account for:
Halt the strategy if any of these occur: