Strategy · Pine Script v4 · On the chart

EMA Cross Crypto Strategy

by fox-buddy· code credited to liquid

The script is a Pine Script v4 strategy that generates buy and sell signals from crossovers of fast EMA (period 5) and slow EMA (period 10).

View on GitHub

GitHub stars4on the repository
Pine versionv4older, still runs
Lines of code148
Settings9inputs
LicenceNone statedfile: MPL-2.0
Last update2 years ago4 Aug 2024

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

148 lines of Pine Script v4 from Tradingview/CryptoEmaCross_Weekly.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

CryptoEmaCross_Weekly.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// This strategy has been created for illustration purposes only and should not be relied upon as a basis for buying, selling, or holding any asset or security.
// © liquid

//@version=4
strategy(
     "EMA Cross Crypto Strategy", overlay=true)



//********************
//****** Inputs ******
//********************
emaFastPeriod = input(title="Fast EMA", type=input.integer, defval=5, minval=1, maxval=9999)
emaSlowPeriod = input(title="Slow EMA", type=input.integer, defval=10, minval=1, maxval=9999)
//emaStopPeriod = input(title="Stop EMA", type=input.integer, defval=34, minval=1, maxval=9999)
smaStopper = input(title="SMA Stopper", type=input.integer, defval=8, minval=1, maxval=9999)
tradeDirection = input(title="Trade Direction", options=["Long", "Short", "Both"], defval="Long")

dateFrom = input(title="Start Date", type=input.time, defval=timestamp("01 Jan 2020 00:00"))
dateTo = input(title="End Date", type=input.time, defval=timestamp("31 Dec 2170 23:59"))

hammerCandleTolerance = input(title="Hammer Body-Wick Faktor", type=input.float, defval=0.8, minval=0.5, step=0.1)
starCandleTolerance = input(title="Shooting Star Body-Wick Faktor", type=input.float, defval=0.8, minval=0.5, step=0.1)
candleVolumeFilter = input(title="Candle Volumenverhältnis zur vorherigen Candle", type=input.float, defval=0.8, minval=1.0, step=0.1)

// *******************************
// ******** Functions *********
// *******************************
isHammerCandle() =>
    candleWickLength = iff(close<open, high-open, high-close)
    candleFuseLength = iff(close<open, close-low, open-low)
    candleBodylength = iff(close<open, open-close, close-open)
    //hammer body size will me multiplied with this value. Reult is the maximum allowd wick lenght
    hammerCandleWickToBodyMaximum = hammerCandleTolerance  
    
    isHammer = (candleWickLength < candleBodylength*hammerCandleWickToBodyMaximum) and (candleFuseLength >= 1.9*candleBodylength)
    isHammer
    
isShootingStarCandle() =>
    candleWickLength = iff(close<open, high-open, high-close)
    candleFuseLength = iff(close<open, close-low, open-low)
    candleBodylength = iff(close<open, open-close, close-open)
    //Shooting Star body size will me multiplied with this value. Reult is the maximum allowd wick lenght
    shootingStarCandleWickToBodyMaximum = starCandleTolerance  
    
    isShootingStar = (candleFuseLength < candleBodylength*shootingStarCandleWickToBodyMaximum) and (candleWickLength >= 1.9*candleBodylength)
    isShootingStar
    
isBullishEngulfingCandle() =>
    lastCandleWasRed = close[1] < open[1]
    lastCandleWasGreen = not lastCandleWasRed
    iAmGreen = close > open
    iAmRed = not iAmGreen
    
    isBullishEngulfing = lastCandleWasRed and iAmGreen and (open<=close[1]) and (close>=open[1])
    isBullishEngulfing

isBearishEngulfingCandle() =>
    lastCandleWasRed = close[1] < open[1]
    lastCandleWasGreen = not lastCandleWasRed
    iAmGreen = close > open
    iAmRed = not iAmGreen
    
    isBearishEngulfing = lastCandleWasGreen and iAmRed and (open>=close[1]) and (close<=open[1])
    isBearishEngulfing
    
isWickLonger() => 
    candleWickLength = iff(close<open, high-open, high-close)
    candleFuseLength = iff(close<open, close-low, open-low)
    
    relationIndicator = candleWickLength >= candleFuseLength
    relationIndicator
    
isFuseLonger() => 
    candleWickLength = iff(close<open, high-open, high-close)
    candleFuseLength = iff(close<open, close-low, open-low)
    
    relationIndicator = candleFuseLength > candleWickLength
    relationIndicator

//********************
//******* Calc *******
//********************
fastEMA = ema(close, emaFastPeriod)
slowEMA = ema(close, emaSlowPeriod)
stopperSMA = sma(close, smaStopper)

rsiValue = rsi(close, 14)

// volumeSum = 0.0
// for counter = 0 to 45
//     volumeSum := volumeSum + volume[counter]
// volumeAverage = volumeSum / 46 
// volumeFactor = 2.5

isUptrendPhase = fastEMA > slowEMA
isDownTrendPhase = fastEMA < slowEMA

//********************
//***** Plotting *****
//********************
plot(series=fastEMA, color=color.orange, linewidth=2)
plot(series=slowEMA, color=color.purple, linewidth=2)
plot(series=stopperSMA, color=color.black, linewidth=2)

