Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Kaufman's Efficiency Ratio Strategy [KL]

A Pine Script v5 strategy with no technical-analysis calculation. It has 12 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss. Each trade is one contract and pays no commission. 15 settings; defaults include Alert MSG for buying (Long position) Long entered, Alert MSG for closing (Long position) Long closed and Alert MSG for selling (Short position) Short entered.

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 Kaufman's Efficiency Ratio Strategy [KL] repaint?
No
No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
How did Kaufman's Efficiency Ratio Strategy [KL] do on BTCUSDT 1D with default settings?
+1.14%
From 26 Jan 2024 to 21 Oct 2026, over 3 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
What alerts does Kaufman's Efficiency Ratio Strategy [KL] have?
4
LONG_MSG_EXIT; SHORT_MSG_EXIT; LONG_MSG_ENTER; SHORT_MSG_ENTER.
Does Kaufman's Efficiency Ratio Strategy [KL] run in Pine Script v6?
Yes
Same 3 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. The v6 script can be downloaded below.
Does Kaufman's Efficiency Ratio Strategy [KL] use a stop loss?
Yes
strategy.exit sets a stop on line 103, 105.

BTCUSDT · 1D · default settings

  • 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 (15)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$1,022,520,000$2,025,272,873Equity from $1,000,000,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. 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.
Net profit
+1.14%
$11,430,600.00
Buy and hold
+102.5%
same period
Closed trades
3
3 won · 0 lost
Profitable
100.0%
of closed trades
Profit factor
—
gross profit ÷ gross loss
Max drawdown
0.02%
−$157,599.00

One run with the author's default settings, $1,000,000,000 starting capital, commission as the script sets it. A long 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.

  • 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
Alerts
Alert MSG for buying (Long position)Long enteredstringalert
Alert MSG for closing (Long position)Long closedstringalert
Enter into short positionsfalseboolentry_signal_short
Alert MSG for selling (Short position)Short enteredstringalert
Alert MSG for covering (Short position)Short coveredstringalert
Time horizon of backtests
Backtest Start Timetimestamp("01 Apr 2020 13:30 +0000")timewithin_timeframe
Define backtest end-timeIf false, will test up to most recent candlefalseboolwithin_timeframe
Backtest End Time (if checked above)timestamp("19 Apr 2021 19:30 +0000")timewithin_timeframe
Main Signal: Kaufman's Eff. Ratio
Lookback period10intER
Order size
Allocation (%) of portfolio into this securityAssume no rebalancing5int · min 0 · max 100initial_order_size
Stop loss
ATR Multiplier for trailing stoploss2.0floatSL_buffer
Length of ATR for trailing stoploss14intstop_loss_price_long stop_loss_price_short risk_amt
Profit taking
First level profitRelative to risk. Example: entry at $10 and inital stop loss at $9. Taking first level profit at 1R means taking profits at $111floatclose LONG close SHORT line 73 line 83
Second level profitRelative to risk. Example: entry at $10 and inital stop loss at $9. Taking second level profit at 2R means taking profits at $122floatclose LONG close SHORT line 76 line 86
Third level profitRelative to risk. Example: entry at $10 and inital stop loss at $9. Taking third level profit at 3R means taking profits at $133floatclose LONG close SHORT line 79 line 89

What it calculates

No technical-analysis calculation: the script works on prices and settings directly.

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.

