Skip to main content
Cart Log in Sign up
Trading strategy

EMA Trend Strategy: EMA-cross backtest template with ATR stop

A simple, transparent EMA-cross strategy with a trend filter, ATR stop, risk-% position sizing and a session/day filter, for backtesting and study in the Strategy Tester.

Platform

License

Price

≈

Version

You own this product. Go to My products
Get the demo

  • Automatic, instant delivery once payment confirms
  • Free updates for every future version
  • 12 months of technical support
  • Refunds under a transparent policy
  • Pay with USDT, BTC, ETH and more
  • Free: no payment, download it right now

Risk warning: Trading financial markets carries a risk of losing capital, and past performance does not guarantee future results. Terms & conditions

Product type
Trading strategy
Platforms
TV
Market / symbol
Gold, FX majors, Indices, Crypto
Experience level
Intermediate
Delivery
File download from your dashboard
Last update
November 30, 2026
Broker
Any broker

Overview

This script is a template, not a system that promises profit. Its purpose is to let you see a common idea, entering on a two-EMA cross in the direction of the bigger trend, with fully defined rules in the Strategy Tester, then change it and measure the effect.

Everything is readable in the code: entries on the fast/slow EMA cross, a trend EMA filter, an ATR-multiple stop, an R-multiple target and a size based on a percent of equity at risk. A session and weekday filter lets you test, for example, London and New York hours only.

We publish no backtest results for it. Results differ for every symbol and timeframe, and a good backtest does not guarantee the future. Before reading any result, set commission and slippage in Properties to match your broker. Trading carries real risk.

  • Fast/slow EMA cross entries with an optional trend EMA filter
  • ATR stop and R-multiple target, with optional exit on the opposite cross
  • Size from percent of equity at risk, with a cap on position value
  • Session hours and weekday filter, with optional close outside the session
  • EMAs, stop and target drawn on the chart

Made by

This tool is written by the TradeKit team. The source code is open and included in the download. It is free to use.

Strategy logic

Entries

  • Long: the fast EMA crosses above the slow EMA, the close is above the trend EMA (if the filter is on), the bar is inside the session and an allowed day, and no position is open.
  • Short is the mirror. Signals are made on the bar close and orders fill at the next bar’s open.

Stop and target

  • Stop distance = ATR × multiplier, measured from the signal bar’s close.
  • Target = that distance × the R multiple. At 0 there is no fixed target.
  • With exit on opposite cross on, the trade also closes when the EMAs cross the other way.

Size

  • Size = (equity × risk %) ÷ (stop distance × syminfo.pointvalue).
  • Size is capped so position value never exceeds “max exposure × equity”, and rounded down to the quantity step if you set one.
  • If the strategy’s account currency differs from the symbol’s, TradingView’s currency conversion affects the result.

Specifications

Requirements

  • TradingView, the free plan is enough; results appear in the Strategy Tester tab
  • Set commission and slippage yourself in Properties; the defaults are zero
  • For forex, set Quantity step to match TradingView’s size units
  • For study and backtesting, not for automated live trading
Platforms
TV
Delivery
Use case
Swing، Trend following
Market
Gold، FX majors، Indices، Crypto
Experience level
Intermediate

Compatible brokers

Which brokers this product works with, and which it works best with.

Works with every broker

No broker restriction: it works with any broker that offers the product's platform.

The broker choice is yours; TradeKit is not a broker. Check account terms before depositing. All brokers

Input parameters

Input parameters
ParameterDefaultDescription
Fast EMAFast EMA length 20 Fast EMA length
Slow EMASlow EMA length; entries come from the fast EMA crossing it 50 Slow EMA length; entries come from the fast EMA crossing it
Use trend filter EMALongs only above the trend EMA, shorts only below it true Longs only above the trend EMA, shorts only below it
Trend filter EMATrend filter EMA length 200 Trend filter EMA length
DirectionTrade direction: both, long only or short only Long and short Trade direction: both, long only or short only
Risk per trade (% of equity)Percent of equity risked per trade 1.0 Percent of equity risked per trade
Stop distance (x ATR)Stop distance from entry, in ATR multiples 2.0 Stop distance from entry, in ATR multiples
Target (R multiple)Target as a multiple of the stop distance (0 = no target) 2.0 Target as a multiple of the stop distance (0 = no target)
Exit on opposite crossExit when the EMAs cross the other way true Exit when the EMAs cross the other way
Max exposure (x equity)Caps position value relative to equity, so a tight stop cannot create a huge position 1.0 Caps position value relative to equity, so a tight stop cannot create a huge position
Quantity stepRound the order size down to this step (0 = no rounding) 0.0 Round the order size down to this step (0 = no rounding)
Trade only inside sessionEnter only inside the chosen session hours false Enter only inside the chosen session hours

Install guide

  1. Unzip the download. It contains EMATrendStrategy.pine and a short readme.
  2. Open EMATrendStrategy.pine in a text editor such as Notepad and copy all of it.
  3. In TradingView open a chart and click the Pine Editor tab at the bottom of the screen.
  4. Create a new blank strategy, select all of the default code and paste over it.
  5. Click Add to chart.
  6. Click Save to keep it in your scripts, so you can add it later from the Indicators menu.

Works on the free TradingView plan; your plan’s limit on indicators per chart still applies.

Changelog

  1. v1.0.0 TV New November 30, 2026
    • Published on TradeKit

Buyer reviews

No reviews yet.

Only verified buyers can review. Reviews are moderated before publishing.

Only verified buyers can review. Reviews are moderated before publishing.

Sign in to write a review

FAQ

Is this strategy profitable?
We make no claim and publish no results. On some symbols and periods it may show a profit and on others a loss. Use it to learn and to build your own idea.
Why does the backtest differ from live trading?
A backtest does not fully simulate variable spread, real slippage, outages or your own in-the-moment decisions. Enter commission and slippage in Properties to bring the numbers closer to reality.
Why are no trades opened?
Usually the size rounded down to zero. Lower Quantity step or set it to 0, or raise the initial capital. Check the session and day filters too.
What is Max exposure for?
With a very tight stop, the risk-% formula can produce a position worth several times the account. This caps position value at a multiple of equity. Raise it if you test with leverage.
Can I connect it to a bot?
Technically yes, through strategy alerts and a webhook, but this code was written for backtesting and study and has not been tested for automated live execution.

Related products

More Strategies and tools from the same family

Compare Compare now