Strategy · Pine Script v6 · On the chart

Forven S01508 — Simple EMA20/50 Cross

by judder659

This strategy calculates and plots a fast Exponential Moving Average (EMA) and a slow EMA directly on the main price chart.

View on GitHub

GitHub stars361on the repository
Pine versionv6current
Lines of code95
Settings5inputs
LicenceAGPL-3.0
Last updatetoday28 Oct 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

95 lines of Pine Script v6 from forven/docs/pine/simple_ema_cross_demo.pine, published under AGPL-3.0. Keep the author's credit and licence lines when you reuse it.

simple_ema_cross_demo.pine
// ============================================================================
// Simple EMA(20)/EMA(50) Cross — TradingView clone of Forven S01508
// ============================================================================
// Purpose: cross-validate Forven backtest math against TradingView.
//
// Forven side
//   strategy_id : S01508  (simple_ema_cross_demo)
//   dataset     : BTC/USDT-1h  (binance)
//   window      : 2025-04-19 17:00 UTC  →  2026-04-19 16:00 UTC  (8760 bars)
//   leverage    : 1x
//   fee model   : ~11 bps round-trip (5.5 bps per side) inferred from trades
//   entry       : ta.crossover(ema_fast, ema_slow)   on bar close
//   exit        : ta.crossunder(ema_fast, ema_slow)  on bar close
//
// How to use
//   1. Open BINANCE:BTCUSDT on the 1H chart in TradingView.
//   2. Paste this script into the Pine Editor and Add to Chart.
//   3. Open the Strategy Tester panel. The script auto-restricts trades to
//      the Forven window, so TradingView's totals should line up with
//      Forven's combined (IS + OOS) figures below.
//
// Expected Forven numbers (leverage=1x, long-only, single-side)
//                        trades   win_rate   return_pct   profit_factor   max_dd
//   In-sample (8.4m)       59       0.237      -0.188         0.686       0.268
//   Out-of-sample (3.6m)   21       0.333      +0.012         1.087       0.139
//   Combined (~1y)         80         —            —          0.793         —
//
// Math note
//   pandas  close.ewm(span=L, adjust=False).mean()
//   Pine    ta.ema(close, L)
//   are mathematically identical: EMA_t = α·src + (1−α)·EMA_{t−1},  α = 2/(L+1),
//   with EMA seeded from the first observation. Expect a handful of trades
//   of difference across the full year strictly from warmup/boundary effects.
// ============================================================================

//@version=6
strategy(
     title              = "Forven S01508 — Simple EMA20/50 Cross",
     shorttitle         = "S01508",
     overlay            = true,
     pyramiding         = 0,
     initial_capital    = 10000,
     default_qty_type   = strategy.percent_of_equity,
     default_qty_value  = 100,
     commission_type    = strategy.commission.percent,
     commission_value   = 0.055,
     slippage           = 0,
     calc_on_every_tick = false,
     process_orders_on_close = true)

// ---- Inputs ----------------------------------------------------------------
ema_fast_len = input.int(20, "EMA fast length",  minval = 2, group = "Signal")
ema_slow_len = input.int(50, "EMA slow length",  minval = 3, group = "Signal")

use_window   = input.bool(true,  "Restrict to Forven window",  group = "Date range")
// Hardcoded epoch ms (const int — Pine v6 requires this for input.time defval):
//   1745082000000 = 2025-04-19 17:00:00 UTC
//   1776614400000 = 2026-04-19 16:00:00 UTC
start_ts     = input.time(1745082000000, "Window start (UTC)", group = "Date range")
end_ts       = input.time(1776614400000, "Window end (UTC)",   group = "Date range")

// ---- Indicators ------------------------------------------------------------
ema_fast = ta.ema(close, ema_fast_len)
ema_slow = ta.ema(close, ema_slow_len)

