Strategy · Pine Script v4 · On the chart

50 EMA + 200 EMA + VMC Cipher Long Strategy

by krosenfeld7

This strategy seeks long entries by combining moving average trend filters with VMC Cipher momentum and money flow indicators.

View on GitHub

GitHub stars5on the repository
Pine versionv4older, still runs
Lines of code163
Settings21inputs
LicenceApache-2.0
Last update3 years ago12 May 2023

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

163 lines of Pine Script v4 from 50_EMA+200_EMA_VMC_Cipher/50_EMA+200_EMA_VMC_Cipher_Long_Strategy.txt, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

50_EMA+200_EMA_VMC_Cipher_Long_Strategy.txt
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © krosenfeld7

//@version=4
strategy("50 EMA + 200 EMA + VMC Cipher Long Strategy", overlay = true, pyramiding = 0, 
         margin_long = 100, margin_short = 100, 
         default_qty_type = strategy.percent_of_equity, 
         default_qty_value = 20, initial_capital = 2000, 
         process_orders_on_close = true)

// Set the starting point for backtesting
start = input(title = "Backtesting Start", type = input.time,
     defval = timestamp("1 Jan 2015"))
maxTimeOpen = input(title = "Order Expiration", type = input.integer,
     defval = 100, minval = 1)
tpSlStrategy = input(title = "Take Profit Strategy", type = input.string,
     defval = "Percent", options = ["Percent", "ATR"])
trailingStop = input(title = "Trailing Stop", type = input.string,
     defval = "Fixed", options = ["Fixed", "Trail"])

// ATR For Stop Loss
atrLength = input(title = "ATR SL Length", defval = 14,
     minval = 1)
atrMultiplier = input(title = "ATR Multiplier", type = input.float, 
     defval = 1, minval = 0.1)
riskLevel = input(title = "Risk Level", type = input.float, 
     defval = 1, minval = 0.1)

longProfitPercent = input(title = "Take Profit %",
     type = input.float, minval = 0.0, step = 0.1, defval = 10) / 100
longLossPercent = input(title = "Stop Loss %",
     type = input.float, minval = 0.0, step = 0.1, defval = 10) / 100

// Algorithm / Strategy Goes here
// Set long variables to execute positions below
// EMA section
len1 = input(50, minval=1, title="Short EMA Length")
src1 = input(close, title="Short EMA Source")
len2 = input(200, minval=1, title="Long EMA Length")
src2 = input(close, title="Long EMA Source")
lookback = input(title = "Pullback Lookback", defval = 10, minval = 1)
ema50  = ema(src1, len1)
ema200 = ema(src2, len2)

plot(ema50, title="Short EMA", color=color.blue, linewidth = 3)
plot(ema200, title="Long EMA", color=color.white, linewidth = 3)

emaLong  = close > ema200
emaShort = close < ema200

emaLongPullback  = low[1]  > ema50 and low  < ema50
emaShortPullback = high[1] < ema50 and high > ema50

emaLong  := barssince(emaLongPullback) < lookback and emaLong
emaShort := barssince(emaShortPullback) < lookback and emaShort

// Money flow section

rsiMFIperiod = input(60, title = 'MFI Period', type = input.integer)
rsiMFIMultiplier = input(150, title = 'MFI Area multiplier', type = input.float)
rsiMFIPosY = input(2.5, title = 'MFI Area Y Pos', type = input.float)

f_rsimfi(_period, _multiplier, _tf) => security(syminfo.tickerid, _tf, sma(((close - open) / (high - low)) * _multiplier, _period) - rsiMFIPosY)

rsiMFI = f_rsimfi(rsiMFIperiod, rsiMFIMultiplier, timeframe.period)

plot(rsiMFI, color = color.new(rsiMFI < 0 ? color.red : color.green, transp=100))

rsiMFILong  = rsiMFI > 0
rsiMFIShort = rsiMFI < 0

wtChannelLen = input(9, title = 'WT Channel Length', type = input.integer)
wtAverageLen = input(12, title = 'WT Average Length', type = input.integer)
wtMASource = input(hlc3, title = 'WT MA Source', type = input.source)
wtMALen = input(3, title = 'WT MA Length', type = input.integer)

f_wavetrend(src, chlen, avg, malen, tf) =>
    tfsrc = security(syminfo.tickerid, tf, src)
    esa = ema(tfsrc, chlen)
    de = ema(abs(tfsrc - esa), chlen)
    ci = (tfsrc - esa) / (0.015 * de)
    wt1 = security(syminfo.tickerid, tf, ema(ci, avg))
    wt2 = security(syminfo.tickerid, tf, sma(wt1, malen))
    [wt1, wt2]

[wt1, wt2] = f_wavetrend(wtMASource, wtChannelLen, wtAverageLen, wtMALen, timeframe.period)

wtLong  = wt1 < 0 and wt2 < 0
wtShort = wt1 > 0 and wt2 > 0

wtCrossUp   = crossover(wt1, wt2)
wtCrossDown = crossunder(wt1, wt2)

plot(wt1, color = color.new(wtCrossUp ? color.green : color.blue,  transp=100))
plot(wt2, color = color.new(wtCrossDown ? color.red : color.blue, transp=100))

wtLong  := wtCrossUp and wtLong
wtShort := wtCrossDown and wtShort

// Computing Strategy
long  = emaLong  and rsiMFILong  and wtLong
short = emaShort and rsiMFIShort and wtShort

// End Algorithm

longExitPrice = 0.0
longStopPrice = 0.0

