Strategy · Pine Script v6 · On the chart

Fakeout-Confirmed Strategy

by trugurpala

This trend-following strategy generates long and short entries when a fast EMA crosses a slow EMA, overlaying directly on the price chart.

View on GitHub

GitHub stars4on the repository
Pine versionv6current
Lines of code170
Settings16inputs
LicenceMIT
Last update2 months ago3 Aug 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

170 lines of Pine Script v6 from examples/strategies/13_fakeout_confirmed_strategy.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

13_fakeout_confirmed_strategy.pine
//@version=6
// Fakeout-Confirmed Strategy — 4 Filter Layers
// Author: Ugur Pala · github.com/trugurpala/pinescriptv6
// TradingView: https://tr.tradingview.com/u/trugurpala/
//
// TR: Dört yapılandırılabilir fakeout filtresi kullanan sinyal stratejisi.
// EN: Signal strategy with four configurable fakeout filters.
// Önerilen TF: 15M, 1H, 4H

// LESSONS_LEARNED kontrol listesi:
// ✅ alertcondition() yok → alert() kullanıldı
// ✅ calc_on_every_tick yok: bar-close calculation setting; fill, data, and cost assumptions remain.
// ✅ barstate.isconfirmed + table → uyarısız, kapanmış barda güncellenir
// ✅ Çok satırlı "and" yok → tek satır
// ✅ [1] + lookahead_on is a confirmed HTF pattern only when the requested timeframe is higher than the chart; this code does not enforce that relation.

strategy("Fakeout-Confirmed Strategy [trugurpala]",
    overlay            = true,
    initial_capital    = 10000,
    default_qty_type   = strategy.percent_of_equity,
    default_qty_value  = 5,
    commission_type    = strategy.commission.percent,
    commission_value   = 0.1,
    slippage           = 2)

// ── Inputs — Strateji ─────────────────────────────────────────────────────────
int   fastLen  = input.int(9,     "Fast EMA",   minval=1, group="Strateji / Strategy")
int   slowLen  = input.int(21,    "Slow EMA",   minval=1, group="Strateji / Strategy")
int   atrLen   = input.int(14,    "ATR",        minval=1, group="Strateji / Strategy")
float slMult   = input.float(2.0, "SL (ATR×)", step=0.1, group="Strateji / Strategy")
float tpMult   = input.float(3.0, "TP (ATR×)", step=0.1, group="Strateji / Strategy")
bool  longOnly = input.bool(false, "Long Only",           group="Strateji / Strategy")

// ── Inputs — F1: Hacim ───────────────────────────────────────────────────────
bool  useVol   = input.bool(true,  "Hacim Filtresi",      group="F1: Hacim / Volume")
int   volLen   = input.int(20,    "Volume MA", minval=5,  group="F1: Hacim / Volume")
float volMult  = input.float(1.5,  "Volume Mult", step=0.1, group="F1: Hacim / Volume")

// ── Inputs — F2: Bar Onayı ───────────────────────────────────────────────────
bool  useBar   = input.bool(true,  "Bar Onayı",           group="F2: Bar")
int   barConf  = input.int(1,     "Kaç Bar", minval=1, maxval=5, group="F2: Bar")

// ── Inputs — F3: HTF Trend ───────────────────────────────────────────────────
bool   useHTF  = input.bool(true,  "HTF Filtresi",        group="F3: HTF")
string htfTF   = input.string("60", "HTF TF", options=["15","30","60","240","D"], group="F3: HTF")
int    htfLen  = input.int(50,    "HTF EMA", minval=10,   group="F3: HTF")

// ── Inputs — F4: ATR Gürültü ─────────────────────────────────────────────────
bool  useATR   = input.bool(true,  "ATR Gürültü",         group="F4: ATR")
float atrNoise = input.float(0.3,  "Min Move (ATR×)", step=0.05, group="F4: ATR")

// ── Hesaplamalar ──────────────────────────────────────────────────────────────
float fastEma = ta.ema(close, fastLen)
float slowEma = ta.ema(close, slowLen)
float atrVal  = ta.atr(atrLen)
float volAvg  = ta.sma(volume, volLen)
// [1] + lookahead_on is a confirmed HTF pattern only when the requested timeframe is higher than the chart; this code does not enforce that relation.
float htfEma  = request.security(syminfo.tickerid, htfTF, ta.ema(close, htfLen)[1], lookahead=barmerge.lookahead_on)

// ── 4 Filtre ─────────────────────────────────────────────────────────────────
bool f1_vol   = not useVol or volume > volAvg * volMult
bool f2_htfL  = not useHTF or close > htfEma
bool f2_htfS  = not useHTF or close < htfEma
bool f4_noise = not useATR or math.abs(close - close[1]) > atrVal * atrNoise

// ── Ham Sinyaller ─────────────────────────────────────────────────────────────
bool rawLong  = ta.crossover(fastEma, slowEma)
bool rawShort = ta.crossunder(fastEma, slowEma)

