Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

KAMA Strategy - Kaufman's Adaptive Moving Average

A Pine Script v5 strategy built on Change (close, 14), Stdev (kama1delta, 14) and EMA (close, 14). It has 2 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 commits 100% of equity and pays no commission. 37 settings; defaults include Source close, KAMA 1: Length 14 and KAMA 1: Fast KAMA Length 2.

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 KAMA Strategy - Kaufman's Adaptive Moving Average repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 6 of 6 trades.
How did KAMA Strategy - Kaufman's Adaptive Moving Average do on BTCUSDT 1D with default settings?
+51.13%
From 26 Jan 2024 to 21 Oct 2026, over 20 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does KAMA Strategy - Kaufman's Adaptive Moving Average 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: 20 before, 18 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
Does KAMA Strategy - Kaufman's Adaptive Moving Average use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does KAMA Strategy - Kaufman's Adaptive Moving Average run in Zeal Terminal?
Yes
It compiles in 35 ms and runs 1,000 bars in 142 ms, in the browser.

BTCUSDT · 1D · default settings

  • KAMA 1
  • KAMA 2
  • KAMA 3
  • KAMA 4
  • KAMA 5
  • KAMA 6
  • KAMA 7
  • KAMA 8
  • 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$15,113$20,253Equity from $10,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots.
Net profit
+51.13%
$5,113.48
Buy and hold
+102.5%
same period
Closed trades
20
8 won · 12 lost
Profitable
40.0%
of closed trades
Profit factor
1.53
gross profit ÷ gross loss
Max drawdown
34.62%
−$6,302.44

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

    1 setting does nothing

    “Trail Mode” is 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.

  • Check

    Every trade uses all the equity

    default_qty_value is 100% of equity.

  • 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 124, 127. The upgraded version below moves each call inside an if block.

Settings

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

SettingDefaultType and rangeFeeds
Sourceclosesourcemom volatility kama kama1 kama2 kama3 kama4 kama5 kama6 kama7 kama8 srcEma
KAMA 1 Stop LosstrueboollongClose
ATR Trailing Stop LossfalseboolplotLow longClose
PSAR Stop LossfalseboolpsarPlot longClose
KAMA 1: Length14intmom volatility kama1 entryMAAF exitMAAF srcEma
KAMA 1: Fast KAMA Length2intfastAlpha kama1
KAMA 1: Slow KAMA Length20intslowAlpha kama1
KAMA 2: Length 215intkama2
KAMA 2: Fast KAMA Length3intkama2
KAMA 2: Slow KAMA Length22intkama2
KAMA 3: Length 316intkama3
KAMA 3: Fast KAMA Length4intkama3
KAMA 3: Slow KAMA Length24intkama3
KAMA 4: Length17intkama4
KAMA 4: Fast KAMA Length5intkama4
KAMA 4: Slow KAMA Length26intkama4
KAMA 5: Length18intkama5
KAMA 5: Fast KAMA Length6intkama5
KAMA 5: Slow KAMA Length28intkama5
KAMA 6: Length19intkama6
KAMA 6: Fast KAMA Length7intkama6
KAMA 6: Slow KAMA Length30intkama6
KAMA 7: Length20intkama7
KAMA 7: Fast KAMA Length8intkama7
KAMA 7: Slow KAMA Length32intkama7
KAMA 8: Length21intkama8
KAMA 8: Fast KAMA Length9intkama8
KAMA 8: Slow KAMA Length34intkama8
KAMA Entry Filter1float · min 0.01entryMAAF
KAMA Exit Filter0.5float · min 0.01exitMAAF
Trailing ATR Lookback Period14intatrValue
Trailing ATR Multiplier3float · min 0.5 · max 4 · step 0.1atrMultiplied
Trail ModeTrailingstring · options ['Running', 'Trailing']unused
Trigger Trailing Stop OnWickstring · options ['Close', 'Wick']trigSupport
PSAR Start0.02floatpsar
PSAR Increment0.02floatpsar
PSAR Max Value0.2floatpsar

What it calculates

  • ChangeSource (close), KAMA 1: Length (14)mom · line 47
  • ChangeSource (close)volatility · line 48
  • Stdevkama1delta, KAMA 1: Length (14)entryMAAF · line 84
  • Stdevkama1delta, KAMA 1: Length (14)exitMAAF · line 85
  • EMASource (close), KAMA 1: Length (14)srcEma · line 86
  • ATRTrailing ATR Lookback Period (14)atrValue · line 96
  • SARPSAR Start (0.02), PSAR Increment (0.02), PSAR Max Value (0.2)psar · line 118
  • Crossunderclose, psarlongClose · line 126

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

