Strategy · Pine Script v5 · On the chart

Edge 59

by subos2008· code credited to bford

Edge 59 is a price-chart strategy that combines an ADX directional filter, a weighted moving average, and a trend-follower channel.

View on GitHub

Repaints

GitHub stars6on the repository
Pine versionv5runs as is
Lines of code136
Settings11inputs
LicenceCustom licencefile: MPL-2.0
Last update2 years ago10 Apr 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

136 lines of Pine Script v5 from pinescript/edge59/e59-strategy.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

e59-strategy.pine
//@version=5
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © bford

strategy(title="Edge 59", overlay=true)

// START of INDICATOR

// ADX
// OG: E59 was 14,14,17,10 - but first visual test I did was with defaults 14,14,18,34 - and this worked really well
lenadx = input.int(14, minval=1, title="DI Length")
lensig = input.int(14, title="ADX Smoothing", minval=1, maxval=50)
limadx = input.int(17, minval=1, title="ADX MA Active")
len = input.int(10, minval=1, title="Length")
up = ta.change(high)
down = -ta.change(low)
trur = ta.rma(ta.tr, lenadx) // TODO: what is 'tr' here?
plus = fixnan(100 * ta.rma(up > down and up > 0 ? up : 0, lenadx) / trur)
minus = fixnan(100 * ta.rma(down > up and down > 0 ? down : 0, lenadx) / trur)
sum = plus + minus 
adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), lensig)
macol = adx > limadx and plus > minus ? color.lime : adx > limadx and plus < minus ? color.red :color.black
src = input(close, title="Source")
out = ta.wma(src, len)
plot(out, color=macol, title="MA", linewidth= 3)
adx_long_filter = macol == color.lime 
adx_short_filter = macol == color.red

// Trend Follower
matype= 'EMA'
prd = input.int(20, title = "Period to Check Trend", minval = 5)
maprd = input.int(20, title = "MA Period", minval = 2)
rateinp = input.float(1, title = "Trend Channel Rate %", minval = 0.1, step = 0.1)
ulinreg = input.bool(true, title = "Use Linear Regression")
linprd = input.int(5, title = "Linear Regression Period", minval = 2)

rate = rateinp / 100
pricerange = ta.highest(280) - ta.lowest(280) // TODO: what are these hardcoded 280's?
chan = pricerange * rate
    
gettrend(len)=>
    masrc = matype == 'EMA' ? ta.ema(close, len) : matype == 'RMA' ? ta.rma(close, len) : matype == 'VWMA' ? ta.vwma(close, len) : matype == 'WMA' ? ta.wma(close, len) : ta.sma(close, len)
    ma = ulinreg ? ta.linreg(masrc, linprd, 0) : masrc
    
    hh = ta.highest(ma, prd)
    ll = ta.lowest(ma, prd)
    diff = math.abs(hh - ll)
    
    inner = ma < hh - chan ? -1 : 0
    middle = ma > ll + chan ? 1 : inner
    trend = diff > chan ? middle : 0
    _ret = trend * diff / chan
    _ret

trend = gettrend(maprd)

trandchanged = trend - nz(trend[1])
tcol =  trend > 0 ? trandchanged> 0 ? #00FF00ff : trandchanged <= 0 ? #00FF006f : #00FF00af :
  trend < 0 ? trandchanged < 0 ? #FF0000ff: trandchanged >= 0 ? #FF00006f : #FF0000af : na

trend_follower_long_filter = tcol == #00FF00ff
trend_follower_short_filter  = tcol == #FF0000ff

// 22 Days high/low body prices
num_breakout_days = input.int(22, minval=1, title="Number of Days (Close Breakout)")

lowest_low = ta.lowest(low, num_breakout_days)[1]
highest_high = ta.highest(high, num_breakout_days)[1]

long_entry_signal = high > highest_high
short_entry_signal = low < lowest_low

// debug
plot(lowest_low)
plot(highest_high)

// Combine Filters

long_filter = adx_long_filter and trend_follower_long_filter
short_filter = adx_short_filter and trend_follower_short_filter

long_entry = long_filter and long_entry_signal
short_entry = short_filter and short_entry_signal

// Plots

// DEBUG: New Price High Lows (unfiltered entry signals)
// plotarrow(long_entry_signal, colorup = color.green)
// plotarrow(-short_entry_signal, colordown = color.red)

// Filters
plotarrow(long_filter?1:0, colorup = color.green, transp= 60)
plotarrow(short_filter?-1:0, colordown = color.red, transp=60)