// ── Bar Onayı ─────────────────────────────────────────────────────────────────
var int barCountL = -1
var int barCountS = -1

if rawLong
    barCountL := 0
if rawShort
    barCountS := 0
if barCountL >= 0 and barCountL < barConf
    barCountL += 1
if barCountS >= 0 and barCountS < barConf
    barCountS += 1

bool barConfL = not useBar or (barCountL == barConf and close > slowEma)
bool barConfS = not useBar or (barCountS == barConf and close < slowEma)

// ── Final Sinyaller — LESSONS_LEARNED: tek satır, "and" başta değil ──────────
bool longEntry  = (useBar ? barConfL : rawLong) and f1_vol and f2_htfL and f4_noise
bool shortEntry = (useBar ? barConfS : rawShort) and f1_vol and f2_htfS and f4_noise and not longOnly

// ── Girişler ──────────────────────────────────────────────────────────────────
if longEntry and strategy.position_size == 0
    strategy.entry("Long", strategy.long)
    strategy.exit("Long Exit", "Long",
        stop           = close - slMult * atrVal,
        limit          = close + tpMult * atrVal,
        comment_loss   = "SL",
        comment_profit = "TP")

if shortEntry and strategy.position_size == 0
    strategy.entry("Short", strategy.short)
    strategy.exit("Short Exit", "Short",
        stop           = close + slMult * atrVal,
        limit          = close - tpMult * atrVal,
        comment_loss   = "SL",
        comment_profit = "TP")

// ── Alertler — LESSONS_LEARNED: alert() kullan, alertcondition() değil ───────
if longEntry
    alert("FC LONG — " + syminfo.ticker + " @ " + str.tostring(close, "#.##"), alert.freq_once_per_bar)
if shortEntry
    alert("FC SHORT — " + syminfo.ticker + " @ " + str.tostring(close, "#.##"), alert.freq_once_per_bar)

// ── Görseller ────────────────────────────────────────────────────────────────
plot(fastEma, "Fast EMA", fastEma > slowEma ? color.green : color.red,    linewidth=1)
plot(slowEma, "Slow EMA", fastEma > slowEma ? color.lime  : color.orange, linewidth=2)
plot(htfEma,  "HTF EMA",  color.new(color.gray, 40), linewidth=1)

plotshape(longEntry,  "Long",  shape.triangleup,   location.belowbar, color.green, size=size.normal)
plotshape(shortEntry, "Short", shape.triangledown,  location.abovebar, color.red,   size=size.normal)
plotshape(rawLong  and not longEntry,  "Raw Long (filtered)",  shape.circle, location.belowbar, color.new(color.green, 70), size=size.tiny)
plotshape(rawShort and not shortEntry, "Raw Short (filtered)", shape.circle, location.abovebar, color.new(color.red,   70), size=size.tiny)

// ── Filtre Tablosu — barstate.isconfirmed, 0 warning ────────────────────────
var table ft = table.new(
    position.top_right, 2, 6,
    bgcolor      = color.new(color.black, 70),
    border_width = 2,
    frame_color  = color.new(color.gray, 50),
    frame_width  = 2)

if barstate.isconfirmed
    // Başlık
    table.cell(ft, 0, 0, "◈ FİLTRE",
        bgcolor=color.new(color.navy, 20), text_color=color.white,
        text_size=size.normal, text_halign=text.align_left, width=10)
    table.cell(ft, 1, 0, "DURUM",
        bgcolor=color.new(color.navy, 20), text_color=color.white,
        text_size=size.normal, text_halign=text.align_center, width=7)
    // F1 Hacim
    table.cell(ft, 0, 1, "F1  Hacim",
        bgcolor=color.new(color.gray, 80), text_color=color.white, text_size=size.normal)
    table.cell(ft, 1, 1, useVol ? (f1_vol ? "  ✓" : "  ✗") : " OFF",
        text_color=useVol ? (f1_vol ? color.lime : color.red) : color.gray,
        bgcolor=color.new(color.gray, 80), text_size=size.large)
    // F2 HTF
    table.cell(ft, 0, 2, "F2  HTF Trend",
        bgcolor=color.new(color.gray, 82), text_color=color.white, text_size=size.normal)
    table.cell(ft, 1, 2, useHTF ? (f2_htfL ? "  ✓" : "  ✗") : " OFF",
        text_color=useHTF ? (f2_htfL ? color.lime : color.red) : color.gray,
        bgcolor=color.new(color.gray, 82), text_size=size.large)
    // F3 Bar
    table.cell(ft, 0, 3, "F3  Bar Onayı",
        bgcolor=color.new(color.gray, 80), text_color=color.white, text_size=size.normal)
    table.cell(ft, 1, 3, useBar ? (barConfL ? "  ✓" : "  ✗") : " OFF",
        text_color=useBar ? (barConfL ? color.lime : color.red) : color.gray,
        bgcolor=color.new(color.gray, 80), text_size=size.large)
    // F4 ATR
    table.cell(ft, 0, 4, "F4  ATR Gürültü",
        bgcolor=color.new(color.gray, 82), text_color=color.white, text_size=size.normal)
    table.cell(ft, 1, 4, useATR ? (f4_noise ? "  ✓" : "  ✗") : " OFF",
        text_color=useATR ? (f4_noise ? color.lime : color.red) : color.gray,
        bgcolor=color.new(color.gray, 82), text_size=size.large)
    // Sinyal
    string sigText = longEntry ? "▲  LONG" : shortEntry ? "▼  SHORT" : "—  BEKLE"
    color  sigBg   = longEntry ? color.new(color.green, 30) : shortEntry ? color.new(color.red, 30) : color.new(color.gray, 60)
    color  sigFg   = longEntry ? color.lime : shortEntry ? color.red : color.silver
    table.cell(ft, 0, 5, "◉  SİNYAL",
        bgcolor=sigBg, text_color=color.white, text_size=size.large, text_halign=text.align_left)
    table.cell(ft, 1, 5, sigText,
        text_color=sigFg, bgcolor=sigBg, text_size=size.large, text_halign=text.align_center)