closecloseprice dataer_lookbackperiodLookback periodsetting · 10lowlowprice datahighhighprice dataSL_bufferLength of ATR for trail…setting · 14pcnt_allocAllocation (%) of portf…setting · 5timetimeprice databacktest_timeframe_startBacktest Start Timesetting · timestamp("01 Apr 2…backtest_timeframe_endBacktest End Time (if c…setting · timestamp("19 Apr 2…volumevolumeprice datahigh · low · closehigh · low · closeprice dataFIRST_LVL_PROFITFirst level profitsetting · 1SECOND_LVL_PROFITSecond level profitsetting · 2THIRD_LVL_PROFITThird level profitsetting · 3LONG_MSG_EXITAlert MSG for closing (…setting · Long closedSHORT_MSG_EXITAlert MSG for covering …setting · Short coveredLONG_MSG_ENTERAlert MSG for buying (L…setting · Long enteredSHORT_MSG_ENTERAlert MSG for selling (…setting · Short enteredtotal_abs_chngtotal_abs_chngvaluenet_chngnet_chngvalueerervalueERERvalueTSL_source_longTSL_source_longvalueTSL_source_shortTSL_source_shortvaluestop_loss_price_longstop_loss_price_longvaluestop_loss_price_shortstop_loss_price_shortvaluetp_count_longtp_count_longvaluetp_count_shorttp_count_shortvalueinitial_order_sizeinitial_order_sizevalueinitial_entry_pinitial_entry_pvaluerisk_amtrisk_amtvalueTSL_transp_long, TSL_transp_shortTSL_transp_long · TSL_t…2 valueswithin_timeframewithin_timeframeconditionentry_signal_longentry_signal_longconditionentry_signal_shortentry_signal_shortconditionclose:LONGClose LONGstrategy.closeclose:SHORTClose SHORTstrategy.closeexit:LONGexit LONGstrategy.exitexit:SHORTexit SHORTstrategy.exitentry:LONGOpen LONGstrategy.entryentry:SHORTOpen SHORTstrategy.entryalert:95alertalertalert:99alertalertalert:109alertalertalert:116alertalertplot:121plotplotplot:122plotplot

Order rules

OrderFires whenBy defaultLine
Close LONGtp_count_long == 0 and close >= strategy.position_avg_price + (FIRST_LVL_PROFIT * risk_amt)On74
Close LONGtp_count_long == 1 and close >= strategy.position_avg_price + (SECOND_LVL_PROFIT * risk_amt)On77
Close LONGtp_count_long == 2 and close >= strategy.position_avg_price + (THIRD_LVL_PROFIT * risk_amt)On80
Close SHORTtp_count_short == 0 and close <= strategy.position_avg_price + (-FIRST_LVL_PROFIT * risk_amt)On84
Close SHORTtp_count_short == 1 and close <= strategy.position_avg_price + (-SECOND_LVL_PROFIT * risk_amt)On87
Close SHORTtp_count_short == 2 and close <= strategy.position_avg_price + (-THIRD_LVL_PROFIT * risk_amt)On90
Close LONGpos_opened_long and TSL_source_long <= stop_loss_price_longOn96
Close SHORTpos_opened_short and (TSL_source_short >= stop_loss_price_short)On100
Exit LONG stoppos_opened_longOn103
Exit SHORT stoppos_opened_shortOn105
Open LONG longwithin_timeframe and entry_signal_longOn111
Open SHORT shortwithin_timeframe and entry_signal_shortOn117

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

Alerts

AlertCallMessageLine
(no title)alertLONG_MSG_EXIT95
(no title)alertSHORT_MSG_EXIT99
(no title)alertLONG_MSG_ENTER109
(no title)alertSHORT_MSG_ENTER116

Does it repaint?

No

No repainting patterns in the source.

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].
  • 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+1.1%+102.5%3100%—0.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+0.3%+5.5%3100%—1.4%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+1.8%+9.8%3100%—0.7%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.3%+8.4%3100%—1.8%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+1.9%+16.7%3100%—0.7%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.5%+21.5%3100%—1.8%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+2.5%+148.3%3100%—0.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.3%+17.1%3100%—0.6%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 barsTradesWonP&L
Rising market0—$0.00
Sideways market3100%$11,430,600.00
Falling market0—$0.00

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

How bad could the drawdown be?

0.0%

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

0%1%
All 3 trades
SideEntryExitBarsP&L
long6 Feb 2024 42,708.7025 Feb 2024 51,568.2019$2,932,500.00
long6 Feb 2024 42,708.7026 Feb 2024 51,728.8020$2,985,670.00
long6 Feb 2024 42,708.7017 Mar 2024 65,300.6040$5,512,430.00

Similar scripts

No other indicator or strategy here shares enough of its calculations.

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.

  • 1 setting uses the untyped input() (line 14). 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 3 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 14: input() → input.bool()
⋯var string LONG_MSG_EXIT  = input.string("Long closed", title="Alert MSG for closing (Long position)", group=GROUP_ALERT)-USE_SHORT       = input(false, title="Enter into short positions", group=GROUP_ALERT)+USE_SHORT       = input.bool(false, title="Enter into short positions", group=GROUP_ALERT)ENUM_SHORT      = "SHORT"                                                                    ⋯

Does it run in Pine Script v6?

Yes

Same 3 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. It differs from the v5 version by 1 edit.

Download the v6 script

⋯// © DojiEmoji (kevinhhl)-//@version=5+//@version=6strategy("[KL] Eff. Ratio Strategy", overlay=true, pyramiding=1, initial_capital=1000000000)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 49 msWith a workaround 1,000 bars in 94 msNot measured
PineTSNot testedNot testedNot 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.

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/// © DojiEmoji (kevinhhl)//@version=5strategy("[KL] Eff. Ratio Strategy", overlay=true, pyramiding=1, initial_capital=1000000000)var string GROUP_ALERT    = "Alerts"var string GROUP_SL       = "Stop loss"var string GROUP_ORDER    = "Order size"var string GROUP_TP       = "Profit taking"var string GROUP_HORIZON  = "Time horizon of backtests"var string GROUP_ER       = "Main Signal: Kaufman's Eff. Ratio"var string ENUM_LONG      = "LONG"var string LONG_MSG_ENTER = input.string("Long entered", title="Alert MSG for buying (Long position)", group=GROUP_ALERT)var string LONG_MSG_EXIT  = input.string("Long closed", title="Alert MSG for closing (Long position)", group=GROUP_ALERT)USE_SHORT       = input(false, title="Enter into short positions", group=GROUP_ALERT)ENUM_SHORT      = "SHORT"                                                                    SHORT_MSG_ENTER = input.string("Short entered", title="Alert MSG for selling (Short position)")SHORT_MSG_EXIT  = input.string("Short covered", title="Alert MSG for covering (Short position)")backtest_timeframe_start = input.time(defval=timestamp("01 Apr 2020 13:30 +0000"), title="Backtest Start Time", group=GROUP_HORIZON)USE_ENDTIME              = input.bool(false, title="Define backtest end-time", group=GROUP_HORIZON, tooltip="If false, will test up to most recent candle")backtest_timeframe_end   = input.time(defval=timestamp("19 Apr 2021 19:30 +0000"), title="Backtest End Time (if checked above)", group=GROUP_HORIZON)within_timeframe         = time >= backtest_timeframe_start and (time <= backtest_timeframe_end or not USE_ENDTIME)// Kaufman"s efficiency ratio {er_lookbackperiod = input.int(10, title="Lookback period", group=GROUP_ER)kaufman_ER(src, len) =>    total_abs_chng = float(0)  // [B]    for i = 1 to len by 1        total_abs_chng := total_abs_chng + math.abs(src[i - 1] - src[i])        total_abs_chng    net_chng = src - src[len]  // [A]    er = net_chng / total_abs_chng * 100  // = ([A]/[B]) * 100    erER            = kaufman_ER(close, er_lookbackperiod)// Removed: Confirmation of ER being low/med/high; through backtesting, noticed it's better to simply use "entry_signal_long = ER > 0"// ER_bar        = ta.sma(math.abs(ER), er_lookbackperiod)// ER_sigma      = ta.stdev(math.abs(ER), er_lookbackperiod)// ER_std_err    = ER_sigma / math.pow(er_lookbackperiod, 0.5)// ER_sigma_mult = input.float(1.0, "stdev multiplier", tooltip="For determining low/medium/high ER.", group=GROUP_ER)// dynamic_low   = ER_bar - ER_sigma * ER_sigma_mult * ER_std_err// dynamic_high  = ER_bar + ER_sigma * ER_sigma_mult * ER_std_err// ER_is_low     = math.abs(ER) <= dynamic_low// ER_is_mid     = math.abs(ER) > dynamic_low and math.abs(ER) < dynamic_high// ER_is_high    = math.abs(ER) >= dynamic_high// } end of block: Kaufman"s efficiency ratio// Signals for entryentry_signal_long = ER > 0entry_signal_short = ER < 0 and ta.tr > ta.atr(14) and volume > ta.sma(volume, 5) and USE_SHORT// Portfolio mgtpcnt_alloc = input.int(5, title="Allocation (%) of portfolio into this security", tooltip="Assume no rebalancing", minval=0, maxval=100, group=GROUP_ORDER) / 100// Trailing stop loss ("TSL") {tsl_multi                 = input.float(2.0, title="ATR Multiplier for trailing stoploss", group=GROUP_SL)SL_buffer                 = ta.atr(input.int(14, title="Length of ATR for trailing stoploss", group=GROUP_SL)) * tsl_multiTSL_source_long           = lowTSL_source_short          = highvar stop_loss_price_long  = float(0)var stop_loss_price_short = float(9999999999)var pos_opened_long       = falsevar pos_opened_short      = falsestop_loss_price_long := pos_opened_long ? math.max(stop_loss_price_long, TSL_source_long - SL_buffer) : TSL_source_long - SL_bufferstop_loss_price_short := pos_opened_short ? math.min(stop_loss_price_short, TSL_source_short + SL_buffer) : TSL_source_short + SL_buffer// } end of block: Trailing stop loss// Profit takingvar int tp_count_long  = 0 // counts how many levels of profits had been taken during holding period; resets when position size becomes zerovar int tp_count_short = 0var float initial_order_size = 0 // to be divided by 3, then math.floor'ed to determine size of disposalFIRST_LVL_PROFIT             = input.float(1, title="First level profit", tooltip="Relative to risk. Example: entry at $10 and inital stop loss at $9. Taking first level profit at 1R means taking profits at $11", group=GROUP_TP)SECOND_LVL_PROFIT            = input.float(2, title="Second level profit", tooltip="Relative to risk. Example: entry at $10 and inital stop loss at $9. Taking second level profit at 2R means taking profits at $12", group=GROUP_TP)THIRD_LVL_PROFIT             = input.float(3, title="Third level profit", tooltip="Relative to risk. Example: entry at $10 and inital stop loss at $9. Taking third level profit at 3R means taking profits at $13", group=GROUP_TP)// MAIN: {var float initial_entry_p = float(0)  // initial entry pricevar float risk_amt = float(0)         // initial entry price minus initial stop loss price// (1) Taking profits at user defined target levels relative to risked amount (i.e 1R, 2R, 3R)if not entry_signal_long    if tp_count_long == 0 and close >= strategy.position_avg_price + (FIRST_LVL_PROFIT * risk_amt)        strategy.close(ENUM_LONG, comment="TP lvl1", qty=math.floor(initial_order_size / 3))        tp_count_long := tp_count_long + 1    else if tp_count_long == 1 and close >= strategy.position_avg_price + (SECOND_LVL_PROFIT * risk_amt)        strategy.close(ENUM_LONG, comment="TP lvl2", qty=math.floor(initial_order_size / 3))        tp_count_long := tp_count_long + 1    else if tp_count_long == 2 and close >= strategy.position_avg_price + (THIRD_LVL_PROFIT * risk_amt)        strategy.close(ENUM_LONG, comment="TP lvl3", qty=math.floor(initial_order_size / 3))        tp_count_long := tp_count_long + 1if not entry_signal_short    if tp_count_short == 0 and close <= strategy.position_avg_price + (-FIRST_LVL_PROFIT * risk_amt)        strategy.close(ENUM_SHORT, comment="TP lvl1", qty=math.floor(initial_order_size / 3))        tp_count_short := tp_count_short + 1    else if tp_count_short == 1 and close <= strategy.position_avg_price + (-SECOND_LVL_PROFIT * risk_amt)        strategy.close(ENUM_SHORT, comment="TP lvl2", qty=math.floor(initial_order_size / 3))        tp_count_short := tp_count_short + 1    else if tp_count_short == 2 and close <= strategy.position_avg_price + (-THIRD_LVL_PROFIT * risk_amt)        strategy.close(ENUM_SHORT, comment="TP lvl3", qty=math.floor(initial_order_size / 3))        tp_count_short := tp_count_short + 1// (2) States update: pos_opened_long, pos_opened_shortif pos_opened_long and TSL_source_long <= stop_loss_price_long    pos_opened_long := false    alert(LONG_MSG_EXIT, alert.freq_once_per_bar)    strategy.close(ENUM_LONG, comment=close < strategy.position_avg_price ? "stop loss" : "take profit")if pos_opened_short and (TSL_source_short >= stop_loss_price_short)    pos_opened_short := false    alert(SHORT_MSG_EXIT, alert.freq_once_per_bar)    strategy.close(ENUM_SHORT, comment=close > strategy.position_avg_price ? "stop loss" : "take profit")// (3) Update the stoploss to latest trailing amt.if pos_opened_long    strategy.exit(ENUM_LONG, stop=stop_loss_price_long, comment="SL")if pos_opened_short    strategy.exit(ENUM_SHORT, stop=stop_loss_price_short, comment="SL")// (4) INITIAL ENTRY:if within_timeframe and entry_signal_long    pos_opened_long := true    alert(LONG_MSG_ENTER, alert.freq_once_per_bar)    initial_order_size := math.floor(pcnt_alloc * strategy.equity / close)    strategy.entry(ENUM_LONG, strategy.long, comment="long", qty=initial_order_size)    risk_amt := SL_buffer      // for taking profits at 1R, 2R, and 3R    initial_entry_p := close    // ""if within_timeframe and entry_signal_short    pos_opened_short := true    alert(SHORT_MSG_ENTER, alert.freq_once_per_bar)            strategy.entry(ENUM_SHORT, strategy.short, comment="short")// Plotting: TSL_transp_long = pos_opened_long and within_timeframe ? 0 : 100TSL_transp_short = pos_opened_short and within_timeframe ? 0 : 100plot(stop_loss_price_long, color=color.new(color.green, TSL_transp_long))plot(stop_loss_price_short, color=color.new(color.red, TSL_transp_short))// CLEAN UP: Setting variables back to default values once no longer in useif ta.change(strategy.position_size) and strategy.position_size == 0    risk_amt := float(0)    initial_entry_p := float(0)    initial_order_size := 0    pos_opened_long := false    pos_opened_short := falseif not pos_opened_long    stop_loss_price_long := float(0)    tp_count_long := 0if not pos_opened_short    stop_loss_price_short := float(9999999999)    tp_count_short := 0// } end of MAIN block