// Filtered Entry (actual edge signal)
plotarrow(long_entry?1:0, colorup = color.green)
plotarrow(short_entry?-1:0, colordown = color.red)
// Study exit API
// long_entry and short_entry: entry signal with filters applied
// long_filter and short_filter: entry/stay in position filters are active: close position whenever this is false

// END of INDICATOR


// START of STRATEGY

// Entry and Exit

// Stops - 5-10% for each individual entry
long_stop_price = close * 0.9
short_stop_price = close *1.1
// note we might need to cancel stop orders manually when we exit

max_ordersize=math.floor(strategy.equity/close) // To dynamically calculate the order size as the account equity increases or decreases.
position_size = max_ordersize

// Entry is crossunder/over of lowest_body/highest_body, when = matching long/short_filter
// long entry
strategy.entry("long", strategy.long, position_size, when=long_entry)
// short entry
strategy.entry("short", strategy.short, position_size, when=short_entry)
// TODO: add stops with:  strategy.exit
// TODO: this is not adding to positions


// close_all when filters dont match trade direction
strategy.close('long', when=not long_filter)
strategy.close('short', when=not short_filter)
// plot(strategy.position_size)


//scratch
// if (not long_filter)
//     strategy.exit("long_trailing_stop", "long", trail_points = 4000, trail_offset = 1500)
// if (not short_filter)
//     strategy.exit("short_trailing_stop", "short", trail_points = 4000, trail_offset = 1500)

Overview

The channel uses an exponential moving average of close, optionally smoothed by linear regression, and a percentage of a fixed 280-bar price range. It marks long when the ADX and trend filters agree and price breaks the prior N-bar high, and short on the matching breakdown of the prior low. Inputs change ADX lengths, the MA and trend periods, the channel rate, and the breakout lookback. It has no stop loss by default.

Details

Published by

subos2008 on GitHub

Code credit

bford, as written in the script's header

Draws

On the price chart

Markets

Crypto

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)
  • The strategy enters trades without a stop loss

Topics

binancebinance-trading-botstrading-bot

Settings

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

SettingTypeDefaultVariable
DI Lengthint14lenadx
ADX Smoothingint14lensig
ADX MA Activeint17limadx
Lengthint10len
Sourcesourceclosesrc
Period to Check Trendint20prd
MA Periodint20maprd
Trend Channel Rate %float1rateinp
Use Linear Regressionbooltrueulinreg
Linear Regression Periodint5linprd
Number of Days (Close Breakout)int22num_breakout_days
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

ADA4H Optuna Strategy

by skywalker0803r
42 stars

This strategy trades longs and shorts on the price chart. Long entries require a close above the prior Donchian high, a close above a long-term SMA, and RSI above a threshold, with size set as a percentage of equity. Long exits use a stop at the prior Donchian

Strategy v5 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of ADA4H Optuna Strategy

AG Momentum Breakout

by eltonaguiar
4 stars

AG Momentum Breakout is a strategy that identifies continuation signals after pullbacks in trending markets. It filters for uptrends using EMAs and detects recent pullbacks via RSI conditions before entering on RSI crossovers above 50 with ADX confirmation. Th

Strategy v6 TrendOscillators & momentum
Updated 2 days ago · None stated GitHub repository of AG Momentum Breakout
4 stars

Christian Qullamaggie Strategy is a trend-following and breakout strategy overlay designed to identify high-momentum trading opportunities directly on the price chart. It evaluates market conditions using fast, mid, and slow EMAs, average true range (ATR), and

Strategy v6 BreakoutTrend
Updated 7 months ago · None stated GitHub repository of Christian Qullamaggie Strategy

RSI-7 Breakout

by aofwittawat
4 stars

This strategy identifies breakout trades using a 7-period RSI combined with price extreme lookbacks. A long entry triggers when the RSI rises above 70 and price reaches a new lookback high, provided price remains above an optional EMA trend filter and passes a

Strategy v5 Oscillators & momentumBreakout
Updated 4 years ago · None stated GitHub repository of RSI-7 Breakout

RSI EMA Breakout

by latentwill
4 stars

This strategy trades momentum breakouts by combining an Exponential Moving Average with the Relative Strength Index. It enters a long position when the closing price is above the EMA and the RSI crosses above the breakout threshold. It enters a short position

Strategy v5 TrendOscillators & momentum
Updated 8 days ago · None stated GitHub repository of RSI EMA Breakout

More Trend scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers