Strategy · Pine Script v5 · On the chart

J8 30 123 SPY Scalping PRO 2 Jerry

by g-moe· code credited to goodgains

This intraday strategy is designed for short-term scalping on equity and index markets like SPY.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code590
Settings40inputs
LicenceNone statedfile: MPL-2.0
Last update5 months ago27 May 2026

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

590 lines of Pine Script v5 from Tradingview/j8-30-123-spy-scalping-pro-2-jerry.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

j8-30-123-spy-scalping-pro-2-jerry.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © goodgains


//@version=5
strategy("J8_30_123_SPY_Scalping_PRO_2_Jerry", overlay=true, margin_long=100, margin_short=100, default_qty_value = 100)

// @keywords: spy-scalping, strategy, supertrend, moving-average, hull-moving-average, rsi, macd, bollinger-bands, iron-condor, bull-put-spread, bear-call-spread, zlsma, linear-regression, atr, trailing-stop, multi-timeframe, crossover, performance-dashboard, alerts, eod-exit

// ma function
getMA(src, len, type) =>
    ma_value = type == 'MA' ? ta.sma(src, len) : type == 'WMA' ? ta.wma(src, len) : type == 'VWMA' ? ta.vwma(src, len) : type == 'EMA' ? ta.ema(src, len) : type == 'HMA' ? ta.hma(src, len) : ta.sma(src, len)
    ma_value


// function to calculate supertrend side
f_mtf_st(st_mult, ts_atr_length, st_type) =>

    float mtf_atr = switch st_type
        "MA" => ta.sma(ta.tr(false), ts_atr_length)
        "WMA" => ta.wma(ta.tr(false), ts_atr_length)
        "VWMA" => ta.vwma(ta.tr(false), ts_atr_length)
        "EMA" => ta.ema(ta.tr(false), ts_atr_length)
        "HMA" => ta.hma(ta.tr(false), ts_atr_length)

    mtf_up = hl2 + (st_mult * mtf_atr)
    mtf_down = hl2 + (-st_mult * mtf_atr)
    
    var float mtf_st = na
    mtf_st := close < mtf_st[1] ? mtf_up : mtf_down

    var int mtf_st_side = na
    mtf_st_side := close > mtf_st ? 1 : close < mtf_st ? -1 : mtf_st_side[1]

    mtf_st_side


// inputs
show_dash_labels = input.bool(true, title = 'Show Dash Labels', group = 'Settings', inline = '1', tooltip = 'Turn on or off all dash labels. Default = YES to show labels.')
show_daytrading_labels = input.bool(true, title = 'Show Day Trade Labels', group = 'Settings', inline = '2', tooltip = 'Select YES for Daytrading to turn off most DASH labels that are not needed')
st_colorbars = input.bool(true, title = 'Paint Bars', group = 'Settings', inline = '3', tooltip = 'Yes to PAINT the trend candlesticks.  Default YES')
use_alerts = input.bool(true, title = 'Use Alerts', group = 'Settings', inline = '4', tooltip = 'Default NO. Turns on alert for Bear and Bull Spreads.')