Order rules

OrderFires whenBy defaultLine
Open Buy longlongkama1delta > 0 and kama1delta > entryMAAFOn124
Close BuylongCloseOn127

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.

6/6trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D+51.1%+102.5%2040%1.5334.6%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−5.6%+5.5%2030%0.8320.7%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+27.3%+9.8%2035%1.2141.4%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−1.9%+8.4%2025%0.9619.3%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+6.4%+16.7%1833%1.0554.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+2.7%+21.5%2030%1.0520.7%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+61.9%+148.3%2025%1.5441.4%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−1.6%+17.1%2129%0.9315.5%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

Settings heatmap

Two settings that feed the entry signal, moved around their defaults. The best in-sample pair (KAMA 1: Length 10, KAMA Entry Filter 1.7) made +100.9% before 26 Dec 2025 and +16.4% after it, against +16.2% for the defaults. 100% of the 64 combinations made money in-sample and 56% out-of-sample.

Before 26 Dec 2025 · in-sample
KAMA Entry Filter ↓ · KAMA 1: Length →78101214172024
0.5+42%+70%+98%+41%+49%+36%+14%+35%
0.6+41%+60%+99%+43%+46%+36%+10%+35%
0.7+37%+60%+97%+47%+45%+30%+10%+35%
0.85+47%+64%+99%+61%+50%+22%+8%+32%
1+60%+51%+98%+58%+35%+17%+4%+32%
1.2+47%+51%+93%+56%+35%+16%+2%+25%
1.4+49%+56%+91%+49%+23%+22%+8%+21%
1.7+49%+61%+101%+54%+20%+19%+12%+22%
From 26 Dec 2025 · out-of-sample
KAMA Entry Filter ↓ · KAMA 1: Length →78101214172024
0.5+23%+29%−3%+11%+23%+11%−1%−17%
0.6+22%+15%−4%+11%+21%+11%−2%−20%
0.7+21%+13%+3%+9%+20%−1%−2%−20%
0.85+9%+12%+3%−2%+21%−1%−9%−20%
1+10%+8%+1%−2%+16%−1%−10%−23%
1.2+9%+8%+17%−0%+4%+1%−10%−23%
1.4+10%+8%+16%−11%+3%+1%−10%−24%
1.7+10%+8%+16%−16%−7%−0%−11%−13%

Net P&L of trades opened in each period, as a share of starting capital. marks the defaults and the best in-sample cell. Hover a cell for its trade count. Backtests are simulations on historical data and are not investment advice.

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market560%−$221.55
Sideways market1030%$4,188.95
Falling market540%$1,146.08

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

39.0%

The 95th percentile of the worst drawdown when the same 20 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 18.5% to 39.0%; the tick is what actually happened, 33.4%. Order luck alone moves it this much.

