What the strategy is trying to do
This is an open-source script published by GoldenPathFN. The publication page is titled “EHMA Range Strategy”; the strategy() name is “Exponential Hull Moving Average Range [GoldenPathStrategies],” and the source header is credited to GoldenPathStrategies. The script first computes an exponential Hull moving average, then draws percentage bands above and below it. Unlike a plain moving-average cross, it waits for the close to break the upper band before a long, and it does not exit that long until the close breaks the lower band. While price oscillates between the two bands, the stored trend keeps its previous value, so a touch of the midline is not a flip.
The author's chart is BINANCE:BTCUSDT on the daily timeframe, so this entry is filed under BTC. The script does not hard-code a symbol and will load on other charts, but the guide and the image follow that publication chart. In the publication notes, the author credits borserman's Exponential Hull Moving Average for the EHMA math and presents the channel and the order rules as this strategy's own addition. It is long-only by default, sizes each entry at 100% of equity, and sets initial capital at 100000. The strategy() call sets commission_type to percent but does not set commission_value, so Pine's default fee of 0 applies. Change the size and the fee for your venue before you read the tester.

How the indicators are calculated
- EHMA is the Borserman EMA combination in the source: the close is smoothed at period/2 and at period, then “twice the shorter average minus the longer one” is smoothed again with a length of sqrt(period). Length defaults to 180.
- The upper band is EHMA + EHMA × Range Width; the lower band is EHMA − EHMA × Range Width. Range Width defaults to 0.02, or 2% on each side.
- The trend state is kept with var. A close above the upper band sets it to 1, and a close below the lower band sets it to −1. If the close moves back between the bands, the previous value is kept; it is not reset to zero.
- trend_up fires when trend has just become 1; trend_down fires when it has just become −1. The signal is the first close outside the band, not every later bar that remains outside it.
- A date filter uses Backtest Start Date (default 2017-01-01) and Backtest End Date (default 2029-01-01). New entries and signal exits are considered only while the bar time is inside that window. After the end date, any remaining position is closed with strategy.close_all.
Entry rules
- Position Type defaults to Long. A long (order name Long) requires the date window, trend having just become 1, and no open position.
- If you set Position Type to Both, longs still use that upper-band signal. A short (order name Short) also opens when trend has just become −1 and no position is open.
- Short only skips longs and opens a short when trend has just become −1.
- If a trade is already open, a break of the opposite band is handled as an exit. In Both mode the new-entry branch also requires position_size == 0, so the same bar does not immediately open the opposite trade.
- The source does not wait for barstate.isconfirmed. On a daily chart, whether the close has cleared the upper band can still change before the bar ends; whether a fill stands depends on your TradingView order settings. calc_on_every_tick is false in strategy().
Exits and position size
- In the default long-only mode, a long exits when the date window is valid, a long is open, and trend has just become −1, meaning the close has broken the lower band. A move back toward the EHMA is not enough if the lower band has not been broken.
- With Both or Short enabled, a short exits when trend has just become 1 (the close has cleared the upper band again). That is the same signal used to enter a long.
- If the bar time is already past Backtest End Date and a position is still open, the script closes everything, with the comment Backtest End.
- There is no separate stop or take-profit order, and no fixed-point exit.
- Each entry is 100% of equity. The notional changes with the symbol and account equity, so treat the size as your own risk setting.
Inputs (source defaults)
| Input | Default | Role |
|---|---|---|
| Length | 180 | Lookback for the EHMA. A longer value is smoother and slower. |
| Range Width | 0.02 | Percentage width of each band around the EHMA; 2% on each side by default. |
| Position Type | Long | One of Both, Long, or Short. Longs only by default. |
| Backtest Start Date / End Date | 2017-01-01 to 2029-01-01 | Entries and signal exits are only considered inside this window; after the end date any remaining position is forced closed. |
| Show Bar Colors | true | Colors the bars by trend. Display only. |
| Buy / Sell Alert Message | Buy alert! / Sell alert! | Text passed through to strategy order alerts. The input tooltip includes a sample JSON payload; the api_key in that example is a placeholder, not a real key. |
Things to know before using it
- The default size is 100% of equity, and the commission may be 0 under Pine's default. Live bitcoin fees and slippage are usually higher, so tester results are not a live forecast.
- The exit looks at the opposite band, not the EHMA itself. If price falls back inside the channel but has not closed below the lower band, a long stays open.
- The date window ends on 2029-01-01 by default. If you still want the script to trade after that date, change the end date yourself; otherwise it will close any remaining position and will not open new ones.
- The alert-message tooltip shows a sample JSON payload with bot_id and api_key. That is only an example in the input hint. It is not a built-in secret, and you should not put a real key into a parameter that may be saved or shared.
- The band fill uses the bearish color as a wash, and bar coloring follows a slightly finer rule. Those choices are display only and do not change the orders.
Installing it on TradingView
- Download the .pine file from Coinpred (active membership required, see below), or check the original page for a newer version.
- Open the Pine Editor, create a blank script, paste the full source, and save.
- Click Add to chart. To match the author image, start with BINANCE:BTCUSDT on the daily timeframe.
- Review the position size, commission, EHMA length, band width, and date window in the strategy properties, then inspect fills in the Strategy Tester.
- Past tester results do not guarantee future returns.
About backtest figures
Source, license and version
- Source: https://www.tradingview.com/script/N4zgN11X-EHMA-Range-Strategy/
- Publication author: GoldenPathFN; the source header is © GoldenPathStrategies. Source version 2.0 (Pine v5), scriptAccess=open_no_auth.
- License: Mozilla Public License 2.0. Redistribution must keep the copyright and license notices; modified files must remain under MPL 2.0. Coinpred ships the unmodified full source.
- The publication notes credit borserman's public EHMA indicator for the average math; this page describes the rules from the unmodified source.
- Members can download the .pine file on this page to study the rules. Judge the risk yourself, and follow your venue's rules.