// color inputs
up_color = input.color(color.green, title = 'Up⠀⠀⠀⠀⠀⠀', group = 'Color Settings', inline = '1')
dn_color = input.color(color.red, title = '⠀⠀⠀⠀⠀⠀Down⠀⠀⠀⠀⠀⠀', group = 'Color Settings', inline = '1')
label_color = input.color(#ffffff, title = 'Label⠀⠀⠀⠀', group = 'Color Settings', inline = '2')
transition_color = input.color(color.yellow, title = '⠀⠀⠀⠀⠀⠀Transition⠀⠀⠀', group = 'Color Settings', inline = '2')

maxxed_color = input.color(color.new(#32C8FF, 0),  title = 'Maxxed⠀⠀⠀', group = 'Color Settings', inline = '3')
rising_color = input.color(color.new(#00FF00, 0),  title = '⠀⠀⠀⠀⠀⠀Rising⠀⠀⠀⠀⠀', group = 'Color Settings', inline = '3')
bear_color = input.color(color.new(#E10000,0),  title = 'Bear⠀⠀⠀⠀⠀', group = 'Color Settings', inline = '4')
pretrend_color = input.color(color.new(#C87DFF,0),  title = '⠀⠀⠀⠀⠀⠀Pretrend⠀⠀⠀', group = 'Color Settings', inline = '4')

ob_color = input.color(color.new(#ABABE1,0),  title = 'OB⠀⠀⠀⠀⠀⠀', group = 'Color Settings', inline = '5')
os_color = input.color(color.new(#DCDC80,0),  title = '⠀⠀⠀⠀⠀⠀OS⠀⠀⠀⠀⠀⠀⠀', group = 'Color Settings', inline = '5')





// trade inputs
input_price = input.source(close, title = 'Price', group = 'Trade Settings')
use_z_exits = input.bool(true, title = 'Use Z Exits', group = 'Trade Settings', tooltip = ' Must select 1 or 2 exit strategies. DEFAULT YES')
use_ts_exits = input.bool(true, title = 'Use Trailing Stop Exits', group = 'Trade Settings', tooltip = 'Must select 1 or 2 exit strategies. DEFAULT YES')
use_close_eod = input.bool(true, title = 'Use EOD Exits', group = 'Trade Settings', tooltip = 'Yes for daytrading.')

spreads_credit_target = input.float(0.20, title = ' Spread Credit Target', group = 'Trade Settings', tooltip = 'Normally .20 - .25. Goal Risk $70 to Make $30. This will vary based on VIX volatility so adjust it as needed based on the current market')
spreads_size = input.float(10.00, title = ' Spread Size', group = 'Trade Settings', tooltip = 'How big of a spread do you want? Default=10. If entering later (> 12:00 PM) consider 8')
wings = input.float(1.00, title = 'Wings', group = 'Trade Settings', tooltip = 'How big is each wing? Default 1 (Small wings = smaller profits with higher probability) >>NORMALLY .1-.3 DELTA<<')


// supertrend
st_ts_atr_mult = input.float(1.0, title = 'ATR Mult', group = 'Supertrend', inline = '1' , tooltip = 'This is a trend setting. Default = 1')
st_natr = input.int(4, title = 'st_natr', group = 'Supertrend', inline = '2' , tooltip = 'This is a trend setting. Default = 4')
st_avgtype = input.string(title='AvgType ST', defval='HMA', options=['MA', 'WMA', 'VWMA', 'EMA', 'HMA'], group = 'Supertrend', inline = '3') 

tr = math.max(close[1], high) - math.min(close[1], low)
atr = getMA(tr, st_natr, st_avgtype)
ST_UP = hl2 + (st_ts_atr_mult * atr)
ST_DN = hl2 - (st_ts_atr_mult * atr)
var float ST = na
ST := close < ST[1] ? ST_UP : ST_DN
plot(ST, title = 'Supertrend', color = close < ST ? dn_color : up_color, display = display.all)
barcolor(not st_colorbars ? na : close < ST ? dn_color : close > ST ? up_color : na)


// limit count
st_showarrows = input.bool(true, title = 'Show Arrows', group = 'Settings', inline = '4', tooltip = 'Shows most recent cross over when price crosses the trend.')
st_arrowcount = input.int(2, title = '' ,group = 'Settings', inline = '4', minval = 0)
var arr_arrows = array.new_label(st_arrowcount, na) 

show_arrowbubble = input.bool(false, title = 'Show Bubbles', group = 'Settings', inline = '5', tooltip = 'Default NO.')
var arr_arrowsbubble = array.new_label(st_arrowcount, na) 


if st_showarrows
    if ta.crossover(close, ST)
        array.unshift(arr_arrows, label.new(x = bar_index, y = low, xloc = xloc.bar_index, yloc = yloc.belowbar, color = up_color, style = label.style_triangleup, size = size.small))
        last = array.pop(arr_arrows)
        label.delete(last)
    if ta.crossunder(close, ST)
        array.unshift(arr_arrows, label.new(x = bar_index, y = low, xloc = xloc.bar_index, yloc = yloc.abovebar, color = dn_color, style = label.style_triangledown, size = size.small))
        last = array.pop(arr_arrows)
        label.delete(last)

if show_arrowbubble
    if ta.crossover(close, ST)
        array.unshift(arr_arrowsbubble, label.new(x = bar_index, y = low, xloc = xloc.bar_index, yloc = yloc.belowbar, color = up_color, style = label.style_label_up, size = size.small, text = str.tostring(high[1])))
        last = array.pop(arr_arrowsbubble)
        label.delete(last)
    if ta.crossunder(close, ST)
        array.unshift(arr_arrowsbubble, label.new(x = bar_index, y = low, xloc = xloc.bar_index, yloc = yloc.abovebar, color = dn_color, style = label.style_label_down, size = size.small,text = str.tostring(low[1])))
        last = array.pop(arr_arrowsbubble)
        label.delete(last)




// iron condor vars
IC_Buy_Put2   = math.round(close, 0) - (spreads_size / 2) 
IC_Sell_Puts2 = math.round(close, 0) - (spreads_size / 2 - wings)
IC_Sell_Call2 = math.round(close, 0) + (spreads_size / 2 - wings)
IC_Buy_Call2 = math.round(close, 0) + (spreads_size / 2)
Width = spreads_size - (2 * (wings))


// criteria 1 supertrend cond
Buy_Signal_Supertrend1 = close > ST
Sell_Signal_Supertrend1 = close < ST


// criteria 2 ema trend direction
ma_length1 = input.int(13, title = 'EMA Length 1', group = 'EMA Trend Settings', inline = '1', tooltip = 'Default 13 scalping. Can try 10 for scalping')
ma_length2 = input.int(50, title = 'EMA Length 2', group = 'EMA Trend Settings', inline = '2', tooltip = 'Default 50 scalping. Long Term 50, 100, 200. Short Term = 2, 5, 8, 20')
ma_length3 = input.int(75, title = 'EMA Length 3', group = 'EMA Trend Settings', inline = '3', tooltip = 'Default 75 scalping. Try 100 for fewer signals')
ma_averagetype = input.string(title ='Avg Type', defval='EMA', options=['MA', 'WMA', 'VWMA', 'EMA', 'HMA'], group = 'EMA Trend Settings', inline = '4')

ma1 = getMA(input_price, ma_length1, ma_averagetype)
ma2 = getMA(input_price, ma_length2, ma_averagetype)
ma3 = getMA(input_price, ma_length3, ma_averagetype)

plot(ma1, title = 'MA 1', color = color.aqua)
plot(ma2, title = 'MA 2', color = color.red)
plot(ma3, title = 'MA 3', color = color.fuchsia)


// ema condition statement
// #----- Bullish Criteria
ECondition1 = ma1 > ma2 and ma1 > ma3 ? 1 : 0
Econdition2 = ma2 > ma3 ? 1 : 0
Econdition3 = ma1 > ma1[1] and ma1[1] > ma1[2] ? 1 : 0
Econdition4 = ma2 > ma2[1] ? 1 : 0
Econdition5 = ma3 > ma3[1] ? 1 : 0
ECondition6 = close > ma1 ? 1 : 0


// #----- Bearish Criteria
ECondition10 = ma1 < ma2 and ma1 < ma3 ? 1 : 0
Econdition11 = ma2 < ma3 ? 1 : 0
Econdition12 = ma1 < ma1[1] and ma1[1] < ma1[2] ? 1 : 0
Econdition13 = ma2 < ma2[1] ? 1 : 0
Econdition14 = ma3 < ma3[1] ? 1 : 0
ECondition15 = close < ma1 ? 1 : 0


// #----- Criteria 2.0 EMA Conditions (THIS ONE TESTED BETTER)
EMA_Bullish =  ma1 > ma2 and ma1 > ma3 and ma3 > ma3[1]
EMA_Bearish =  ma1 < ma2  and ma1 < ma3 and ma3 < ma3[1] 


// #----- Criteria 2.1 EMA Conditions (DID NOT TEST WELL - Was too limiting)
// EMA_bullish = econdition1 + econdition2 +econdition3 + econdition4 + econdition5 + econdition6 == 6
// EMA_Bearish = econdition10 + econdition11 +econdition12 + econdition13 + econdition14 + econdition15 == 6


// criteria 3 rsi
show_RSI_label = input.bool(false, title = 'Show RSI Label', group = 'RSI Settings', inline = '1', tooltip = 'Default No')
rsi_ob = input.int(70, title = 'RSI OB', group = 'RSI Settings', inline = '2', tooltip = 'Default 70. Consider entering spreads between  ? OB and OS range.')
rsi_os = input.int(35, title = 'RSI OS', group = 'RSI Settings', inline = '2', tooltip = 'Default 70. Consider entering spreads between  ? OB and OS range.')
rsi_length = input.int(12, title = 'RSI Length', group = 'RSI Settings', inline = '2', tooltip = 'Default 12. Consdier 14 for testing')

rsi_value = ta.rsi(input_price, rsi_length)
plot(rsi_value, title = 'RSI', color = rsi_value > rsi_ob ? maxxed_color : rsi_value < rsi_os ? pretrend_color : rsi_value > rsi_value[1] ? rising_color : bear_color, display = display.none)
plot(rsi_ob, title = 'Overbought', display = display.none, color = ob_color)
plot(rsi_os, title = 'Oversold', display = display.none, color = os_color)


plotshape(ta.crossover(rsi_value, rsi_os) ? rsi_os : na, title = 'RSI Cross OS', style = shape.triangleup, 
     size = size.normal, location = location.absolute, display = display.none, color = up_color)
plotshape(ta.crossunder(rsi_value, rsi_ob) ? rsi_ob : na, title = 'RSI Cross OB', style = shape.triangledown, 
     size = size.normal, location = location.absolute, display = display.none, color =  dn_color)

rsi_label = rsi_value > rsi_ob ? "3 Maxxed" 
     : rsi_value < rsi_os ? "3 Pre-trend" 
     : rsi_value > rsi_value[1] ? "3 Bull " + str.tostring(math.round(rsi_value, 0)) 
     : "3 Bear " + str.tostring(math.round(rsi_value, 0))

rsi_label_color = rsi_value > rsi_ob ? maxxed_color 
     : rsi_value < rsi_os ? pretrend_color 
     : rsi_value > rsi_value[1] ? rising_color 
     : bear_color

rsi_condition = rsi_value > rsi_ob ? 1 : rsi_value < rsi_os ? 2 : rsi_value > rsi_value[1] ? 3 : 4

RSI_Maxxed = rsi_condition == 1
RSI_Pretrend = rsi_condition == 2
RSI_Bullish = rsi_condition == 3
RSI_Bearish = rsi_condition == 4


// criteria 4 macd dots 
md_bb_length = input.int(10, title = 'BB Length', group = 'MACD Dots', inline = '1', tooltip = 'Default 10')
md_bb_dev = input.float(1.0, title = 'BB Deviation', group = 'MACD Dots', inline = '2', tooltip = 'Default 1')
md_fastlength = input.int(12, title = 'MACD Fast', group = 'MACD Dots', inline = '3', tooltip = 'Default 12')
md_slowlength = input.int(26, title = 'MACD Slow', group = 'MACD Dots', inline = '4', tooltip = 'Default 26')
md_macdlength = input.int(5, title = 'MACD Length', group = 'MACD Dots', inline = '5', tooltip = 'Default 5')

[macd_dots, signalLine, histLine] = ta.macd(close, md_fastlength, md_slowlength, md_macdlength)
[bb_midline, bb_upper, bb_lower] = ta.bb(macd_dots, md_bb_length, md_bb_dev)


plot(macd_dots, title = 'MACD Dots', display = display.none, 
     color = macd_dots > macd_dots[1] and macd_dots > bb_upper and macd_dots < 0 ? color.yellow 
     : macd_dots > macd_dots[1] and macd_dots > 0 ? color.green 
     : macd_dots < macd_dots[1] and macd_dots > bb_upper ? color.new(#097209,0) 
     : macd_dots < macd_dots[1] and macd_dots < bb_lower ? color.red 
     : macd_dots > macd_dots[1] and macd_dots < bb_lower ? color.new(#8a0a0a,0) 
     : color.gray)
plot(macd_dots, title = 'MACD Line', display = display.none)

plot(bb_midline, title = 'BB Middle', display = display.none)
plot(bb_upper, title = 'BB Upper', display = display.none)
plot(bb_upper, title = 'BB Lower', display = display.none)


// #----- Jerry MACD Dot Color: 1 = yellow, 2 = green, 3 = dark green, 4 = red, 5 = dark red, 6 = gray
macd_dot_color = macd_dots > macd_dots[1] and macd_dots > bb_upper and macd_dots < 0  ? 1 
     : macd_dots > macd_dots[1] and macd_dots > bb_upper and macd_dots > 0  ? 2
     : macd_dots < macd_dots[1] and macd_dots > bb_upper  ? 3
     : macd_dots < macd_dots[1] and macd_dots < bb_lower  ? 4 
     : macd_dots > macd_dots[1] and macd_dots < bb_lower  ? 5 
     : 6


// #----- MACD Dot Color used for determining momentum
macd_dot_not_red = macd_dot_color != 4 and macd_dot_color != 5
// #macd_dot_not_green = macd_dot_color != 2 and macd_dot_color != 3 and macd_dot_color != 1  #and yellow
macd_dot_not_green = macd_dot_color > 3


// #---------- Iron Condor Entry Criteria----------#
show_ic_label = input.bool(false, title = 'Show Iron Condor Label', group = 'Iron Condor Settings', inline = '1'
     , tooltip = 'Default NO. This labels shows enter or exit IC')
ic_md_value = input.float(0.25, title = 'IC MACD Dot Value', group = 'Iron Condor Settings', inline = '3', 
     tooltip = 'MACD dots must be between this value and the - value. Default .25')
ic_md_exit_value = input.float(0.50, title = 'IC MACD Dot Value', group = 'Iron Condor Settings', inline = '4',
     tooltip = 'Consider exiting iron condor if above this value.')

macd_dot0 = macd_dots > -ic_md_value and macd_dots < ic_md_value
macd_dot1 = macd_dot0[1]
macd_dot2 = macd_dot0[2]
macd_dot3 = macd_dot0[3]
macd_dot4 = macd_dot0[4]


// #----- Criteria 4 Iron Condor Condition. APPLIES ONLY TO SPY Ticker
chart_is_SPY = syminfo.ticker(syminfo.tickerid)  == "SPY" ? true : false

entry_iron_condor = chart_is_SPY and macd_dot0 and macd_dot1 and macd_dot2 and macd_dot3 and macd_dot4
exit_iron_condor = chart_is_SPY and ta.crossover(macd_dots,ic_md_exit_value)
ic_label = entry_iron_condor ? "Enter IC" 
     : exit_iron_condor ? "Exit IC"
     : na 
ic_label_color = entry_iron_condor ? color.white 
     : exit_iron_condor ? color.red
     : color.gray



// Buy Signals Defined
mtf1_st_mult = 1.0
mtf1_st_ts_atr_length = 4
mtf1_st_timeframe = '30'
mtf_st_side = request.security(syminfo.tickerid, mtf1_st_timeframe, f_mtf_st(mtf1_st_mult, mtf1_st_ts_atr_length, 'HMA')[1], lookahead = barmerge.lookahead_on)

bull_put_spread = Buy_Signal_Supertrend1 and EMA_Bullish and rsi_value >= 50 and macd_dot_not_red and mtf_st_side == 1 
bear_call_spread = Sell_Signal_Supertrend1 and EMA_Bearish and  rsi_value <= 50 and macd_dot_not_green and mtf_st_side == -1


if use_alerts and barstate.islast
    if bull_put_spread
        alert('SELL Bull Spread', alert.freq_once_per_bar_close)
    if bear_call_spread
        alert('SELL Bear Call Spread', alert.freq_once_per_bar_close)


// ZLSMA Exit
zlsma_length_1 = input.int(50, title = 'Z Exit Length', group = 'ZLSMA Settings', inline = '1')
zlsma_length_2 = input.int(5, title = 'Z Exit Length 2', group = 'ZLSMA Settings', inline = '2')

lsma = ta.linreg(close, zlsma_length_1,0)
lsma2 = ta.linreg(lsma, zlsma_length_1,0)
b = lsma - lsma2
z_2 = lsma + b
trig2 = ta.ema(z_2, zlsma_length_2)

// #----- Exit Strategy 1 Conditions
bull_put_spread_exit = use_z_exits and ta.crossunder(z_2, trig2)
bear_call_spread_exit = use_z_exits and  ta.crossover(z_2, trig2)






// create signals
strategy_start = input.time(timestamp("01 January 2020 00:00:00 UTC-5"), "Strategy Start Date", group = "Additional Strategy Settings")
use_trading_hours = input.bool(false, title = "Use Trading Hours", tooltip = "This is ignored if the chart timeframe is greater than or equal to the daily timeframe.", group = "Additional Strategy Settings")
trading_time = input.session("1000-1557", title = "Trading Time", tooltip = "This uses Eastern Time Zone or U.S. NY Market Hours.", group = "Additional Strategy Settings")
trading_hours_cond = not use_trading_hours or time("",trading_time, "America/New_York")
past_strategy_start_date = time >= strategy_start ? true : false

long_trades = input.bool(true, title = "Long Trades", tooltip = "Do we want to take long trades?" , group = "Additional Strategy Settings")
short_trades = input.bool(true, title = "Short Trades", tooltip = "Do we want to take short trades?" , group = "Additional Strategy Settings")

long_entry = long_trades and trading_hours_cond and bull_put_spread
long_exit = long_trades and trading_hours_cond and bull_put_spread_exit

short_entry = short_trades and trading_hours_cond and bear_call_spread
short_exit = short_trades and trading_hours_cond and bear_call_spread_exit


// trailing stop
use_ts_atr = input.bool(true, title = 'ATR Trailing Stop', group = 'Trailing Stop', inline = '1')
ts_atr_mult = input.float(2.00, title = 'ATR Mult', group = 'Trailing Stop', inline = '2')
ts_atr_length = input.int(14, title = 'ATR Length', group = 'Trailing Stop', inline = '3')

atr_calculation = ta.atr(ts_atr_length)
J8_TS = atr_calculation / close * 100 * ts_atr_mult
entryPrice = strategy.position_avg_price
plot(entryPrice, title = 'Average Price', color = color.gray, style = plot.style_circles, display = display.none)

var float long_ts_price = na
var float short_ts_price = na
long_ts_price := long_entry[1] ? entryPrice - atr_calculation : entryPrice > 0 ? math.max(long_ts_price[1], high - atr_calculation)
     : na
short_ts_price := short_entry[1] ? entryPrice + atr_calculation : entryPrice > 0 ? math.min(short_ts_price[1], low + atr_calculation)
     : na
plot(long_ts_price > 0 ? long_ts_price : short_ts_price > 0 ? short_ts_price : na, title = 'Trailing Stop', 
     color = color.fuchsia, style = plot.style_circles, display = display.none)

long_ts_exit = use_ts_exits and use_ts_atr and low <= long_ts_price
short_ts_exit = use_ts_exits and use_ts_atr and high >= short_ts_price

if past_strategy_start_date
    if trading_hours_cond
        if long_entry
            strategy.entry(id = 'LE', comment  = "SELL BULL PS", direction = strategy.long) 
        if short_entry
            strategy.entry(id = 'SS_E', comment  = "SELL BEAR CS", direction = strategy.short) 

    if long_exit
        strategy.close(id = 'LE', comment = 'Closed')
    if short_exit
        strategy.close(id = 'SS_E', comment = 'Closed')

    if long_ts_exit
        strategy.close(id = 'LE', comment = 'L_TS')
    if short_ts_exit
        strategy.close(id = 'SS_E', comment = 'SS_TS')

    if use_trading_hours and not trading_hours_cond
        strategy.close(id = 'LE', comment = 'EOD')
        strategy.close(id = 'SS_E', comment = 'EOD')








// DASHBOARD

initial_capital = strategy.initial_capital
LabelSize = input.string(defval="small", options=["small", "medium", "large"], group = "Dashboard Settings", title = "Label Size", inline = '1')
label_size = LabelSize == "small" ? size.small : LabelSize == "medium" ? size.normal : LabelSize == "large" ? size.large : size.small
dashboard_text_color = input.color(color.new(#000000, 0 ), "Text Color", group = "Dashboard Settings", inline = '2')
bull_color = input.color(color.new(#04fc04,0), "Bull Color", group = "Dashboard Settings", inline = '2')
dash_bear_color = input.color(color.new(#fc0404,0), "Bear Color", group = "Dashboard Settings", inline = '2')
neutral_color = input.color(color.new(color.white,0), "Neutral Color", group = "Dashboard Settings", inline = '2')
var table d = table.new(position.bottom_right, 1, 20, border_width = 1, frame_color = #000000)

//trade size function
get_trade_size() =>
    total_contracts = 0.00
    
    for i = 0 to strategy.closedtrades-1
        total_contracts += math.abs(strategy.closedtrades.size(i))
    total_contracts

trade_size = math.round(get_trade_size() / strategy.closedtrades,0)
    
//lots of values
get_dashboard_values_function() =>
    
    combined_dollars_f = 0.00
    trades_pnl_f = array.new_float(0)
    winning_trade_sum_f = array.new_float(0)
    wins_combined_dollars_f = 0.00
    losing_trade_sum_f = array.new_float(0)
    loss_combined_dollars_f = 0.00
    
    for i = 0 to strategy.closedtrades-1
    
        combined_dollars_f += strategy.closedtrades.entry_price(i) * trade_size
        array.push(trades_pnl_f, strategy.closedtrades.profit(i))
        
        if strategy.closedtrades.profit(i) > 0 
            array.push(winning_trade_sum_f, strategy.closedtrades.profit(i))
            wins_combined_dollars_f += strategy.closedtrades.entry_price(i) * trade_size
        
        if strategy.closedtrades.profit(i) < 0
            array.push(losing_trade_sum_f, strategy.closedtrades.profit(i))
            loss_combined_dollars_f += strategy.closedtrades.entry_price(i) * trade_size
            
    max_win_f = array.max(trades_pnl_f)
    max_loss_f = array.min(trades_pnl_f)
    
    win_trade_sum_f = array.sum(winning_trade_sum_f)
    loss_trade_sum_f = array.sum(losing_trade_sum_f)
        
    [combined_dollars_f, max_win_f, max_loss_f, win_trade_sum_f, wins_combined_dollars_f, loss_trade_sum_f, loss_combined_dollars_f]

// Buy and Hold
buyAndHoldReturnInAccount(from) =>
    if time >= from
        money = open * syminfo.pointvalue
        var begin = strategy.convert_to_account(money)
        (strategy.convert_to_account(money) - begin) / begin * 100
        percent = (close - begin) / begin * 100

//max win/loss stuff     
find_entry_value_win_loss(value) =>
    entryP = 0.00
    for i = 0 to strategy.closedtrades-1
        if value == strategy.closedtrades.profit(i) 
            entryP := strategy.closedtrades.entry_price(i)
    entryP
 
//avg bars in tradetable
avgBarsInTrade() =>
    result = 0
    win_result = 0
    loss_result = 0
    for i = 0 to strategy.closedtrades-1
        result += strategy.closedtrades.exit_bar_index(i) - strategy.closedtrades.entry_bar_index(i) + 1
        
        if strategy.closedtrades.profit(i) > 0 
            win_result += strategy.closedtrades.exit_bar_index(i) - strategy.closedtrades.entry_bar_index(i) + 1
            
        if strategy.closedtrades.profit(i) < 0 
            loss_result += strategy.closedtrades.exit_bar_index(i) - strategy.closedtrades.entry_bar_index(i) + 1
        
    avg_return = math.round(strategy.closedtrades > 0 ? result / strategy.closedtrades : na)
    win_return = math.round(strategy.closedtrades > 0 ? win_result / strategy.wintrades : na)
    loss_return = math.round(strategy.closedtrades > 0 ? loss_result / strategy.losstrades : na)
    
    [avg_return, win_return, loss_return]
    
// #buy and hold return
show_buy_and_hold = input.bool(true, "Show Buy & Hold Return", group = "Dashboard Settings", inline = '8')
buy_hold_timeframe = input.time(timestamp("01 July 2021 00:00:00 UTC-5"), "Start Date", group = "Dashboard Settings", inline = '8')
new_bh_return = math.round(buyAndHoldReturnInAccount(buy_hold_timeframe),0)
    
if (barstate.isconfirmed or barstate.islast)
    //#total closed trades
    show_total_closed_trades = input.bool(true, "Show Total Closed Trades", group = "Dashboard Settings", inline = '3')
    total_closed_orders = strategy.closedtrades
    
    // #total winning/losing trades
    show_winning_losing_trades_counter = input.bool(true, "Show Total W/L Trades", group = "Dashboard Settings", inline = '4')
    winning_trades = strategy.wintrades
    losing_trades = strategy.losstrades
    win_lose_color = winning_trades > losing_trades ? bull_color : dash_bear_color
    
    // #profit factor
    show_profit_factor = input.bool(true, "Show Profit Factor", group = "Dashboard Settings", inline = '5')
    target_profit_factor = input.float(1.50, " | Target Profit Factor", group = "Dashboard Settings", tooltip = 'A profit factor of 1.5 means that if you invest $1, you can expect to earn $1.5. The profit factor is the ratio between gross profits and gross losses.', inline = '5') 
    profit_factor = math.round(strategy.grossprofit / strategy.grossloss,2)
    profit_factor_color = profit_factor > target_profit_factor ? bull_color : dash_bear_color
    
    // #win rate
    show_percent_profitable = input.bool(true,"Show Percent Profitable", group = "Dashboard Settings", inline = '6')
    target_win_rate = input.float(50.00, " | Target Win %", group = "Dashboard Settings", inline = '6') 
    win_rate = math.round(winning_trades / total_closed_orders * 100, 1)
    win_rate_color = win_rate >= target_win_rate ? bull_color : dash_bear_color
    
    [combined_dollars, max_win, max_loss, winning_trade_sum, wins_combined_dollars, losing_trade_sum, loss_combined_dollars] = get_dashboard_values_function()
    
    // #net profit on capital$ and % - % is based off account size
    show_net_profit = input.bool(true,"Show Net Profit", group = "Dashboard Settings", inline = '7')
    target_roi_on_capital = input.float(20.00, " | Target ROI %", group = "Dashboard Settings", inline = '7', tooltip = 'What roi on your trading capital do you want? (this will color net profit white if condition is met)')
    net_profit = math.round(strategy.netprofit,0)
    avg_trade_size = math.round(combined_dollars/total_closed_orders,0)
    net_profit_roi_pct = math.round(net_profit / avg_trade_size * 100 ,1)
    net_profit_roi_pct_color = net_profit > 0 and net_profit_roi_pct < target_roi_on_capital ? color.white : net_profit_roi_pct >= target_roi_on_capital ? bull_color : dash_bear_color
    
    // #largest winning trade - % is based off position size
    show_max_win_trade = input.bool(true, "Show Largest Winning Trade", group = "Dashboard Settings", inline = '9')
    max_win_entry = find_entry_value_win_loss(max_win)
    max_win_pct = math.round((max_win / (max_win_entry * trade_size) * 100),1)
    
    // #largest losing trade - % is based off position size
    show_max_loss_trade = input.bool(true, "Show Largest Losing Trade", group = "Dashboard Settings", inline = '10')
    max_loss_entry = find_entry_value_win_loss(max_loss)
    max_loss_pct = math.round((max_loss / (max_loss_entry * trade_size) * 100),1)
    
    // #avg trade 
    show_avg_trade = input.bool(true, "Show Avg. Trade", group = "Dashboard Settings", inline = '11')
    avg_trade = math.round(net_profit / total_closed_orders,2)
    avg_trade_roi = math.round((net_profit / combined_dollars *100),1)
    [avg_duration,avg_win_duration, avg_loss_duration] = avgBarsInTrade()
    avg_trade_color = avg_trade > 0 ? bull_color : dash_bear_color
    
    // #avg winning trade
    show_avg_winning_trade = input.bool(true, "Show Avg. Winning Trade", group = "Dashboard Settings", inline = '12')
    target_roi_on_wins = input.float(5.00, " | Target ROI %", group = "Dashboard Settings", inline = '12', tooltip = 'What roi on your trading capital do you want? (this will color net profit white if condition is met)')
    avg_winning_trade =  math.round(winning_trade_sum/winning_trades,2)
    win_trade_roi = math.round((winning_trade_sum / wins_combined_dollars *100) ,1)
    avg_win_color = win_trade_roi >= target_roi_on_wins and profit_factor > target_profit_factor ? neutral_color : bull_color 
    
    // #avg losing trade
    show_avg_losing_trade = input.bool(true, "Show Avg. Losing Trade", group = "Dashboard Settings", inline = '13')
    avg_losing_trade =  math.round(losing_trade_sum/losing_trades,2)
    loss_trade_roi = math.round((losing_trade_sum / loss_combined_dollars *100) ,1)
    avg_loss_color = dash_bear_color 
    
    // #MAX DRAWDOWN - % is based off account size
    show_max_dd = input.bool(true, "Show Max DD", group = "Dashboard Settings", inline = '14')
    max_dd = strategy.max_drawdown
    max_dd_pct = math.round(max_dd / initial_capital * 100, 2)
    
    // #OPEN TRADE PNL
    show_open_trade = input.bool(true, "Show Open Trade", group = "Dashboard Settings", inline = '15')
    show_open_trade_fixed = show_open_trade and strategy.opentrades != 0
    open_trade_pnl = strategy.openprofit
    open_trade_pct = math.round(open_trade_pnl / (strategy.position_avg_price * trade_size) * 100,2)
    open_trade_color = open_trade_pnl > 0 ? bull_color : dash_bear_color

    // STRATEGY
    if show_RSI_label
        table.cell(d, 0, 1, text = rsi_label, width = 0, bgcolor = rsi_label_color, text_size = label_size, text_color = dashboard_text_color)
    if show_ic_label
        table.cell(d, 0, 2, text = ic_label, width = 0, bgcolor = ic_label_color, text_size = label_size, text_color = dashboard_text_color)
    table.cell(d, 0, 0, text = "J8 TS: " + str.tostring(math.round(J8_TS,2)) + "%", width = 0, bgcolor = color.new(#ffafaf,0), text_size = label_size, text_color = dashboard_text_color)


    //FOR DASHBOARD
    if show_total_closed_trades 
        table.cell(d, 0, 3, text = "Total: " + str.tostring(total_closed_orders), width = 0, bgcolor = neutral_color, text_size = label_size, text_color = dashboard_text_color)
    if show_winning_losing_trades_counter
        table.cell(d, 0, 4, text ="W: " + str.tostring(winning_trades) + " | L: " + str.tostring(losing_trades) , width = 0, bgcolor = win_lose_color, text_size = label_size, text_color = dashboard_text_color)
    if show_net_profit
        table.cell(d, 0, 5, text = "Net Profit: $" + str.tostring(net_profit) + " on $" + str.tostring(avg_trade_size) + " | ROI " + str.tostring(net_profit_roi_pct) + "%" , width = 0, bgcolor = net_profit_roi_pct_color, text_size = label_size, text_color = dashboard_text_color)  
    if show_buy_and_hold
        table.cell(d, 0, 6, text ="B&H: " + str.tostring(new_bh_return) + "%", width = 0, bgcolor = neutral_color, text_size = label_size, text_color = dashboard_text_color)  
    
    if show_daytrading_labels
        if show_profit_factor
            table.cell(d, 0, 7, text = "Profit Factor: " + str.tostring(profit_factor) + "x" , width = 0, bgcolor = profit_factor_color, text_size = label_size, text_color = dashboard_text_color)  
        if show_percent_profitable
            table.cell(d, 0, 8, text = "WinRate: " + str.tostring(win_rate) + "%" , width = 0, bgcolor = win_rate_color, text_size = label_size, text_color = dashboard_text_color)  
        if show_max_win_trade
            table.cell(d, 0, 9, text =  "MaxWin: $" + str.tostring(max_win) + " | " + str.tostring(max_win_pct) + "%", width = 0, bgcolor = bull_color, text_size = label_size, text_color = dashboard_text_color)  
        if show_max_loss_trade
            table.cell(d, 0, 10, text = "MaxLoss: $" + str.tostring(max_loss) + " | " + str.tostring(max_loss_pct) + "%", width = 0, bgcolor = dash_bear_color, text_size = label_size, text_color = dashboard_text_color)  
        if show_avg_trade
            table.cell(d, 0, 11, text = "Avg trade: $" + str.tostring(math.round(avg_trade,0)) + " | "  +  str.tostring(avg_trade_roi) + "%" + " | " + str.tostring(avg_duration) + "bars", width = 0, bgcolor = avg_trade_color, text_size = label_size, text_color = dashboard_text_color)  
        if show_avg_winning_trade
            table.cell(d, 0, 12, text = "Avg Win: $" + str.tostring(math.round(avg_winning_trade,0)) + " | "  +  str.tostring(win_trade_roi) + "%" + " | " + str.tostring(avg_win_duration) + "bars", width = 0, bgcolor = avg_win_color, text_size = label_size, text_color = dashboard_text_color)  
        if show_avg_losing_trade
            table.cell(d, 0, 13, text = "Avg Loss: $" + str.tostring(math.round(avg_losing_trade,0)) + " | "  +  str.tostring(loss_trade_roi) + "%" + " | " + str.tostring(avg_loss_duration) + "bars" , width = 0, bgcolor = avg_loss_color, text_size = label_size, text_color = dashboard_text_color)  
        if show_max_dd
            table.cell(d, 0, 14, text = "Max DD: $" + str.tostring(math.round(max_dd,0)) + " | "  +  str.tostring(max_dd_pct) + "%", width = 0, bgcolor = dash_bear_color, text_size = label_size, text_color = dashboard_text_color)  
        
    if show_open_trade_fixed
        table.cell(d, 0, 15, text = "OpenT: $" + str.tostring(open_trade_pnl) + " | "  +  str.tostring(open_trade_pct) + "%" , width = 0, bgcolor = open_trade_color, text_size = label_size, text_color = dashboard_text_color)

Overview

J8 30 123 SPY Scalping PRO 2 Jerry evaluates price movement using configurable exponential and Hull moving averages combined with an ATR-based Supertrend calculation. The script plots signal arrows, custom candlestick coloring, and on-chart dashboard labels directly over price bars. It incorporates multiple position exit mechanisms, including trailing stop losses, target spread limits, and mandatory end-of-day closes, though standard fixed stop loss inputs are absent.

Details

Published by

g-moe on GitHub

Code credit

goodgains, as written in the script's header

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Trend, Moving averages, Volatility & bands, Scalping

Markets

Stocks, Indices

Timeframes

M1-M5, M15-H1

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
Show Dash Labelsbooltrueshow_dash_labels
Show Day Trade Labelsbooltrueshow_daytrading_labels
Paint Barsbooltruest_colorbars
Use Alertsbooltrueuse_alerts
Up⠀⠀⠀⠀⠀⠀colorcolor.greenup_color
⠀⠀⠀⠀⠀⠀Down⠀⠀⠀⠀⠀⠀colorcolor.reddn_color
Label⠀⠀⠀⠀color#fffffflabel_color
⠀⠀⠀⠀⠀⠀Transition⠀⠀⠀colorcolor.yellowtransition_color
Maxxed⠀⠀⠀colorcolor.new(#32C8FF, 0)maxxed_color
⠀⠀⠀⠀⠀⠀Rising⠀⠀⠀⠀⠀colorcolor.new(#00FF00, 0)rising_color
Bear⠀⠀⠀⠀⠀colorcolor.new(#E10000,0)bear_color
⠀⠀⠀⠀⠀⠀Pretrend⠀⠀⠀colorcolor.new(#C87DFF,0)pretrend_color
Show all 40 settings
SettingTypeDefaultVariable
OB⠀⠀⠀⠀⠀⠀colorcolor.new(#ABABE1,0)ob_color
⠀⠀⠀⠀⠀⠀OS⠀⠀⠀⠀⠀⠀⠀colorcolor.new(#DCDC80,0)os_color
Pricesourcecloseinput_price
Use Z Exitsbooltrueuse_z_exits
Use Trailing Stop Exitsbooltrueuse_ts_exits
Use EOD Exitsbooltrueuse_close_eod
Spread Credit Targetfloat0.20spreads_credit_target
Spread Sizefloat10.00spreads_size
Wingsfloat1.00wings
ATR Multfloat1.0st_ts_atr_mult
st_natrint4st_natr
AvgType STstringHMAst_avgtype
Show Arrowsbooltruest_showarrows
st_arrowcountint2st_arrowcount
Show Bubblesboolfalseshow_arrowbubble
EMA Length 1int13ma_length1
EMA Length 2int50ma_length2
EMA Length 3int75ma_length3
Avg TypestringEMAma_averagetype
Show RSI Labelboolfalseshow_RSI_label
RSI OBint70rsi_ob
RSI OSint35rsi_os
RSI Lengthint12rsi_length
BB Lengthint10md_bb_length
BB Deviationfloat1.0md_bb_dev
MACD Fastint12md_fastlength
MACD Slowint26md_slowlength
MACD Lengthint5md_macdlength
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

2 stars

This trend-following strategy plots on the price chart and identifies continuation trades during established trends. It calculates dual exponential moving averages alongside an average directional index filter. Entries trigger when price pulls back into the mo

Strategy v6 TrendMoving averages
Updated 4 weeks ago · Custom licence GitHub repository of MP EMA 9/21 Pullback Continuation

This mean-reversion strategy plots Bollinger Bands and a long-term moving average directly on the price chart. It enters trades when price candles penetrate the outer Bollinger Bands beyond a user-defined body percentage, anticipating a price reversal. Entries

Strategy v5 Mean reversionVolatility & bands
Updated 2 months ago · None stated GitHub repository of Bollinger Bands Winner PRO [Alorse]
257 stars

This overlay strategy targets one-minute ES futures and plots volume-weighted moving-average bands from the open, scaled by a standard-deviation multiple, plus a slower band from ten-minute opens. A higher-timeframe exponential moving average can filter trades

Strategy v6 Moving averagesVolatility & bands
Updated 6 weeks ago · None stated GitHub repository of ES - Futures 1M No Repaint

STRG-BBForce

by harryguiacorn
219 stars

STRG-BBForce is a Bollinger Bands trend-following strategy. It calculates standard Bollinger Bands and tracks directional alignment across the upper, lower, and basis lines. When all three lines slope upward, it opens a long position and closes short positions

Strategy v5 TrendVolatility & bands
Updated 1 year ago · None stated GitHub repository of STRG-BBForce
106 stars

This trading strategy combines three Exponential Moving Averages (8, 14, and 50 periods by default) with Stochastic RSI and Average True Range (ATR). It enters a long position when EMA 1 is above EMA 2, EMA 2 is above EMA 3, and the Stochastic RSI %K line cros

Strategy v4 TrendOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of 3 x EMA + Stochastic RSI + ATR

Bollinger Bands Strategy

by cklose2000
105 stars

This strategy generates buy and sell signals based on Bollinger Band crossovers combined with a simple moving average trend filter. It enters a long position when price crosses above the lower band while trading above the SMA filter line, and enters a short po

Strategy v5 Volatility & bandsMoving averages
Updated 1 year ago · None stated GitHub repository of Bollinger Bands 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