Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Villa Dinamic Pivot Supertrend Strategy

A Pine Script v5 strategy built on Pivothigh (2, 2), Pivotlow (2, 2) and ATR (9). It has 6 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade is one contract and pays no commission. 37 settings; defaults include Stop Loss ATR Multiplier 2.5, Take Profit ATR Multiplier 4 and 2 Steps TP qty% 50.

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 Villa Dinamic Pivot Supertrend Strategy repaint?
Yes
At least one pattern in the source can repaint: intrabar recalculation.
How did Villa Dinamic Pivot Supertrend Strategy 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.
Does Villa Dinamic Pivot Supertrend Strategy run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L60:C15: cannot use 'float' as a condition — Pine Script v6 does not cast 'int' or 'float' to 'bool' implicitly. Wrap it in bool(). The v6 version is shown for reference and is not offered as a download.
Does Villa Dinamic Pivot Supertrend Strategy use a stop loss?
Yes
strategy.exit sets a stop on line 188, 246.
Does Villa Dinamic Pivot Supertrend Strategy run in Zeal Terminal?
Yes
It compiles in 51 ms and runs 1,000 bars in 119 ms, in the browser.

BTCUSDT · 1D · default settings

  • Pivothigh
  • Pivotlow
  • ATR
  • ATR
  • EMA
  • EMA
  • EMA
  • EMA
  • EMA
  • SMA
  • ATR
  • ATR
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (37)
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOct$1,000,000$2,025,273Equity from $1,000,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. The script plots nothing itself; the lines and the lower pane are its own calculations, drawn for reference.
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, $1,000,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.

  • Likely bug

    ta.atr(14) ignores the settings line 117

    Line 117 hard-codes 14 where line 68 uses “PVT ST ATR Period”. Changing those settings moves one band but not this one.

    ta.atr(14)ta.atr(Pd)
  • Check

    No commission

    The backtest assumes free trading. Results on any real exchange will be lower.

  • Note

    No slippage

    Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Strategy Inputs
Use Simple EMA Filterfalseboolema_cond_b ema_cond_s
Use DEMA Angle Filtertruebooldema_ang_cond_b dema_ang_cond_s
Use DEMA Filtertruebooldema_cond_b dema_cond_s
Take Every Supertrend Signalfalseboolst_cond_b st_cond_s
Stop Loss at Supertrendtrueboolsl_b tp_b sl_s tp_s
2 Steps Take Profitfalseboolclose Long close Short line 184 line 242
Move SLtrueboolline 186 line 244
Stop Loss ATR Multiplier2.5floatsl_b tp_b sl_s tp_s
Take Profit ATR Multiplier4floattp_b tp_s
2 Steps TP qty%50intclose Long close Short
DEMA Angle Threshold (+ & -)0floatdema_ang_cond_b dema_ang_cond_s
DEMA Angle Lookback1intdema_angle_rad
TestingBackteststring · options ["Backtest", "Forwardtest", "All"]date_range_cond
MarketForexstring · options ['Forex', 'Stocks']div_ang
BT Date Range
Backtesting start year2021intbt_date_range
Backtesting start month1intbt_date_range
Backtesting start day1intbt_date_range
Backtesting end year2021intbt_date_range
Backtesting end month12intbt_date_range
Backtesting end day31intbt_date_range
FT Date Range
Forwardtesting start year2022intft_date_range
Forwardtesting start month1intft_date_range
Forwardtesting start day1intft_date_range
Forwardtesting end year2022intft_date_range
Forwardtesting end month03intft_date_range
Forwardtesting end day26intft_date_range
Pivot Supertrend
PVT ST Pivot Point Period2intph pl
PVT ST ATR Factor3floatUp Dn
PVT ST ATR Period9intUp Dn
D-EMAs
DEMA Len200intema_fd dema
D-EMAs Sourceclosesourceema_fd ema1 ema2 ema3
EMA 1 Len21intema1
EMA 2 Len50intema2
EMA 3 Len200intema3
Normal Supertrend
ST ATR Period21intatr2 atr3
ST Supertrend Sourcehl2sourceup dn
ST ATR Multiplier2.0floatup dn

