Strategy · Pine Script v5 · On the chart

Crossing EMAs D

by ruckard

Crossing EMAs D is a moving average crossover strategy designed to automate trade execution through Zignaly webhook and email integration.

View on GitHub

GitHub stars13on the repository
Pine versionv5runs as is
Lines of code64
Settings15inputs
LicenceNone statedfile: MPL-2.0
Last update1 year ago2 Mar 2025

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

64 lines of Pine Script v5 from scripts/zignaly_tutorial/crossing_emas/crossing_emas_d_every_input.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

crossing_emas_d_every_input.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ruckard

//@version=5
strategy("Crossing EMAs D", overlay=true, margin_long=100, margin_short=100)

import ruckard/ZignalyBeta/21 as zig

i_showDebugLabels = input.bool(true, '(DEBUG) Show Debug Labels? {True}')

i_zignalyServiceSecretKey = input.string('MYSECRETKEY', '(ZIG) Service Secret Key {MYSECRETKEY}')

_ZIGEXTYPESPOT_ = 'spot', _ZIGEXFUTURES_ = 'futures'
i_zignalyExchangeType = input.string(_ZIGEXFUTURES_, '(ZIG) Exchange Type {Futures}', options=[_ZIGEXFUTURES_, _ZIGEXTYPESPOT_])

i_CapitalPercentage = input.float(25.0, title='(CAPITAL) Capital percentage invested per order (%) {25.0}', minval=0, step=0.01) * 0.01

i_zignalyLeverage = input.int(1, '(ZIG) Leverage {1}', minval=1, step=1, maxval=125)

i_enableTakeProfit = input.bool(false, '(STOPTAKE) Take Profit? {false}')
i_takeProfit = input.float(1.1, title='(STOPTAKE) Take Profit % {3.0}')
i_takeProfitPerOne = i_takeProfit / 100

i_enableStopLoss = input.bool(true, '(STOPTAKE) Stop Loss? {True}')
i_stopLoss = input.float(7.0, title='(STOPTAKE) Stop Loss % {7.0}', minval=0.01) / 100
i_stopLossPercentage = i_stopLoss * 100.0

i_enableTrailingTakeProfit = input.bool(false, title='(TRAILING) Enable Trailing Take Profit (%) {False}')
i_trailingTakeProfitPercentageTrigger = input.float(1.2, '(TRAILING) Trailing Take Profit Trigger (%) {2.5}', minval=0, step=0.01)
i_trailingTakeProfitPercentageTriggerPerOne = i_trailingTakeProfitPercentageTrigger * 0.01
i_trailingTakeProfitPercentageOffset = input.float(25.0, '(TRAILING) Trailing Take Profit as a percentage of Trailing Take Profit Trigger (%) {25.0}', minval=0, step=0.01)
i_trailingTakeProfitPercentageOffsetPerOne = i_trailingTakeProfitPercentageOffset * 0.01

_ZIGNALYE_ = 'Email', _ZIGNALYW_ = 'WebHook'
i_zignalyAlertTypePre = input.string(_ZIGNALYW_, '(ZIG) Zignaly Alert Type {WebHook}', options=[_ZIGNALYW_, _ZIGNALYE_])
i_zignalyAlertType = (i_zignalyAlertTypePre == _ZIGNALYW_) ? 'webhook' : 'email'

_ZIGHYBRIDINTEGRATION_ = 'Hybrid', _ZIGTVONLYINTEGRATION_ = 'TradingView only'
i_zignalyIntegrationTypePre = input.string(_ZIGHYBRIDINTEGRATION_, '(ZIG) Integration type', options=[_ZIGTVONLYINTEGRATION_, _ZIGHYBRIDINTEGRATION_])
i_zignalyIntegrationType = (i_zignalyIntegrationTypePre == _ZIGHYBRIDINTEGRATION_) ? 'hybrid' : 'nonhybrid'

i_priceDecimalDigits = input.int(2, 'Number of decimal digits for Prices {2}', minval=0, maxval=10, step=1)


string tmpOrderAlertMessage = ''

float entryQuantity = na
float currentCapital = strategy.initial_capital + strategy.netprofit
entryQuantity := i_CapitalPercentage * currentCapital


longCondition = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))
if (longCondition)
    tmpOrderAlertMessage := zig.reverseLongEntry(key = i_zignalyServiceSecretKey, exchangeAccountType = i_zignalyExchangeType, positionSizeQuote = entryQuantity, leverage = i_zignalyLeverage, takeProfit = i_enableTakeProfit, takeProfitPercentage1 = i_takeProfit, stopLoss = i_enableStopLoss, stopLossPercentage = i_stopLossPercentage, trailingStopLoss = i_enableTrailingTakeProfit, trailingStopTriggerPercentage = i_trailingTakeProfitPercentageTrigger, trailingStopDistancePercentage = i_trailingTakeProfitPercentageOffset, alertType = i_zignalyAlertType, integration = i_zignalyIntegrationType, priceDecimalDigits = i_priceDecimalDigits)
    if i_showDebugLabels
        label.new(x=bar_index, y=high, text=tmpOrderAlertMessage, textalign=text.align_left)
    strategy.entry("My Long Entry Id", strategy.long, alert_message=tmpOrderAlertMessage)

shortCondition = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))
if (shortCondition)
    tmpOrderAlertMessage := zig.reverseShortEntry(key = i_zignalyServiceSecretKey, exchangeAccountType = i_zignalyExchangeType, positionSizeQuote = entryQuantity, leverage = i_zignalyLeverage, takeProfit = i_enableTakeProfit, takeProfitPercentage1 = i_takeProfit, stopLoss = i_enableStopLoss, stopLossPercentage = i_stopLossPercentage, trailingStopLoss = i_enableTrailingTakeProfit, trailingStopTriggerPercentage = i_trailingTakeProfitPercentageTrigger, trailingStopDistancePercentage = i_trailingTakeProfitPercentageOffset, alertType = i_zignalyAlertType, integration = i_zignalyIntegrationType, priceDecimalDigits = i_priceDecimalDigits)
    if i_showDebugLabels
        label.new(x=bar_index, y=high, text=tmpOrderAlertMessage, textalign=text.align_left)
    strategy.entry("My Short Entry Id", strategy.short, alert_message=tmpOrderAlertMessage)

Overview

Crossing EMAs D detects simple moving average crossovers (14-period and 28-period) and formats detailed payload alert messages for crypto spot and futures exchanges. Traders can adjust capital percentage allocation, leverage, take profit, stop loss, trailing take profit parameters, and debug label visibility directly on the price chart.

Details

Published by

ruckard on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Moving averages, Trend

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
(DEBUG) Show Debug Labels? {True}booltruei_showDebugLabels
(ZIG) Service Secret Key {MYSECRETKEY}stringMYSECRETKEYi_zignalyServiceSecretKey
(ZIG) Exchange Type {Futures}string_ZIGEXFUTURES_i_zignalyExchangeType
(CAPITAL) Capital percentage invested per order (%) {25.0}float25.0i_CapitalPercentage
(ZIG) Leverage {1}int1i_zignalyLeverage
(STOPTAKE) Take Profit? {false}boolfalsei_enableTakeProfit
(STOPTAKE) Take Profit % {3.0}float1.1i_takeProfit
(STOPTAKE) Stop Loss? {True}booltruei_enableStopLoss
(STOPTAKE) Stop Loss % {7.0}float7.0i_stopLoss
(TRAILING) Enable Trailing Take Profit (%) {False}boolfalsei_enableTrailingTakeProfit
(TRAILING) Trailing Take Profit Trigger (%) {2.5}float1.2i_trailingTakeProfitPercentageTrigger
(TRAILING) Trailing Take Profit as a percentage of Trailing Take Profit Trigger (%) {25.0}float25.0i_trailingTakeProfitPercentageOffset
Show all 15 settings
SettingTypeDefaultVariable
(ZIG) Zignaly Alert Type {WebHook}string_ZIGNALYW_i_zignalyAlertTypePre
(ZIG) Integration typestring_ZIGHYBRIDINTEGRATION_i_zignalyIntegrationTypePre
Number of decimal digits for Prices {2}int2i_priceDecimalDigits
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

This strategy calculates and plots a fast Exponential Moving Average (EMA) and a slow EMA directly on the main price chart. It 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

Strategy v6 TrendMoving averages
Updated today · AGPL-3.0 GitHub repository of Forven S01508 — Simple EMA20/50 Cross
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

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