Pine Script v4 · Strategy
[DS]Entry_Exit_TRADE.V01-Strategy
A Pine Script v4 strategy built on EMA (close, 8), Pivothigh (4, 4) and Pivotlow (4, 4). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 17 settings; defaults include Return Candels ? 190, Left Bars 4 and Right Bars 4.
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 [DS]Entry_Exit_TRADE.V01-Strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 4 of 4 trades.
- How did [DS]Entry_Exit_TRADE.V01-Strategy do on BTCUSDT 1D with default settings?
- +72.54%
- From 26 Jan 2024 to 21 Oct 2026, over 39 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can [DS]Entry_Exit_TRADE.V01-Strategy be converted to Pine Script v5?
- Yes
- The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
- Does [DS]Entry_Exit_TRADE.V01-Strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does [DS]Entry_Exit_TRADE.V01-Strategy run in Zeal Terminal?
- Yes
- It compiles in 56 ms and runs 1,000 bars in 158 ms, in the browser.
BTCUSDT · 1D · default settings
- DEMA 72
- EMA ohlc4
- Cross UP
- Cross DOWN
- Pivot High
- Pivot Low
- Plot
- Plot
- Dema ohlc4
- Dema 72
- HighlH1
- LowlL1
- (+)MACD UP
- (-)MACD DN
- (+)TSI Up
- (-)TSI DN
- Net profit
- +72.54%
- $72,538.10
- Buy and hold
- +102.5%
- same period
- Closed trades
- 39
- 19 won · 20 lost
- Profitable
- 48.7%
- of closed trades
- Profit factor
- 1.85
- gross profit ÷ gross loss
- Max drawdown
- 31.74%
- −$43,994.40
One run with the author's default settings, $100,000 starting capital, commission as the script sets it. A short position was still open at the last bar. 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.
-
Likely bug
ema(close, 8) ignores the settings line 27
Line 27 hard-codes close where line 202 uses “Source” and 8 where line 202 uses “Fast Length”. Changing those settings moves one band but not this one.
ema(close,8)ema(src_Macd, fast_length_Macd) -
Likely bug
ema(e1, 8) ignores the settings line 28
Line 28 hard-codes 8 where line 202 uses “Fast Length”. Changing those settings moves one band but not this one.
ema(e1,8)ema(e1, fast_length_Macd) -
Likely bug
ema(close, 17) ignores the settings line 32
Line 32 hard-codes close where line 202 uses “Source” and 17 where line 202 uses “Fast Length”. Changing those settings moves one band but not this one.
ema(close,17)ema(src_Macd, fast_length_Macd) -
Likely bug
ema(e1, 17) ignores the settings line 33
Line 33 hard-codes 17 where line 202 uses “Fast Length”. Changing those settings moves one band but not this one.
ema(e1,17)ema(e1, fast_length_Macd) -
Likely bug
ema(close, 34) ignores the settings line 37
Line 37 hard-codes close where line 202 uses “Source” and 34 where line 202 uses “Fast Length”. Changing those settings moves one band but not this one.
ema(close,34)ema(src_Macd, fast_length_Macd) -
Likely bug
ema(e1, 34) ignores the settings line 38
Line 38 hard-codes 34 where line 202 uses “Fast Length”. Changing those settings moves one band but not this one.
ema(e1,34)ema(e1, fast_length_Macd) -
Likely bug
ema(close, 72) ignores the settings line 42
Line 42 hard-codes close where line 202 uses “Source” and 72 where line 202 uses “Fast Length”. Changing those settings moves one band but not this one.
ema(close,72)ema(src_Macd, fast_length_Macd) -
Likely bug
ema(e1, 72) ignores the settings line 43
Line 43 hard-codes 72 where line 202 uses “Fast Length”. Changing those settings moves one band but not this one.
ema(e1,72)ema(e1, fast_length_Macd) -
Likely bug
ema(close, 72) ignores the settings line 49
Line 49 hard-codes close where line 202 uses “Source” and 72 where line 202 uses “Fast Length”. Changing those settings moves one band but not this one.
ema(close,72)ema(src_Macd, fast_length_Macd) -
Likely bug
ema(ohlc4, 8) ignores the settings line 50
Line 50 hard-codes ohlc4 where line 202 uses “Source” and 8 where line 202 uses “Fast Length”. Changing those settings moves one band but not this one.
ema(ohlc4,8)ema(src_Macd, fast_length_Macd) -
Check
4 settings do nothing
“══════ Pivots ══════”, “══════ William R% Mod ══════”, “═════ Macd ══════════”, “═════ Tsi ══════════” are declared but never read.
-
Check
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Check
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Note
3 settings have no label
In the settings dialog leftBars (line 82), rightBars (line 83), length_William (line 97) show 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 transp =, which v5 removed line 59
transp = on line 59, 60, 73, 75, 85, 87, 179, 180, 181, 183, 184, 185, 187, 188, 189, 210, 211, 233, 234, 248, 250. v5 folds the transparency into the colour with color.new(c, transp).
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 ema → ta.ema, crossover → ta.crossover, crossunder → ta.crossunder, pivothigh → ta.pivothigh, pivotlow → ta.pivotlow, highest → ta.highest, lowest → ta.lowest, tostring → str.tostring, change → ta.change, abs → math.abs.
v4 → v5
VerifiedSame 39 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 21: return is reserved in v5: renamed return_
- Line 21: input(type = input.integer) → input.int()
- Line 27: ema → ta.ema
- Line 28: ema → ta.ema
- Line 32: ema → ta.ema
63 more edits
- Line 33: ema → ta.ema
- Line 37: ema → ta.ema
- Line 38: ema → ta.ema
- Line 42: ema → ta.ema
- Line 43: ema → ta.ema
- Line 49: ema → ta.ema
- Line 50: ema → ta.ema
- Line 59: transp = 0 → color.new(color.orange, 0)
- Line 60: transp = 0 → color.new(emaOhlc4>dema72 ? color.new(color.green,0) : color.new(color.red,0), 0)
- Line 73: crossover → ta.crossover
- Line 73: transp = 0 → color.new(color.green, 0)
- Line 75: crossunder → ta.crossunder
- Line 75: transp = 50 → color.new(color.red, 50)
- Line 81: input(type = input.bool) → input.bool()
- Line 84: pivothigh → ta.pivothigh
- Line 85: transp = 50 → color.new(color.purple, 50)
- Line 86: pivotlow → ta.pivotlow
- Line 87: transp = 50 → color.new(color.blue, 50)
- Line 94: input(type = input.bool) → input.bool()
- Line 95: input(type = input.integer) → input.int()
- Line 96: input(type = input.integer) → input.int()
- Line 98: highest → ta.highest
- Line 99: lowest → ta.lowest
- Line 134: tostring → str.tostring
- Line 179: transp = 0 → color.new(color.new(color.white,100), 0)
- Line 180: transp = 0 → color.new(color.new(color.white,100), 0)
- Line 181: transp = 70 → color.new(emaOhlc4>dema72 ? color.new(color.green,90) : color.new(color.red,90), 70)
- Line 183: transp = 90 → color.new(color.green, 90)
- Line 184: transp = 100 → color.new(color.green, 100)
- Line 185: transp = 0 → color.new(color.new(color.purple,90), 0)
- Line 187: transp = 90 → color.new(color.red, 90)
- Line 188: transp = 100 → color.new(color.red, 100)
- Line 189: transp = 0 → color.new(color.new(color.blue,90), 0)
- Line 196: input(type = input.bool) → input.bool()
- Line 197: input(type = input.integer) → input.int()
- Line 198: input(type = input.integer) → input.int()
- Line 199: input(type = input.source) → input.source()
- Line 200: input(type = input.integer) → input.int()
- Line 202: ema → ta.ema
- Line 203: ema → ta.ema
- Line 205: ema → ta.ema
- Line 208: crossover → ta.crossover
- Line 209: crossunder → ta.crossunder
- Line 210: transp = 30 → color.new(color.green, 30)
- Line 211: transp = 30 → color.new(color.red, 30)
- Line 217: input(type = input.bool) → input.bool()
- Line 218: input(type = input.integer) → input.int()
- Line 219: input(type = input.integer) → input.int()
- Line 220: input(type = input.integer) → input.int()
- Line 223: ema → ta.ema
- Line 224: ema → ta.ema
- Line 225: change → ta.change
- Line 227: abs → math.abs
- Line 230: crossover → ta.crossover
- Line 230: ema → ta.ema
- Line 231: crossunder → ta.crossunder
- Line 231: ema → ta.ema
- Line 233: transp = 30 → color.new(color.green, 30)
- Line 234: transp = 30 → color.new(color.red, 30)
- Line 241: crossover → ta.crossover
- Line 242: crossunder → ta.crossunder
- Line 248: transp = 0 → color.new(color.green, 0)
- Line 250: transp = 0 → color.new(color.red, 0)
⋯// © DalmarSantos-//@version=4+//@version=5//Entry and Exit points to TRADE ==> Pontos de Entrada e Saida de TRADE⋯//variable ==> variáveis-return = input(title="Return Candels ?", type=input.integer, defval=190) //quantity of candles to analise ==> quantidade de candles para analise+return_ = input.int(title="Return Candels ?", defval=190) //quantity of candles to analise ==> quantidade de candles para analise//⋯//Dema 08-e1 = ema(close,8)+e1 = ta.ema(close,8)-e2 = ema(e1,8)+e2 = ta.ema(e1,8)dema08 = 2 * e1 - e2⋯//Dema 17-e1 := ema(close,17)+e1 := ta.ema(close,17)-e2 := ema(e1,17)+e2 := ta.ema(e1,17)dema17 = 2 * e1 - e2⋯//Dema 34-e1 := ema(close,34)+e1 := ta.ema(close,34)-e2 := ema(e1,34)+e2 := ta.ema(e1,34)dema34 = 2 * e1 - e2⋯//Dema 72-e1 := ema(close,72)+e1 := ta.ema(close,72)-e2 := ema(e1,72)+e2 := ta.ema(e1,72)dema72 = 2 * e1 - e2⋯//******************************-ema72 = ema(close,72)+ema72 = ta.ema(close,72)-emaOhlc4=ema(ohlc4,8)+emaOhlc4=ta.ema(ohlc4,8)//⋯//plot(dema34, title="DEMA 34", color=color.new(color.black,0), linewidth=1, style=plot.style_line, transp=0, show_last=return) // Doble Exponential Moving Avarage 34-plot(dema72, title="DEMA 72", color=color.orange, linewidth=2, style=plot.style_line, transp=0, show_last=return) // Doble Exponential Moving Avarage 72+plot(dema72, title="DEMA 72", color=color.new(color.orange, 0), linewidth=2, style=plot.style_line, show_last=return_) // Doble Exponential Moving Avarage 72-plot(emaOhlc4, title="EMA ohlc4", color=emaOhlc4>dema72 ? color.new(color.green,0) : color.new(color.red,0), linewidth=2, style=plot.style_line, transp=0, show_last=return) // Doble Exponential Moving Avarage 72+plot(emaOhlc4, title="EMA ohlc4", color=color.new(emaOhlc4>dema72 ? color.new(color.green,0) : color.new(color.red,0), 0), linewidth=2, style=plot.style_line, show_last=return_) // Doble Exponential Moving Avarage 72//⋯//Show color TRADE bar if emaOhlc4>dema72 green (Buy) if not red (Red) ==> Mostra a cor da barra de TRADE se emaOhlc4>dema72 verde (Compra) se não vermelha (Venda)-barcolor(close>dema34 and close>dema72 or close>close[1] ? color.new(color.green,0) : color.new(color.red,0), show_last=return)+barcolor(close>dema34 and close>dema72 or close>close[1] ? color.new(color.green,0) : color.new(color.red,0), show_last=return_)//⋯//UP ==> para CIMA-plot(crossover(emaOhlc4,dema72) ? dema72 : na, title="Cross UP", color=color.green, transp=0, style=plot.style_circles, linewidth=5, show_last=return)+plot(ta.crossover(emaOhlc4,dema72) ? dema72 : na, title="Cross UP", color=color.new(color.green, 0), style=plot.style_circles, linewidth=5, show_last=return_)//DOWM ==> para BAIXO-plot(crossunder(emaOhlc4,dema72) ? dema72 : na, title="Cross DOWN", color=color.red, transp=50, style=plot.style_circles, linewidth=5, show_last=return)+plot(ta.crossunder(emaOhlc4,dema72) ? dema72 : na, title="Cross DOWN", color=color.new(color.red, 50), style=plot.style_circles, linewidth=5, show_last=return_)//⋯//********************************-_Pivots = input(title = "══════ Pivots ══════", type = input.bool, defval = false)+_Pivots = input.bool(title = "══════ Pivots ══════", defval = false)leftBars = input(4)rightBars=input(4)-pivotHigh = pivothigh(leftBars, rightBars) //pivot de alta+pivotHigh = ta.pivothigh(leftBars, rightBars) //pivot de alta-plot(pivotHigh>ema72[rightBars] ? pivotHigh : na, title="Pivot High", style=plot.style_cross, linewidth=3, color= color.purple, transp=50, offset=-rightBars, show_last=return)+plot(pivotHigh>ema72[rightBars] ? pivotHigh : na, title="Pivot High", style=plot.style_cross, linewidth=3, color= color.new(color.purple, 50), offset=-rightBars, show_last=return_)-pivotLow = pivotlow(leftBars, rightBars) //pivot de baixa+pivotLow = ta.pivotlow(leftBars, rightBars) //pivot de baixa-plot(pivotLow<ema72[rightBars] ? pivotLow : na, title="Pivot Low", style=plot.style_cross, linewidth=3, color= color.blue, transp=50, offset=-rightBars, show_last=return)+plot(pivotLow<ema72[rightBars] ? pivotLow : na, title="Pivot Low", style=plot.style_cross, linewidth=3, color= color.new(color.blue, 50), offset=-rightBars, show_last=return_)//⋯// Getting inputs-_WilliamR = input(title = "══════ William R% Mod ══════", type = input.bool, defval = false)+_WilliamR = input.bool(title = "══════ William R% Mod ══════", defval = false)-SOB_William = input(title="OverBought Area", type=input.integer, defval=-7) //OverBought area ==> Area de SobreCompra+SOB_William = input.int(title="OverBought Area", defval=-7) //OverBought area ==> Area de SobreCompra-SOS_William = input(title="OverSold Area", type=input.integer, defval=-93) //OverSold area ==> Area de SobreVenda+SOS_William = input.int(title="OverSold Area", defval=-93) //OverSold area ==> Area de SobreVendalength_William = input(17, minval=1) //interval ==> intervalo-highestHigh_William = highest(length_William) //maximum value ==> valor máximo+highestHigh_William = ta.highest(length_William) //maximum value ==> valor máximo-highestLow_William = lowest(length_William) //minumum value ==> valor mínimo+highestLow_William = ta.lowest(length_William) //minumum value ==> valor mínimoR_William = (highestHigh_William - close) / (highestHigh_William - highestLow_William) * -100⋯// Make a label at the high of the current bar-myLabel = label.new(x=bar_index, y=close, style= estilo, color=corTest, text=tostring(R_William,"#.#")+"% "+textW, textcolor=colorText, size=size.normal)+myLabel = label.new(x=bar_index, y=close, style= estilo, color=corTest, text=str.tostring(R_William,"#.#")+"% "+textW, textcolor=colorText, size=size.normal)// Get the label text⋯ExtremoLow=low-(low-highestLow_William)-plot(ExtremoHigh, color=color.new(color.red,70), style=plot.style_line, linewidth=1, show_last=return)+plot(ExtremoHigh, color=color.new(color.red,70), style=plot.style_line, linewidth=1, show_last=return_)-plot(ExtremoLow, color=color.new(color.green,70), style=plot.style_line, linewidth=1, show_last=return)+plot(ExtremoLow, color=color.new(color.green,70), style=plot.style_line, linewidth=1, show_last=return_)//Show the Extreme High and Low close position ==> Mostra a extrema posicao alta e baixa do fechamento⋯//Show TRADE area in red (Sell) and green (Buy) ==> Mostra a área de trade em vermelho (Venda) e verde (Compra)-Line1 = plot(emaOhlc4, title="Dema ohlc4", color=color.new(color.white,100), linewidth=1, transp=0, show_last=return)+Line1 = plot(emaOhlc4, title="Dema ohlc4", color=color.new(color.new(color.white,100), 0), linewidth=1, show_last=return_)-Line2 = plot(dema72, title="Dema 72", color=color.new(color.white,100), linewidth=1,transp=0, show_last=return)+Line2 = plot(dema72, title="Dema 72", color=color.new(color.new(color.white,100), 0), linewidth=1, show_last=return_)-fill(Line1, Line2, color=emaOhlc4>dema72 ? color.new(color.green,90) : color.new(color.red,90), transp=70, show_last=return)+fill(Line1, Line2, color=color.new(emaOhlc4>dema72 ? color.new(color.green,90) : color.new(color.red,90), 70), show_last=return_)//High area ==> Area de alta-HighlH1 = plot(lH1, title="HighlH1", color=color.green, linewidth=1, transp=90, show_last=return, style=plot.style_linebr)+HighlH1 = plot(lH1, title="HighlH1", color=color.new(color.green, 90), linewidth=1, show_last=return_, style=plot.style_linebr)-HighlHInt = plot(lHInt, title="HighlHInt", color=color.green, linewidth=1, transp=100, show_last=return, style=plot.style_linebr)+HighlHInt = plot(lHInt, title="HighlHInt", color=color.new(color.green, 100), linewidth=1, show_last=return_, style=plot.style_linebr)-fill(HighlH1, HighlHInt, color=color.new(color.purple,90), transp=0, show_last=return)+fill(HighlH1, HighlHInt, color=color.new(color.new(color.purple,90), 0), show_last=return_)//Low area ==> Area de baixa-LowlL1 = plot(lL1, title="LowlL1", color=color.red, linewidth=1, transp=90, show_last=return, style=plot.style_linebr)+LowlL1 = plot(lL1, title="LowlL1", color=color.new(color.red, 90), linewidth=1, show_last=return_, style=plot.style_linebr)-LowlLInt = plot(lLInt, title="LowlLInt", color=color.red, linewidth=1, transp=100, show_last=return, style=plot.style_linebr)+LowlLInt = plot(lLInt, title="LowlLInt", color=color.new(color.red, 100), linewidth=1, show_last=return_, style=plot.style_linebr)-fill(LowlL1, LowlLInt, color=color.new(color.blue,90), transp=0, show_last=return)+fill(LowlL1, LowlLInt, color=color.new(color.new(color.blue,90), 0), show_last=return_)//⋯// Getting inputs-_Macd = input(title = "═════ Macd ══════════", type = input.bool, defval = false)+_Macd = input.bool(title = "═════ Macd ══════════", defval = false)-fast_length_Macd = input(title="Fast Length", type=input.integer, defval=12)+fast_length_Macd = input.int(title="Fast Length", defval=12)-slow_length_Macd = input(title="Slow Length", type=input.integer, defval=26)+slow_length_Macd = input.int(title="Slow Length", defval=26)-src_Macd = input(title="Source", type=input.source, defval=close)+src_Macd = input.source(title="Source", defval=close)-signal_length_Macd = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)+signal_length_Macd = input.int(title="Signal Smoothing", minval = 1, maxval = 50, defval = 9)// Calculating-fast_ma_Macd = ema(src_Macd, fast_length_Macd)+fast_ma_Macd = ta.ema(src_Macd, fast_length_Macd)-slow_ma_Macd = ema(src_Macd, slow_length_Macd)+slow_ma_Macd = ta.ema(src_Macd, slow_length_Macd)macd_Macd = fast_ma_Macd - slow_ma_Macd-signal_Macd = ema(macd_Macd, signal_length_Macd)+signal_Macd = ta.ema(macd_Macd, signal_length_Macd)hist_Macd = macd_Macd - signal_Macd//cross Macd-MacdUp = crossover(macd_Macd,signal_Macd) ? 1 : 0+MacdUp = ta.crossover(macd_Macd,signal_Macd) ? 1 : 0-MacdDown = crossunder (macd_Macd,signal_Macd) ? 1 : 0+MacdDown = ta.crossunder (macd_Macd,signal_Macd) ? 1 : 0-plotshape(MacdUp, text="+Md", title="(+)MACD UP", location=location.belowbar, color=color.green, transp=30, style=shape.triangleup, size=size.tiny, show_last=return)+plotshape(MacdUp, text="+Md", title="(+)MACD UP", location=location.belowbar, color=color.new(color.green, 30), style=shape.triangleup, size=size.tiny, show_last=return_)-plotshape(MacdDown, text="-Md", title="(-)MACD DN", location=location.abovebar, color=color.red, transp=30, style=shape.triangledown, size=size.tiny, show_last=return)+plotshape(MacdDown, text="-Md", title="(-)MACD DN", location=location.abovebar, color=color.new(color.red, 30), style=shape.triangledown, size=size.tiny, show_last=return_)//⋯//*****************************************************************************************-_Tsi = input(title = "═════ Tsi ══════════", type = input.bool, defval = false)+_Tsi = input.bool(title = "═════ Tsi ══════════", defval = false)-long_tsi = input(title="Long Length", type=input.integer, defval=72)+long_tsi = input.int(title="Long Length", defval=72)-short_tsi = input(title="Short Length", type=input.integer, defval=17)+short_tsi = input.int(title="Short Length", defval=17)-signal_tsi = input(title="Signal Length", type=input.integer, defval=17)+signal_tsi = input.int(title="Signal Length", defval=17)price_tsi = closedouble_smooth(src_tsi, long_tsi, short_tsi) =>- fist_smooth_tsi = ema(src_tsi, long_tsi)+ fist_smooth_tsi = ta.ema(src_tsi, long_tsi)- ema(fist_smooth_tsi, short_tsi)+ ta.ema(fist_smooth_tsi, short_tsi)-pc_tsi = change(price_tsi)+pc_tsi = ta.change(price_tsi)double_smoothed_pc_tsi = double_smooth(pc_tsi, long_tsi, short_tsi)-double_smoothed_abs_pc_tsi = double_smooth(abs(pc_tsi), long_tsi, short_tsi)+double_smoothed_abs_pc_tsi = double_smooth(math.abs(pc_tsi), long_tsi, short_tsi)tsi_value_tsi = 100 * (double_smoothed_pc_tsi / double_smoothed_abs_pc_tsi)//TSI signal ==> Signal do TSI-TsiUp = crossover(tsi_value_tsi,ema(tsi_value_tsi, signal_tsi)) ? 1 : 0+TsiUp = ta.crossover(tsi_value_tsi,ta.ema(tsi_value_tsi, signal_tsi)) ? 1 : 0-TsiDown = crossunder(tsi_value_tsi,ema(tsi_value_tsi, signal_tsi)) ? 1 : 0+TsiDown = ta.crossunder(tsi_value_tsi,ta.ema(tsi_value_tsi, signal_tsi)) ? 1 : 0//Show the Position ==> Mostra a posicao-plotshape(TsiUp==1 ? low : na, text="+Tsi", title="(+)TSI Up", location=location.belowbar, color=color.green, transp=30, style=shape.triangleup, size=size.tiny, show_last=return)+plotshape(TsiUp==1 ? low : na, text="+Tsi", title="(+)TSI Up", location=location.belowbar, color=color.new(color.green, 30), style=shape.triangleup, size=size.tiny, show_last=return_)-plotshape(TsiDown==1 ? high : na, text="-Tsi", title="(-)TSI DN", location=location.abovebar, color=color.red, transp=30, style=shape.triangledown, size=size.tiny, show_last=return)+plotshape(TsiDown==1 ? high : na, text="-Tsi", title="(-)TSI DN", location=location.abovebar, color=color.new(color.red, 30), style=shape.triangledown, size=size.tiny, show_last=return_)//⋯//Cross Point ==> pontos de cruzamento-crossUP=crossover(emaOhlc4,dema34)+crossUP=ta.crossover(emaOhlc4,dema34)-crossDN=crossunder(emaOhlc4,dema34)+crossDN=ta.crossunder(emaOhlc4,dema34)//Show de Buy and Sell points ==> mostra pontos de compra e venda⋯//line buy or sell ==> linha de compra ou venda-plot(crossUP ? dema34 : crossDN ? dema34: na, color=tradeColor, style=plot.style_line, linewidth=4, editable=false, show_last=return)+plot(crossUP ? dema34 : crossDN ? dema34: na, color=tradeColor, style=plot.style_line, linewidth=4, editable=false, show_last=return_)//Buy point ==> pontos de compra-plotshape(crossUP ? dema34 : na, style=shape.labelup, location=location.absolute, text="Buy", transp=0, textcolor = color.white, color=color.green, editable=false, show_last=return)+plotshape(crossUP ? dema34 : na, style=shape.labelup, location=location.absolute, text="Buy", textcolor = color.white, color=color.new(color.green, 0), editable=false, show_last=return_)//Sell points ==> pontos de venda-plotshape(crossDN ? dema34: na, style=shape.labeldown, location=location.absolute, text="Sell", transp=0, textcolor = color.white, color=color.red, editable=false, show_last=return)+plotshape(crossDN ? dema34: na, style=shape.labeldown, location=location.absolute, text="Sell", textcolor = color.white, color=color.new(color.red, 0), editable=false, show_last=return_)//⋯Same 39 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 82: input() → input.int()
- Line 83: input() → input.int()
- Line 97: input() → input.int()
⋯_Pivots = input.bool(title = "══════ Pivots ══════", defval = false)-leftBars = input(4)+leftBars = input.int(4)-rightBars=input(4)+rightBars=input.int(4)pivotHigh = ta.pivothigh(leftBars, rightBars) //pivot de alta⋯SOS_William = input.int(title="OverSold Area", defval=-93) //OverSold area ==> Area de SobreVenda-length_William = input(17, minval=1) //interval ==> intervalo+length_William = input.int(17, minval=1) //interval ==> intervalohighestHigh_William = ta.highest(length_William) //maximum value ==> valor máximo⋯Does it run in Pine Script v6?
No
The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 39 before, 28 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © DalmarSantos-//@version=5+//@version=6//Entry and Exit points to TRADE ==> Pontos de Entrada e Saida de TRADE⋯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 |
|---|---|---|---|
| Return Candels ? | 190 | int (written input.integer) | Dema ohlc4 Dema 72 HighlH1 HighlHInt LowlL1 LowlLInt DEMA 72 EMA ohlc4 barcolor Cross UP Cross DOWN Pivot High Pivot Low plot fill (+)MACD UP (-)MACD DN (+)TSI Up (-)TSI DN plotshape |
| ══════ Pivots ══════ | false | bool | unused |
| Left Bars (no label in the script) | 4 | int | pivotHigh pivotLow |
| Right Bars (no label in the script) | 4 | int | pivotHigh pivotLow Pivot High Pivot Low |
| ══════ William R% Mod ══════ | false | bool | unused |
| OverBought Area | -7 | int (written input.integer) | line 112 line 116 |
| OverSold Area | -93 | int (written input.integer) | line 125 line 129 |
| Length William (no label in the script) | 17 | int · min 1 | highestHigh_William highestLow_William |
| ═════ Macd ══════════ | false | bool | unused |
| Fast Length | 12 | int (written input.integer) | fast_ma_Macd |
| Slow Length | 26 | int (written input.integer) | slow_ma_Macd |
| Source | close | source | fast_ma_Macd slow_ma_Macd |
| Signal Smoothing | 9 | int (written input.integer) · min 1 · max 50 | signal_Macd |
| ═════ Tsi ══════════ | false | bool | unused |
| Long Length | 72 | int (written input.integer) | fist_smooth_tsi double_smoothed_pc_tsi double_smoothed_abs_pc_tsi |
| Short Length | 17 | int (written input.integer) | double_smoothed_pc_tsi double_smoothed_abs_pc_tsi line 224 |
| Signal Length | 17 | int (written input.integer) | TsiUp TsiDown |
What it calculates
- EMA (
ema,ta.emain v5)close, 8e1 · line 27 - EMA (
ema,ta.emain v5)e1, 8e2 · line 28 - EMA (
ema,ta.emain v5)close, 72ema72 · line 49 - EMA (
ema,ta.emain v5)ohlc4, 8emaOhlc4 · line 50 - Pivothigh (
pivothigh,ta.pivothighin v5)Left Bars (4), Right Bars (4)pivotHigh · line 84 - Pivotlow (
pivotlow,ta.pivotlowin v5)Left Bars (4), Right Bars (4)pivotLow · line 86 - Highest (
highest,ta.highestin v5)Length William (17)highestHigh_William · line 98 - Lowest (
lowest,ta.lowestin v5)Length William (17)highestLow_William · line 99 - EMA (
ema,ta.emain v5)Source (close), Fast Length (12)fast_ma_Macd · line 202 - EMA (
ema,ta.emain v5)Source (close), Slow Length (26)slow_ma_Macd · line 203 - EMA (
ema,ta.emain v5)macd_Macd, Signal Smoothing (9)signal_Macd · line 205 - Crossover (
crossover,ta.crossoverin v5)macd_Macd, signal_MacdMacdUp · line 208 - Crossunder (
crossunder,ta.crossunderin v5)macd_Macd, signal_MacdMacdDown · line 209 - EMA (
ema,ta.emain v5)src_tsi, Long Length (72)fist_smooth_tsi · line 223 - Change (
change,ta.changein v5)price_tsipc_tsi · line 225 - Crossover / EMA (
crossover,ta.crossoverin v5)tsi_value_tsi, ema(tsi_value_tsi, signal_tsi)TsiUp · line 230 - Crossunder / EMA (
crossunder,ta.crossunderin v5)tsi_value_tsi, ema(tsi_value_tsi, signal_tsi)TsiDown · line 231 - Crossover (
crossover,ta.crossoverin v5)emaOhlc4, dema34crossUP · line 241 - Crossunder (
crossunder,ta.crossunderin v5)emaOhlc4, dema34crossDN · line 242
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 78 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 |
|---|---|---|---|
| Close Short | crossUP | On | 263 |
| Open Long long | crossUP | On | 264 |
| Close Long | crossDN | On | 269 |
| Open Short short | crossDN | On | 270 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
No
No repainting patterns in the source, and the live replay matched history.
- ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
- 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 | +72.5% | +102.5% | 39 | 49% | 1.85 | 31.7% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +20.2% | +5.5% | 43 | 42% | 1.67 | 6.1% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +3.6% | +9.8% | 33 | 58% | 1.90 | 1.8% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.8% | +8.4% | 39 | 33% | 1.60 | 0.4% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.1% | +16.7% | 41 | 44% | 1.32 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 35 | 40% | 1.71 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.3% | +148.3% | 45 | 36% | 0.80 | 1.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.2% | +17.1% | 54 | 48% | 1.81 | 0.1% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
The trades
By market direction
| At entry, last 90 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 10 | 60% | $32,294.80 |
| Sideways market | 22 | 36% | −$15,413.70 |
| Falling market | 7 | 71% | $55,657.10 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
33.9%
The 95th percentile of the worst drawdown when the same 39 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 15.3% to 33.9%; the tick is what actually happened, 27.4%. Order luck alone moves it this much.
All 39 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 17 May 2024 65,235.20 | 4 Jun 2024 68,809.90 | 18 | $3,574.68 |
| short | 4 Jun 2024 68,809.90 | 6 Jun 2024 71,108.00 | 2 | −$2,298.11 |
| long | 6 Jun 2024 71,108.00 | 10 Jun 2024 69,648.10 | 4 | −$1,459.85 |
| short | 10 Jun 2024 69,648.10 | 15 Jul 2024 60,797.90 | 35 | $8,850.24 |
| long | 15 Jul 2024 60,797.90 | 4 Aug 2024 60,698.00 | 20 | −$99.92 |
| short | 4 Aug 2024 60,698.00 | 21 Aug 2024 59,013.80 | 17 | $1,684.19 |
| long | 21 Aug 2024 59,013.80 | 3 Sep 2024 59,132.10 | 13 | $118.32 |
| short | 3 Sep 2024 59,132.10 | 4 Sep 2024 57,487.70 | 1 | $1,644.38 |
| long | 4 Sep 2024 57,487.70 | 5 Sep 2024 57,970.90 | 1 | $483.16 |
| short | 5 Sep 2024 57,970.90 | 14 Sep 2024 60,498.00 | 9 | −$2,527.09 |
| long | 14 Sep 2024 60,498.00 | 5 Oct 2024 62,086.00 | 21 | $1,588.01 |
| short | 5 Oct 2024 62,086.00 | 16 Oct 2024 67,074.10 | 11 | −$4,988.14 |
| long | 16 Oct 2024 67,074.10 | 28 Oct 2024 68,021.70 | 12 | $947.55 |
| short | 28 Oct 2024 68,021.70 | 30 Oct 2024 72,736.40 | 2 | −$4,714.72 |
| long | 30 Oct 2024 72,736.40 | 4 Nov 2024 68,776.00 | 5 | −$3,960.42 |
| short | 4 Nov 2024 68,776.00 | 9 Nov 2024 76,509.80 | 5 | −$7,733.79 |
| long | 9 Nov 2024 76,509.80 | 27 Nov 2024 91,965.20 | 18 | $15,455.40 |
| short | 27 Nov 2024 91,965.20 | 21 Jan 2025 102,260.00 | 55 | −$10,294.80 |
| long | 21 Jan 2025 102,260.00 | 28 Jan 2025 102,083.00 | 7 | −$177.17 |
| short | 28 Jan 2025 102,083.00 | 17 Mar 2025 82,574.50 | 48 | $19,508.30 |
| long | 17 Mar 2025 82,574.50 | 20 May 2025 105,574.00 | 64 | $22,999.20 |
| short | 20 May 2025 105,574.00 | 24 May 2025 107,318.00 | 4 | −$1,744.57 |
| long | 24 May 2025 107,318.00 | 25 May 2025 107,762.00 | 1 | $443.60 |
| short | 25 May 2025 107,762.00 | 12 Jul 2025 117,528.00 | 48 | −$9,765.76 |
| long | 12 Jul 2025 117,528.00 | 23 Jul 2025 119,954.00 | 11 | $2,426.77 |
| short | 23 Jul 2025 119,954.00 | 12 Sep 2025 115,483.00 | 51 | $4,471.74 |
| long | 12 Sep 2025 115,483.00 | 25 Sep 2025 113,307.00 | 13 | −$2,175.68 |
| short | 25 Sep 2025 113,307.00 | 3 Oct 2025 120,529.00 | 8 | −$7,222.34 |
| long | 3 Oct 2025 120,529.00 | 12 Oct 2025 110,644.00 | 9 | −$9,884.95 |
| short | 12 Oct 2025 110,644.00 | 29 Oct 2025 112,898.00 | 17 | −$2,254.04 |
| long | 29 Oct 2025 112,898.00 | 2 Nov 2025 110,098.00 | 4 | −$2,800.34 |
| short | 2 Nov 2025 110,098.00 | 3 Nov 2025 110,541.00 | 1 | −$442.59 |
| long | 3 Nov 2025 110,541.00 | 5 Nov 2025 101,497.00 | 2 | −$9,043.46 |
| short | 5 Nov 2025 101,497.00 | 29 Nov 2025 90,890.70 | 24 | $10,606.50 |
| long | 29 Nov 2025 90,890.70 | 25 Jan 2026 89,225.30 | 57 | −$1,665.37 |
| short | 25 Jan 2026 89,225.30 | 18 Feb 2026 67,503.50 | 24 | $21,721.80 |
| long | 18 Feb 2026 67,503.50 | 13 May 2026 80,504.50 | 84 | $13,000.90 |
| short | 13 May 2026 80,504.50 | 17 Jun 2026 65,675.00 | 35 | $14,829.40 |
| long | 17 Jun 2026 65,675.00 | 8 Sep 2026 79,112.00 | 83 | $13,437.00 |
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 |
|---|---|---|---|---|---|
| [DS]Entry_Exit_TRADE.V01-Strategy this page | — | v4 strategy | +72.5% | 39 | 31.7% |
| MACD 5 iN 1 [Pro-Tool] by HamidBox | ema pivotlow pivothigh highest lowest | v4 strategy | No trades on this market | ||
| X48 - Strategy - MA Type Cross + TPSL - Future&Spot - V.2 by X4815162342 | ema highest lowest pivothigh pivotlow | v5 strategy | does not run in Zeal Terminal | ||
| CC Trend strategy 2- Downtrend Short by CheatCode1 | ema highest lowest | v5 strategy | No trades on this market | ||
| TrianglePoint strategy by mohanee | highest lowest ema | v4 strategy | +45.4% | 11 | 101.9% |
| Lagged Donchian Channel + EMA by Mysteriown | ema highest lowest | v4 strategy | −12.3% | 4 | 12.3% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 56 ms | With a workaround 1,000 bars in 158 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
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.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © DalmarSantos//@version=4//Entry and Exit points to TRADE ==> Pontos de Entrada e Saida de TRADE//Functions in use ==> Funções em uso//(1) DEMA - Double Exponential Moving Average 08/17/34/72 ==> Média Móvel Exponencial Dupla//(2) ema() - Exponential Moving Averge 72/ochl4 ==> Média Móvel Exponencial//(3) plot()//(4) barcolor()//(5) cross()//(6) pivots()//(7) William R% Md//(8) Maximum and Minimum Value//(9) fill()//(10) macd() - Moving Average Convergence Divergence//(11) tsi() - Trading Strenght Indicator==> Índice de Força Real (IFR)//(12) Buy and Sell TRADE Points//(13) Strategy Buy and Sell TRADE Pointsstrategy("[DS]Entry_Exit_TRADE.V01-Strategy", overlay=true)//variable ==> variáveisreturn = input(title="Return Candels ?", type=input.integer, defval=190) //quantity of candles to analise ==> quantidade de candles para analise////****************************//Function==> Função | (1)DEMA//****************************//Dema 08e1 = ema(close,8)e2 = ema(e1,8)dema08 = 2 * e1 - e2////Dema 17e1 := ema(close,17)e2 := ema(e1,17)dema17 = 2 * e1 - e2////Dema 34e1 := ema(close,34)e2 := ema(e1,34)dema34 = 2 * e1 - e2////Dema 72e1 := ema(close,72)e2 := ema(e1,72)dema72 = 2 * e1 - e2////******************************//Function==> Função | (2) ema()//******************************ema72 = ema(close,72)emaOhlc4=ema(ohlc4,8)////******************************//Function==> Função | (3)plot()//******************************//////Show the avareges ==> Apresenta as médias //plot(dema17, title="DEMA 17", color=color.new(color.lime,0), linewidth=1, style=plot.style_line, transp=0, show_last=return) // Doble Exponential Moving Avarage 17//plot(dema34, title="DEMA 34", color=color.new(color.black,0), linewidth=1, style=plot.style_line, transp=0, show_last=return) // Doble Exponential Moving Avarage 34plot(dema72, title="DEMA 72", color=color.orange, linewidth=2, style=plot.style_line, transp=0, show_last=return) // Doble Exponential Moving Avarage 72plot(emaOhlc4, title="EMA ohlc4", color=emaOhlc4>dema72 ? color.new(color.green,0) : color.new(color.red,0), linewidth=2, style=plot.style_line, transp=0, show_last=return) // Doble Exponential Moving Avarage 72////***********************************//Function==> Função | (4) barcolor()//***********************************//Show color TRADE bar if emaOhlc4>dema72 green (Buy) if not red (Red) ==> Mostra a cor da barra de TRADE se emaOhlc4>dema72 verde (Compra) se não vermelha (Venda)barcolor(close>dema34 and close>dema72 or close>close[1] ? color.new(color.green,0) : color.new(color.red,0), show_last=return)////********************************//Function==> Função | (5) cross()//********************************// Show the intersections crossing average on the graph ==> Apresenta no gráfico o local dos cruzamentos das médias //UP ==> para CIMAplot(crossover(emaOhlc4,dema72) ? dema72 : na, title="Cross UP", color=color.green, transp=0, style=plot.style_circles, linewidth=5, show_last=return)//DOWM ==> para BAIXOplot(crossunder(emaOhlc4,dema72) ? dema72 : na, title="Cross DOWN", color=color.red, transp=50, style=plot.style_circles, linewidth=5, show_last=return)////********************************//Function==> Função | (6) pivot()//Reference: Pine Script Manual//********************************_Pivots = input(title = "══════ Pivots ══════", type = input.bool, defval = false)leftBars = input(4)rightBars=input(4)pivotHigh = pivothigh(leftBars, rightBars) //pivot de altaplot(pivotHigh>ema72[rightBars] ? pivotHigh : na, title="Pivot High", style=plot.style_cross, linewidth=3, color= color.purple, transp=50, offset=-rightBars, show_last=return)pivotLow = pivotlow(leftBars, rightBars) //pivot de baixaplot(pivotLow<ema72[rightBars] ? pivotLow : na, title="Pivot Low", style=plot.style_cross, linewidth=3, color= color.blue, transp=50, offset=-rightBars, show_last=return)////***************************************//Function==> Função | (7) WILLIAM R% MOD//Reference: Pine Script Manual//***************************************// Getting inputs_WilliamR = input(title = "══════ William R% Mod ══════", type = input.bool, defval = false)SOB_William = input(title="OverBought Area", type=input.integer, defval=-7) //OverBought area ==> Area de SobreCompraSOS_William = input(title="OverSold Area", type=input.integer, defval=-93) //OverSold area ==> Area de SobreVendalength_William = input(17, minval=1) //interval ==> intervalohighestHigh_William = highest(length_William) //maximum value ==> valor máximohighestLow_William = lowest(length_William) //minumum value ==> valor mínimoR_William = (highestHigh_William - close) / (highestHigh_William - highestLow_William) * -100//Show the position ==> mostra a posição//plotshape(R_William > SOS_William ? na : high, text="+R%", title="+r(+)%R Up", location=location.belowbar, color=color.green, transp=30, style=shape.triangleup, size=size.tiny, show_last=return)//plotshape(R_William < SOB_William ? na : low, text="-R%", title="(-)%R DN", location=location.abovebar, color=color.red, transp=30, style=shape.triangledown, size=size.tiny, show_last=return)//// Show label with William %R value ==> Mostra a etiqueta com o valor do William %R// The color label red is when the value arrive on OverBought Area and green on OverSold Area, be careful with these areas ==> O rótulo de cor vermelha é quando o valor chega na área de SobreCompra e verde na área de SobreVenda, cuidado com estas áreas//corTest=color.whitecolorText = color.whiteestilo = label.style_label_upper_lefttextW=""if R_William>SOB_William corTest := color.new(color.red,0) //vermelho escuro estilo := label.style_label_lower_left textW:="OB"if R_William>-30 and R_William<=SOB_William corTest := #f5948e //vermelho intermediário estilo := label.style_label_lower_leftif R_William>-50 and R_William<=-30 corTest := #f5d5d3 //vermelho claro colorText := color.blackif R_William>-70 and R_William<=-50 corTest := #e7f5d3 //verde claro colorText := color.blackif R_William>=SOS_William and R_William<=-70 corTest := color.lime //verde intermediario estilo := label.style_label_upper_left colorText := color.blackif R_William<SOS_William corTest := color.new(color.green,0) // verde escuro estilo := label.style_label_upper_left textW:="OS"// Make a label at the high of the current barmyLabel = label.new(x=bar_index, y=close, style= estilo, color=corTest, text=tostring(R_William,"#.#")+"% "+textW, textcolor=colorText, size=size.normal)// Get the label textlabelText = label.get_text(id=myLabel)// Then set the label's text to a new string that// includes its current textlabel.set_text(id=myLabel, text=labelText)label.delete(myLabel[1])////**************************************************//Function==> Função | (8) MAXIMUM AND MINIMUM VALUE//Reference: Pine Script Manual//**************************************************//Maximum High and Minimum Low close position ==> Posição Máxima e Minima de fechamento ExtremoHigh=high+(highestHigh_William-high)ExtremoLow=low-(low-highestLow_William)plot(ExtremoHigh, color=color.new(color.red,70), style=plot.style_line, linewidth=1, show_last=return)plot(ExtremoLow, color=color.new(color.green,70), style=plot.style_line, linewidth=1, show_last=return)//Show the Extreme High and Low close position ==> Mostra a extrema posicao alta e baixa do fechamentolH1 = 0.0lHInt = closelL1 = closelLInt = closeVr_LinhaH=0.0Vr_LinhaL=0.0Vr_LinhaC=0.0if emaOhlc4<dema72 Vr_LinhaH := high+(highestHigh_William-high) lH1 := Vr_LinhaH>dema72 ? Vr_LinhaH : dema72 lHInt:=emaOhlc4<dema72 ? dema72 : emaOhlc4 lLInt := lHInt==emaOhlc4 ? dema72 : emaOhlc4 Vr_LinhaL:= low-(low-highestLow_William) lL1 := Vr_LinhaL>lLInt ? lLInt : Vr_LinhaLif emaOhlc4>dema72 Vr_LinhaH := high+(highestHigh_William-high) lH1 := Vr_LinhaH>dema72 ? Vr_LinhaH : dema72 lHInt:=dema72>emaOhlc4 ? dema72 : emaOhlc4 lLInt := lHInt==dema72 ? emaOhlc4 : dema72 Vr_LinhaL:= low-(low-highestLow_William) lL1 := Vr_LinhaL>lLInt ? lLInt : Vr_LinhaL////*******************************//Function==> Função | (9) fill()//Reference: Pine Script Manual//*******************************//Show TRADE area in red (Sell) and green (Buy) ==> Mostra a área de trade em vermelho (Venda) e verde (Compra)Line1 = plot(emaOhlc4, title="Dema ohlc4", color=color.new(color.white,100), linewidth=1, transp=0, show_last=return)Line2 = plot(dema72, title="Dema 72", color=color.new(color.white,100), linewidth=1,transp=0, show_last=return)fill(Line1, Line2, color=emaOhlc4>dema72 ? color.new(color.green,90) : color.new(color.red,90), transp=70, show_last=return)//High area ==> Area de altaHighlH1 = plot(lH1, title="HighlH1", color=color.green, linewidth=1, transp=90, show_last=return, style=plot.style_linebr)HighlHInt = plot(lHInt, title="HighlHInt", color=color.green, linewidth=1, transp=100, show_last=return, style=plot.style_linebr)fill(HighlH1, HighlHInt, color=color.new(color.purple,90), transp=0, show_last=return)//Low area ==> Area de baixaLowlL1 = plot(lL1, title="LowlL1", color=color.red, linewidth=1, transp=90, show_last=return, style=plot.style_linebr)LowlLInt = plot(lLInt, title="LowlLInt", color=color.red, linewidth=1, transp=100, show_last=return, style=plot.style_linebr)fill(LowlL1, LowlLInt, color=color.new(color.blue,90), transp=0, show_last=return)////***************************************************************************//Function==> Função | (10) macd() - Moving Average Convergence Divergence//Reference: Pine Script Manual - adapted TradingView version - Dalmar Santos//***************************************************************************// Getting inputs_Macd = input(title = "═════ Macd ══════════", type = input.bool, defval = false)fast_length_Macd = input(title="Fast Length", type=input.integer, defval=12)slow_length_Macd = input(title="Slow Length", type=input.integer, defval=26)src_Macd = input(title="Source", type=input.source, defval=close)signal_length_Macd = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)// Calculatingfast_ma_Macd = ema(src_Macd, fast_length_Macd)slow_ma_Macd = ema(src_Macd, slow_length_Macd)macd_Macd = fast_ma_Macd - slow_ma_Macdsignal_Macd = ema(macd_Macd, signal_length_Macd)hist_Macd = macd_Macd - signal_Macd//cross MacdMacdUp = crossover(macd_Macd,signal_Macd) ? 1 : 0MacdDown = crossunder (macd_Macd,signal_Macd) ? 1 : 0plotshape(MacdUp, text="+Md", title="(+)MACD UP", location=location.belowbar, color=color.green, transp=30, style=shape.triangleup, size=size.tiny, show_last=return)plotshape(MacdDown, text="-Md", title="(-)MACD DN", location=location.abovebar, color=color.red, transp=30, style=shape.triangledown, size=size.tiny, show_last=return)////*****************************************************************************************//Function==> Função | (11) tsi() - Trading Strenght Indicator ==> Indice de Força do Trading//Reference: Pine Script Manual - adapted TradingView version - Dalmar Santos//*****************************************************************************************_Tsi = input(title = "═════ Tsi ══════════", type = input.bool, defval = false)long_tsi = input(title="Long Length", type=input.integer, defval=72)short_tsi = input(title="Short Length", type=input.integer, defval=17)signal_tsi = input(title="Signal Length", type=input.integer, defval=17)price_tsi = closedouble_smooth(src_tsi, long_tsi, short_tsi) => fist_smooth_tsi = ema(src_tsi, long_tsi) ema(fist_smooth_tsi, short_tsi)pc_tsi = change(price_tsi)double_smoothed_pc_tsi = double_smooth(pc_tsi, long_tsi, short_tsi)double_smoothed_abs_pc_tsi = double_smooth(abs(pc_tsi), long_tsi, short_tsi)tsi_value_tsi = 100 * (double_smoothed_pc_tsi / double_smoothed_abs_pc_tsi)//TSI signal ==> Signal do TSITsiUp = crossover(tsi_value_tsi,ema(tsi_value_tsi, signal_tsi)) ? 1 : 0TsiDown = crossunder(tsi_value_tsi,ema(tsi_value_tsi, signal_tsi)) ? 1 : 0//Show the Position ==> Mostra a posicaoplotshape(TsiUp==1 ? low : na, text="+Tsi", title="(+)TSI Up", location=location.belowbar, color=color.green, transp=30, style=shape.triangleup, size=size.tiny, show_last=return)plotshape(TsiDown==1 ? high : na, text="-Tsi", title="(-)TSI DN", location=location.abovebar, color=color.red, transp=30, style=shape.triangledown, size=size.tiny, show_last=return)////***************************************************************************//Function==> Função | (12) Buy and Sell TRADE Points//Reference: Pine Script Manual - adapted TradingView version - Dalmar Santos//***************************************************************************//Cross Point ==> pontos de cruzamentocrossUP=crossover(emaOhlc4,dema34)crossDN=crossunder(emaOhlc4,dema34)//Show de Buy and Sell points ==> mostra pontos de compra e vendatradeColor=crossUP ? color.red : crossDN ? color.green : na//line buy or sell ==> linha de compra ou vendaplot(crossUP ? dema34 : crossDN ? dema34: na, color=tradeColor, style=plot.style_line, linewidth=4, editable=false, show_last=return)//Buy point ==> pontos de compraplotshape(crossUP ? dema34 : na, style=shape.labelup, location=location.absolute, text="Buy", transp=0, textcolor = color.white, color=color.green, editable=false, show_last=return)//Sell points ==> pontos de vendaplotshape(crossDN ? dema34: na, style=shape.labeldown, location=location.absolute, text="Sell", transp=0, textcolor = color.white, color=color.red, editable=false, show_last=return)////************************************************************//Function==> Função | (13) Strategy Buy and Sell TRADE Points//Reference: Pine Script Manual - Dalmar Santos//************************************************************//Start backtest year, month, day, hour, minute, second ==> Inicio do backtest ano, mês, dia, hora, minuto, segundostart = timestamp(2021,01,01,1,00,00)//*****************//BUY ==> COMPRA//*****************if time>= start if crossUP strategy.close("Short", comment="Close Sell") strategy.entry("Long", strategy.long, 1, comment="Open Buy")//*****************//SELL ==> Venda//***************** if crossDN strategy.close("Long", comment="Close Buy") strategy.entry("Short", strategy.short, 1, comment="Open Sell")