// Calculating exact prices for stop loss and exit prices
longExitPercentPrice = strategy.position_avg_price * (1 + 
     (longProfitPercent * riskLevel))
longStopPercentPrice = strategy.position_avg_price * (1 - 
     longLossPercent)

// Profit & Loss via ATR
atr = atr(atrLength)

atr := valuewhen(strategy.position_size == 0, atr, 0)

longExitAtrPrice = strategy.position_avg_price + (atr * 
     atrMultiplier * riskLevel)
longStopAtrPrice = strategy.position_avg_price - (atr * 
     atrMultiplier)

if tpSlStrategy == "Percent"
    longExitPrice := longExitPercentPrice
    
    if trailingStop == "Fixed"
        longStopPrice := longStopPercentPrice
    else if trailingStop == "Trail"
        stopValue      = close * (1 - longLossPercent)
        longStopPrice := (strategy.position_size > 0) ? 
             max(stopValue, longStopPrice[1]) : 0

else if tpSlStrategy == "ATR"
    if strategy.position_size > 0
        longExitPrice := longExitAtrPrice
        
    if trailingStop == "Fixed"
        longStopPrice := longStopAtrPrice
    else if trailingStop == "Trail"
        stopValue      = close - (atr * atrMultiplier)
        longStopPrice := (strategy.position_size > 0) ? 
             max(stopValue, longStopPrice[1]) : 0

// Plotting profit / loss targets
plot(series = (strategy.position_size > 0) ? longExitPrice : na, 
     color = color.green, style = plot.style_linebr, 
     linewidth = 3, title = "Long Target")
plot(series = (strategy.position_size > 0) ? longStopPrice : na, 
     color = color.red, style = plot.style_linebr, 
     linewidth = 3, title = "Long Stop Loss")

// Submit entry orders
if time >= start
    strategy.entry(id = "Long", long = strategy.long, 
         comment = "Long Open", when = long)

// Submit exit orders
strategy.exit(id = "Long", limit = longExitPrice, stop = longStopPrice, 
     comment = "Long Close", when = strategy.position_size > 0)
strategy.close(id = "Long", comment = "Expired: >" + tostring(maxTimeOpen), 
     when = (barssince(change(strategy.opentrades)) + 1) >= maxTimeOpen)

Overview

50 EMA + 200 EMA + VMC Cipher Long Strategy identifies bullish trend alignment when price trades above the 200 EMA and records recent pullbacks to the 50 EMA, confirmed by positive RSI Money Flow and WaveTrend conditions. It executes trades on the price chart with configurable take profit and stop loss levels based on either percentage targets or ATR multiples, alongside optional trailing stops and a bar-count expiration filter.

Details

Published by

krosenfeld7 on GitHub

Type

Strategy, Pine Script v4

Draws

On the price chart

Category

Trend, Moving averages, Oscillators & momentum

Markets

Any symbol

Timeframes

Any timeframe

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.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Backtesting Starttimetimestamp("1 Jan 2015")start
Order Expirationint100maxTimeOpen
Take Profit StrategystringPercenttpSlStrategy
Trailing StopstringFixedtrailingStop
ATR SL Lengthint14atrLength
ATR Multiplierfloat1atrMultiplier
Risk Levelfloat1riskLevel
Take Profit %float10longProfitPercent
Stop Loss %float10longLossPercent
Short EMA Lengthint50len1
Short EMA Sourcesourceclosesrc1
Long EMA Lengthint200len2
Show all 21 settings
SettingTypeDefaultVariable
Long EMA Sourcesourceclosesrc2
Pullback Lookbackint10lookback
MFI Periodint60rsiMFIperiod
MFI Area multiplierfloat150rsiMFIMultiplier
MFI Area Y Posfloat2.5rsiMFIPosY
WT Channel Lengthint9wtChannelLen
WT Average Lengthint12wtAverageLen
WT MA Sourcesourcehlc3wtMASource
WT MA Lengthint3wtMALen
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

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

This strategy combines Arnaud Legoux Moving Average percentage price change calculations with an adaptive Gaussian Moving Average to generate trend-following signals. Long and short entries are triggered when the ALMA change calculation crosses above or below

Strategy v5 Moving averagesOscillators & momentum
Updated 6 weeks ago · None stated GitHub repository of ESM2024 - ALMA Smoothed Gaussian Moving Average
218 stars

This strategy generates trading signals based on a selectable momentum engine, supporting MACD, RSI, Stochastic, or Rate of Change. Entries trigger on signal crosses, zero-line crosses, or threshold crosses, with an optional moving average trend filter. Risk m

Strategy v6 Oscillators & momentumTrend
Updated 3 months ago · None stated GitHub repository of Momentum Strategy Template

255 EMA Strategy

by hasnocool
106 stars

255 EMA Strategy combines an exponential moving average with Average True Range bands and standard MACD crossovers to generate entry signals. Drawn directly on the price chart, it plots the central 255 EMA along with upper and lower volatility envelopes. Trade

Strategy v4 Moving averagesOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of 255 EMA Strategy

SMA RSI Strategy

by PythonForForex
64 stars

This strategy evaluates simple moving averages and the Relative Strength Index to generate trading signals. It calculates a 10-period SMA, a 30-period SMA, and a 14-period RSI. Long positions are entered when the fast SMA crosses above the slow SMA while RSI i

Strategy v5 TrendOscillators & momentum
Updated 4 years ago · None stated GitHub repository of SMA RSI 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