Pine Script v4 · Strategy
PSAR + EMA-TEMA-RSI-OBV
A Pine Script v4 strategy built on EMA (sourceTEMA, length), Change (close) and Crossover (temaSlow, temaFast). It has 6 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss. Each trade commits 20% of equity and pays 0.1% commission. 59 settings; defaults include Source for indicator close, PSAR Start 0.02 and PSAR Increment 0.02.
Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.
- Does PSAR + EMA-TEMA-RSI-OBV repaint?
- Yes
- At least one pattern in the source can repaint: intrabar recalculation.
- How did PSAR + EMA-TEMA-RSI-OBV do on BTCUSDT 1D with default settings?
- Not measured
- It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its code limits trading to a date window, which can leave this period out. It closed no trades on the other markets either. A backtest, not investment advice.
- Can PSAR + EMA-TEMA-RSI-OBV be converted to Pine Script v5?
- Not tested
- The steps are shown below, but neither version placed a trade on any market tested, so there was nothing to compare and no download is offered.
- What alerts does PSAR + EMA-TEMA-RSI-OBV have?
- 3
- PSAR buy/long signal confirmed for {{ticker}} on {{interval}}.; PSAR sell/short signal confirmed for {{ticker}} on {{interval}}.; PSAR has changed direction for {{ticker}} on {{interval}}..
- Does PSAR + EMA-TEMA-RSI-OBV use a stop loss?
- Yes
- strategy.exit sets a stop on line 331, 335.
BTCUSDT · 1D · default settings
- EMA Fast Plot
- EMA Slow Plot
- EMA Additional Plot
- EMA Cross Up
- EMA Cross Down
- PSAR
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- 0.00%
- $0.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 0
- 0 won · 0 lost
- Profitable
- 0.0%
- of closed trades
- Profit factor
- —
- gross profit ÷ gross loss
- Max drawdown
- 0.00%
- $0.00
One run with the author's default settings, $5,000 starting capital, commission as the script sets it. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.
Review
What a careful reader of this script would point out, found by checking the source and the backtest.
-
Check
1 setting does nothing
“EMA length” is declared but never read.
-
Note
1 setting has no label
In the settings dialog lengthCMF (line 137) shows an empty name. The labels on this page come from the variable names.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
-
Note
Uses an argument v6 removed
when = on line 329, 332, 333, 336. The upgraded version below moves each call inside an if block.
-
Note
Uses iff(), which v5 removed line 194
iff() on line 194, 195, 195, 196, 196, 201, 203, 203, 345, 345, 348, 348. v5 writes it as the ternary c ? a : b.
-
Note
Uses long =, which v5 renamed line 329
long = on line 329, 333. v5 writes it as direction = strategy.long or strategy.short.
Upgrade and export
Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.
- Upgrading to v5 renames rising → ta.rising, ema → ta.ema, atan → math.atan, change → ta.change, cum → ta.cum, crossover → ta.crossover, crossunder → ta.crossunder, sar → ta.sar, rsi → ta.rsi, sma → ta.sma, stoch → ta.stoch, sum → math.sum, tostring → str.tostring, round → math.round.
- 4 strategy calls use the when = argument (line 329, 332, 333, 336). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 56: //@version=4 → //@version=5
- Line 85: input(type = input.source) → input.source()
- Line 86: input(type = input.bool) → input.bool()
- Line 87: input(type = input.bool) → input.bool()
- Line 89: input(type = input.float) → input.float()
- Line 90: input(type = input.float) → input.float()
92 more edits
- Line 91: input(type = input.float) → input.float()
- Line 94: input(type = input.bool) → input.bool()
- Line 95: input(type = input.bool) → input.bool()
- Line 96: input(type = input.bool) → input.bool()
- Line 97: input(type = input.color) → input.color()
- Line 98: input(type = input.color) → input.color()
- Line 99: input(type = input.bool) → input.bool()
- Line 101: input(type = input.bool) → input.bool()
- Line 103: input(type = input.color) → input.color()
- Line 105: input(type = input.color) → input.color()
- Line 106: input(type = input.integer) → input.int()
- Line 107: input(type = input.bool) → input.bool()
- Line 108: input(type = input.bool) → input.bool()
- Line 109: input(type = input.integer) → input.int()
- Line 110: input(type = input.color) → input.color()
- Line 111: input(type = input.integer) → input.int()
- Line 112: input(type = input.color) → input.color()
- Line 113: input(type = input.integer) → input.int()
- Line 114: input(type = input.color) → input.color()
- Line 115: input(type = input.bool) → input.bool()
- Line 116: input(type = input.integer) → input.int()
- Line 117: input(type = input.integer) → input.int()
- Line 118: input(type = input.integer) → input.int()
- Line 119: input(type = input.integer) → input.int()
- Line 120: input(type = input.bool) → input.bool()
- Line 121: input(type = input.bool) → input.bool()
- Line 124: input(type = input.integer) → input.int()
- Line 125: input(type = input.color) → input.color()
- Line 126: input(type = input.color) → input.color()
- Line 127: input(type = input.integer) → input.int()
- Line 128: input(type = input.integer) → input.int()
- Line 132: input(type = input.integer) → input.int()
- Line 133: input(type = input.integer) → input.int()
- Line 134: input(type = input.integer) → input.int()
- Line 135: input(type = input.integer) → input.int()
- Line 136: input(type = input.integer) → input.int()
- Line 138: input(type = input.bool) → input.bool()
- Line 144: input(type = input.bool) → input.bool()
- Line 147: input(type = input.time) → input.time()
- Line 149: input(type = input.time) → input.time()
- Line 167: rising → ta.rising
- Line 169: ema → ta.ema
- Line 170: ema → ta.ema
- Line 171: ema → ta.ema
- Line 194: iff(c, a, b) → (c ? a : b)
- Line 194: atan → math.atan
- Line 195: iff(c, a, b) → (c ? a : b)
- Line 195: iff(c, a, b) → (c ? a : b)
- Line 196: iff(c, a, b) → (c ? a : b)
- Line 196: iff(c, a, b) → (c ? a : b)
- Line 199: atan → math.atan
- Line 201: iff(c, a, b) → (c ? a : b)
- Line 203: iff(c, a, b) → (c ? a : b)
- Line 203: iff(c, a, b) → (c ? a : b)
- Line 205: change → ta.change
- Line 206: cum → ta.cum
- Line 210: crossover → ta.crossover
- Line 211: crossunder → ta.crossunder
- Line 213: ema → ta.ema
- Line 214: ema → ta.ema
- Line 215: ema → ta.ema
- Line 216: crossover → ta.crossover
- Line 217: crossunder → ta.crossunder
- Line 220: ema → ta.ema
- Line 221: change → ta.change
- Line 222: ema → ta.ema
- Line 223: sar → ta.sar
- Line 228: rsi → ta.rsi
- Line 268: crossover → ta.crossover
- Line 269: crossunder → ta.crossunder
- Line 271: sma → ta.sma
- Line 271: stoch → ta.stoch
- Line 272: sma → ta.sma
- Line 273: ema → ta.ema
- Line 274: ema → ta.ema
- Line 276: ema → ta.ema
- Line 278: sum → math.sum
- Line 278: sum → math.sum
- Line 329: long = strategy.long → direction = strategy.long
- Line 333: long = strategy.short → direction = strategy.short
- Line 344: tostring → str.tostring
- Line 344: round → math.round
- Line 345: iff(c, a, b) → (c ? a : b)
- Line 345: iff(c, a, b) → (c ? a : b)
- Line 347: tostring → str.tostring
- Line 347: round → math.round
- Line 348: iff(c, a, b) → (c ? a : b)
- Line 348: iff(c, a, b) → (c ? a : b)
- Line 353: rising → ta.rising
- Line 359: rising → ta.rising
- Line 365: rising → ta.rising
- Line 372: tostring → str.tostring
⋯// - EMA, RSI and SRSI built-ins.-//@version=4+//@version=5strategy(overlay=true, title="PSAR + EMA/TEMA/RSI/OBV", currency = 'USD', shorttitle="PSAR+", ⋯// ------------------------------------------------<[ User Input ]>----------------------------------------------------sourceGlobal = input(title="Source for indicator", defval=close, type=input.source, group="Global")+sourceGlobal = input.source(title="Source for indicator", defval=close, group="Global")-tradeLong = input(title="Create long positions?", defval=true, type=input.bool, group="Global")+tradeLong = input.bool(title="Create long positions?", defval=true, group="Global")-tradeShort = input(title="Create short positions?", defval=false, type=input.bool, group="Global")+tradeShort = input.bool(title="Create short positions?", defval=false, group="Global")showPSAR = input(true, "Show PSAR?", group="PSAR")-psarStart = input(title="PSAR Start", type=input.float, step=0.001, defval=0.02, group="PSAR")+psarStart = input.float(title="PSAR Start", step=0.001, defval=0.02, group="PSAR")-psarIncrement = input(title="PSAR Increment", type=input.float, step=0.001, defval=0.02, group="PSAR")+psarIncrement = input.float(title="PSAR Increment", step=0.001, defval=0.02, group="PSAR")-psarMaximum = input(title="PSAR Maximum", type=input.float, step=0.01, defval=0.2, group="PSAR")+psarMaximum = input.float(title="PSAR Maximum", step=0.01, defval=0.2, group="PSAR")psarConfirmation = input(title="Confirmation signal:", defval="EMA", options=["EMA", "TEMA", "eMAMA", "RSI", "OBV"], group="PSAR")-psarHighlightStartPoints = input(title="PSAR Highlight Start Points?", type=input.bool, defval=true, group="PSAR")+psarHighlightStartPoints = input.bool(title="PSAR Highlight Start Points?", defval=true, group="PSAR")-psarShowLabels = input(title="PSAR Show Buy/Sell Labels?", type=input.bool, defval=true, group="PSAR")+psarShowLabels = input.bool(title="PSAR Show Buy/Sell Labels?", defval=true, group="PSAR")-psarHighlightState = input(title="PSAR Highlight State?", type=input.bool, defval=false, group="PSAR")+psarHighlightState = input.bool(title="PSAR Highlight State?", defval=false, group="PSAR")-colorPSARLong = input(title="Long", type=input.color, defval=lime, group="PSAR", inline="colors")+colorPSARLong = input.color(title="Long", defval=lime, group="PSAR", inline="colors")-colorPSARShort = input(title="Short", type=input.color, defval=red, group="PSAR", inline="colors")+colorPSARShort = input.color(title="Short", defval=red, group="PSAR", inline="colors")-useSL = input(defval=false, type=input.bool, title="Set stop loss to PSAR plot?")+useSL = input.bool(defval=false, title="Set stop loss to PSAR plot?")showTEMA = input(false, "Show TEMA?", group="Triple EMA", inline="showTEMA")-showTEMAfill = input(title="Shade TEMA?", defval=false, type=input.bool, group="Triple EMA", inline="showTEMA")+showTEMAfill = input.bool(title="Shade TEMA?", defval=false, group="Triple EMA", inline="showTEMA")lengthTEMAFast = input(title="TEMA Fast length", defval=13, minval=1, group="Triple EMA", inline="TemaFast")-colorTEMAFast = input(title="",type=input.color, defval=lime, inline="TemaFast", group="Triple EMA")+colorTEMAFast = input.color(title="", defval=lime, inline="TemaFast", group="Triple EMA")lengthTEMASlow = input(title="TEMA Slow length", defval=34, minval=1, group="Triple EMA", inline="TemaSlow")-colorTEMASlow = input(title="",type=input.color, defval=red, group="Triple EMA", inline="TemaSlow")+colorTEMASlow = input.color(title="", defval=red, group="Triple EMA", inline="TemaSlow")-thicknessTEMA=input(title="Line thickness", defval=2, type=input.integer, minval=1, maxval=4, step=1, group="Triple EMA")+thicknessTEMA=input.int(title="Line thickness", defval=2, minval=1, maxval=4, step=1, group="Triple EMA")-showEMA = input(defval=true, type=input.bool, title="Show EMA?", group="EMA", inline="showEMA")+showEMA = input.bool(defval=true, title="Show EMA?", group="EMA", inline="showEMA")-showEMAfill = input(title="Shade EMA?", defval=false, type=input.bool, group="EMA", inline="showEMA")+showEMAfill = input.bool(title="Shade EMA?", defval=false, group="EMA", inline="showEMA")-lengthEMAFast = input(9, title='EMA Fast Length', step=1, type=input.integer, group="EMA", inline="EmaFast")+lengthEMAFast = input.int(9, title='EMA Fast Length', step=1, group="EMA", inline="EmaFast")-colorEMAFast = input(title="",type=input.color, defval=lime, inline="EmaFast", group="EMA")+colorEMAFast = input.color(title="", defval=lime, inline="EmaFast", group="EMA")-lengthEMASlow = input(21, title='EMA Slow Length', step=1, type=input.integer, group="EMA", inline="EmaSlow")+lengthEMASlow = input.int(21, title='EMA Slow Length', step=1, group="EMA", inline="EmaSlow")-colorEMASlow = input(title="",type=input.color, defval=red, group="EMA", inline="EmaSlow")+colorEMASlow = input.color(title="", defval=red, group="EMA", inline="EmaSlow")-lengthEMA200 = input(200, title='EMA Additional Length', step=1, type=input.integer, group="EMA", inline="EMA200")+lengthEMA200 = input.int(200, title='EMA Additional Length', step=1, group="EMA", inline="EMA200")-colorEMA200 = input(title="",type=input.color, defval=orange, group="EMA", inline="EMA200")+colorEMA200 = input.color(title="", defval=orange, group="EMA", inline="EMA200")-filterEMA200 = input(title="Use as filter?", defval=false, type=input.bool, group="EMA", inline="EMA200", tooltip="Buy and sell signals are filtered on the additional EMA line, commonly set to 200. This takes effect even if the PSAR confirmation is set to something other than EMA.")+filterEMA200 = input.bool(title="Use as filter?", defval=false, group="EMA", inline="EMA200", tooltip="Buy and sell signals are filtered on the additional EMA line, commonly set to 200. This takes effect even if the PSAR confirmation is set to something other than EMA.")-thicknessEMA=input(title="Line thickness", defval=2, type=input.integer, minval=1, maxval=4, step=1, group="EMA")+thicknessEMA=input.int(title="Line thickness", defval=2, minval=1, maxval=4, step=1, group="EMA")-lengthRSI = input(title="RSI Length", type=input.integer, defval=14, group="RSI")+lengthRSI = input.int(title="RSI Length", defval=14, group="RSI")-rsiOverbought = input(title="Overbought Level", type=input.integer, defval=60, group="RSI", inline="levels")+rsiOverbought = input.int(title="Overbought Level", defval=60, group="RSI", inline="levels")-rsiOversold = input(title="Oversold Level", type=input.integer, defval=40, group="RSI", inline="levels")+rsiOversold = input.int(title="Oversold Level", defval=40, group="RSI", inline="levels")-showeMAMA = input(defval=false, title="Show eMAMA?", type=input.bool, group="Ehler's MESA Adaptive Moving Average", inline="fill")+showeMAMA = input.bool(defval=false, title="Show eMAMA?", group="Ehler's MESA Adaptive Moving Average", inline="fill")-showEMAMAfill = input(title="Shade eMAMA?", defval=false, type=input.bool, group="Ehler's MESA Adaptive Moving Average", inline="fill")+showEMAMAfill = input.bool(title="Shade eMAMA?", defval=false, group="Ehler's MESA Adaptive Moving Average", inline="fill")fastlimitEMAMA=input(.5, title="Fast Limit", group="Ehler's MESA Adaptive Moving Average")slowlimitEMAMA=input(.05, title="Slow Limit", group="Ehler's MESA Adaptive Moving Average")-thicknessEMAMA=input(title="Line thickness", defval=2, type=input.integer, minval=1, maxval=4, step=1, group="Ehler's MESA Adaptive Moving Average")+thicknessEMAMA=input.int(title="Line thickness", defval=2, minval=1, maxval=4, step=1, group="Ehler's MESA Adaptive Moving Average")-coloreMAMA = input(title="eMAMA",type=input.color, defval=lime, group="Ehler's MESA Adaptive Moving Average", inline="colors")+coloreMAMA = input.color(title="eMAMA", defval=lime, group="Ehler's MESA Adaptive Moving Average", inline="colors")-coloreFAMA = input(title="eFAMA",type=input.color, defval=red, group="Ehler's MESA Adaptive Moving Average", inline="colors")+coloreFAMA = input.color(title="eFAMA", defval=red, group="Ehler's MESA Adaptive Moving Average", inline="colors")-lengthOBV = input(defval=20, title="OBV Length", type=input.integer, group="On Balance Volume")+lengthOBV = input.int(defval=20, title="OBV Length", group="On Balance Volume")-emaOBV = input(defval=9, title="EMA length", type=input.integer, group="On Balance Volume")+emaOBV = input.int(defval=9, title="EMA length", group="On Balance Volume")lengthStoch = input(14, "Stochastic Length", minval=1, group="SRSI")⋯smoothD = input(3, "SRSI D Smoothing", minval=1, group="SRSI")-srsiOverbought = input(defval=80, title="Overbought level", type=input.integer, group="SRSI", inline="levels")+srsiOverbought = input.int(defval=80, title="Overbought level", group="SRSI", inline="levels")-srsiOversold = input(defval=20, title="Oversold level", type=input.integer, group="SRSI", inline="levels")+srsiOversold = input.int(defval=20, title="Oversold level", group="SRSI", inline="levels")-lengthMACDfast = input(title="Fast Length", type=input.integer, defval=12, group="MACD")+lengthMACDfast = input.int(title="Fast Length", defval=12, group="MACD")-lengthMACDslow = input(title="Slow Length", type=input.integer, defval=26, group="MACD")+lengthMACDslow = input.int(title="Slow Length", defval=26, group="MACD")-lengthMACDsignal = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9, group="MACD")+lengthMACDsignal = input.int(title="Signal Smoothing", minval = 1, maxval = 50, defval = 9, group="MACD")lengthCMF = input(20, minval=1, group="Chaiken Money Flow")-showTable = input(defval=false, title="Show summary table?", type=input.bool, group="Summary Table")+showTable = input.bool(defval=false, title="Show summary table?", group="Summary Table")tablePosition = input(title="Summary Table Position", defval=position.bottom_left, ⋯ options=[size.auto, size.tiny, size.small, size.normal, size.large, size.huge], group="Summary Table")-useDateRange = input(defval=true, title="Limit backtesting by date", type=input.bool, group="Limit by date", +useDateRange = input.bool(defval=true, title="Limit backtesting by date", group="Limit by date", tooltip="Limit window for backtesting. This allows you to compare different TFs over the same period.")rangeType = input(defval="30 Days", title="Date range:", options=["Custom", "30 Days", "90 Days", "180 Days", "Year to Date"], group="Limit by date")-startDate = input(title="Start Date (DD/MM/YYYY)", type=input.time,+startDate = input.time(title="Start Date (DD/MM/YYYY)", defval=timestamp("1 Jan 2021 1:01 -0400"), group="Limit by date")-endDate = input(title="End Date (DD/MM/YYYY) ", type=input.time,+endDate = input.time(title="End Date (DD/MM/YYYY) ", defval=timestamp("31 Dec 2100 19:59 -0400"), group="Limit by date", tooltip="You likely want to leave this far in the future.")⋯fDirection(series, length) =>- rising(series,length) ? "↑" : "↓"+ ta.rising(series,length) ? "↑" : "↓"fTEMA(sourceTEMA, length) =>- Tema1 = ema(sourceTEMA, length)+ Tema1 = ta.ema(sourceTEMA, length)- Tema2 = ema(Tema1, length)+ Tema2 = ta.ema(Tema1, length)- Tema3 = ema(Tema2, length)+ Tema3 = ta.ema(Tema2, length) 3 * Tema1 - 3 * Tema2 + Tema3 ⋯ im := .2*im_ + .8*nz(im[1])- p1 = iff(im!=0 and re!=0, 360/atan(im/re), nz(p[1]))+ p1 = (im!=0 and re!=0 ? 360/math.atan(im/re) : nz(p[1]))- p2 = iff(p1 > 1.5*nz(p1[1]), 1.5*nz(p1[1]), iff(p1 < 0.67*nz(p1[1]), 0.67*nz(p1[1]), p1))+ p2 = (p1 > 1.5*nz(p1[1]) ? 1.5*nz(p1[1]) : (p1 < 0.67*nz(p1[1]) ? 0.67*nz(p1[1]) : p1))- p3 = iff(p2<6, 6, iff (p2 > 50, 50, p2))+ p3 = (p2<6 ? 6 : (p2 > 50 ? 50 : p2)) p := .2*p3 + .8*nz(p3[1]) spp := .33*p + .67*nz(spp[1])- phaseEMAMA = atan(q1 / i1)+ phaseEMAMA = math.atan(q1 / i1) dphase_ = nz(phaseEMAMA[1]) - phaseEMAMA- dphase = iff(dphase_< 1, 1, dphase_)+ dphase = (dphase_< 1 ? 1 : dphase_) alpha_ = fastlimitEMAMA / dphase- alpha = iff(alpha_ < slowlimitEMAMA, slowlimitEMAMA, iff(alpha_ > fastlimitEMAMA, fastlimitEMAMA, alpha_))+ alpha = (alpha_ < slowlimitEMAMA ? slowlimitEMAMA : (alpha_ > fastlimitEMAMA ? fastlimitEMAMA : alpha_))fOBV(src) =>- changeOBV = change(src)+ changeOBV = ta.change(src)- cum(changeOBV > 0 ? volume : changeOBV < 0 ? -volume : 0*volume)+ ta.cum(changeOBV > 0 ? volume : changeOBV < 0 ? -volume : 0*volume)// -------------------------------------------<[ Variable Calculations ]>------------------------------------------⋯temaFast = fTEMA(sourceGlobal, lengthTEMAFast)-shortTema = crossover(temaSlow, temaFast)+shortTema = ta.crossover(temaSlow, temaFast)-longTema = crossunder(temaSlow, temaFast)+longTema = ta.crossunder(temaSlow, temaFast)fillTema = temaFast>temaSlow ? color.new(colorTEMAFast,80) : color.new(colorTEMASlow,80)-emaFast = ema(sourceGlobal, lengthEMAFast)+emaFast = ta.ema(sourceGlobal, lengthEMAFast)-emaSlow = ema(sourceGlobal, lengthEMASlow)+emaSlow = ta.ema(sourceGlobal, lengthEMASlow)-ema200 = ema(sourceGlobal, lengthEMA200)+ema200 = ta.ema(sourceGlobal, lengthEMA200)-longEMA = crossover(emaFast, emaSlow)+longEMA = ta.crossover(emaFast, emaSlow)-shortEMA = crossunder(emaFast , emaSlow)+shortEMA = ta.crossunder(emaFast , emaSlow)fillEMA = emaFast>emaSlow ? color.new(colorEMAFast,80) : color.new(colorEMASlow,80)cumOBV = fOBV(sourceGlobal)-oscOBV = (cumOBV - ema(cumOBV,lengthOBV))+oscOBV = (cumOBV - ta.ema(cumOBV,lengthOBV))-changeOBV = change(sourceGlobal)+changeOBV = ta.change(sourceGlobal)-shortOBV = ema(cumOBV, lengthOBV)+shortOBV = ta.ema(cumOBV, lengthOBV)-psar = sar(psarStart, psarIncrement, psarMaximum)+psar = ta.sar(psarStart, psarIncrement, psarMaximum)psarDir = psar < close ? 1 : -1⋯psarChangeCond = psarDir != psarDir[1]-valueRSI = rsi(sourceGlobal, lengthRSI)+valueRSI = ta.rsi(sourceGlobal, lengthRSI)if psarConfirmation == "EMA"⋯eFAMA := .5*fMAMA(sourceGlobal, slowlimitEMAMA, fastlimitEMAMA)*eMAMA + (1 - .5*fMAMA(sourceGlobal, slowlimitEMAMA, fastlimitEMAMA))*nz(eFAMA[1])-longMAMA=crossover(eMAMA, eFAMA)+longMAMA=ta.crossover(eMAMA, eFAMA)-shortMAMA=crossunder(eMAMA,eFAMA)+shortMAMA=ta.crossunder(eMAMA,eFAMA)fillEMAMA = eMAMA>eFAMA ? color.new(coloreMAMA, 80) : color.new(coloreFAMA, 80)-srsiK = sma(stoch(valueRSI, valueRSI, valueRSI, lengthStoch), smoothK)+srsiK = ta.sma(ta.stoch(valueRSI, valueRSI, valueRSI, lengthStoch), smoothK)-srsiD = sma(srsiK, smoothD)+srsiD = ta.sma(srsiK, smoothD)-fastMACD = ema(sourceGlobal, lengthMACDfast)+fastMACD = ta.ema(sourceGlobal, lengthMACDfast)-slowMACD = ema(sourceGlobal, lengthMACDslow)+slowMACD = ta.ema(sourceGlobal, lengthMACDslow)macd = fastMACD - slowMACD-signalMACD = ema(macd, lengthMACDsignal)+signalMACD = ta.ema(macd, lengthMACDsignal)adCMF = close==high and close==low or high==low ? 0 : ((2*close-low-high)/(high-low))*volume-mfCMF = sum(adCMF, lengthCMF) / sum(volume, lengthCMF)+mfCMF = math.sum(adCMF, lengthCMF) / math.sum(volume, lengthCMF)// ================================== //⋯// ---------------------------------------------------<[ Strategy Execution ]>--------------------------------------------------strategy.entry(id="long", long=strategy.long, comment="enL", when=psarBuySignal and psarConfirmationBuy and tradeLong)+strategy.entry(id="long", direction = strategy.long, comment="enL", when=psarBuySignal and psarConfirmationBuy and tradeLong)if useSL⋯strategy.close(id="long", comment="exL", when=psarSellSignal and psarConfirmationSell and tradeLong)-strategy.entry(id="short", long=strategy.short, comment="enS", when=psarSellSignal and psarConfirmationSell and tradeShort)+strategy.entry(id="short", direction = strategy.short, comment="enS", when=psarSellSignal and psarConfirmationSell and tradeShort)if useSL⋯ rsiDirection = fDirection(valueRSI,1)- table.cell(summaryTable, 0, 1, "RSI " + tostring(round(valueRSI,0)) + rsiDirection,text_size=tableTextSize, + table.cell(summaryTable, 0, 1, "RSI " + str.tostring(math.round(valueRSI,0)) + rsiDirection,text_size=tableTextSize, - bgcolor = iff(valueRSI > rsiOverbought, color.red, iff(valueRSI < rsiOversold, color.green, color.yellow)))+ bgcolor = (valueRSI > rsiOverbought ? color.red : (valueRSI < rsiOversold ? color.green : color.yellow))) srsiDirection = fDirection(srsiK,1)- table.cell(summaryTable, 0, 2, "K " + tostring(round(srsiK,0)) + srsiDirection, text_size=tableTextSize, + table.cell(summaryTable, 0, 2, "K " + str.tostring(math.round(srsiK,0)) + srsiDirection, text_size=tableTextSize, - bgcolor=iff(srsiK > srsiOverbought, color.red, iff(srsiK < srsiOversold, color.green, srsiK > srsiD ? color.green : color.red)))+ bgcolor=(srsiK > srsiOverbought ? color.red : (srsiK < srsiOversold ? color.green : srsiK > srsiD ? color.green : color.red))) emaDirection = fDirection(emaFast,1)⋯ // See if emaFast has increased over the last two periods.- if rising(emaFast,2) and emaFast < emaSlow+ if ta.rising(emaFast,2) and emaFast < emaSlow table.cell_set_bgcolor(summaryTable, 1, 0, color.yellow)⋯ // See if temaFast has increased over the last two periods.- if rising(temaFast,2) and temaFast < temaSlow+ if ta.rising(temaFast,2) and temaFast < temaSlow table.cell_set_bgcolor(summaryTable, 1, 1, color.yellow)⋯ // See if temaFast has increased over the last two periods.- if rising(eMAMA,2) and eMAMA < eFAMA+ if ta.rising(eMAMA,2) and eMAMA < eFAMA table.cell_set_bgcolor(summaryTable, 1, 2, color.yellow)⋯ directionCMF = fDirection(mfCMF,2)- table.cell(summaryTable, 2, 2, "CMF " + directionCMF + tostring(mfCMF, "#.##"), text_size=tableTextSize, bgcolor= mfCMF > 0 ? color.green : color.red)+ table.cell(summaryTable, 2, 2, "CMF " + directionCMF + str.tostring(mfCMF, "#.##"), text_size=tableTextSize, bgcolor= mfCMF > 0 ? color.green : color.red)// ---------------------------------------------------<[ Alerts ]>-------------------------------------------------⋯Clean v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 88: input() → input.bool()
- Line 92: input() → input.string()
- Line 100: input() → input.bool()
- Line 102: input() → input.int()
- Line 104: input() → input.int()
- Line 122: input() → input.float()
10 more edits
- Line 123: input() → input.float()
- Line 129: input() → input.int()
- Line 130: input() → input.int()
- Line 131: input() → input.int()
- Line 137: input() → input.int()
- Line 146: input() → input.string()
- Line 329: when = psarBuySignal and psarConfirmationBuy and tradeLong → if block
- Line 332: when = psarSellSignal and psarConfirmationSell and tradeLong → if block
- Line 333: when = psarSellSignal and psarConfirmationSell and tradeShort → if block
- Line 336: when = psarBuySignal and psarConfirmationBuy and tradeShort → if block
⋯tradeShort = input.bool(title="Create short positions?", defval=false, group="Global")-showPSAR = input(true, "Show PSAR?", group="PSAR")+showPSAR = input.bool(true, "Show PSAR?", group="PSAR")psarStart = input.float(title="PSAR Start", step=0.001, defval=0.02, group="PSAR")⋯psarMaximum = input.float(title="PSAR Maximum", step=0.01, defval=0.2, group="PSAR")-psarConfirmation = input(title="Confirmation signal:", defval="EMA", +psarConfirmation = input.string(title="Confirmation signal:", defval="EMA", options=["EMA", "TEMA", "eMAMA", "RSI", "OBV"], group="PSAR")⋯useSL = input.bool(defval=false, title="Set stop loss to PSAR plot?")-showTEMA = input(false, "Show TEMA?", group="Triple EMA", inline="showTEMA")+showTEMA = input.bool(false, "Show TEMA?", group="Triple EMA", inline="showTEMA")showTEMAfill = input.bool(title="Shade TEMA?", defval=false, group="Triple EMA", inline="showTEMA")-lengthTEMAFast = input(title="TEMA Fast length", defval=13, minval=1, group="Triple EMA", inline="TemaFast")+lengthTEMAFast = input.int(title="TEMA Fast length", defval=13, minval=1, group="Triple EMA", inline="TemaFast")colorTEMAFast = input.color(title="", defval=lime, inline="TemaFast", group="Triple EMA")-lengthTEMASlow = input(title="TEMA Slow length", defval=34, minval=1, group="Triple EMA", inline="TemaSlow")+lengthTEMASlow = input.int(title="TEMA Slow length", defval=34, minval=1, group="Triple EMA", inline="TemaSlow")colorTEMASlow = input.color(title="", defval=red, group="Triple EMA", inline="TemaSlow")⋯showEMAMAfill = input.bool(title="Shade eMAMA?", defval=false, group="Ehler's MESA Adaptive Moving Average", inline="fill")-fastlimitEMAMA=input(.5, title="Fast Limit", group="Ehler's MESA Adaptive Moving Average")+fastlimitEMAMA=input.float(.5, title="Fast Limit", group="Ehler's MESA Adaptive Moving Average")-slowlimitEMAMA=input(.05, title="Slow Limit", group="Ehler's MESA Adaptive Moving Average")+slowlimitEMAMA=input.float(.05, title="Slow Limit", group="Ehler's MESA Adaptive Moving Average")thicknessEMAMA=input.int(title="Line thickness", defval=2, minval=1, maxval=4, step=1, group="Ehler's MESA Adaptive Moving Average")⋯emaOBV = input.int(defval=9, title="EMA length", group="On Balance Volume")-lengthStoch = input(14, "Stochastic Length", minval=1, group="SRSI")+lengthStoch = input.int(14, "Stochastic Length", minval=1, group="SRSI")-smoothK = input(3, "SRSI K Smoothing", minval=1, group="SRSI")+smoothK = input.int(3, "SRSI K Smoothing", minval=1, group="SRSI")-smoothD = input(3, "SRSI D Smoothing", minval=1, group="SRSI")+smoothD = input.int(3, "SRSI D Smoothing", minval=1, group="SRSI")srsiOverbought = input.int(defval=80, title="Overbought level", group="SRSI", inline="levels")⋯lengthMACDsignal = input.int(title="Signal Smoothing", minval = 1, maxval = 50, defval = 9, group="MACD")-lengthCMF = input(20, minval=1, group="Chaiken Money Flow")+lengthCMF = input.int(20, minval=1, group="Chaiken Money Flow")showTable = input.bool(defval=false, title="Show summary table?", group="Summary Table")⋯ tooltip="Limit window for backtesting. This allows you to compare different TFs over the same period.")-rangeType = input(defval="30 Days", title="Date range:", options=["Custom", "30 Days", "90 Days", "180 Days", "Year to Date"], group="Limit by date")+rangeType = input.string(defval="30 Days", title="Date range:", options=["Custom", "30 Days", "90 Days", "180 Days", "Year to Date"], group="Limit by date")startDate = input.time(title="Start Date (DD/MM/YYYY)",⋯// ---------------------------------------------------<[ Strategy Execution ]>--------------------------------------------------strategy.entry(id="long", direction = strategy.long, comment="enL", when=psarBuySignal and psarConfirmationBuy and tradeLong)+if psarBuySignal and psarConfirmationBuy and tradeLong+ strategy.entry(id="long", direction = strategy.long, comment="enL")if useSL strategy.exit(id="long", stop=psar, comment="SL")-strategy.close(id="long", comment="exL", when=psarSellSignal and psarConfirmationSell and tradeLong)+if psarSellSignal and psarConfirmationSell and tradeLong+ strategy.close(id="long", comment="exL")-strategy.entry(id="short", direction = strategy.short, comment="enS", when=psarSellSignal and psarConfirmationSell and tradeShort)+if psarSellSignal and psarConfirmationSell and tradeShort+ strategy.entry(id="short", direction = strategy.short, comment="enS")if useSL strategy.exit(id="short", stop=psar, comment="SL")-strategy.close(id="short", comment="exS", when=psarBuySignal and psarConfirmationBuy and tradeShort)+if psarBuySignal and psarConfirmationBuy and tradeShort+ strategy.close(id="short", comment="exS")// -------------------------------------------------------<[ Tables ]>---------------------------------------------------------⋯Does it run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L160:C0: a 'bool' cannot be 'na' in Pine Script v6 — declare it as true or false. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// - EMA, RSI and SRSI built-ins.-//@version=5+//@version=6strategy(overlay=true, title="PSAR + EMA/TEMA/RSI/OBV", currency = 'USD', shorttitle="PSAR+", ⋯Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Global | |||
| Source for indicator | close | source | eMAMA eFAMA changeOBV temaSlow temaFast emaFast emaSlow ema200 cumOBV valueRSI fastMACD slowMACD |
| Create long positions? | true | bool | entry long close long |
| Create short positions? | false | bool | entry short close short |
| PSAR | |||
| Show PSAR? | true | bool | PSAR PSAR Long Start PSAR Buy Label PSAR Short Start PSAR Sell Label |
| PSAR Start | 0.02 | float · step 0.001 | psar |
| PSAR Increment | 0.02 | float · step 0.001 | psar |
| PSAR Maximum | 0.2 | float · step 0.01 | psar |
| Confirmation signal: | EMA | string · options ["EMA", "TEMA", "eMAMA", "RSI", "OBV"] | line 229 line 236 line 243 line 250 line 257 |
| PSAR Highlight Start Points? | true | bool | PSAR Long Start PSAR Short Start |
| PSAR Show Buy/Sell Labels? | true | bool | PSAR Buy Label PSAR Sell Label |
| PSAR Highlight State? | false | bool | colorPSARFill |
| Long | lime | color | colorPSARFill PSAR Long Start PSAR Buy Label |
| Short | red | color | colorPSARFill PSAR Short Start PSAR Sell Label |
| Set stop loss to PSAR plot? | false | bool | exit long exit short line 330 line 334 |
| Triple EMA | |||
| Show TEMA? | false | bool | TEMA Slow plot TEMA Fast plot TEMA Cross Up TEMA Cross Down |
| Shade TEMA? | false | bool | TEMA fill |
| TEMA Fast length | 13 | int · min 1 | temaFast |
| Color TEMAFast (no label in the script) | lime | color | fillTema TEMA Fast plot TEMA Cross Up |
| TEMA Slow length | 34 | int · min 1 | temaSlow |
| Color TEMASlow (no label in the script) | red | color | fillTema TEMA Slow plot TEMA Cross Down |
| Line thickness | 2 | int (written input.integer) · min 1 · max 4 · step 1 | TEMA Slow plot TEMA Fast plot |
| EMA | |||
| Show EMA? | true | bool | EMA Fast Plot EMA Slow Plot EMA Additional Plot EMA Cross Up EMA Cross Down |
| Shade EMA? | false | bool | EMA fill |
| EMA Fast Length | 9 | int (written input.integer) · step 1 | emaFast |
| Color EMAFast (no label in the script) | lime | color | fillEMA EMA Fast Plot EMA Cross Up |
| EMA Slow Length | 21 | int (written input.integer) · step 1 | emaSlow |
| Color EMASlow (no label in the script) | red | color | fillEMA EMA Slow Plot EMA Cross Down |
| EMA Additional Length | 200 | int (written input.integer) · step 1 | ema200 |
| Color EMA200 (no label in the script) | orange | color | EMA Additional Plot |
| Use as filter?Buy and sell signals are filtered on the additional EMA line, commonly set to 200. This takes effect even if the PSAR confirmation is set to something other than EMA. | false | bool | psarBuySignal psarSellSignal |
| Line thickness | 2 | int (written input.integer) · min 1 · max 4 · step 1 | EMA Fast Plot EMA Slow Plot EMA Additional Plot |
| RSI | |||
| RSI Length | 14 | int (written input.integer) | valueRSI |
| Overbought Level | 60 | int (written input.integer) | line 345 |
| Oversold Level | 40 | int (written input.integer) | line 345 |
| Ehler's MESA Adaptive Moving Average | |||
| Show eMAMA? | false | bool | Ehler's MAMA Ehler's FAMA eMAMA Cross Up eMAMA Cross Down |
| Shade eMAMA? | false | bool | eMAMA fill |
| Fast Limit | .5 | float | eMAMA eFAMA alpha_ alpha |
| Slow Limit | .05 | float | eMAMA eFAMA alpha |
| Line thickness | 2 | int (written input.integer) · min 1 · max 4 · step 1 | Ehler's MAMA Ehler's FAMA |
| eMAMA | lime | color | fillEMAMA Ehler's MAMA eMAMA Cross Up |
| eFAMA | red | color | fillEMAMA Ehler's FAMA eMAMA Cross Down |
| On Balance Volume | |||
| OBV Length | 20 | int (written input.integer) | oscOBV shortOBV |
| EMA length | 9 | int (written input.integer) | unused |
| SRSI | |||
| Stochastic Length | 14 | int · min 1 | srsiK |
| SRSI K Smoothing | 3 | int · min 1 | srsiK |
| SRSI D Smoothing | 3 | int · min 1 | srsiD |
| Overbought level | 80 | int (written input.integer) | line 348 |
| Oversold level | 20 | int (written input.integer) | line 348 |
| MACD | |||
| Fast Length | 12 | int (written input.integer) | fastMACD |
| Slow Length | 26 | int (written input.integer) | slowMACD |
| Signal Smoothing | 9 | int (written input.integer) · min 1 · max 50 | signalMACD |
| Chaiken Money Flow | |||
| Length CMF (no label in the script) | 20 | int · min 1 | mfCMF |
| Summary Table | |||
| Show summary table? | false | bool | line 341 |
| Summary Table Position | position.bottom_left | value · options [position.bottom_left, position.top_left, position.bottom_right, position.top_right] | summaryTable |
| Table Text Size | size.tiny | value · options [size.auto, size.tiny, size.small, size.normal, size.large, size.huge] | line 342 line 344 line 347 line 350 line 356 line 362 line 368 line 370 line 372 |
| Limit by date | |||
| Limit backtesting by dateLimit window for backtesting. This allows you to compare different TFs over the same period. | true | bool | inDateRange |
| Date range: | 30 Days | string · options ["Custom", "30 Days", "90 Days", "180 Days", "Year to Date"] | startDate |
| Start Date (DD/MM/YYYY) | timestamp("1 Jan 2021 1:01 -0400") | time | inDateRange |
| End Date (DD/MM/YYYY) You likely want to leave this far in the future. | timestamp("31 Dec 2100 19:59 -0400") | time | inDateRange |
What it calculates
- EMA (
ema,ta.emain v5)sourceTEMA, lengthTema1 · line 169 - EMA (
ema,ta.emain v5)Tema1, lengthTema2 · line 170 - EMA (
ema,ta.emain v5)Tema2, lengthTema3 · line 171 - Change (
change,ta.changein v5)Source for indicator (close)changeOBV · line 221 - Crossover (
crossover,ta.crossoverin v5)temaSlow, temaFastshortTema · line 210 - Crossunder (
crossunder,ta.crossunderin v5)temaSlow, temaFastlongTema · line 211 - EMA (
ema,ta.emain v5)Source for indicator (close), EMA Fast Length (9)emaFast · line 213 - EMA (
ema,ta.emain v5)Source for indicator (close), EMA Slow Length (21)emaSlow · line 214 - EMA (
ema,ta.emain v5)Source for indicator (close), EMA Additional Length (200)ema200 · line 215 - Crossover (
crossover,ta.crossoverin v5)emaFast, emaSlowlongEMA · line 216 - Crossunder (
crossunder,ta.crossunderin v5)emaFast, emaSlowshortEMA · line 217 - EMA (
ema,ta.emain v5)cumOBV, OBV Length (20)oscOBV · line 220 - EMA (
ema,ta.emain v5)cumOBV, OBV Length (20)shortOBV · line 222 - SAR (
sar,ta.sarin v5)PSAR Start (0.02), PSAR Increment (0.02), PSAR Maximum (0.2)psar · line 223 - RSI (
rsi,ta.rsiin v5)Source for indicator (close), RSI Length (14)valueRSI · line 228 - Crossover (
crossover,ta.crossoverin v5)eMAMA, eFAMAlongMAMA · line 268 - Crossunder (
crossunder,ta.crossunderin v5)eMAMA, eFAMAshortMAMA · line 269 - SMA / Stoch (
sma,ta.smain v5)stoch(valueRSI, valueRSI, valueRSI, lengthStoch), SRSI K Smoothing (3)srsiK · line 271 - SMA (
sma,ta.smain v5)srsiK, SRSI D Smoothing (3)srsiD · line 272 - EMA (
ema,ta.emain v5)Source for indicator (close), Fast Length (12)fastMACD · line 273 - EMA (
ema,ta.emain v5)Source for indicator (close), Slow Length (26)slowMACD · line 274 - EMA (
ema,ta.emain v5)macd, Signal Smoothing (9)signalMACD · line 276
Signal flow
How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.
The script has 128 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open long long | psarBuySignal and psarConfirmationBuy and tradeLong | On | 329 |
| Exit long stop | useSL | Off “Set stop loss to PSAR plot?” | 331 |
| Close long | psarSellSignal and psarConfirmationSell and tradeLong | On | 332 |
| Open short short | psarSellSignal and psarConfirmationSell and tradeShort | On | 333 |
| Exit short stop | useSL | Off “Set stop loss to PSAR plot?” | 335 |
| Close short | psarBuySignal and psarConfirmationBuy and tradeShort | On | 336 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| (no title) | alert | PSAR buy/long signal confirmed for {{ticker}} on {{interval}}. | 375 |
| (no title) | alert | PSAR sell/short signal confirmed for {{ticker}} on {{interval}}. | 377 |
| (no title) | alert | PSAR has changed direction for {{ticker}} on {{interval}}. | 379 |
Does it repaint?
Yes
At least one pattern in the source can repaint; it is marked Check below.
- ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- CheckIntrabar recalculationcalc_on_every_tick = true. Live values can differ from history.
- ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.
The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.
Other markets
The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | 0.0% | +102.5% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | +9.8% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | 0.0% | +8.4% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | 0.0% | +16.7% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | 0.0% | +21.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | 0.0% | +148.3% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | 0.0% | +17.1% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
Similar scripts
Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| PSAR + EMA-TEMA-RSI-OBV this page | — | v4 strategy | 0.0% | 0 | 0.0% |
| RSI Mean Reversion Bot Strategy by Solutions1978 | rsi ema stoch sma | v4 strategy | No trades on this market | ||
| MACD, RSI, & RVOL Strategy by BobBarker42069 | rsi ema sma | v4 strategy | +32.6% | 1 | 1.5% |
| IFR2 - RSI2 by jocker.soad | rsi sma ema | v4 strategy | No trades on this market | ||
| MACD,RSI & EMA strategy with MA+PSAR by MAM by maizirul959 | sar ema rsi | v4 strategy | −35.2% | 40 | 66.0% |
| Vin's Playzone Strategy by Vvaz_ | ema rsi sma | v5 strategy | −908.1% | 21 | 3,570.5% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 106 ms | With a workaround 1,000 bars in 381 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
Zeal Terminal's engine currently reads an order side written as long = strategy.long, long = strategy.short as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 329, 333) so the engine trades the way the script says. The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report. PineTS runs Pine Script v5 and v6 only.
Source
Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.
//// ██╗ █████╗ ███████╗ ██████╗██╗██╗ ██╗██╗ ██████╗ ██╗ ██╗███████╗ ███╗ ███╗ ██████╗ ███╗ ██╗██╗ ██╗// ██║ ██╔══██╗██╔════╝██╔════╝██║██║ ██║██║██╔═══██╗██║ ██║██╔════╝ ████╗ ████║██╔═══██╗████╗ ██║██║ ██╔╝// ██║ ███████║███████╗██║ ██║██║ ██║██║██║ ██║██║ ██║███████╗ ██╔████╔██║██║ ██║██╔██╗ ██║█████╔╝ // ██║ ██╔══██║╚════██║██║ ██║╚██╗ ██╔╝██║██║ ██║██║ ██║╚════██║ ██║╚██╔╝██║██║ ██║██║╚██╗██║██╔═██╗ // ███████╗██║ ██║███████║╚██████╗██║ ╚████╔╝ ██║╚██████╔╝╚██████╔╝███████║ ██║ ╚═╝ ██║╚██████╔╝██║ ╚████║██║ ██╗// ╚══════╝╚═╝ ╚═╝╚══════╝ ╚═════╝╚═╝ ╚═══╝ ╚═╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚═╝// https://www.tradingview.com/u/LasciviousMonk/// © LasciviousMonk////// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// This script provided freely. No guarantee of functionality is provided. You are welcome to use, revise, or modify// this code in any way you wish. However, I kindly request that you publish any scripts originating from this code as // 'Public'. Please do not use this code as a basis for "Protected" or "Invite Only" scripts.////// PSAR + EMA + TEMA combines Parabolic PSAR plus EMA and TEMA trendlines.// - EMA and TEMA crossovers have an up or down triangle to indicate direction of cross. Please note// that because these are Moving Averages (MAs), the triangle may not exactly line up with the crossover.// - Added MESA Adaptive Moving Average (eMAMA). Crossovers of the fast and slow eMAMA may be used instead of // EMA or TEMA.// - Added third EMA line. May be used to filter entries. For example, set the additional EMA to 200. Buy signals// wil only be sent if the price is greater than the additional EMA.// - Added RSI and OBV as alternative PSAR confirmations.//// "Traffic Light" table: summarizes PSAR, RSI, SRSI, TEMA, EMA, eMAMA, MACD, OBV, and CMF indicators in a table. // This is intended as a quick "heads up", not to replace the indicators themselves. // - Arrows indicate direction of change since the last bar.// - Moving average indicators are indicated as green if the fast MA > slow MA and fast [T]EMA is increasing, red otherwise. // [T]EMA will be yellow if fast MA has increased over the last 2 periods but fast MA < slow MA. // - PSAR is as green if the PSAR is increasing, red if it is decreasing.// - RSI is indicated as green if RSI < oversold, red if RSI > overbought, yellow otherwise. // - SRSI is indicated as green K < oversold, and red if K > overbought. If oversold < K < overbought,// green if K > D and red if K < D.// - MACD, OBV and CMF are green if bullish, red if bearish.////// Suggestions for use:// - Use fast EMA crossing above slow EMA as a confirmation for PSAR signals.// - TEMA or eMAMA can also be used for confirmation signals insead.// - Instead of using a moving average (EMA, TEMA, etc) for confirmation, you may use RSI or OBV.// - The "traffic light" table is intended as a "heads up" to call your attention to other indicators// you may want to check. I suggest Cipher B/VMC Cipher_B, Neglected Volume, and/or CM_Ult_MacD_MTF// as useful comparions.//// Please don't rely solely on the table. It is intended to alert you to look more closely at a plot, not to // provide all the information you need to enter or exit a position. I find the table to be a nice companion // to VMC Cipher_B, which can be overwhelming in its complexity.//// Code used:// - TEMA With Alert by BerkSay// - Parabolic SAR by Alex Orekhov (everget)// - Ehlers MESA Adaptive Moving Average [LazyBear]// - EMA, RSI and SRSI built-ins.//@version=4strategy(overlay=true, title="PSAR + EMA/TEMA/RSI/OBV", currency = 'USD', shorttitle="PSAR+", pyramiding = 0, default_qty_type=strategy.percent_of_equity, default_qty_value=20, initial_capital=5000, calc_on_every_tick=true, calc_on_order_fills=false, commission_type=strategy.commission.percent, commission_value=0.1)// ------------------------------------------------<[ Color Constants ]>----------------------------------------------// Color values used from Pine Magic. https://www.tradingview.com/script/yyDYIrRQ-Pine-Color-Magic-and-Chart-Theme-Simulator/var transparent = color.new(color.black, 100)var darkpurple = #550055, dpurple = darkpurple // Alias for dark purple, Not recommended for use on "Dark Charts"var purple = #990099var fuchsia = #FF00FFvar violet = #AA00FFvar hanpurple = #6000FFvar blue = #0000FFvar cichlid = #0040FFvar azure = #0080FFvar skyblue = #00C0FFvar aqua = #00FFFF // Not recommended for use on "Light Charts" with 1px line thicknessvar mint = #00FF80var lime = #00FF00var chartreuse = #80FF00var yellow = #FFFF00 // Not recommended for use on "Light Charts"var amber = #FFCC00var orange = #FF8000var redorange = #FF4000var red = #FF0000var hotpink = #FF0080var pink = #FF80FF // Not recommended for use on "Light Charts"// ------------------------------------------------<[ User Input ]>---------------------------------------------------sourceGlobal = input(title="Source for indicator", defval=close, type=input.source, group="Global")tradeLong = input(title="Create long positions?", defval=true, type=input.bool, group="Global")tradeShort = input(title="Create short positions?", defval=false, type=input.bool, group="Global")showPSAR = input(true, "Show PSAR?", group="PSAR")psarStart = input(title="PSAR Start", type=input.float, step=0.001, defval=0.02, group="PSAR")psarIncrement = input(title="PSAR Increment", type=input.float, step=0.001, defval=0.02, group="PSAR")psarMaximum = input(title="PSAR Maximum", type=input.float, step=0.01, defval=0.2, group="PSAR")psarConfirmation = input(title="Confirmation signal:", defval="EMA", options=["EMA", "TEMA", "eMAMA", "RSI", "OBV"], group="PSAR")psarHighlightStartPoints = input(title="PSAR Highlight Start Points?", type=input.bool, defval=true, group="PSAR")psarShowLabels = input(title="PSAR Show Buy/Sell Labels?", type=input.bool, defval=true, group="PSAR")psarHighlightState = input(title="PSAR Highlight State?", type=input.bool, defval=false, group="PSAR")colorPSARLong = input(title="Long", type=input.color, defval=lime, group="PSAR", inline="colors")colorPSARShort = input(title="Short", type=input.color, defval=red, group="PSAR", inline="colors")useSL = input(defval=false, type=input.bool, title="Set stop loss to PSAR plot?")showTEMA = input(false, "Show TEMA?", group="Triple EMA", inline="showTEMA")showTEMAfill = input(title="Shade TEMA?", defval=false, type=input.bool, group="Triple EMA", inline="showTEMA")lengthTEMAFast = input(title="TEMA Fast length", defval=13, minval=1, group="Triple EMA", inline="TemaFast")colorTEMAFast = input(title="",type=input.color, defval=lime, inline="TemaFast", group="Triple EMA")lengthTEMASlow = input(title="TEMA Slow length", defval=34, minval=1, group="Triple EMA", inline="TemaSlow")colorTEMASlow = input(title="",type=input.color, defval=red, group="Triple EMA", inline="TemaSlow")thicknessTEMA=input(title="Line thickness", defval=2, type=input.integer, minval=1, maxval=4, step=1, group="Triple EMA")showEMA = input(defval=true, type=input.bool, title="Show EMA?", group="EMA", inline="showEMA")showEMAfill = input(title="Shade EMA?", defval=false, type=input.bool, group="EMA", inline="showEMA")lengthEMAFast = input(9, title='EMA Fast Length', step=1, type=input.integer, group="EMA", inline="EmaFast")colorEMAFast = input(title="",type=input.color, defval=lime, inline="EmaFast", group="EMA")lengthEMASlow = input(21, title='EMA Slow Length', step=1, type=input.integer, group="EMA", inline="EmaSlow")colorEMASlow = input(title="",type=input.color, defval=red, group="EMA", inline="EmaSlow")lengthEMA200 = input(200, title='EMA Additional Length', step=1, type=input.integer, group="EMA", inline="EMA200")colorEMA200 = input(title="",type=input.color, defval=orange, group="EMA", inline="EMA200")filterEMA200 = input(title="Use as filter?", defval=false, type=input.bool, group="EMA", inline="EMA200", tooltip="Buy and sell signals are filtered on the additional EMA line, commonly set to 200. This takes effect even if the PSAR confirmation is set to something other than EMA.")thicknessEMA=input(title="Line thickness", defval=2, type=input.integer, minval=1, maxval=4, step=1, group="EMA")lengthRSI = input(title="RSI Length", type=input.integer, defval=14, group="RSI")rsiOverbought = input(title="Overbought Level", type=input.integer, defval=60, group="RSI", inline="levels")rsiOversold = input(title="Oversold Level", type=input.integer, defval=40, group="RSI", inline="levels")showeMAMA = input(defval=false, title="Show eMAMA?", type=input.bool, group="Ehler's MESA Adaptive Moving Average", inline="fill")showEMAMAfill = input(title="Shade eMAMA?", defval=false, type=input.bool, group="Ehler's MESA Adaptive Moving Average", inline="fill")fastlimitEMAMA=input(.5, title="Fast Limit", group="Ehler's MESA Adaptive Moving Average")slowlimitEMAMA=input(.05, title="Slow Limit", group="Ehler's MESA Adaptive Moving Average")thicknessEMAMA=input(title="Line thickness", defval=2, type=input.integer, minval=1, maxval=4, step=1, group="Ehler's MESA Adaptive Moving Average")coloreMAMA = input(title="eMAMA",type=input.color, defval=lime, group="Ehler's MESA Adaptive Moving Average", inline="colors")coloreFAMA = input(title="eFAMA",type=input.color, defval=red, group="Ehler's MESA Adaptive Moving Average", inline="colors")lengthOBV = input(defval=20, title="OBV Length", type=input.integer, group="On Balance Volume")emaOBV = input(defval=9, title="EMA length", type=input.integer, group="On Balance Volume")lengthStoch = input(14, "Stochastic Length", minval=1, group="SRSI")smoothK = input(3, "SRSI K Smoothing", minval=1, group="SRSI")smoothD = input(3, "SRSI D Smoothing", minval=1, group="SRSI")srsiOverbought = input(defval=80, title="Overbought level", type=input.integer, group="SRSI", inline="levels")srsiOversold = input(defval=20, title="Oversold level", type=input.integer, group="SRSI", inline="levels")lengthMACDfast = input(title="Fast Length", type=input.integer, defval=12, group="MACD")lengthMACDslow = input(title="Slow Length", type=input.integer, defval=26, group="MACD")lengthMACDsignal = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9, group="MACD")lengthCMF = input(20, minval=1, group="Chaiken Money Flow")showTable = input(defval=false, title="Show summary table?", type=input.bool, group="Summary Table")tablePosition = input(title="Summary Table Position", defval=position.bottom_left, options=[position.bottom_left, position.top_left, position.bottom_right, position.top_right], group="Summary Table")tableTextSize = input(title="Table Text Size", defval=size.tiny, options=[size.auto, size.tiny, size.small, size.normal, size.large, size.huge], group="Summary Table")useDateRange = input(defval=true, title="Limit backtesting by date", type=input.bool, group="Limit by date", tooltip="Limit window for backtesting. This allows you to compare different TFs over the same period.")rangeType = input(defval="30 Days", title="Date range:", options=["Custom", "30 Days", "90 Days", "180 Days", "Year to Date"], group="Limit by date")startDate = input(title="Start Date (DD/MM/YYYY)", type=input.time, defval=timestamp("1 Jan 2021 1:01 -0400"), group="Limit by date")endDate = input(title="End Date (DD/MM/YYYY) ", type=input.time, defval=timestamp("31 Dec 2100 19:59 -0400"), group="Limit by date", tooltip="You likely want to leave this far in the future.")startDate := rangeType == "Custom" ? startDate : rangeType == "30 Days" ? timenow - 2592000000 : rangeType == "90 Days" ? timenow - 7776000000 : rangeType == "180 Days" ? timenow - 15552000000 : rangeType == "Year to Date" ? timestamp(syminfo.timezone, year(timenow), 01, 01, 00, 01) : na inDateRange = (time >= startDate) and (time < endDate)inDateRange := useDateRange ? inDateRange : 1// ------------------------------------------------<[ Variable Declarations ]>----------------------------------------------var bool psarConfirmationBuy = navar bool psarConfirmationSell = navar float eMAMA = navar float eFAMA = navar float historicalHigh = 0 // for OBV scaling// -------------------------------------------------------<[ Functions ]>----------------------------------------------------fDirection(series, length) => rising(series,length) ? "↑" : "↓"fTEMA(sourceTEMA, length) => Tema1 = ema(sourceTEMA, length) Tema2 = ema(Tema1, length) Tema3 = ema(Tema2, length) 3 * Tema1 - 3 * Tema2 + Tema3 fMAMA(sourceEMAMA, slowlimitEMAMA, fastlimitEMAMA) => var float p = na var float i2 = na var float q2 = na var float re = na var float im = na var float spp = na sp = (4*sourceEMAMA + 3*sourceEMAMA[1] + 2*sourceEMAMA[2] + sourceEMAMA[3]) / 10.0 dt = (.0962*sp + .5769*nz(sp[2]) - .5769*nz(sp[4])- .0962*nz(sp[6]))*(.075*nz(p[1]) + .54) q1 = (.0962*dt + .5769*nz(dt[2]) - .5769*nz(dt[4])- .0962*nz(dt[6]))*(.075*nz(p[1]) + .54) i1 = nz(dt[3]) jI = (.0962*i1 + .5769*nz(i1[2]) - .5769*nz(i1[4])- .0962*nz(i1[6]))*(.075*nz(p[1]) + .54) jq = (.0962*q1 + .5769*nz(q1[2]) - .5769*nz(q1[4])- .0962*nz(q1[6]))*(.075*nz(p[1]) + .54) i2_ = i1 - jq q2_ = q1 + jI i2 := .2*i2_ + .8*nz(i2[1]) q2 := .2*q2_ + .8*nz(q2[1]) re_ = i2*nz(i2[1]) + q2*nz(q2[1]) im_ = i2*nz(q2[1]) - q2*nz(i2[1]) re := .2*re_ + .8*nz(re[1]) im := .2*im_ + .8*nz(im[1]) p1 = iff(im!=0 and re!=0, 360/atan(im/re), nz(p[1])) p2 = iff(p1 > 1.5*nz(p1[1]), 1.5*nz(p1[1]), iff(p1 < 0.67*nz(p1[1]), 0.67*nz(p1[1]), p1)) p3 = iff(p2<6, 6, iff (p2 > 50, 50, p2)) p := .2*p3 + .8*nz(p3[1]) spp := .33*p + .67*nz(spp[1]) phaseEMAMA = atan(q1 / i1) dphase_ = nz(phaseEMAMA[1]) - phaseEMAMA dphase = iff(dphase_< 1, 1, dphase_) alpha_ = fastlimitEMAMA / dphase alpha = iff(alpha_ < slowlimitEMAMA, slowlimitEMAMA, iff(alpha_ > fastlimitEMAMA, fastlimitEMAMA, alpha_))fOBV(src) => changeOBV = change(src) cum(changeOBV > 0 ? volume : changeOBV < 0 ? -volume : 0*volume)// -------------------------------------------<[ Variable Calculations ]>------------------------------------------temaSlow = fTEMA(sourceGlobal, lengthTEMASlow)temaFast = fTEMA(sourceGlobal, lengthTEMAFast)shortTema = crossover(temaSlow, temaFast)longTema = crossunder(temaSlow, temaFast)fillTema = temaFast>temaSlow ? color.new(colorTEMAFast,80) : color.new(colorTEMASlow,80)emaFast = ema(sourceGlobal, lengthEMAFast)emaSlow = ema(sourceGlobal, lengthEMASlow)ema200 = ema(sourceGlobal, lengthEMA200)longEMA = crossover(emaFast, emaSlow)shortEMA = crossunder(emaFast , emaSlow)fillEMA = emaFast>emaSlow ? color.new(colorEMAFast,80) : color.new(colorEMASlow,80)cumOBV = fOBV(sourceGlobal)oscOBV = (cumOBV - ema(cumOBV,lengthOBV))changeOBV = change(sourceGlobal)shortOBV = ema(cumOBV, lengthOBV)psar = sar(psarStart, psarIncrement, psarMaximum)psarDir = psar < close ? 1 : -1colorPSAR = psarDir == 1 ? color.new(#3388bb,0) : color.new(#fdcc02,0)colorPSARFill = psarHighlightState ? (psarDir == 1 ? color.new(colorPSARLong,90) : color.new(colorPSARShort,90)) : napsarChangeCond = psarDir != psarDir[1]valueRSI = rsi(sourceGlobal, lengthRSI)if psarConfirmation == "EMA" if emaFast > emaSlow psarConfirmationBuy := true psarConfirmationSell := false else if emaFast < emaSlow psarConfirmationSell := true psarConfirmationBuy := falseelse if psarConfirmation == "TEMA" if temaFast > temaSlow psarConfirmationBuy := true psarConfirmationSell := false else if temaFast < temaSlow psarConfirmationSell := true psarConfirmationBuy := falseelse if psarConfirmation == "eMAMA" if eMAMA > eFAMA psarConfirmationBuy := true psarConfirmationSell := false else if eMAMA < eFAMA psarConfirmationSell := true psarConfirmationBuy := falseelse if psarConfirmation == "RSI" if valueRSI < 40 psarConfirmationBuy := true psarConfirmationSell := false else if valueRSI > 60 psarConfirmationSell := true psarConfirmationBuy := falseelse if psarConfirmation == "OBV" if oscOBV > 0 psarConfirmationBuy := true psarConfirmationSell := false else if oscOBV < 0 psarConfirmationSell := true psarConfirmationBuy := false psarBuySignal = psarDir == 1 and psarDir[1] == -1 and (filterEMA200 ? open > ema200 : true) and inDateRangepsarSellSignal = psarDir == -1 and psarDir[1] == 1 and (filterEMA200 ? open < ema200 : true) and inDateRangeeMAMA := fMAMA(sourceGlobal, slowlimitEMAMA, fastlimitEMAMA)*sourceGlobal + (1 - fMAMA(sourceGlobal, slowlimitEMAMA, fastlimitEMAMA))*nz(eMAMA[1])eFAMA := .5*fMAMA(sourceGlobal, slowlimitEMAMA, fastlimitEMAMA)*eMAMA + (1 - .5*fMAMA(sourceGlobal, slowlimitEMAMA, fastlimitEMAMA))*nz(eFAMA[1])longMAMA=crossover(eMAMA, eFAMA)shortMAMA=crossunder(eMAMA,eFAMA)fillEMAMA = eMAMA>eFAMA ? color.new(coloreMAMA, 80) : color.new(coloreFAMA, 80)srsiK = sma(stoch(valueRSI, valueRSI, valueRSI, lengthStoch), smoothK)srsiD = sma(srsiK, smoothD)fastMACD = ema(sourceGlobal, lengthMACDfast)slowMACD = ema(sourceGlobal, lengthMACDslow)macd = fastMACD - slowMACDsignalMACD = ema(macd, lengthMACDsignal)adCMF = close==high and close==low or high==low ? 0 : ((2*close-low-high)/(high-low))*volumemfCMF = sum(adCMF, lengthCMF) / sum(volume, lengthCMF)// ================================== //// ----> Conditional Parameters <---- //// ================================== // // ================================== //// -------> Risk Mitigation <-------- //// ================================== // // ================================== //// --------> Logical Order <--------- //// ================================== // // -------------------------------------------<[ Graphical Display ]>------------------------------------------// TEMA plotsplotTemaSlow = plot(showTEMA ? temaSlow: na, color=color.new(colorTEMASlow,20), title="TEMA Slow plot", linewidth=thicknessTEMA)plotTemaFast = plot(showTEMA ? temaFast: na, color=color.new(colorTEMAFast,20), title="TEMA Fast plot", linewidth=thicknessTEMA)plotshape(showTEMA and longTema ? temaFast: na, style=shape.triangleup, location=location.absolute, size=size.tiny, title="TEMA Cross Up", color=color.new(colorTEMAFast,10))plotshape(showTEMA and shortTema ? temaSlow: na, style=shape.triangledown, location=location.absolute, size=size.tiny, title="TEMA Cross Down", color=color.new(colorTEMASlow,10))fill(plotTemaFast, plotTemaSlow, color=showTEMAfill ? fillTema : transparent, title="TEMA fill")// EMA plotsplotEmaFast = plot(showEMA ? emaFast: na, title='EMA Fast Plot', color=colorEMAFast, linewidth=thicknessEMA)plotEmaSlow = plot(showEMA ? emaSlow: na, title='EMA Slow Plot', color=colorEMASlow, linewidth=thicknessEMA)plotEMA200 = plot(showEMA ? ema200: na, title='EMA Additional Plot', color=colorEMA200, linewidth=thicknessEMA)plotshape(showEMA and longEMA ? emaFast : na, style=shape.triangleup, location=location.absolute, size=size.tiny, title="EMA Cross Up",color=colorEMAFast)plotshape(showEMA and shortEMA ? emaFast : na, style=shape.triangledown, location=location.absolute, size=size.tiny, title="EMA Cross Down",color=colorEMASlow)fill(plotEmaFast, plotEmaSlow, color=showEMAfill ? fillEMA : transparent, title="EMA fill")// PSAR plotspsarPlot = plot(showPSAR ? psar: na, title="PSAR", style=plot.style_circles, linewidth=1, color=colorPSAR)plotshape(showPSAR and psarBuySignal and psarHighlightStartPoints ? psar : na, title="PSAR Long Start", location=location.absolute, style=shape.circle, size=size.tiny, color=colorPSARLong)plotshape(showPSAR and psarBuySignal and psarShowLabels and psarConfirmationBuy ? psar : na, title="PSAR Buy Label", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=colorPSARLong, textcolor=color.white)plotshape(showPSAR and psarSellSignal and psarHighlightStartPoints ? psar : na, title="PSAR Short Start", location=location.absolute, style=shape.circle, size=size.tiny, color=colorPSARShort)plotshape(showPSAR and psarSellSignal and psarShowLabels and psarConfirmationSell ? psar : na, title="PSAR Sell Label", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=colorPSARShort, textcolor=color.white)psarMidPricePlot = plot(ohlc4, title="", display=display.none, editable=false)fill(psarMidPricePlot, psarPlot, title="PSAR Trade State Filling", color=colorPSARFill)ploteMAMA = plot(showeMAMA ? eMAMA : na, title="Ehler's MAMA", linewidth=thicknessEMAMA, style=plot.style_line, color=coloreMAMA)ploteFAMA = plot(showeMAMA ? eFAMA : na, title="Ehler's FAMA", linewidth=thicknessEMAMA, style=plot.style_line, color=coloreFAMA)plotshape(showeMAMA and longMAMA ? eFAMA: na, style=shape.triangleup, location=location.absolute, size=size.tiny, title="eMAMA Cross Up", color=color.new(coloreMAMA,10))plotshape(showeMAMA and shortMAMA ? eFAMA: na, style=shape.triangledown, location=location.absolute, size=size.tiny, title="eMAMA Cross Down", color=color.new(coloreFAMA,10))fill(ploteMAMA, ploteFAMA, color=showEMAMAfill ? fillEMAMA : transparent, title="eMAMA fill")// ---------------------------------------------------<[ Strategy Execution ]>-------------------------------------------------strategy.entry(id="long", long=strategy.long, comment="enL", when=psarBuySignal and psarConfirmationBuy and tradeLong)if useSL strategy.exit(id="long", stop=psar, comment="SL")strategy.close(id="long", comment="exL", when=psarSellSignal and psarConfirmationSell and tradeLong)strategy.entry(id="short", long=strategy.short, comment="enS", when=psarSellSignal and psarConfirmationSell and tradeShort)if useSL strategy.exit(id="short", stop=psar, comment="SL")strategy.close(id="short", comment="exS", when=psarBuySignal and psarConfirmationBuy and tradeShort)// -------------------------------------------------------<[ Tables ]>---------------------------------------------------------// Shows red for bearish signals, green for bullish signals.var table summaryTable = table.new(tablePosition, 3, 3) if (barstate.islast and showTable) table.cell(summaryTable, 0, 0, "PSAR",text_size=tableTextSize, bgcolor = psarDir == 1 ? color.green : color.red) rsiDirection = fDirection(valueRSI,1) table.cell(summaryTable, 0, 1, "RSI " + tostring(round(valueRSI,0)) + rsiDirection,text_size=tableTextSize, bgcolor = iff(valueRSI > rsiOverbought, color.red, iff(valueRSI < rsiOversold, color.green, color.yellow))) srsiDirection = fDirection(srsiK,1) table.cell(summaryTable, 0, 2, "K " + tostring(round(srsiK,0)) + srsiDirection, text_size=tableTextSize, bgcolor=iff(srsiK > srsiOverbought, color.red, iff(srsiK < srsiOversold, color.green, srsiK > srsiD ? color.green : color.red))) emaDirection = fDirection(emaFast,1) table.cell(summaryTable, 1, 0, "EMA" + emaDirection,text_size=tableTextSize, bgcolor = emaFast > emaSlow and emaFast > emaFast[1] ? color.green : color.red) // See if emaFast has increased over the last two periods. if rising(emaFast,2) and emaFast < emaSlow table.cell_set_bgcolor(summaryTable, 1, 0, color.yellow) directionTEMA = fDirection(temaFast,1) table.cell(summaryTable, 1, 1, "TEMA" + directionTEMA,text_size=tableTextSize, bgcolor = temaFast > temaSlow and temaFast > temaFast[1] ? color.green : color.red) // See if temaFast has increased over the last two periods. if rising(temaFast,2) and temaFast < temaSlow table.cell_set_bgcolor(summaryTable, 1, 1, color.yellow) directionMAMA = fDirection(eMAMA,1) table.cell(summaryTable, 1, 2, "eMAMA" + directionMAMA,text_size=tableTextSize, bgcolor = eMAMA > eFAMA and eMAMA > eFAMA[1] ? color.green : color.red) // See if temaFast has increased over the last two periods. if rising(eMAMA,2) and eMAMA < eFAMA table.cell_set_bgcolor(summaryTable, 1, 2, color.yellow) directionMACD = fDirection(macd,2) table.cell(summaryTable, 2, 0, "MACD " + directionMACD, text_size=tableTextSize, bgcolor= macd > signalMACD ? color.green : color.red) directionOBV = fDirection(shortOBV,2) table.cell(summaryTable, 2, 1, "OBV " + directionOBV, text_size=tableTextSize, bgcolor= shortOBV > 0 ? color.green : color.red) directionCMF = fDirection(mfCMF,2) table.cell(summaryTable, 2, 2, "CMF " + directionCMF + tostring(mfCMF, "#.##"), text_size=tableTextSize, bgcolor= mfCMF > 0 ? color.green : color.red)// ---------------------------------------------------<[ Alerts ]>-------------------------------------------------if psarBuySignal and psarConfirmationBuy alert("PSAR buy/long signal confirmed for {{ticker}} on {{interval}}.", alert.freq_once_per_bar)if psarSellSignal and psarConfirmationSell alert("PSAR sell/short signal confirmed for {{ticker}} on {{interval}}.", alert.freq_once_per_bar)if psarChangeCond alert("PSAR has changed direction for {{ticker}} on {{interval}}.", alert.freq_once_per_bar)