What it calculates

  • PivothighPVT ST Pivot Point Period (2), PVT ST Pivot Point Period (2)ph · line 56
  • PivotlowPVT ST Pivot Point Period (2), PVT ST Pivot Point Period (2)pl · line 57
  • ATRPVT ST ATR Period (9)Up · line 68
  • ATRPVT ST ATR Period (9)Dn · line 69
  • EMAD-EMAs Source (close), DEMA Len (200)ema_fd · line 89
  • EMAema_fd, DEMA Len (200)dema · line 90
  • EMAD-EMAs Source (close), EMA 1 Len (21)ema1 · line 95
  • EMAD-EMAs Source (close), EMA 2 Len (50)ema2 · line 96
  • EMAD-EMAs Source (close), EMA 3 Len (200)ema3 · line 97
  • SMAta.tr, ST ATR Period (21)atr2 · line 103
  • ATRST ATR Period (21)atr3 · line 104
  • ATR14atr · line 117

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 92 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.

Order rules

OrderFires whenBy defaultLine
Open Long long(longCondition)On179
Close Longdin_tpOff “2 Steps Take Profit”185
Exit Exit stop and limitevery barOn188
Open Short short(shortCondition)On237
Close Shortdin_tpOff “2 Steps Take Profit”243
Exit Exit stop and limitevery barOn246

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Does it repaint?

Yes

At least one pattern in the source can repaint; it is marked Check below.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D0.0%+102.5%00%—0.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h0.0%+5.5%00%—0.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D0.0%+9.8%00%—0.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h0.0%+8.4%00%—0.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D0.0%+16.7%00%—0.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h0.0%+21.5%00%—0.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D0.0%+148.3%00%—0.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h0.0%+17.1%00%—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.

ScriptSharesTypeNetTradesMax drawdown
Villa Dinamic Pivot Supertrend Strategy this page—v5 strategy0.0%00.0%
Golden Triangle Strategy by mohaneesma pivothigh pivotlow atrv4 strategy+156.1%10101.2%
Ta Strategy by AHMEDABDELAZIZZIZOpivothigh pivotlow ema smav5 strategy+0.3%80.3%
ATR with EOM and VORTEX by SoftKill21atr ema smav4 strategy+66.2%2229.9%
cATRpillar Strategy by Obi-wanClintobeatr sma emav4 strategy+1.02827e+24%2788,097.2%
Optimized Zhaocaijinbao strategy by fzj20020403sma ema atrv5 strategy+15.6%129.8%

Upgrade and export

Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.

  • No v6-only features. v6 is not needed to run this script.

Clean v5

Verified

Nothing to change.

Does it run in Pine Script v6?

No

The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L60:C15: cannot use 'float' as a condition — Pine Script v6 does not cast 'int' or 'float' to 'bool' implicitly. Wrap it in bool(). The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// © evillalobos1123-//@version=5+//@version=6strategy("Villa Dinamic Pivot Supertrend Strategy", overlay=true, calc_on_every_tick = true, default_qty_type = strategy.fixed)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 51 msYes 1,000 bars in 119 msNot measured
PineTSNot testedNot testedNot measured