Overview

To reduce false signals, it applies four configurable fakeout filters: volume moving average threshold, consecutive bar confirmation, higher-timeframe EMA trend alignment, and minimum ATR move size. Strategy exits are managed using ATR-multiplier stop loss and take profit targets. Configurable inputs allow users to toggle long-only mode, adjust filter thresholds, and modify EMA lengths.

Details

Published by

trugurpala on GitHub

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

Trend, Moving averages, Volatility & bands, Volume

Markets

Any symbol

Timeframes

M15-H1, H4 and above

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

aialgorithmic-tradingclaude-codecodexcoding-agentsgithub-copilotopen-sourcepine-scriptpine-script-v6technical-analysis

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Fast EMAint9fastLen
Slow EMAint21slowLen
ATRint14atrLen
SL (ATR×)float2.0slMult
TP (ATR×)float3.0tpMult
Long OnlyboolfalselongOnly
Hacim FiltresibooltrueuseVol
Volume MAint20volLen
Volume Multfloat1.5volMult
Bar OnayıbooltrueuseBar
Kaç Barint1barConf
HTF FiltresibooltrueuseHTF
Show all 16 settings
SettingTypeDefaultVariable
HTF TFstring60htfTF
HTF EMAint50htfLen
ATR GürültübooltrueuseATR
Min Move (ATR×)float0.3atrNoise
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

Prototype

by hasnocool
106 stars

This strategy overlays Supertrend-style ATR trailing stop levels on the price chart alongside multi-period moving averages, volume metrics, and Bollinger Bands. It flags trend direction changes using an ATR offset channel, plotting buy and sell signals directl

Strategy v4 TrendVolatility & bands
Updated 2 years ago · GPL-3.0 GitHub repository of Prototype

This strategy enters long or short when eight conditions align over the last two bars. It requires EMA 10 and EMA 55 alignment on the one-hour, four-hour and daily charts, a positive ADX slope, matching monitor direction, and price relative to a 400-bar point

Strategy v5 TrendMoving averages
Updated 1 year ago · None stated GitHub repository of Ruckard ABCBitcoin TradingLatino B002
8 stars

This overlay strategy combines three distinct SuperTrend levels with multiple moving averages and volume profile analytics on the main price chart. It calculates trend directions using three configurable ATR periods and multipliers alongside SMA, EMA, and HMA

Strategy v5 TrendVolatility & bands
Updated 4 years ago · None stated GitHub repository of ATR 3Lvls VP Strategy
2 stars

This overlay strategy enters long when a fast EMA crosses above a slow EMA, the candle closes above the fast EMA and above its open, and volume is at least a set multiple of its SMA. Position size defaults to 95 percent of equity with no pyramiding. It exits w

Strategy v5 TrendMoving averages
Updated 8 weeks ago · None stated GitHub repository of EMA20/50 ATR Trail Spot

My First Indicator

by wynnforthework
2 stars

This strategy plots EMA 25 in yellow and EMA 100 in green on the price chart. It generates buy signals on EMA 25 crossing above EMA 100 when ATR length 14 rises over two prior bars and volume exceeds prior bar. It opens a long position of 1 unit on signal. It

Strategy v5 Moving averagesTrend
Updated 1 year ago · None stated GitHub repository of My First Indicator
2 stars

The SuperTrend Regime Confluence strategy combines an adaptive SuperTrend indicator with market regime detection to generate trading signals. It computes a composite conviction score using an ADX regime lookback, a trend EMA, and a volume moving average. Trade

Strategy v6 TrendVolatility & bands
Updated 2 weeks ago · MIT GitHub repository of SuperTrend Regime Confluence

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers