Pine Script v4 · Strategy
VFI strategy [based on VFI indicator published by UTS]
A Pine Script v4 strategy built on SMA or EMA or WMA or ALMA (sig, len), Stdev (inter, 30) and EMA (close, 200). It has 3 order rules, 1 entry among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 18 settings; defaults include Length 8, Coef 0.2 and Volume Cutoff 2.5.
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 VFI strategy [based on VFI indicator published by UTS] repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did VFI strategy [based on VFI indicator published by UTS] do on BTCUSDT 1D with default settings?
- +181.41%
- From 26 Jan 2024 to 21 Oct 2026, over 8 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can VFI strategy [based on VFI indicator published by UTS] 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 VFI strategy [based on VFI indicator published by UTS] use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does VFI strategy [based on VFI indicator published by UTS] run in Zeal Terminal?
- Yes
- It compiles in 19 ms and runs 1,000 bars in 85 ms, in the browser.
BTCUSDT · 1D · default settings
- VFI
- Plot
- Buy Line
- Sell Line
- MA
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +181.41%
- $18,141.30
- Buy and hold
- +102.5%
- same period
- Closed trades
- 8
- 6 won · 2 lost
- Profitable
- 75.0%
- of closed trades
- Profit factor
- 1.79
- gross profit ÷ gross loss
- Max drawdown
- 154.24%
- −$49,324.10
One run with the author's default settings, $10,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
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
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 91, 93, 97. The upgraded version below moves each call inside an if block.
-
Note
Uses iff(), which v5 removed line 72
iff() on line 72, 72. v5 writes it as the ternary c ? a : b.
-
Note
Uses transp =, which v5 removed line 87
transp = on line 87. v5 folds the transparency into the colour with color.new(c, transp).
-
Note
Uses long =, which v5 renamed line 91
long = on line 91. 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 sma → ta.sma, ema → ta.ema, wma → ta.wma, alma → ta.alma, log → math.log, stdev → ta.stdev, min → math.min, sum → math.sum, crossover → ta.crossover, crossunder → ta.crossunder.
- 3 strategy calls use the when = argument (line 91, 93, 97). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 8 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 6: //@version=4 → //@version=5
- Line 55: sma → ta.sma
- Line 57: ema → ta.ema
- Line 59: wma → ta.wma
- Line 61: alma → ta.alma
- Line 65: log → math.log
14 more edits
- Line 65: log → math.log
- Line 66: stdev → ta.stdev
- Line 70: min → math.min
- Line 72: iff(c, a, b) → (c ? a : b)
- Line 72: iff(c, a, b) → (c ? a : b)
- Line 73: sum → math.sum
- Line 78: ema → ta.ema
- Line 79: ema → ta.ema
- Line 80: ema → ta.ema
- Line 87: transp = 75 → color.new(color_osc, 75)
- Line 91: long = true → direction = strategy.long
- Line 91: crossover → ta.crossover
- Line 93: crossunder → ta.crossunder
- Line 97: crossunder → ta.crossunder
⋯// I have added buy line and sell line to the indicator and tested SPY stock/index on one hour chart-//@version=4+//@version=5strategy(title="VFI strategy [based on VFI indicator published by UTS]", overlay=false,pyramiding=2, default_qty_type=strategy.fixed, initial_capital=10000, currency=currency.USD)⋯ if t == kSma // Simple- ma := sma(sig, len)+ ma := ta.sma(sig, len) if t == kEma // Exponential- ma := ema(sig, len)+ ma := ta.ema(sig, len) if t == kWma // Weighted- ma := wma(sig, len)+ ma := ta.wma(sig, len) if t == kAlma // Arnaud Legoux- ma := alma(sig, len, vfi_almaOffset, vfi_almaSigma)+ ma := ta.alma(sig, len, vfi_almaOffset, vfi_almaSigma) ma⋯ avg = nz(hlc3)- inter = log(avg) - log(avg[1])+ inter = math.log(avg) - math.log(avg[1])- vInter = stdev(inter, 30)+ vInter = ta.stdev(inter, 30) cutOff = coef * vInter * close⋯ vMax = vAve * vCoef- vC = min(volume, vMax)+ vC = math.min(volume, vMax) mf = avg - avg[1]- vCp = iff(mf > cutOff, vC, iff(mf < -cutOff, -vC, 0))+ vCp = (mf > cutOff ? vC : (mf < -cutOff ? -vC : 0))- sVfi = sum(vCp, fviPeriod) / vAve+ sVfi = math.sum(vCp, fviPeriod) / vAve vfi = smooth(smoothType, sVfi, smoothLen)⋯value_ma = smooth(vfi_maType, value_vfi, vfi_maLength)-longEMAval= ema(close, vfi_longEMA)+longEMAval= ta.ema(close, vfi_longEMA)-shortEMAval1= ema(close, vfi_shortEMA1)+shortEMAval1= ta.ema(close, vfi_shortEMA1)-shortEMAval2= ema(close, vfi_shortEMA2)+shortEMAval2= ta.ema(close, vfi_shortEMA2)color_vfi = vfi_showTrend ? vfi_trendColor(value_vfi) : vfi_color(value_vfi)⋯plot_fill = plot(0, color=color_vfi, editable=false)-fill(plot_vfi, plot_fill, title="Oscillator Fill", color=color_osc, transp=75) +fill(plot_vfi, plot_fill, title="Oscillator Fill", color=color.new(color_osc, 75)) hline(vfi_buyLine, color=color.green, title="Buy Line", linewidth=2, linestyle=hline.style_dashed)⋯plot(value_ma, title="MA", color=color_ma, linewidth=2)-strategy.entry(id="VFI LE", long=true, when=crossover(value_vfi,vfi_buyLine) and ( shortEMAval1 >= longEMAval ))+strategy.entry(id="VFI LE", direction = strategy.long, when=ta.crossover(value_vfi,vfi_buyLine) and ( shortEMAval1 >= longEMAval ))//strategy.close(id="VFI LE", comment="Exit", when=crossunder(value_vfi,vfi_sellLine))-strategy.close(id="VFI LE", comment="TP Exit", when=crossunder(value_vfi,vfi_sellLine) and close>strategy.position_avg_price)+strategy.close(id="VFI LE", comment="TP Exit", when=ta.crossunder(value_vfi,vfi_sellLine) and close>strategy.position_avg_price)//strategy.close(id="VFI LE", comment="Exit", when= (shortEMAval1 > shortEMAval2 ) and crossunder(close, shortEMAval2))⋯stopLossVal = strategy.position_avg_price - (strategy.position_avg_price*stopLoss*0.01) -strategy.close(id="VFI LE", comment="SL Exit", when=crossunder(value_vfi,vfi_sellLine) and close < stopLossVal)+strategy.close(id="VFI LE", comment="SL Exit", when=ta.crossunder(value_vfi,vfi_sellLine) and close < stopLossVal)Same 8 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 18: input() → input.int()
- Line 19: input() → input.float()
- Line 20: input() → input.float()
- Line 21: input() → input.int()
- Line 24: input() → input.int()
- Line 25: input() → input.int()
13 more edits
- Line 26: input() → input.int()
- Line 28: input() → input.int()
- Line 29: input() → input.int()
- Line 30: input() → input.int()
- Line 31: input() → input.bool()
- Line 32: input() → input.bool()
- Line 33: input() → input.bool()
- Line 35: input() → input.int()
- Line 36: input() → input.float()
- Line 37: input() → input.float()
- Line 91: when = ta.crossover(value_vfi,vfi_buyLine) and ( shortEMAval1 >= longEMAval ) → if block
- Line 93: when = ta.crossunder(value_vfi,vfi_sellLine) and close>strategy.position_avg_price → if block
- Line 97: when = ta.crossunder(value_vfi,vfi_sellLine) and close < stopLossVal → if block
⋯// Input-vfi_length = input(8, title="Length", minval=1) //default 130+vfi_length = input.int(8, title="Length", minval=1) //default 130-vfi_coef = input(0.2, title="Coef", minval=0.1)+vfi_coef = input.float(0.2, title="Coef", minval=0.1)-vfi_volCutoff = input(2.5, title="Volume Cutoff", minval=0.1)+vfi_volCutoff = input.float(2.5, title="Volume Cutoff", minval=0.1)-vfi_smoothLen = input(3, title="Smoothing Period", minval=1)+vfi_smoothLen = input.int(3, title="Smoothing Period", minval=1)vfi_smoothType = input(kEma, title="Smoothing Type", options=[kAlma, kEma, kSma, kWma])//These are adde by me for the strategy purpose BEGIN-vfi_buyLine = input(-4, title="Buy Line", minval=-10)+vfi_buyLine = input.int(-4, title="Buy Line", minval=-10)-vfi_sellLine = input(5, title="Sell Line", minval=-10)+vfi_sellLine = input.int(5, title="Sell Line", minval=-10)-stopLoss = input(title="Stop Loss%", defval=5, minval=1)+stopLoss = input.int(title="Stop Loss%", defval=5, minval=1)//These are adde by me for the strategy purpose END-vfi_longEMA = input(200, title="Long EMA", minval=1)+vfi_longEMA = input.int(200, title="Long EMA", minval=1)-vfi_shortEMA1 = input(50, title="short EMA1", minval=1)+vfi_shortEMA1 = input.int(50, title="short EMA1", minval=1)-vfi_shortEMA2 = input(9, title="short EM2A", minval=1)+vfi_shortEMA2 = input.int(9, title="short EM2A", minval=1)-vfi_showTrend = input(false, title="Visualize Trend")+vfi_showTrend = input.bool(false, title="Visualize Trend")-vfi_showFill = input(true, title="Apply Filling")+vfi_showFill = input.bool(true, title="Apply Filling")-vfi_showMa = input(true, title="Show Moving Average")+vfi_showMa = input.bool(true, title="Show Moving Average")vfi_maType = input(kSma, title="Moving Average Type", options=[kAlma, kEma, kSma, kWma])-vfi_maLength = input(30, title="Moving Average Length", minval=1)+vfi_maLength = input.int(30, title="Moving Average Length", minval=1)-vfi_almaOffset = input(0.85, title="• ALMA - Offset (global setting)", minval=0.0, maxval=1.0, step=0.05) // more smoothness (closer to 1) vs. more responsiveness (closer to 0)+vfi_almaOffset = input.float(0.85, title="• ALMA - Offset (global setting)", minval=0.0, maxval=1.0, step=0.05) // more smoothness (closer to 1) vs. more responsiveness (closer to 0)-vfi_almaSigma = input(6.0, title="• ALMA - Sigma (global setting)", minval=0.0, step=0.05) // the larger sigma the smoother ALMA+vfi_almaSigma = input.float(6.0, title="• ALMA - Sigma (global setting)", minval=0.0, step=0.05) // the larger sigma the smoother ALMA// Functionality⋯plot(value_ma, title="MA", color=color_ma, linewidth=2)-strategy.entry(id="VFI LE", direction = strategy.long, when=ta.crossover(value_vfi,vfi_buyLine) and ( shortEMAval1 >= longEMAval ))+if ta.crossover(value_vfi,vfi_buyLine) and ( shortEMAval1 >= longEMAval )+ strategy.entry(id="VFI LE", direction = strategy.long)//strategy.close(id="VFI LE", comment="Exit", when=crossunder(value_vfi,vfi_sellLine))-strategy.close(id="VFI LE", comment="TP Exit", when=ta.crossunder(value_vfi,vfi_sellLine) and close>strategy.position_avg_price)+if ta.crossunder(value_vfi,vfi_sellLine) and close>strategy.position_avg_price+ strategy.close(id="VFI LE", comment="TP Exit")//strategy.close(id="VFI LE", comment="Exit", when= (shortEMAval1 > shortEMAval2 ) and crossunder(close, shortEMAval2))⋯stopLossVal = strategy.position_avg_price - (strategy.position_avg_price*stopLoss*0.01) -strategy.close(id="VFI LE", comment="SL Exit", when=ta.crossunder(value_vfi,vfi_sellLine) and close < stopLossVal)+if ta.crossunder(value_vfi,vfi_sellLine) and close < stopLossVal+ strategy.close(id="VFI LE", comment="SL Exit")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: 8 before, 0 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.
⋯// I have added buy line and sell line to the indicator and tested SPY stock/index on one hour chart-//@version=5+//@version=6strategy(title="VFI strategy [based on VFI indicator published by UTS]", overlay=false,pyramiding=2, default_qty_type=strategy.fixed, initial_capital=10000, currency=currency.USD)⋯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 |
|---|---|---|---|
| Length | 8 | int · min 1 | value_vfi |
| Coef | 0.2 | float · min 0.1 | value_vfi |
| Volume Cutoff | 2.5 | float · min 0.1 | value_vfi |
| Smoothing Period | 3 | int · min 1 | value_vfi |
| Smoothing Type | kEma | value · options [kAlma, kEma, kSma, kWma] | value_vfi |
| Buy Line | -4 | int · min -10 | Buy Line entry VFI LE |
| Sell Line | 5 | int · min -10 | Sell Line close VFI LE |
| Stop Loss% | 5 | int · min 1 | stopLossVal |
| Long EMA | 200 | int · min 1 | longEMAval |
| short EMA1 | 50 | int · min 1 | shortEMAval1 |
| short EM2A | 9 | int · min 1 | shortEMAval2 |
| Visualize Trend | false | bool | color_vfi |
| Apply Filling | true | bool | color_osc |
| Show Moving Average | true | bool | color_ma |
| Moving Average Type | kSma | value · options [kAlma, kEma, kSma, kWma] | value_ma |
| Moving Average Length | 30 | int · min 1 | value_ma |
| • ALMA - Offset (global setting) | 0.85 | float · min 0.0 · max 1.0 · step 0.05 | ma |
| • ALMA - Sigma (global setting) | 6.0 | float · min 0.0 · step 0.05 | ma |
What it calculates
- SMA / EMA / WMA / ALMA (
sma,ta.smain v5)sig, lenma · line 53 - Stdev (
stdev,ta.stdevin v5)inter, 30vInter · line 66 - EMA (
ema,ta.emain v5)close, Long EMA (200)longEMAval · line 78 - EMA (
ema,ta.emain v5)close, short EMA1 (50)shortEMAval1 · line 79 - EMA (
ema,ta.emain v5)close, short EM2A (9)shortEMAval2 · line 80
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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open VFI LE long | crossover(value_vfi,vfi_buyLine) and ( shortEMAval1 >= longEMAval ) | On | 91 |
| Close VFI LE | crossunder(value_vfi,vfi_sellLine) and close>strategy.position_avg_price | On | 93 |
| Close VFI LE | crossunder(value_vfi,vfi_sellLine) and close < stopLossVal | On | 97 |
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.
- 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 | +181.4% | +102.5% | 8 | 75% | 1.79 | 154.2% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +122.4% | +5.5% | 7 | 71% | 16.00 | 29.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −25.9% | +9.8% | 6 | 33% | 0.28 | 35.5% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +11.6% | +8.4% | 8 | 88% | 205.58 | 5.1% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −1.3% | +16.7% | 5 | 20% | 0.12 | 2.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.7% | +21.5% | 9 | 89% | 67.44 | 0.2% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.8% | +148.3% | 8 | 63% | 0.78 | 4.4% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +1.0% | +17.1% | 4 | 100% | — | 0.4% | 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 | 2 | 100% | $28,275.60 |
| Sideways market | 6 | 67% | −$10,134.30 |
| Falling market | 0 | — | $0.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
41.2%
The 95th percentile of the worst drawdown when the same 8 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 26.3% to 41.2%; the tick is what actually happened, 41.2%. Order luck alone moves it this much.
All 8 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 7 Mar 2025 89,931.90 | 1 May 2025 94,172.00 | 55 | $4,240.12 |
| long | 5 Jun 2025 104,697.00 | 17 Jul 2025 118,630.00 | 42 | $13,933.60 |
| long | 7 Jun 2025 104,288.00 | 17 Jul 2025 118,630.00 | 40 | $14,342.00 |
| long | 8 Aug 2025 117,472.00 | 15 Aug 2025 118,295.00 | 7 | $823.07 |
| long | 24 Aug 2025 115,438.00 | 14 Sep 2025 115,918.00 | 21 | $480.23 |
| long | 30 Sep 2025 114,312.00 | 10 Oct 2025 121,662.00 | 10 | $7,350.44 |
| long | 19 Oct 2025 107,185.00 | 7 Jan 2026 93,748.00 | 80 | −$13,437.00 |
| long | 8 Nov 2025 103,339.00 | 7 Jan 2026 93,748.00 | 60 | −$9,591.12 |
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 |
|---|---|---|---|---|---|
| VFI strategy [based on VFI indicator published by UTS] this page | — | v4 strategy | +181.4% | 8 | 154.2% |
| Escaping of Rate from Avarage By Mustafa OZVER Strategy by Mustafaozver | wma stdev ema | v4 strategy | +122.0% | 96 | 79.1% |
| Volume Weighted Bollinger Bands Strategy by Ankit_1618 | ema sma stdev | v4 strategy | +10.0% | 15 | 27.5% |
| BB21_MA200_Strategy by mohanee | ema sma stdev | v4 strategy | No trades on this market | ||
| Super Breakout day trading by beststockalert | stdev sma ema | v4 strategy | No trades on this market | ||
| Super Auto Breakout Day Trade Volatile stocks by beststockalert | stdev sma ema | v4 strategy | −6.1% | 51 | 29.1% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 19 ms | With a workaround 1,000 bars in 85 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
Zeal Terminal's engine currently reads an order side written as long = true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 91) so the engine trades the way the script says.
“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/// © mohanee//This strategy is based on VFI indicator published by UTS. //more details of VFI indicator can be found at [url=http://mkatsanos.com/VFI.html]http://mkatsanos.com/VFI.html[/url] // I have added buy line and sell line to the indicator and tested SPY stock/index on one hour chart//@version=4strategy(title="VFI strategy [based on VFI indicator published by UTS]", overlay=false,pyramiding=2, default_qty_type=strategy.fixed, initial_capital=10000, currency=currency.USD)// ConstkMaColor = color.aquakNeutralColor = color.graykBearColor = color.redkBullColor = color.greenkAlma = "ALMA"kEma = "EMA"kSma = "SMA"kWma = "WMA"// Inputvfi_length = input(8, title="Length", minval=1) //default 130vfi_coef = input(0.2, title="Coef", minval=0.1)vfi_volCutoff = input(2.5, title="Volume Cutoff", minval=0.1)vfi_smoothLen = input(3, title="Smoothing Period", minval=1)vfi_smoothType = input(kEma, title="Smoothing Type", options=[kAlma, kEma, kSma, kWma])//These are adde by me for the strategy purpose BEGINvfi_buyLine = input(-4, title="Buy Line", minval=-10)vfi_sellLine = input(5, title="Sell Line", minval=-10)stopLoss = input(title="Stop Loss%", defval=5, minval=1)//These are adde by me for the strategy purpose ENDvfi_longEMA = input(200, title="Long EMA", minval=1)vfi_shortEMA1 = input(50, title="short EMA1", minval=1)vfi_shortEMA2 = input(9, title="short EM2A", minval=1)vfi_showTrend = input(false, title="Visualize Trend")vfi_showFill = input(true, title="Apply Filling")vfi_showMa = input(true, title="Show Moving Average")vfi_maType = input(kSma, title="Moving Average Type", options=[kAlma, kEma, kSma, kWma])vfi_maLength = input(30, title="Moving Average Length", minval=1)vfi_almaOffset = input(0.85, title="• ALMA - Offset (global setting)", minval=0.0, maxval=1.0, step=0.05) // more smoothness (closer to 1) vs. more responsiveness (closer to 0)vfi_almaSigma = input(6.0, title="• ALMA - Sigma (global setting)", minval=0.0, step=0.05) // the larger sigma the smoother ALMA// FunctionalityisRising(sig) => sig > sig[1] isFlat(sig) => sig == sig[1]vfi_trendColor(sig) => isFlat(sig) ? kNeutralColor : isRising(sig) ? kBullColor : kBearColor vfi_color(sig) => isFlat(sig) ? kNeutralColor : sig > 0 ? kBullColor : kBearColor osc_color(sig) => sig == 0 ? kNeutralColor : sig > 0 ? kBullColor : kBearColorsmooth(t, sig, len) => ma = float(sig) // None if t == kSma // Simple ma := sma(sig, len) if t == kEma // Exponential ma := ema(sig, len) if t == kWma // Weighted ma := wma(sig, len) if t == kAlma // Arnaud Legoux ma := alma(sig, len, vfi_almaOffset, vfi_almaSigma) macalc_vfi(fviPeriod, smoothType, smoothLen, coef, vCoef) => avg = nz(hlc3) inter = log(avg) - log(avg[1]) vInter = stdev(inter, 30) cutOff = coef * vInter * close vAve = smooth(kSma, volume[1], fviPeriod) vMax = vAve * vCoef vC = min(volume, vMax) mf = avg - avg[1] vCp = iff(mf > cutOff, vC, iff(mf < -cutOff, -vC, 0)) sVfi = sum(vCp, fviPeriod) / vAve vfi = smooth(smoothType, sVfi, smoothLen) value_vfi = calc_vfi(vfi_length, vfi_smoothType, vfi_smoothLen, vfi_coef, vfi_volCutoff)value_ma = smooth(vfi_maType, value_vfi, vfi_maLength)longEMAval= ema(close, vfi_longEMA)shortEMAval1= ema(close, vfi_shortEMA1)shortEMAval2= ema(close, vfi_shortEMA2)color_vfi = vfi_showTrend ? vfi_trendColor(value_vfi) : vfi_color(value_vfi)color_osc = vfi_showFill ? osc_color(value_vfi) : nacolor_ma = vfi_showMa ? kMaColor : na// Drawingsplot_vfi = plot(value_vfi, title="VFI", color=color_vfi, linewidth=1)plot_fill = plot(0, color=color_vfi, editable=false)fill(plot_vfi, plot_fill, title="Oscillator Fill", color=color_osc, transp=75) hline(vfi_buyLine, color=color.green, title="Buy Line", linewidth=2, linestyle=hline.style_dashed)hline(vfi_sellLine, color=color.purple, title="Sell Line", linewidth=2, linestyle=hline.style_dashed)plot(value_ma, title="MA", color=color_ma, linewidth=2)strategy.entry(id="VFI LE", long=true, when=crossover(value_vfi,vfi_buyLine) and ( shortEMAval1 >= longEMAval ))//strategy.close(id="VFI LE", comment="Exit", when=crossunder(value_vfi,vfi_sellLine))strategy.close(id="VFI LE", comment="TP Exit", when=crossunder(value_vfi,vfi_sellLine) and close>strategy.position_avg_price)//strategy.close(id="VFI LE", comment="Exit", when= (shortEMAval1 > shortEMAval2 ) and crossunder(close, shortEMAval2))//stoplossstopLossVal = strategy.position_avg_price - (strategy.position_avg_price*stopLoss*0.01) strategy.close(id="VFI LE", comment="SL Exit", when=crossunder(value_vfi,vfi_sellLine) and close < stopLossVal)