“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.

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/// © evillalobos1123//@version=5strategy("Villa Dinamic Pivot Supertrend Strategy", overlay=true, calc_on_every_tick = true, default_qty_type = strategy.fixed)//INPUTSema_b = input.bool(false, "Use Simple EMA Filter", group = "Strategy Inputs")ema_b_ang = input.bool(true, "Use DEMA Angle Filter", group = "Strategy Inputs")dema_b = input.bool(true, "Use DEMA Filter", group = "Strategy Inputs")st_sig = input.bool(false, "Take Every Supertrend Signal" , group = "Strategy Inputs")take_p = input.bool(true, "Stop Loss at Supertrend", group = "Strategy Inputs")din_tp = input.bool(false, "2 Steps Take Profit", group = "Strategy Inputs")move_sl = input.bool(true, "Move SL", group = "Strategy Inputs")sl_atr = input.float(2.5, "Stop Loss ATR Multiplier", group = "Strategy Inputs")tp_atr = input.float(4, "Take Profit ATR Multiplier", group = "Strategy Inputs")din_tp_qty = input.int(50, "2 Steps TP qty%", group = "Strategy Inputs")dema_a_filter = input.float(0, "DEMA Angle Threshold (+ & -)", group = "Strategy Inputs")dema_a_look = input.int(1, "DEMA Angle Lookback", group = "Strategy Inputs")dr_test = input.string("Backtest", "Testing", options = ["Backtest", "Forwardtest", "All"], group = "Strategy Inputs")test_act = input.string('Forex', 'Market', options = ['Forex', 'Stocks'], group = "Strategy Inputs")not_in_trade = strategy.position_size == 0//Backtesting date rangestart_year = input.int(2021, "Backtesting start year", group = "BT Date Range")start_month = input.int(1, "Backtesting start month", group = "BT Date Range")start_date = input.int(1, "Backtesting start day", group = "BT Date Range")end_year = input.int(2021, "Backtesting end year", group = "BT Date Range")end_month = input.int(12, "Backtesting end month", group = "BT Date Range")end_date = input.int(31, "Backtesting end day", group = "BT Date Range")bt_date_range = (time >= timestamp(syminfo.timezone, start_year,         start_month, start_date, 0, 0)) and     (time < timestamp(syminfo.timezone, end_year, end_month, end_date, 0, 0))     //Forward testing date rangestart_year_f = input.int(2022, "Forwardtesting start year", group = "FT Date Range")start_month_f = input.int(1, "Forwardtesting start month", group = "FT Date Range")start_date_f = input.int(1, "Forwardtesting start day", group = "FT Date Range")end_year_f = input.int(2022, "Forwardtesting end year", group = "FT Date Range")end_month_f = input.int(03, "Forwardtesting end month", group = "FT Date Range")end_date_f = input.int(26, "Forwardtesting end day", group = "FT Date Range")ft_date_range = (time >= timestamp(syminfo.timezone, start_year_f,         start_month_f, start_date_f, 0, 0)) and     (time < timestamp(syminfo.timezone, end_year_f, end_month_f, end_date_f, 0, 0))//date conditiondate_range_cond = if dr_test == "Backtest"    bt_date_rangeelse if dr_test == "Forwardtest"    ft_date_rangeelse    true    //INDICATORS//PIVOT SUPERTRENDprd = input.int(2, "PVT ST Pivot Point Period", group = "Pivot Supertrend")Factor=input.float(3, "PVT ST ATR Factor", group = "Pivot Supertrend")Pd=input.int(9 ,  "PVT ST ATR Period", group = "Pivot Supertrend")// get Pivot High/Lowfloat ph = ta.pivothigh(prd, prd)float pl = ta.pivotlow(prd, prd)// calculate the Center line using pivot pointsvar float center = nafloat lastpp = ph ? ph : pl ? pl : naif lastpp    if na(center)        center := lastpp    else        //weighted calculation        center := (center * 2 + lastpp) / 3// upper/lower bands calculationUp = center - (Factor * ta.atr(Pd))Dn = center + (Factor * ta.atr(Pd))// get the trendfloat TUp = nafloat TDown = naTrend = 0TUp := close[1] > TUp[1] ? math.max(Up, TUp[1]) : UpTDown := close[1] < TDown[1] ? math.min(Dn, TDown[1]) : DnTrend := close > TDown[1] ? 1: close < TUp[1]? -1: nz(Trend[1], 1)Trailingsl = Trend == 1 ? TUp : TDown// check and plot the signalsbsignal = Trend == 1 and Trend[1] == -1ssignal = Trend == -1 and Trend[1] == 1//get S/R levels using Pivot Pointsfloat resistance = nafloat support = nasupport := pl ? pl : support[1]resistance := ph ? ph : resistance[1]//DEMAdema_ln = input.int(200, "DEMA Len", group = 'D-EMAs')dema_src = input.source(close, "D-EMAs Source", group = 'D-EMAs')ema_fd = ta.ema(dema_src, dema_ln)dema = (2*ema_fd)-(ta.ema(ema_fd,dema_ln))//EMAema1_l = input.int(21, "EMA 1 Len", group = 'D-EMAs')ema2_l = input.int(50, "EMA 2 Len", group = 'D-EMAs')ema3_l = input.int(200, "EMA 3 Len", group = 'D-EMAs')ema1 = ta.ema(dema_src, ema1_l)ema2 = ta.ema(dema_src, ema2_l)ema3 = ta.ema(dema_src, ema3_l)//SupertrendPeriods = input.int(21, "ST ATR Period", group = "Normal Supertrend")src_st = input.source(hl2, "ST Supertrend Source", group = "Normal Supertrend")Multiplier = input.float(2.0 , "ST ATR Multiplier", group = "Normal Supertrend")changeATR= trueatr2 = ta.sma(ta.tr, Periods)atr3= changeATR ? ta.atr(Periods) : atr2up=src_st-(Multiplier*atr3)up1 = nz(up[1],up)up := close[1] > up1 ? math.max(up,up1) : updn=src_st+(Multiplier*atr3)dn1 = nz(dn[1], dn)dn := close[1] < dn1 ? math.min(dn, dn1) : dntrend = 1trend := nz(trend[1], trend)trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trendbuySignal = trend == 1 and trend[1] == -1sellSignal = trend == -1 and trend[1] == 1//ATRatr = ta.atr(14)///CONDITIONS//BUY /// ema simpleema_cond_b = if ema_b    ema1 > ema2 and ema2 > ema3else    true///ema anglediv_ang = if test_act == 'Forex'    0.0001else    1dema_angle_rad = math.atan((dema - dema[dema_a_look])/div_ang)dema_angle = dema_angle_rad * (180/math.pi)dema_ang_cond_b = if ema_b_ang    if dema_angle >= dema_a_filter        true    else        falseelse    true    ///ema distancedema_cond_b = if dema_b    close > demaelse     true    //supertrends///if pivot buy sig or (st buy sig and pivot. trend = 1)pvt_cond_b = bsignalst_cond_b = if st_sig    buySignal and Trend == 1else    falsest_entry_cond = pvt_cond_b or st_cond_b///stop loss tpsl_b = if take_p    if trend == 1        up    else        close - (atr * sl_atr)else    close - (atr * sl_atr)tp_b = if take_p    if trend == 1        close + ((close - up) * (tp_atr / sl_atr))    else        close + (atr * tp_atr)else    close + (atr * tp_atr)    //position size init_cap = strategy.equitypos_size_b = math.round((init_cap * .01) / (close - sl_b))ent_price = strategy.opentrades.entry_price(strategy.opentrades - 1)var sl_b_n = 0.0var tp_b_n = 0.0longCondition = (ema_cond_b and dema_cond_b and dema_ang_cond_b and st_entry_cond and date_range_cond and not_in_trade)if (longCondition)        strategy.entry("Long", strategy.long, qty = pos_size_b)    sl_b_n := sl_b    tp_b_n := tp_b    ent_price := strategy.opentrades.entry_price(strategy.opentrades - 1)if (up[1] < ent_price and up >= ent_price and trend[0] == 1)    if din_tp        strategy.close("Long", qty_percent = din_tp_qty)    if move_sl        sl_b_n := ent_pricestrategy.exit("Exit", "Long", stop =sl_b_n, limit = tp_b_n)       //sell///ema simpleema_cond_s = if ema_b    ema1 < ema2 and ema2 < ema3else    true//ema distancedema_cond_s = if dema_b    close < demaelse     true//dema angledema_ang_cond_s = if ema_b_ang    if dema_angle <= -(dema_a_filter)        true    else        falseelse    true//supertrends///if pivot buy sig or (st buy sig and pivot. trend = 1)pvt_cond_s = ssignalst_cond_s = if st_sig    sellSignal and Trend == -1else    falsest_entry_cond_s = pvt_cond_s or st_cond_s///stop loss tpsl_s = if take_p    if trend == -1        dn    else        close + (atr * sl_atr)else    close + (atr * sl_atr)tp_s = if take_p    if trend == -1        close - ((dn - close) * (tp_atr / sl_atr))    else        close - (atr * tp_atr)else    close - (atr * tp_atr)shortCondition = (ema_cond_s and dema_cond_s and dema_ang_cond_s and date_range_cond and st_entry_cond_s and not_in_trade)pos_size_s = math.round((init_cap * .01) / (sl_s - close))var sl_s_n = 0.0var tp_s_n = 0.0if (shortCondition)    strategy.entry("Short", strategy.short, qty = pos_size_s)    sl_s_n := sl_s    tp_s_n := tp_s    if (dn[1] > ent_price and dn <= ent_price and trend[0] == -1)    if din_tp        strategy.close("Short", qty_percent = din_tp_qty)    if move_sl        sl_s_n := ent_pricestrategy.exit("Exit", "Short", stop = sl_s_n, limit = tp_s_n)