Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Indicators to Strategy Blueprint

Here is the architectural breakdown for transforming the “Pro Scalper: Liquidation Mirror” indicator into a production-ready automated execution framework.

1. Execution Triggers (Entry & Direction)

The core logic of the indicator identifies potential exhaustion points, which we will use as our primary entry signals. The goal is to enter after the liquidation spike bar has closed, confirming the event.

Execution Nuances:

2. Multi-Tiered Exit Logic

A static exit strategy is insufficient. We will implement a dynamic, multi-layered approach to manage the trade from inception to completion.

3. Capital Allocation & Risk Management

Position sizing is the most critical component for long-term viability. We will move from fixed-lot sizing to a dynamic risk-based model.

4. Implementation Snippet (Pine Logic)

This snippet demonstrates the transition from the indicator to a professional strategy, incorporating the architectural components discussed above.

//@version=5
// STRATEGY DECLARATION: From Indicator to a full-fledged execution engine
strategy("Pro Scalper: Liquidation Mirror (Strategy)", 
     overlay=true, 
     pyramiding=0, // No pyramiding for this reversal strategy
     process_orders_on_close=true, // Ensures signals are confirmed before execution
     default_qty_type=strategy.calculated, // Enables risk-based position sizing
     commission_value=0.05, // Example commission per trade (in currency)
     slippage=2) // Example slippage in ticks

// ============================================================================
// 1. INPUTS (Original + New Risk/Exit Inputs)
// ============================================================================
// --- Original Inputs
grp_trend    = "Trend Filter"
emaLength    = input.int(50, "Macro EMA Length", group=grp_trend)
stFactor     = input.float(3.0, "Supertrend Factor", group=grp_trend)
stPeriod     = input.int(10, "Supertrend Period", group=grp_trend)
grp_rev      = "Reversal Logic"
breakoutLen  = input.int(20, "Lookback Length (High/Low)", group=grp_rev)
volLimit     = input.float(1.5, "Liquidation Vol Multiplier", step=0.1, group=grp_rev)
adxMin       = input.int(30, "Min ADX (Trend Strength)", group=grp_rev)

// --- New Risk & Exit Management Inputs
grp_risk     = "Risk & Exit Management"
riskPercent  = input.float(1.0, "Risk per Trade (%)", minval=0.1, maxval=10, group=grp_risk)
atrLen       = input.int(14, "ATR Length (for Stops)", group=grp_risk)
stopAtrMult  = input.float(2.0, "Stop Loss ATR Multiplier", group=grp_risk)
tpRr         = input.float(1.5, "Take Profit R:R", group=grp_risk, tooltip="Initial Take Profit based on Risk/Reward ratio.")
maxBarsInTrade = input.int(120, "Max Bars in Trade (Stagnation Exit)", group=grp_risk)

// ============================================================================
// 2. CORE CALCULATIONS (Unchanged + ATR)
// ============================================================================
macroEma = ta.ema(close, emaLength)
[_, direction] = ta.supertrend(stFactor, stPeriod)
[_, _, adx] = ta.dmi(14, 14)
[_, _, hist] = ta.macd(close, 12, 26, 9)
volSma = ta.sma(volume, 20)
isLiquidation = volume > (volSma * volLimit) 
momentumFade = (hist > 0 and hist < hist[1] * 1.02) or (hist < 0 and hist > hist[1] * 1.02)
adxHigh = adx > adxMin
recentHigh = ta.highest(high[1], breakoutLen)
recentLow  = ta.lowest(low[1], breakoutLen)
atr = ta.atr(atrLen)

// ============================================================================
// 3. ENTRY & EXIT LOGIC
// ============================================================================
// --- Entry Conditions
topEscaping = (direction < 0) and (high >= recentHigh) and isLiquidation and adxHigh and momentumFade
bottomFishing = (direction > 0) and (low <= recentLow) and isLiquidation and adxHigh and momentumFade

// --- Position Sizing Calculation
stopLossPoints = atr * stopAtrMult * syminfo.pointvalue
dollarRisk = (riskPercent / 100) * strategy.equity
positionSize = dollarRisk / stopLossPoints

// --- Execute Trades
if (strategy.position_size == 0) // Only take new trades if flat
    // LONG ENTRY
    if (bottomFishing)
        stopLossPrice = low - (atr * stopAtrMult)
        takeProfitPrice = close + (close - stopLossPrice) * tpRr
        strategy.entry("Long", strategy.long, qty=positionSize)
        strategy.exit("Long Exit", from_entry="Long", stop=stopLossPrice, limit=takeProfitPrice)

    // SHORT ENTRY
    if (topEscaping)
        stopLossPrice = high + (atr * stopAtrMult)
        takeProfitPrice = close - (stopLossPrice - close) * tpRr
        strategy.entry("Short", strategy.short, qty=positionSize)
        strategy.exit("Short Exit", from_entry="Short", stop=stopLossPrice, limit=takeProfitPrice)

// --- Time-Based Exit (Stagnation)
if (strategy.position_size != 0 and bar_index - strategy.opentrades.entry_bar_index(0) > maxBarsInTrade)
    strategy.close_all(comment="Stagnation Exit")

// --- EOD Exit (Example for US Equities session)
isEod = hour(time_close, "America/New_York") == 15 and minute(time_close, "America/New_York") >= 45
if isEod
    strategy.close_all(comment="EOD Exit")

// ============================================================================
// 4. VISUALS (Plotting stops and TPs for verification)
// ============================================================================
plot(strategy.position_size > 0 ? strategy.opentrades.entry_price(0) : na, "Entry Price", color.yellow, style=plot.style_linebr)
plot(strategy.position_size != 0 ? strategy.opentrades.stop_price(0) : na, "Stop Loss", color.red, style=plot.style_linebr)
plot(strategy.position_size != 0 ? strategy.opentrades.limit_price(0) : na, "Take Profit", color.green, style=plot.style_linebr)