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

Based on the provided indicator script, here is the architectural blueprint for its transformation into a production-ready, automated execution framework.

1. Execution Triggers (Entry & Direction)

The original script’s logic is based on a three-bar pattern that must complete at the end of a 15-minute block on a 5-minute chart. This confirmation is based on the closing price of the third bar.

Execution Nuances

2. Multi-Tiered Exit Logic

The original script’s “auto SL” is a static stop based on the pattern’s extremity. A professional framework requires a more dynamic and comprehensive exit plan.

3. Capital Allocation & Risk Management

Position sizing will be dynamic, ensuring that each trade risks a consistent, predefined percentage of total account equity.

4. Implementation Snippet (Pine Logic)

This snippet demonstrates the conversion of the indicator into a strategy incorporating the architectural principles above.

//@version=5
// Transformed from Indicator to a full Strategy Framework
strategy(
     "Pro Execution: 3-Bar Reversal", 
     overlay=true, 
     process_orders_on_close=true, // CRITICAL: Execute on bar close to match logic
     initial_capital=100000,
     commission_type=strategy.commission.percent,
     commission_value=0.075, // Realistic commission
     slippage=2 // Realistic slippage in ticks
)

// --- Risk Management Inputs ---
riskPercent = input.float(1.0, "Risk per Trade %", minval=0.1, maxval=5.0)
rrRatio = input.float(2.0, "Take Profit Risk/Reward Ratio", minval=0.5)
useEodExit = input.bool(true, "Use End-of-Day Exit?")
eodExitTime = input.int(1545, "EOD Exit Time (HHMM)")

// === Original 3-Candle Reversal Logic ===
is5min = timeframe.period == "5"
isNewDay = ta.change(time("D"))

// Simplified block logic for clarity
isThirdBarOf15Min = minute % 15 == 10 and is5min // e.g., 9:10, 9:25, 9:40 -> bar closes at 9:15, 9:30, 9:45

c0g = close[2] > open[2]
c1r = close[1] < open[1]
c2r = close < open
c0r = close[2] < open[2]
c1g = close[1] > open[1]
c2g = close > open

buySignal = isThirdBarOf15Min and c0r and c1g and c2g and close > high[2]
sellSignal = isThirdBarOf15Min and c0g and c1r and c2r and close < low[2]

// === Execution & Risk Calculation ===
if (strategy.position_size == 0) // Only enter if flat
    // --- Long Entry ---
    if (buySignal)
        longStopPrice = ta.lowest(low, 3)
        initialRiskPerShare = close - longStopPrice
        
        if (initialRiskPerShare > 0)
            capitalToRisk = strategy.equity * (riskPercent / 100)
            positionSize = capitalToRisk / initialRiskPerShare
            longTakeProfitPrice = close + (initialRiskPerShare * rrRatio)
            
            strategy.entry("Long", strategy.long, qty=positionSize)
            strategy.exit("Exit Long", from_entry="Long", stop=longStopPrice, limit=longTakeProfitPrice)

    // --- Short Entry ---
    if (sellSignal)
        shortStopPrice = ta.highest(high, 3)
        initialRiskPerShare = shortStopPrice - close

        if (initialRiskPerShare > 0)
            capitalToRisk = strategy.equity * (riskPercent / 100)
            positionSize = capitalToRisk / initialRiskPerShare
            shortTakeProfitPrice = close - (initialRiskPerShare * rrRatio)

            strategy.entry("Short", strategy.short, qty=positionSize)
            strategy.exit("Exit Short", from_entry="Short", stop=shortStopPrice, limit=shortTakeProfitPrice)

// === Time-Based Exit Logic ===
isTradingSession = time(timeframe.period, "0930-1600")
isEod = isTradingSession and (hour * 100 + minute >= eodExitTime)

if (useEodExit and isEod and strategy.position_size != 0)
    strategy.close_all(comment="EOD Exit")

// --- Visuals for confirmation ---
plot(strategy.position_size != 0 ? strategy.opentrades.entry_price(strategy.opentrades - 1) : na, "Entry Price", color.blue, style=plot.style_linebr)