0%45%
All 20 trades
SideEntryExitBarsP&L
long10 Feb 2024 47,132.803 Apr 2024 65,464.0053$3,889.27
long9 Apr 2024 71,620.0013 Apr 2024 67,116.504−$873.36
long16 May 2024 66,206.5014 Jun 2024 66,773.0029$111.37
long19 Jul 2024 63,987.903 Aug 2024 61,498.3015−$510.74
long22 Aug 2024 61,156.002 Sep 2024 57,301.8011−$795.14
long20 Sep 2024 62,948.0010 Oct 2024 60,636.0020−$434.18
long15 Oct 2024 66,084.0023 Dec 2024 95,186.3069$5,014.74
long7 Jan 2025 102,236.005 Feb 2025 97,763.1029−$717.53
long23 Apr 2025 93,443.006 Jun 2025 101,509.0044$1,353.83
long30 Jun 2025 108,357.001 Aug 2025 115,764.0032$1,164.71
long14 Aug 2025 123,306.0020 Aug 2025 112,873.006−$1,540.23
long13 Sep 2025 116,029.0026 Sep 2025 108,994.0013−$1,010.27
long4 Oct 2025 122,232.0016 Oct 2025 110,763.0012−$1,468.66
long10 Dec 2025 92,678.8015 Dec 2025 88,172.205−$689.71
long3 Jan 2026 89,995.1021 Jan 2026 88,427.7018−$235.03
long5 Mar 2026 72,666.8028 Mar 2026 66,407.3023−$1,142.13
long10 Apr 2026 71,788.0020 May 2026 76,834.4040$851.77
long15 Jul 2026 65,044.0014 Aug 2026 63,490.9030−$309.67
long18 Aug 2026 64,532.1011 Sep 2026 76,568.7024$2,361.18
long20 Sep 2026 81,250.009 Oct 2026 81,754.5019$93.26

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
KAMA Strategy - Kaufman's Adaptive Moving Average this page—v5 strategy+51.1%2034.6%
Trend #2 - BB+EMA by zxcv55602ema stdev sarv4 strategy−0.6%143.9%
Trend Following with Bollinger Bands by Robrecht99stdev ema atrv5 strategy+2.5%71.7%
[KL] BOLL + MACD Strategy v2 (published) by DojiEmojistdev ema atrv4 strategy−32.1%2854.0%
[EURUSD60] BB Expansion Strategy by kasaismstdev ema atrv4 strategyNo trades on this market
888 BOT #backtest by UnknownUnicorn2151907ema sar stdev atrv4 strategy+3.0%120.9%

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.

  • 2 strategy calls use the when = argument (line 124, 127). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
  • 32 settings use the untyped input() (line 13, 15, 16, 17, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 32, 33, 34, 35, 36, 37, 38, 39, 40, 42, 43, 44, 91, 115, 116, 117). It still compiles in v6; input.int, input.float or input.source state the type.
  • No v6-only features. v6 is not needed to run this script.

Clean v5

VerifiedDownload the v5 script

Same 20 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 13: input() → input.source()
  • Line 15: input() → input.bool()
  • Line 16: input() → input.bool()
  • Line 17: input() → input.bool()
  • Line 19: input() → input.int()
  • Line 20: input() → input.int()
28 more edits
  • Line 21: input() → input.int()
  • Line 22: input() → input.int()
  • Line 23: input() → input.int()
  • Line 24: input() → input.int()
  • Line 25: input() → input.int()
  • Line 26: input() → input.int()
  • Line 27: input() → input.int()
  • Line 28: input() → input.int()
  • Line 29: input() → input.int()
  • Line 30: input() → input.int()
  • Line 32: input() → input.int()
  • Line 33: input() → input.int()
  • Line 34: input() → input.int()
  • Line 35: input() → input.int()
  • Line 36: input() → input.int()
  • Line 37: input() → input.int()
  • Line 38: input() → input.int()
  • Line 39: input() → input.int()
  • Line 40: input() → input.int()
  • Line 42: input() → input.int()
  • Line 43: input() → input.int()
  • Line 44: input() → input.int()
  • Line 91: input() → input.int()
  • Line 115: input() → input.float()
  • Line 116: input() → input.float()
  • Line 117: input() → input.float()
  • Line 124: when = long → if block
  • Line 127: when = longClose → if block
