Pine Script v5 · Strategy
Athena Momentum Squeeze - Short, Lean, and Mean
A Pine Script v5 strategy built on EMA (src, len), SMA (sqz_source, 20) and Stdev (sqz_source, 20). 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. 30 settings; defaults include Broker tradovate, Pair: MSFT and Qty: 1.
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 Athena Momentum Squeeze - Short, Lean, and Mean repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 3 of 3 trades.
- How did Athena Momentum Squeeze - Short, Lean, and Mean do on BTCUSDT 1D with default settings?
- +3.73%
- From 26 Jan 2024 to 21 Oct 2026, over 10 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Athena Momentum Squeeze - Short, Lean, and Mean 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: 10 before, 8 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 Athena Momentum Squeeze - Short, Lean, and Mean use a stop loss?
- Yes
- strategy.exit sets a stop on line 213, 215.
- Does Athena Momentum Squeeze - Short, Lean, and Mean run in Zeal Terminal?
- Yes
- It compiles in 95 ms and runs 1,000 bars in 109 ms, in the browser.
BTCUSDT · 1D · default settings
- Dark blue dot count
- Moving Average
- Entry Price
- Stop Loss
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +3.73%
- $37,285.30
- Buy and hold
- +102.5%
- same period
- Closed trades
- 10
- 7 won · 3 lost
- Profitable
- 70.0%
- of closed trades
- Profit factor
- 5.34
- gross profit ÷ gross loss
- Max drawdown
- 0.60%
- −$6,033.02
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.
-
Check
1 setting does nothing
“BB MultFactor” is declared but never read.
-
Check
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Note
1 setting has no label
In the settings dialog in_ma_w (line 58) shows an empty name. The labels on this page come from the variable names.
-
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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| AutoView | |||
| Brokertradovate/tradovatesim | tradovate | string | lo_mess sh_mess exl_mess exs_mess |
| Pair:ZNH2/MSFT/ESH2 | MSFT | string | lo_mess sh_mess exl_mess exs_mess |
| Qty:q=10% (% of accountsize) \n q=50(Qty) | 1 | string | lo_mess sh_mess |
| Entry | |||
| Long entry | entry_long_light_green | string | entry_long_sel_light_green entry_long_sel_dark_green |
| Short entry | entry_short_light_red | string | entry_short_sel_light_red entry_short_sel_dark_red |
| Enable squeeze filter?Checks number of dark blue dots before entering a position | true | bool | sqz_filter_cnt_cond |
| Squeeze dot count | 6 | int | sqz_filter_cnt_cond |
| Exit | |||
| Long close | exit_long_dark_green | string | exit_long_sel_light_green exit_long_sel_dark_green exit_long_sel_light_red exit_long_sel_dark_red |
| Short close | exit_short_dark_red | string | exit_short_sel_light_green exit_short_sel_dark_green exit_short_sel_light_red exit_short_sel_dark_red |
| Close only in profit | false | bool | strat_profit_cond_close |
| Take profit type | exit_type_none_tp | string | strat_tp_price_long strat_tp_price_short |
| Take profit valuePercantage: Percentage value\nATR: ATR multiplier\nRisk/Reward: R:R ratio | 2.0 | float · step 0.1 | strat_tp_price_long strat_tp_price_short |
| Stop loss type | exit_type_atr_sl | string | strat_sl_price_long strat_sl_price_short |
| Stop loss valuePercantage: Percentage value\nATR: ATR multiplier | 2.0 | float · step 0.1 | strat_sl_price_long strat_sl_price_short |
| ATR length | 14 | int | atr_val |
| Squeeze Momentum | |||
| BB Length | 20 | int | sqz_basis sqz_dev |
| BB MultFactor | 2.0 | float | unused |
| KC Length | 20 | int | sqz_ma sqz_rangema sqz_val |
| KC MultFactor | 1.5 | float | sqz_dev sqz_upperKC sqz_lowerKC |
| Use TrueRange (KC) | true | bool | sqz_range_1 |
| Moving Average | |||
| Enable moving average filter? | true | bool | ma_cond_long ma_cond_short Moving Average |
| Type | ma_type_sma | string | ma_val |
| Source | close | source | ma_val |
| Length | 200 | int | ma_val |
| Plot? | true | bool | Moving Average |
| In ma col (no label in the script) | color.yellow | color | Moving Average |
| In ma w (no label in the script) | 2 | int | Moving Average |
| Display | |||
| Entry Price | color.gray | color | Entry Price |
| Take Profit | color.green | color | Take Profit Take Profit Fill |
| Stop Loss | color.red | color | Stop Loss Stop Loss Fill |
What it calculates
- EMAsrc, len
e1 · line 98 - EMAe1, len
e2 · line 99 - EMAsrc, len
ema1 · line 102 - EMAema1, len
ema2 · line 103 - EMAema2, len
ema3 · line 104 - SMAsqz_source, BB Length (20)
sqz_basis · line 117 - Stdevsqz_source, BB Length (20)
sqz_dev · line 118 - SMAsqz_source, KC Length (20)
sqz_ma · line 122 - TR
sqz_range_1 · line 123 - SMAsqz_range_1, KC Length (20)
sqz_rangema · line 124 - Linreg / Highest / Lowest / SMAsqz_source - math.avg(math.avg(ta.highest(high, in_sqz_lengthKC), ta.lowest(low, in_sqz_lengthKC)), ta.sma(close, in_sqz_lengthKC)), KC Length (20), 0
sqz_val · line 130 - ATRATR length (14)
atr_val · line 155
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 77 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | (strat_long_cond) | On | 162 |
| Open Short short | (strat_short_cond) | On | 164 |
| Close Long | (strat_is_long and sqz_close_cond_long and strat_profit_cond_close) | On | 167 |
| Close Short | (strat_is_short and sqz_close_cond_short and strat_profit_cond_close) | On | 169 |
| Exit LE stop and limit | (strat_is_long) | On | 213 |
| Exit SE stop and limit | (strat_is_short) | On | 215 |
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.
- 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 | +3.7% | +102.5% | 10 | 70% | 5.34 | 0.6% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −0.6% | +5.5% | 13 | 23% | 0.15 | 0.7% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +0.0% | +9.8% | 11 | 45% | 1.37 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.0% | +8.4% | 8 | 25% | 2.66 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.0% | +16.7% | 11 | 36% | 1.72 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 11 | 36% | 1.16 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.0% | +148.3% | 18 | 33% | 1.10 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.0% | +17.1% | 13 | 31% | 1.88 | 0.0% | 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% | $23,562.60 |
| Sideways market | 7 | 71% | $17,395.70 |
| Falling market | 1 | 0% | −$3,673.02 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
0.8%
The 95th percentile of the worst drawdown when the same 10 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 0.4% to 0.8%; the tick is what actually happened, 0.5%. Order luck alone moves it this much.
All 10 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 7 Sep 2024 53,963.00 | 11 Sep 2024 57,636.00 | 4 | −$3,673.02 |
| long | 17 Oct 2024 67,620.00 | 24 Oct 2024 66,668.60 | 7 | −$951.35 |
| long | 8 Nov 2024 75,857.90 | 24 Nov 2024 97,672.40 | 16 | $21,814.50 |
| long | 24 Apr 2025 93,691.10 | 29 Apr 2025 95,011.20 | 5 | $1,320.11 |
| long | 11 Jul 2025 116,010.00 | 16 Jul 2025 117,758.00 | 5 | $1,748.07 |
| long | 16 Sep 2025 115,350.00 | 20 Sep 2025 115,632.00 | 4 | $282.68 |
| short | 9 Nov 2025 102,313.00 | 24 Nov 2025 86,830.00 | 15 | $15,482.90 |
| short | 28 May 2026 74,449.30 | 31 May 2026 73,884.40 | 3 | $564.93 |
| short | 1 Jul 2026 58,624.70 | 4 Jul 2026 62,583.30 | 3 | −$3,958.55 |
| long | 21 Aug 2026 73,027.00 | 31 Aug 2026 77,682.00 | 10 | $4,654.98 |
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 |
|---|---|---|---|---|---|
| Athena Momentum Squeeze - Short, Lean, and Mean this page | — | v5 strategy | +3.7% | 10 | 0.6% |
| [fpemehd] SSL Baseline Strategy by DuDu95 | ema sma highest lowest stdev tr atr | v5 strategy | +2.3% | 71 | 3.7% |
| SSL + Wave Trend Strategy by kevinmck100 | ema sma highest lowest stdev tr atr | v5 strategy | −1.0% | 1 | 1.0% |
| CHOP Zone Entry Strategy + DMI-PSAR Exit by IronCasper | atr highest lowest sma linreg ema | v4 strategy | +17.1% | 8 | 20.0% |
| Investments-swing trading strategy for different assets by StrategiesForEveryone | sma stdev tr linreg ema atr | v5 strategy | +4.2% | 17 | 17.6% |
| ATR GOD Strategy by TradeSmart (PineConnector-compatible) by TradeSmart22 | atr tr lowest highest sma stdev | v5 strategy | No trades on this market | ||
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.
- 5 settings use the untyped input() (line 43, 44, 45, 46, 47). 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.
Same 10 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 43: input() → input.int()
- Line 44: input() → input.float()
- Line 45: input() → input.int()
- Line 46: input() → input.float()
- Line 47: input() → input.bool()
⋯sqz_gr_name = "Squeeze Momentum"-in_sqz_length = input(20, title='BB Length', group=sqz_gr_name)+in_sqz_length = input.int(20, title='BB Length', group=sqz_gr_name)-in_sqz_mult = input(2.0, title='BB MultFactor', group=sqz_gr_name)+in_sqz_mult = input.float(2.0, title='BB MultFactor', group=sqz_gr_name)-in_sqz_lengthKC = input(20, title='KC Length', group=sqz_gr_name)+in_sqz_lengthKC = input.int(20, title='KC Length', group=sqz_gr_name)-in_sqz_multKC = input(1.5, title='KC MultFactor', group=sqz_gr_name)+in_sqz_multKC = input.float(1.5, title='KC MultFactor', group=sqz_gr_name)-in_sqz_useTrueRange = input(true, title='Use TrueRange (KC)', group=sqz_gr_name)+in_sqz_useTrueRange = input.bool(true, title='Use TrueRange (KC)', group=sqz_gr_name)//}⋯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: 10 before, 8 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.
⋯// © vitruvius-//@version=5+//@version=6strategy("Athena Momentum Squeeze - Autoview", overlay=true)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 95 ms | Yes 1,000 bars in 109 ms | Not measured |
| PineTS | Not tested | Not tested | Not 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/// © vitruvius//@version=5strategy("Athena Momentum Squeeze - Autoview", overlay=true)// Inputs {// -- Automate broker = input.string("tradovate","Broker",group="AutoView",tooltip = "tradovate/tradovatesim")pair0 = input.string("MSFT","Pair:",group="AutoView",tooltip = "ZNH2/MSFT/ESH2")qty = input.string("1","Qty:",group="AutoView",tooltip = "q=10% (% of accountsize) \n q=50(Qty)")lo_mess = "e="+str.tostring(broker) +" s="+str.tostring(pair0) +" b=long" +" q="+str.tostring(qty) + " t=market delay=1"sh_mess = "e="+str.tostring(broker) +" s="+str.tostring(pair0) +" b=short" +" q="+str.tostring(qty) + " t=market delay=1"exl_mess = "e="+str.tostring(broker) +" s="+str.tostring(pair0) +"b=long c=position t=market"exs_mess = "e="+str.tostring(broker) +" s="+str.tostring(pair0) +"b=short c=position t=market"// Entry {entry_gr_name = "Entry"entry_tt_sqz_filter = "Checks number of dark blue dots before entering a position"entry_long_light_green = "Light green", entry_long_dark_green = "Dark green", entry_long_none = "None"entry_short_light_red = "Light red", entry_short_dark_red = "Dark red", entry_short_none = "None"in_entry_sqz_bar_type_long = input.string(entry_long_light_green, "Long entry", [entry_long_light_green, entry_long_dark_green, entry_long_none], group=entry_gr_name)in_entry_sqz_bar_type_short = input.string(entry_short_light_red, "Short entry", [entry_short_light_red, entry_short_dark_red, entry_short_none], group=entry_gr_name)in_entry_sqz_filter_en = input.bool(true, "Enable squeeze filter?", tooltip=entry_tt_sqz_filter, group=entry_gr_name)in_entry_sqz_filter_cnt = input.int(6, "Squeeze dot count", group=entry_gr_name)//}// Exit {exit_gr_name = "Exit"exit_long_light_green = "Light green", exit_long_dark_green = "Dark green", exit_long_light_red = "Light red", exit_long_dark_red = "Dark red", exit_long_none = "None"exit_short_light_green = "Light green", exit_short_dark_green = "Dark green", exit_short_light_red = "Light red", exit_short_dark_red = "Dark red", exit_short_none = "None"exit_type_per_tp = "Percentage", exit_type_atr_tp = "ATR", exit_type_rr_tp = "Risk/Reward", exit_type_none_tp = "None"exit_type_per_sl = "Percentage", exit_type_atr_sl = "ATR", exit_type_none_sl = "None"exit_tt_val_tp = "Percantage: Percentage value\nATR: ATR multiplier\nRisk/Reward: R:R ratio"exit_tt_val_sl = "Percantage: Percentage value\nATR: ATR multiplier"in_exit_sqz_bar_type_long = input.string(exit_long_dark_green, "Long close", [exit_long_light_green, exit_long_dark_green, exit_long_light_red, exit_long_dark_red, exit_long_none], group=exit_gr_name)in_exit_sqz_bar_type_short = input.string(exit_short_dark_red, "Short close", [exit_short_light_green, exit_short_dark_green, exit_short_light_red, exit_short_dark_red, exit_short_none], group=exit_gr_name)in_exit_sqz_bar_close_in_profit = input.bool(false, "Close only in profit", group=exit_gr_name)in_exit_type_tp = input.string(exit_type_none_tp, "Take profit type", [exit_type_per_tp, exit_type_atr_tp, exit_type_rr_tp, exit_type_none_tp], group=exit_gr_name)in_exit_val_tp = input.float(2.0, "Take profit value", step=0.1, tooltip=exit_tt_val_tp, group=exit_gr_name)in_exit_type_sl = input.string(exit_type_atr_sl, "Stop loss type", [exit_type_per_sl, exit_type_atr_sl, exit_type_none_sl], group=exit_gr_name)in_exit_val_sl = input.float(2.0, "Stop loss value", step=0.1, tooltip=exit_tt_val_sl, group=exit_gr_name)in_exit_atr_len = input.int(14, "ATR length", group=exit_gr_name)//}// Squeeze Momentum {sqz_gr_name = "Squeeze Momentum"in_sqz_length = input(20, title='BB Length', group=sqz_gr_name)in_sqz_mult = input(2.0, title='BB MultFactor', group=sqz_gr_name)in_sqz_lengthKC = input(20, title='KC Length', group=sqz_gr_name)in_sqz_multKC = input(1.5, title='KC MultFactor', group=sqz_gr_name)in_sqz_useTrueRange = input(true, title='Use TrueRange (KC)', group=sqz_gr_name)//}// Moving Average {ma_gr_name = "Moving Average"ma_type_rma = "RMA", ma_type_sma = "SMA", ma_type_ema = "EMA", ma_type_wma = "WMA", ma_type_hma = "HMA", ma_type_vwma = "VWMA", ma_type_dema = "DEMA", ma_type_tema = "TEMA"in_ma_en = input.bool(true, "Enable moving average filter?", group=ma_gr_name)in_ma_type = input.string(ma_type_sma, "Type", [ma_type_rma, ma_type_sma, ma_type_ema, ma_type_dema, ma_type_tema, ma_type_wma, ma_type_hma, ma_type_vwma], group=ma_gr_name)in_ma_src = input.source(close, "Source", group=ma_gr_name)in_ma_len = input.int(200, "Length", group=ma_gr_name)in_ma_show = input.bool(true, "Plot?", inline="ma_plot", group=ma_gr_name)in_ma_col = input.color(color.yellow, "", inline="ma_plot", group=ma_gr_name)in_ma_w = input.int(2, "", inline="ma_plot", group=ma_gr_name)//}// Display {disp_gr_name = "Display"in_disp_ep_col = input.color(color.gray, "Entry Price", group=disp_gr_name)in_disp_tp_col = input.color(color.green, "Take Profit", group=disp_gr_name)in_disp_sl_col = input.color(color.red, "Stop Loss", group=disp_gr_name)//}//}// Variables {// Entry {entry_long_sel_light_green = (in_entry_sqz_bar_type_long == entry_long_light_green)entry_long_sel_dark_green = (in_entry_sqz_bar_type_long == entry_long_dark_green)entry_short_sel_light_red = (in_entry_sqz_bar_type_short == entry_short_light_red)entry_short_sel_dark_red = (in_entry_sqz_bar_type_short == entry_short_dark_red)//}// Exit {exit_long_sel_light_green = (in_exit_sqz_bar_type_long == exit_long_light_green)exit_long_sel_dark_green = (in_exit_sqz_bar_type_long == exit_long_dark_green)exit_long_sel_light_red = (in_exit_sqz_bar_type_long == exit_long_light_red)exit_long_sel_dark_red = (in_exit_sqz_bar_type_long == exit_long_dark_red)exit_short_sel_light_green = (in_exit_sqz_bar_type_short == exit_short_light_green)exit_short_sel_dark_green = (in_exit_sqz_bar_type_short == exit_short_dark_green)exit_short_sel_light_red = (in_exit_sqz_bar_type_short == exit_short_light_red)exit_short_sel_dark_red = (in_exit_sqz_bar_type_short == exit_short_dark_red)//}// Strategy {strat_is_long = strategy.position_size > 0strat_is_short = strategy.position_size < 0strat_is_new_pos = (strategy.position_size[1] == 0 and strategy.position_size != 0) or ((strategy.position_size[1] * strategy.position_size) < 0)//}//}// Functions {// Moving Average {f_ma(type, src, len) => switch type ma_type_rma => ta.rma(src, len) ma_type_sma => ta.sma(src, len) ma_type_ema => ta.ema(src, len) ma_type_dema => e1 = ta.ema(src, len) e2 = ta.ema(e1, len) dema = 2 * e1 - e2 ma_type_tema => ema1 = ta.ema(src, len) ema2 = ta.ema(ema1, len) ema3 = ta.ema(ema2, len) out = 3 * (ema1 - ema2) + ema3 ma_type_wma => ta.wma(src, len) ma_type_hma => ta.hma(src, len) ma_type_vwma => ta.vwma(src, len) => ta.ema(src, len)//}//}// Indicator {// Squeeze Momentum {var sqz_dark_blue_dot_cnt = 0// Calculate BBsqz_source = closesqz_basis = ta.sma(sqz_source, in_sqz_length)sqz_dev = in_sqz_multKC * ta.stdev(sqz_source, in_sqz_length)sqz_upperBB = sqz_basis + sqz_devsqz_lowerBB = sqz_basis - sqz_dev// Calculate KCsqz_ma = ta.sma(sqz_source, in_sqz_lengthKC)sqz_range_1 = in_sqz_useTrueRange ? ta.tr : high - lowsqz_rangema = ta.sma(sqz_range_1, in_sqz_lengthKC)sqz_upperKC = sqz_ma + sqz_rangema * in_sqz_multKCsqz_lowerKC = sqz_ma - sqz_rangema * in_sqz_multKCsqz_sqzOn = sqz_lowerBB > sqz_lowerKC and sqz_upperBB < sqz_upperKCsqz_sqzOff = sqz_lowerBB < sqz_lowerKC and sqz_upperBB > sqz_upperKCsqz_noSqz = sqz_sqzOn == false and sqz_sqzOff == falsesqz_val = ta.linreg(sqz_source - math.avg(math.avg(ta.highest(high, in_sqz_lengthKC), ta.lowest(low, in_sqz_lengthKC)), ta.sma(close, in_sqz_lengthKC)), in_sqz_lengthKC, 0)sqz_bar_light_green = (sqz_val > 0) and (sqz_val > nz(sqz_val[1]))sqz_bar_dark_green = (sqz_val > 0) and not (sqz_val > nz(sqz_val[1]))sqz_bar_light_red = not (sqz_val > 0) and (sqz_val < nz(sqz_val[1]))sqz_bar_dark_red = not (sqz_val > 0) and not (sqz_val < nz(sqz_val[1]))sqz_circle_dark_blue = sqz_noSqz or (not sqz_noSqz and sqz_sqzOn)sqz_circle_light_blue = (not sqz_noSqz and not sqz_sqzOn)sqz_bar_cond_long = entry_long_sel_light_green ? sqz_bar_light_green : entry_long_sel_dark_green ? sqz_bar_dark_green : falsesqz_bar_cond_short = entry_short_sel_light_red ? sqz_bar_light_red : entry_short_sel_dark_red ? sqz_bar_dark_red : falsesqz_bar_cond_long := sqz_bar_cond_long and sqz_circle_light_bluesqz_bar_cond_short := sqz_bar_cond_short and sqz_circle_light_bluesqz_close_cond_long = exit_long_sel_light_green ? sqz_bar_light_green : exit_long_sel_dark_green ? sqz_bar_dark_green : exit_long_sel_light_red ? sqz_bar_light_red : exit_long_sel_dark_red ? sqz_bar_dark_red : falsesqz_close_cond_short = exit_short_sel_light_green ? sqz_bar_light_green : exit_short_sel_dark_green ? sqz_bar_dark_green : exit_short_sel_light_red ? sqz_bar_light_red : exit_short_sel_dark_red ? sqz_bar_dark_red : falsesqz_dark_blue_dot_cnt := sqz_circle_dark_blue ? sqz_dark_blue_dot_cnt + 1 : 0sqz_filter_cnt_cond = in_entry_sqz_filter_en ? (sqz_dark_blue_dot_cnt[1] >= in_entry_sqz_filter_cnt) : trueplotchar(sqz_dark_blue_dot_cnt, "Dark blue dot count", "", color=color.blue)//}// Moving Average {ma_val = f_ma(in_ma_type, in_ma_src, in_ma_len)ma_cond_long = in_ma_en ? (close > ma_val) : truema_cond_short = in_ma_en ? (close < ma_val) : trueplot(in_ma_en and in_ma_show ? ma_val : na, "Moving Average", in_ma_col, in_ma_w)//}// ATR {var float atr_at_entry = naatr_val = ta.atr(in_exit_atr_len)atr_at_entry := strat_is_new_pos ? atr_val[1] : atr_at_entry//}// Strategy {strat_long_cond = sqz_bar_cond_long and sqz_filter_cnt_cond and ma_cond_longstrat_short_cond = sqz_bar_cond_short and sqz_filter_cnt_cond and ma_cond_shortif (strat_long_cond) strategy.entry("Long", strategy.long,alert_message = lo_mess)if (strat_short_cond) strategy.entry("Short", strategy.short,alert_message = sh_mess)strat_profit_cond_close = in_exit_sqz_bar_close_in_profit ? (strategy.openprofit > 0) : trueif (strat_is_long and sqz_close_cond_long and strat_profit_cond_close) strategy.close("Long",alert_message = exl_mess)if (strat_is_short and sqz_close_cond_short and strat_profit_cond_close) strategy.close("Short",alert_message = exs_mess)strat_entry_price = strategy.opentrades.entry_price(strategy.opentrades - 1)// Stop Loss {var float strat_sl_price_long = navar float strat_sl_price_short = nastrat_sl_price_long := if (strat_is_new_pos) switch in_exit_type_sl exit_type_per_sl => strategy.position_avg_price * (1 - (in_exit_val_sl * 0.01)) exit_type_atr_sl => strat_entry_price - (in_exit_val_sl * atr_val) => naelse strat_sl_price_longstrat_sl_price_short := if (strat_is_new_pos) switch in_exit_type_sl exit_type_per_sl => strategy.position_avg_price * (1 + (in_exit_val_sl * 0.01)) exit_type_atr_sl => strat_entry_price + (in_exit_val_sl * atr_val) => naelse strat_sl_price_shortfloat strat_sl_price = strat_is_long ? strat_sl_price_long : strat_is_short ? strat_sl_price_short : nastrat_sl_diff = math.abs(strat_entry_price - strat_sl_price)//}// Take Profit {var float strat_tp_price_long = navar float strat_tp_price_short = nastrat_tp_price_long := if (strat_is_new_pos) switch in_exit_type_tp exit_type_per_tp => strategy.position_avg_price * (1 + (in_exit_val_tp * 0.01)) exit_type_atr_tp => strat_entry_price + (in_exit_val_tp * atr_val) exit_type_rr_tp => strat_entry_price + (in_exit_val_tp * strat_sl_diff) => naelse strat_tp_price_longstrat_tp_price_short := if (strat_is_new_pos) switch in_exit_type_tp exit_type_per_tp => strategy.position_avg_price * (1 - (in_exit_val_tp * 0.01)) exit_type_atr_tp => strat_entry_price - (in_exit_val_tp * atr_val) exit_type_rr_tp => strat_entry_price - (in_exit_val_tp * strat_sl_diff) => naelse strat_tp_price_shortfloat strat_tp_price = strat_is_long ? strat_tp_price_long : strat_is_short ? strat_tp_price_short : na//}if (strat_is_long) strategy.exit("LE", "Long", stop=strat_sl_price, limit=strat_tp_price, comment_loss="L-SL", comment_profit="L-TP",alert_message = exl_mess)if (strat_is_short) strategy.exit("SE", "Short", stop=strat_sl_price, limit=strat_tp_price, comment_loss="S-SL", comment_profit="S-TP",alert_message = exs_mess)//}// Display {p_ep = plot(strat_entry_price, "Entry Price", in_disp_ep_col, 1, plot.style_circles)p_tp = plot(strat_tp_price, "Take Profit", in_disp_tp_col, 1, plot.style_circles)p_sl = plot(strat_sl_price, "Stop Loss", in_disp_sl_col, 1, plot.style_circles)fill(p_ep, p_tp, color.new(in_disp_tp_col, 85), title="Take Profit Fill")fill(p_ep, p_sl, color.new(in_disp_sl_col, 85), title="Stop Loss Fill")//}//}