plot(ema_fast, "EMA fast", color = color.new(color.orange, 0))
plot(ema_slow, "EMA slow", color = color.new(color.blue,   0))

// ---- Window gate -----------------------------------------------------------
in_window = not use_window or (time >= start_ts and time <= end_ts)

// ---- Signals ---------------------------------------------------------------
cross_up   = ta.crossover(ema_fast,  ema_slow)
cross_down = ta.crossunder(ema_fast, ema_slow)

if in_window and cross_up
    strategy.entry("Long", strategy.long)

if cross_down
    strategy.close("Long")

// Force-flat at window end so totals are directly comparable to Forven.
if use_window and (time > end_ts)
    strategy.close_all()

// ---- Visuals ---------------------------------------------------------------
plotshape(cross_up   and in_window, title = "Long entry",
     style = shape.triangleup,   location = location.belowbar,
     color = color.new(color.green, 0), size = size.tiny)

plotshape(cross_down, title = "Long exit",
     style = shape.triangledown, location = location.abovebar,
     color = color.new(color.red, 0),   size = size.tiny)

bgcolor(in_window ? color.new(color.blue, 92) : na, title = "In-window shading")

Overview

Forven S01508 — Simple EMA20/50 Cross enters long trades when the fast EMA crosses above the slow EMA and exits when the fast EMA crosses below the slow EMA. Inputs allow customizing the fast and slow EMA lengths and restricting execution to a defined UTC date range. The strategy relies entirely on moving average crossunder signals for exiting positions, without utilizing dedicated stop loss or take profit orders.

Details

Published by

judder659 on GitHub

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

Trend, Moving averages

Markets

Crypto

Timeframes

M15-H1

Risk Notes

  • The strategy enters trades without a stop loss

Settings

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

SettingTypeDefaultVariable
EMA fast lengthint20ema_fast_len
EMA slow lengthint50ema_slow_len
Restrict to Forven windowbooltrueuse_window
Window start (UTC)time1745082000000start_ts
Window end (UTC)time1776614400000end_ts
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

Doge SMA

by hackingthemarkets
474 stars

Doge SMA is a long-only moving-average crossover strategy drawn on the price chart. It calculates a fast and a slow simple moving average of close and enters a long position when the fast average crosses above the slow average, but only inside a user-defined s

Strategy v4 TrendMoving averages
Updated 4 years ago · None stated GitHub repository of Doge SMA
330 stars

2 EMA/SMA + RSI Strategy [Alorse] combines three configurable moving averages with a short-period Relative Strength Index filter. It plots fast, slow, and trend moving averages on the price chart. Long entries trigger when the fast moving average is above the

Strategy v4 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of 2 EMA/SMA + RSI Strategy [Alorse]

Acrypto - Weighted Strategy

by AlbertoCuadra
318 stars

This strategy plots on the price chart and opens long or short positions when a weighted score from MACD, Stochastic RSI, RSI, Supertrend and a moving-average crossover exceeds a user-set trigger. Each component has its own weight and candle delay. Entries can

Strategy v5 TrendOscillators & momentum
Updated 3 years ago · Custom licence GitHub repository of Acrypto - Weighted Strategy
257 stars

This strategy calculates dynamic support and resistance levels using pivot highs and lows alongside a custom smoothed trend filter and a 3-period EMA. It identifies entry opportunities when price breaks out relative to the trend filter and short-term EMA cross

Strategy v5 TrendSupport & resistance Repaints
Updated 6 weeks ago · None stated GitHub repository of 30s - ES 1m Strategy Candle Bar

STRG-BBForce

by harryguiacorn
219 stars

STRG-BBForce is a Bollinger Bands trend-following strategy. It calculates standard Bollinger Bands and tracks directional alignment across the upper, lower, and basis lines. When all three lines slope upward, it opens a long position and closes short positions

Strategy v5 TrendVolatility & bands
Updated 1 year ago · None stated GitHub repository of STRG-BBForce

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