//Plotting special candles
plotchar(isHammerCandle() and isDownTrendPhase, char='H', color=color.green, size=size.small)
plotchar(isBullishEngulfingCandle() and isDownTrendPhase, char='E', color=color.green, size=size.small)
//plotchar(isWickLonger() and isDownTrendPhase, char='W', color=color.red, size=size.small)
plotchar(isShootingStarCandle() and isUptrendPhase, char='S', color=color.red, size=size.small)
plotchar(isBearishEngulfingCandle() and isUptrendPhase, char='E', color=color.red, size=size.small)
//plotchar(isWickLonger() and isUptrendPhase, char='F', color=color.red, size=size.small)


plotshape(rsiValue > 75 and isUptrendPhase, color=color.red, style=shape.circle, location=location.belowbar, size=size.small)
plotshape(rsiValue < 30 and isUptrendPhase, color=color.green, style=shape.circle, location=location.belowbar, size=size.small)
//********************
//****** Trading *****
//********************
// Check if the close time of the current bar falls inside the date range
inDateRange = (time >= dateFrom) and (time < dateTo)

// Translate input into trading conditions
longOK  = (tradeDirection == "Long") or (tradeDirection == "Both")
shortOK = (tradeDirection == "Short") or (tradeDirection == "Both")

// Decide
longCondition = crossover(fastEMA, slowEMA) or crossover(fastEMA, stopperSMA) 
shortCondition = crossunder(fastEMA, slowEMA) or crossunder(fastEMA, stopperSMA)
longStopCondition= crossunder(fastEMA, stopperSMA)
shortStopCondition= crossover(fastEMA, stopperSMA)



// ORDERS:

// Submit entry (or reverse) orders
if (longCondition and inDateRange)
    strategy.entry(id="long", long=true, when = longOK)
if (shortCondition and inDateRange)
    strategy.entry(id="short", long=false, when = shortOK)
    
// Submit exit orders in the cases where we trade only long or only short
if (strategy.position_size > 0 and longStopCondition)
    strategy.exit(id="exit long", stop=close)
if (strategy.position_size < 0 and shortStopCondition)
    strategy.exit(id="exit short", stop=close)

Overview

EMA Cross Crypto Strategy overlays signals directly on the price chart for cryptocurrency trading. Additional filters check for hammer candles, shooting stars, bullish and bearish engulfing patterns, and candle volume ratios to refine signals. The strategy allows selection of long, short, or both trade directions with start and end date filters. Main settings adjust EMA periods, candle tolerances, and volume ratios. It draws no indicators in a separate pane. Limitations include incomplete entry and exit logic in the source and no defined stop loss.

Details

Published by

fox-buddy on GitHub

Code credit

liquid, as written in the script's header

Type

Strategy, Pine Script v4

Draws

On the price chart

Category

Trend, Moving averages, Candlestick patterns

Markets

Crypto

Timeframes

Any timeframe

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
Fast EMAint5emaFastPeriod
Slow EMAint10emaSlowPeriod
SMA Stopperint8smaStopper
Trade DirectionstringLongtradeDirection
Start Datetimetimestamp("01 Jan 2020 00:00")dateFrom
End Datetimetimestamp("31 Dec 2170 23:59")dateTo
Hammer Body-Wick Faktorfloat0.8hammerCandleTolerance
Shooting Star Body-Wick Faktorfloat0.8starCandleTolerance
Candle Volumenverhältnis zur vorherigen Candlefloat0.8candleVolumeFilter
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

Pin Bar Magic v1

by Alorse
330 stars

This strategy trades price action pin bar patterns aligned with moving average trend alignment on the main price chart. It defines uptrends or downtrends using a fan arrangement of three moving averages (6 EMA, 18 EMA, and 50 SMA). Entry conditions require a b

Strategy v4 Candlestick patternsTrend
Updated 2 months ago · None stated GitHub repository of Pin Bar Magic v1
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 calculates and plots smoothed Heikin-Ashi candles directly onto the main price chart using exponential moving averages of open, high, low, and close prices. It enters a long position after three consecutive bullish smoothed candles with sequentia

Strategy v4 TrendMoving averages
Updated 2 years ago · GPL-3.0 GitHub repository of Abdoli's Heikin Ashi Smoothed Buy & Sell Strategy Rev.4

DI Engulfing A002

by ruckard
13 stars

This strategy executes trades based on candlestick engulfing patterns aligned with a 200-period exponential moving average trend filter. It enters long positions when a bullish engulfing candle follows three consecutive bearish candles while price trades above

Strategy v5 Candlestick patternsTrend
Updated 1 year ago · None stated GitHub repository of DI Engulfing A002
7 stars

This strategy combines Ichimoku Kinko Hyo components, a Stochastic oscillator, and specific candlestick patterns to generate trade signals. It identifies Kumo twists and range breakouts while evaluating candle body shapes using Fibonacci threshold filters. Tra

Strategy v4 TrendOscillators & momentum
Updated 2 years ago · MIT GitHub repository of Soulevement / Ressaut 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