⋯strategy(title='KAMA Strategy - Kaufman\'s Adaptive Moving Average', shorttitle='KAMA Strategy', overlay=true, default_qty_value=100, default_qty_type=strategy.percent_of_equity, initial_capital=10000, max_bars_back=1000)-src = input(title='Source', defval=close)+src = input.source(title='Source', defval=close)// Exits-KAMA1SL = input(title='KAMA 1 Stop Loss', defval=true)+KAMA1SL = input.bool(title='KAMA 1 Stop Loss', defval=true)-ATRTSL = input(title='ATR Trailing Stop Loss', defval=false)+ATRTSL = input.bool(title='ATR Trailing Stop Loss', defval=false)-PSARSL = input(title='PSAR Stop Loss', defval=false)+PSARSL = input.bool(title='PSAR Stop Loss', defval=false)// KAMA 1 (Fastest)-length1 = input(title='KAMA 1: Length', defval=14)+length1 = input.int(title='KAMA 1: Length', defval=14)-fastLength1 = input(title='KAMA 1: Fast KAMA Length', defval=2)+fastLength1 = input.int(title='KAMA 1: Fast KAMA Length', defval=2)-slowLength1 = input(title='KAMA 1: Slow KAMA Length', defval=20)+slowLength1 = input.int(title='KAMA 1: Slow KAMA Length', defval=20)-length2 = input(title='KAMA 2: Length 2', defval=15)+length2 = input.int(title='KAMA 2: Length 2', defval=15)-fastLength2 = input(title='KAMA 2: Fast KAMA Length', defval=3)+fastLength2 = input.int(title='KAMA 2: Fast KAMA Length', defval=3)-slowLength2 = input(title='KAMA 2: Slow KAMA Length', defval=22)+slowLength2 = input.int(title='KAMA 2: Slow KAMA Length', defval=22)-length3 = input(title='KAMA 3: Length 3', defval=16)+length3 = input.int(title='KAMA 3: Length 3', defval=16)-fastLength3 = input(title='KAMA 3: Fast KAMA Length', defval=4)+fastLength3 = input.int(title='KAMA 3: Fast KAMA Length', defval=4)-slowLength3 = input(title='KAMA 3: Slow KAMA Length', defval=24)+slowLength3 = input.int(title='KAMA 3: Slow KAMA Length', defval=24)-length4 = input(title='KAMA 4: Length', defval=17)+length4 = input.int(title='KAMA 4: Length', defval=17)-fastLength4 = input(title='KAMA 4: Fast KAMA Length', defval=5)+fastLength4 = input.int(title='KAMA 4: Fast KAMA Length', defval=5)-slowLength4 = input(title='KAMA 4: Slow KAMA Length', defval=26)+slowLength4 = input.int(title='KAMA 4: Slow KAMA Length', defval=26)// KAMA 5 (Medium)-length5 = input(title='KAMA 5: Length', defval=18)+length5 = input.int(title='KAMA 5: Length', defval=18)-fastLength5 = input(title='KAMA 5: Fast KAMA Length', defval=6)+fastLength5 = input.int(title='KAMA 5: Fast KAMA Length', defval=6)-slowLength5 = input(title='KAMA 5: Slow KAMA Length', defval=28)+slowLength5 = input.int(title='KAMA 5: Slow KAMA Length', defval=28)-length6 = input(title='KAMA 6: Length', defval=19)+length6 = input.int(title='KAMA 6: Length', defval=19)-fastLength6 = input(title='KAMA 6: Fast KAMA Length', defval=7)+fastLength6 = input.int(title='KAMA 6: Fast KAMA Length', defval=7)-slowLength6 = input(title='KAMA 6: Slow KAMA Length', defval=30)+slowLength6 = input.int(title='KAMA 6: Slow KAMA Length', defval=30)-length7 = input(title='KAMA 7: Length', defval=20)+length7 = input.int(title='KAMA 7: Length', defval=20)-fastLength7 = input(title='KAMA 7: Fast KAMA Length', defval=8)+fastLength7 = input.int(title='KAMA 7: Fast KAMA Length', defval=8)-slowLength7 = input(title='KAMA 7: Slow KAMA Length', defval=32)+slowLength7 = input.int(title='KAMA 7: Slow KAMA Length', defval=32)// KAMA 8 (Slowest)-length8 = input(title='KAMA 8: Length', defval=21)+length8 = input.int(title='KAMA 8: Length', defval=21)-fastLength8 = input(title='KAMA 8: Fast KAMA Length', defval=9)+fastLength8 = input.int(title='KAMA 8: Fast KAMA Length', defval=9)-slowLength8 = input(title='KAMA 8: Slow KAMA Length', defval=34)+slowLength8 = input.int(title='KAMA 8: Slow KAMA Length', defval=34)// Kaufman's Adaptive Moving Average⋯// Inputs-atrLookback = input(defval=14, title='Trailing ATR Lookback Period')+atrLookback = input.int(defval=14, title='Trailing ATR Lookback Period')multiplier = input.float(defval=3, title='Trailing ATR Multiplier', step=0.1, minval=0.5, maxval=4)⋯//====================================== PSAR STOP ==========================================-start = input(0.02, 'PSAR Start')+start = input.float(0.02, 'PSAR Start')-increment = input(0.02, 'PSAR Increment')+increment = input.float(0.02, 'PSAR Increment')-maximum = input(0.2, 'PSAR Max Value')+maximum = input.float(0.2, 'PSAR Max Value')psar = ta.sar(start, increment, maximum)⋯long = kama1delta > 0 and kama1delta > entryMAAF-strategy.entry('Buy', strategy.long, when=long)+if long+    strategy.entry('Buy', strategy.long)// CloselongClose = (PSARSL ? ta.crossunder(close, psar) : na) or (KAMA1SL ? kama1delta < 0 and math.abs(kama1delta) > exitMAAF : na) or (ATRTSL ? supportHit : na)-strategy.close('Buy', when=longClose, comment='Sell')+if longClose+    strategy.close('Buy', comment='Sell')

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: 20 before, 18 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.

-//@version=5+//@version=6// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 35 msYes 1,000 bars in 142 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.

//@version=5// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © BenHampson// Credit to:// - ChuckBanger for much of the KAMA code// - cheatcountry for the KAMA Filter code// - millerrh for much of the ATR Stop code// - racer8 for much of the Position Sizing code// I have combined aspects of their work and built upon it to form a strategy I like. // The KAMA, with its filter, is used for entry.// An ATR trailing stop loss, PSAR, and the KAMA can all optionally be used as exits, or you can use a combination of the three.strategy(title='KAMA Strategy - Kaufman\'s Adaptive Moving Average', shorttitle='KAMA Strategy', overlay=true, default_qty_value=100, default_qty_type=strategy.percent_of_equity, initial_capital=10000, max_bars_back=1000)src = input(title='Source', defval=close)// ExitsKAMA1SL = input(title='KAMA 1 Stop Loss', defval=true)ATRTSL = input(title='ATR Trailing Stop Loss', defval=false)PSARSL = input(title='PSAR Stop Loss', defval=false)// KAMA 1 (Fastest)length1 = input(title='KAMA 1: Length', defval=14)fastLength1 = input(title='KAMA 1: Fast KAMA Length', defval=2)slowLength1 = input(title='KAMA 1: Slow KAMA Length', defval=20)length2 = input(title='KAMA 2: Length 2', defval=15)fastLength2 = input(title='KAMA 2: Fast KAMA Length', defval=3)slowLength2 = input(title='KAMA 2: Slow KAMA Length', defval=22)length3 = input(title='KAMA 3: Length 3', defval=16)fastLength3 = input(title='KAMA 3: Fast KAMA Length', defval=4)slowLength3 = input(title='KAMA 3: Slow KAMA Length', defval=24)length4 = input(title='KAMA 4: Length', defval=17)fastLength4 = input(title='KAMA 4: Fast KAMA Length', defval=5)slowLength4 = input(title='KAMA 4: Slow KAMA Length', defval=26)// KAMA 5 (Medium)length5 = input(title='KAMA 5: Length', defval=18)fastLength5 = input(title='KAMA 5: Fast KAMA Length', defval=6)slowLength5 = input(title='KAMA 5: Slow KAMA Length', defval=28)length6 = input(title='KAMA 6: Length', defval=19)fastLength6 = input(title='KAMA 6: Fast KAMA Length', defval=7)slowLength6 = input(title='KAMA 6: Slow KAMA Length', defval=30)length7 = input(title='KAMA 7: Length', defval=20)fastLength7 = input(title='KAMA 7: Fast KAMA Length', defval=8)slowLength7 = input(title='KAMA 7: Slow KAMA Length', defval=32)// KAMA 8 (Slowest)length8 = input(title='KAMA 8: Length', defval=21)fastLength8 = input(title='KAMA 8: Fast KAMA Length', defval=9)slowLength8 = input(title='KAMA 8: Slow KAMA Length', defval=34)// Kaufman's Adaptive Moving AveragegetKAMA(src, length1, fastLength1, slowLength1) =>    mom = math.abs(ta.change(src, length1))    volatility = math.sum(math.abs(ta.change(src)), length1)    // Efficiency Ratio    er = volatility != 0 ? mom / volatility : 0    fastAlpha = 2 / (fastLength1 + 1)    slowAlpha = 2 / (slowLength1 + 1)    // KAMA Alpha    sc = math.pow(er * (fastAlpha - slowAlpha) + slowAlpha, 2)    kama = 0.0    kama := sc * src + (1 - sc) * nz(kama[1])    kamakama1 = getKAMA(src, length1, fastLength1, slowLength1)kama2 = getKAMA(src, length2, fastLength2, slowLength2)kama3 = getKAMA(src, length3, fastLength3, slowLength3)kama4 = getKAMA(src, length4, fastLength4, slowLength4)kama5 = getKAMA(src, length5, fastLength5, slowLength5)kama6 = getKAMA(src, length6, fastLength6, slowLength6)kama7 = getKAMA(src, length7, fastLength7, slowLength7)kama8 = getKAMA(src, length8, fastLength8, slowLength8)//If the kama1 has increased...kama1delta = kama1[0] - kama1[1]kama3delta = kama3[0] - kama3[1]kama8delta = kama8[0] - kama8[1]// KAMA Plotsplot(kama1, title='KAMA 1', color=color.new(#e91e63, 0), display=display.all, linewidth=2)plot(kama2, title='KAMA 2', color=color.new(color.red, 0), display=display.all)plot(kama3, title='KAMA 3', color=color.new(color.red, 0), display=display.all)plot(kama4, title='KAMA 4', color=color.new(color.orange, 0), display=display.all)plot(kama5, title='KAMA 5', color=color.new(color.orange, 0), display=display.all)plot(kama6, title='KAMA 6', color=color.new(color.yellow, 0), display=display.all)plot(kama7, title='KAMA 7', color=color.new(color.yellow, 0), display=display.all)plot(kama8, title='KAMA 8', color=color.new(color.white, 0), display=display.all)//========================================= KAMA FILTER ===========================================// Copyright (c) 2019-present, Franklin Moormann (cheatcountry)// Moving Average Adaptive Filter [CC] script may be freely distributed under the MIT license.entryFilter = input.float(title='KAMA Entry Filter', defval=1, minval=0.01)exitFilter = input.float(title='KAMA Exit Filter', defval=0.5, minval=0.01)entryMAAF = entryFilter * ta.stdev(kama1delta, length1)exitMAAF = exitFilter * ta.stdev(kama1delta, length1)srcEma = ta.ema(src, length1)//========================================= TRAILING ATR STOP ====================================// The following is an adaptation of Trailing ATR Stops by @millerrh// He based it on scripts by @garethyeo & @SimpleCryptoLife// InputsatrLookback = input(defval=14, title='Trailing ATR Lookback Period')multiplier = input.float(defval=3, title='Trailing ATR Multiplier', step=0.1, minval=0.5, maxval=4)trailMode = input.string(title='Trail Mode', defval='Trailing', options=['Running', 'Trailing'])trigInput = input.string(title='Trigger Trailing Stop On', defval='Wick', options=['Close', 'Wick'])// Calculate ATRatrValue = ta.atr(atrLookback)atrMultiplied = atrValue * multiplier// Plot the price minus the ATRatrLow = low - atrMultiplied// Calculate the low trailing ATRs every time. The trailing stop loss never goes down.// Set them to something to start withtrailAtrLow = atrLow// If the ATR Low has gone up AND it has gone above the trail, the low trailing ATR should also go up. If the ATR Low has gone up or down, but not below the trail, the ATR trail stays where it istrailAtrLow := na(trailAtrLow[1]) ? trailAtrLow : atrLow >= trailAtrLow[1] ? atrLow : trailAtrLow[1]// Trigger stop based on candle close or lowtrigSupport = trigInput == 'Close' ? close : trigInput == 'Wick' ? low : na// Determine if price is below supportsupportHit = trigSupport <= trailAtrLow// If price is below support, reset the trailing ATRtrailAtrLow := supportHit ? atrLow : trailAtrLow// Plot LinesplotLow = ATRTSL ? trailAtrLow : naplot(plotLow, title='ATR Low', color=color.new(color.white, 50), style=plot.style_linebr, linewidth=1, display=display.all)//====================================== PSAR STOP ==========================================start = input(0.02, 'PSAR Start')increment = input(0.02, 'PSAR Increment')maximum = input(0.2, 'PSAR Max Value')psar = ta.sar(start, increment, maximum)psarPlot = PSARSL ? psar : naplot(psarPlot, 'Parabolic SAR', style=plot.style_cross, color=color.new(#3A6CA8, 0), display=display.all)//========================================= ENTRY & EXITS =====================================================// Entrylong = kama1delta > 0 and kama1delta > entryMAAFstrategy.entry('Buy', strategy.long, when=long)// CloselongClose = (PSARSL ? ta.crossunder(close, psar) : na) or (KAMA1SL ? kama1delta < 0 and math.abs(kama1delta) > exitMAAF : na) or (ATRTSL ? supportHit : na)strategy.close('Buy', when=longClose, comment='Sell')