Strategy · Pine Script v6 · On the chart

USD/JPY Carry Trend [trugurpala]

by trugurpala

This strategy trades USD/JPY on the price chart during Tokyo and London sessions.

View on GitHub

GitHub stars4on the repository
Pine versionv6current
Lines of code92
Settings8inputs
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

92 lines of Pine Script v6 from global-markets/21_usdjpy_carry_trend.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

21_usdjpy_carry_trend.pine
//@version=6
// USD/JPY — Carry Trade Trend Following Strategy
// Author: Ugur Pala · github.com/trugurpala/pinescriptv6
// TradingView: https://tr.tradingview.com/u/trugurpala/
//
// TR: USD/JPY için özel carry trade trend stratejisi.
//     Tokyo ve Londra seanslarında çalışır.
//     BOJ müdahalelerine karşı geniş ATR stop kullanır.
//     Hızlı trend değişimlerinde pozisyon kapatır.
// EN: Carry trade trend strategy specific to USD/JPY.
//     Active during Tokyo and London sessions.
//     Wide ATR stop as protection against BOJ interventions.
//     Exits on fast trend reversal signals.
//
// Sembol / Symbol: FX:USDJPY / OANDA:USDJPY
// Önerilen TF / Recommended TF: 1H, 4H
strategy("USD/JPY Carry Trend [trugurpala]",
    overlay           = true,
    initial_capital   = 10000,
    default_qty_type  = strategy.percent_of_equity,
    default_qty_value = 2,
    commission_type   = strategy.commission.percent,
    commission_value  = 0.005,
    slippage          = 1)

// ── Inputs ───────────────────────────────────────────────────────────────────
int   fastLen   = input.int(9,    "Fast EMA",              minval=1)
int   slowLen   = input.int(21,   "Slow EMA",              minval=1)
int   trendLen  = input.int(100,  "Trend EMA",             minval=20)
int   rsiLen    = input.int(14,   "RSI",                   minval=1)
float rsiMid    = input.float(50, "RSI Mid",               minval=40, maxval=60)
int   atrLen    = input.int(14,   "ATR",                   minval=1)
float slMult    = input.float(2.5, "SL Mult (wide/BOJ)",   step=0.1)
float tpMult    = input.float(3.0, "TP Mult",              step=0.1)

// ── Tokyo + London Seans ──────────────────────────────────────────────────────
bool tokyo      = not na(time(timeframe.period, "0000-0900", "GMT"))
bool london     = not na(time(timeframe.period, "0800-1600", "GMT"))
bool inSession  = tokyo or london

// ── Calculations ─────────────────────────────────────────────────────────────
float fastEma   = ta.ema(close, fastLen)
float slowEma   = ta.ema(close, slowLen)
float trendEma  = ta.ema(close, trendLen)
float rsi       = ta.rsi(close, rsiLen)
float atrVal    = ta.atr(atrLen)

bool upTrend    = close > trendEma and fastEma > slowEma
bool downTrend  = close < trendEma and fastEma < slowEma

bool longEntry  = ta.crossover(fastEma, slowEma)
                    and upTrend and rsi > rsiMid
                    and inSession and strategy.position_size == 0

bool shortEntry = ta.crossunder(fastEma, slowEma)
                    and downTrend and rsi < rsiMid
                    and inSession and strategy.position_size == 0

// ── Entries ──────────────────────────────────────────────────────────────────
if longEntry
    strategy.entry("Long", strategy.long)
    strategy.exit("Long Exit", "Long",
        stop  = close - slMult * atrVal,
        limit = close + tpMult * atrVal)

if shortEntry
    strategy.entry("Short", strategy.short)
    strategy.exit("Short Exit", "Short",
        stop  = close + slMult * atrVal,
        limit = close - tpMult * atrVal)

// Trend bozulunca kapat / Close on trend break
if strategy.position_size > 0 and ta.crossunder(fastEma, slowEma)
    strategy.close("Long",  comment="Trend Break")
if strategy.position_size < 0 and ta.crossover(fastEma, slowEma)
    strategy.close("Short", comment="Trend Break")

// ── Visuals ──────────────────────────────────────────────────────────────────
plot(fastEma,  "Fast",  fastEma > slowEma ? color.green : color.red,    linewidth=1)
plot(slowEma,  "Slow",  fastEma > slowEma ? color.lime  : color.orange, linewidth=2)
plot(trendEma, "Trend", color.new(color.gray, 30),                      linewidth=2)
bgcolor(tokyo and london ? color.new(color.purple, 93) :
        inSession         ? color.new(color.blue,   96) :
                            color.new(color.gray,   97))
plotshape(longEntry,  "Long",  shape.triangleup,   location.belowbar, color.green, size=size.normal)
plotshape(shortEntry, "Short", shape.triangledown, location.abovebar, color.red,   size=size.normal)

// ── Alerts (alert() — strategy içinde çalışır) ───────────────────────────────
if longEntry
    alert("USD/JPY Carry Trend Long — " + str.tostring(close, "#.###"), alert.freq_once_per_bar)
if shortEntry
    alert("USD/JPY Carry Trend Short — " + str.tostring(close, "#.###"), alert.freq_once_per_bar)

Overview

USD/JPY Carry Trend [trugurpala] enters long when the fast EMA crosses above the slow EMA while price is above the trend EMA and RSI is above its midpoint, and it enters short on the opposite cross. Position size is two percent of equity. Exits place an ATR stop and a wider ATR take profit from the entry close. The main settings change EMA lengths, the RSI midpoint, ATR length, and the stop and target multiples. It only enters while flat and inside those sessions.

Details

Published by

trugurpala on GitHub

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

Trend, Moving averages, Oscillators & momentum, Sessions & time

Markets

Forex

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
Trend EMAint100trendLen
RSIint14rsiLen
RSI Midfloat50rsiMid
ATRint14atrLen
SL Mult (wide/BOJ)float2.5slMult
TP Multfloat3.0tpMult
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

106 stars

This intraday strategy enters positions based on an alignment of trend, momentum, and oscillator indicators. It triggers long entries when the Commodity Channel Index is above a positive threshold, a fast Relative Strength Index crosses above a slow RSI, price

Strategy v5 TrendOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of CCI + EMA with RSI Cross Strategy

Session Wicks

by g-moe
3 stars

This strategy calculates smoothed Heikin-Ashi candles alongside a moving average of the Relative Strength Index to enter trend reversals. It triggers long entries when smoothed Heikin-Ashi turns bullish while RSI trades above its moving average, and short entr

Strategy v5 TrendOscillators & momentum
Updated 5 months ago · None stated GitHub repository of Session Wicks
1 stars

This session-based strategy triggers long entries at the start of the New York trading session when trend and momentum conditions align. It calculates a 38-period Exponential Moving Average and a 14-period RSI. A long position is taken at session open if the c

Strategy v6 Sessions & timeTrend
Updated 5 days ago · Apache-2.0 GitHub repository of PineForge — Borough New York Session
1 stars

This intraday trading strategy combines fast, slow, and trend exponential moving averages with MACD, RSI, and ADX filters to generate trade signals during active trading sessions. It enters long positions when the fast EMA crosses above the slow EMA above the

Strategy v6 TrendOscillators & momentum
Updated 5 months ago · None stated GitHub repository of Señales Intradía EMA + MACD v3
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

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