Strategy · Pine Script v6 · On the chart

PF FX 5dp - SMA20/50 cross

by pineforge-4pass· code credited to PineForge contributors 2026

This strategy generates crossover signals using SMA20 and SMA50 on the EURUSD forex pair at 5 decimal places.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code32
Settings0inputs
LicenceApache-2.0
Last update5 days ago23 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

32 lines of Pine Script v6 from special-validation/forex/symbol-fx-5dp-eurusd-01/strategy.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

strategy.pine
// This Pine Script® code is licensed under Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// © PineForge contributors 2026
//
// PF symbol/FX 5-decimal probe — plain SMA(20) vs SMA(50) crossover on a
// 5-dp forex instrument (OANDA:EURUSD, mintick 0.00001). Isolates two things
// the ETH-USDT feed cannot exercise:
//   1. 5-decimal price scale (prices ~1.0xxxx, not ~1800), so any latent
//      assumption about price magnitude / tick granularity surfaces.
//   2. Sub-pip slippage rounding: slippage=2 ticks * mintick 0.00001 = 0.00002
//      added/subtracted at fill, which must round to the 5th decimal exactly.
// strategy.close on the opposite signal keeps the position flat-or-long/flat-
// or-short with no pyramiding, so each fill is a clean single-leg adjudication.
//@version=6
strategy("PF FX 5dp - SMA20/50 cross", shorttitle="FX5DP",
     overlay=true, initial_capital=1000000, currency=currency.USD,
     commission_type=strategy.commission.percent, commission_value=0, slippage=2,
     default_qty_type=strategy.fixed, default_qty_value=1, pyramiding=1,
     process_orders_on_close=false)

fast = ta.sma(close, 20)
slow = ta.sma(close, 50)

longCond  = ta.crossover(fast, slow)
shortCond = ta.crossunder(fast, slow)

if longCond
    strategy.close("S", comment="close short")
    strategy.entry("L", strategy.long, comment="sma cross up")
if shortCond
    strategy.close("L", comment="close long")
    strategy.entry("S", strategy.short, comment="sma cross dn")

Overview

PF FX 5dp - SMA20/50 cross enters a long position when the fast SMA crosses above the slow SMA and immediately closes any existing short position. It enters a short position on the downward SMA20 cross below SMA50 and closes any existing long position. The strategy uses fixed position sizing of one unit and overlays signals directly on the price chart. It has no stop loss and no pyramiding because opposite positions close before new entries.

Details

Published by

pineforge-4pass on GitHub

Code credit

PineForge contributors 2026, as written in the script's header

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

Moving averages, Trend, Scalping

Markets

Forex

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Topics

algorithmic-tradingbacktestingparitypine-scriptpinescriptquantitative-financetest-corpustradingview

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

257 stars

This overlay strategy marks short-term turning points on the price chart and enters SPY option-style trades from them. It plots simple moving averages of highs and lows, draws up and down reversal arrows, and colors bars when a short-term extreme coincides wit

Strategy v5 TrendMoving averages Repaints
Updated 6 weeks ago · None stated GitHub repository of SPY Options Trading - Alert

This strategy generates trading signals on the 5-minute price chart using Williams Fractals for trend reversals, combined with EMA fast and slow trend filters and optional RSI confirmation. Long entries trigger on bullish fractals aligned with rising EMA and R

Strategy v5 TrendOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of 5min Williams Fractals Scalping (3commas)
53 stars

This strategy trades EUR/USD on the price chart using a fast and slow exponential moving average crossover filtered by RSI. It enters long when the fast EMA crosses above the slow EMA while RSI is above 50 and below the overbought level, and enters short on th

Strategy v6 TrendMoving averages
Updated 2 months ago · MPL-2.0 GitHub repository of EUR/USD EMA9-21 + RSI Scalping Strategy
13 stars

This strategy plots on the price chart and enters from a moving-average filter, ADX and Gann colours. Price above a 200-period EMA allows only longs; price below allows only shorts. A Gann aqua colour with ADX above a key level opens a long, and a Gann brown c

Strategy v5 TrendOscillators & momentum
Updated 1 year ago · None stated GitHub repository of Ruckard TradingZone ADX Gann

Scalping 3EMA

by rodrigo-brito
9 stars

This long-only strategy calculates three exponential moving averages with lengths of 50, 100, and 150 periods, plotting them directly on the price chart. It also calculates a 14-period RSI and MACD. The strategy opens long positions when the moving averages al

Strategy v4 TrendOscillators & momentum
Updated 5 years ago · MIT GitHub repository of Scalping 3EMA

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