Pine Script v5 · Strategy
Coral Trend Pullback Strategy (TradeIQ)
A Pine Script v5 strategy built on SMA (DX, 14), SMA or EMA or WMA or ALMA (close, ashLen) and WMA (close, ashLen). It has 3 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 commits 1 in cash and pays no commission. 25 settings; defaults include Risk : Reward 1 : 1.5, Portfolio Risk % 1 and Local High/Low Lookback 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 Coral Trend Pullback Strategy (TradeIQ) repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did Coral Trend Pullback Strategy (TradeIQ) do on BTCUSDT 1D with default settings?
- −1.01%
- From 26 Jan 2024 to 21 Oct 2026, over 1 closed trade, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Coral Trend Pullback Strategy (TradeIQ) run in Pine Script v6?
- Yes
- Same 1 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 Coral Trend Pullback Strategy (TradeIQ) use a stop loss?
- Yes
- strategy.exit sets a stop on line 366.
- Does Coral Trend Pullback Strategy (TradeIQ) run in Zeal Terminal?
- Yes
- It compiles in 137 ms and runs 1,000 bars in 216 ms, in the browser.
BTCUSDT · 1D · default settings
- Trend
- prePullbackBullBreakout
- prePullbackBearBreakout
- barssincePullbackStart
- isCoralBullish
- isCoralBearish
- barssinceCoralflip
- isPullbackValid
- entryBreakout
- slHit
- slPrice
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −1.01%
- −$10.11
- Buy and hold
- +102.5%
- same period
- Closed trades
- 1
- 0 won · 1 lost
- Profitable
- 0.0%
- of closed trades
- Profit factor
- 0.00
- gross profit ÷ gross loss
- Max drawdown
- 1.01%
- −$10.11
One run with the author's default settings, $1,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 commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Note
4 settings have no label
In the settings dialog startMonth (line 84), startDate (line 85), endMonth (line 87), endDate (line 88) show 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 |
|---|---|---|---|
| Strategy: Risk Management | |||
| Risk : Reward 1 :Previous high or low (long/short dependant) is used to determine TP level. 'Risk : Reward' ratio is then used to calculate SL based of previous high/low level.\n\nIn short, the higher the R:R ratio, the smaller the SL since TP target is fixed by previous high/low price data. | 1.5 | float · min 0 · step 0.1 | tpPercent |
| Portfolio Risk % Percentage of portfolio you lose if trade hits SL.\n\nYou then stand to gain\n Portfolio Risk % * Risk : Reward\nif trade hits TP. | 1 | float · min 0 · step 0.1 | riskAmt |
| Strategy: Stop Loss Settings | |||
| Local High/Low Lookback This strategy calculates the Stop Loss value from the recent local high/low. This lookback period determines the number of candles to include for the local high/low. | 5 | int · min 1 | longSlPrice shortSlPrice |
| Strategy: Date Range | |||
| Start Date | 2010 | int · min 1900 · max 2100 | inDateRange |
| Start Month (no label in the script) | 1 | int · options [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] | inDateRange |
| Start Date (no label in the script) | 1 | int · options [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31] | inDateRange |
| End Date | 2100 | int · min 1900 · max 2100 | inDateRange |
| End Month (no label in the script) | 1 | int · options [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] | inDateRange |
| End Date (no label in the script) | 1 | int · options [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31] | inDateRange |
| Strategy: Drawings | |||
| Show TP / SL BoxesShow or hide TP and SL position boxes.\n\nNote: TradingView limits the maximum number of boxes that can be displayed to 500 so they may not appear for all price data under test. | true | bool | line 249 line 257 |
| Show Trade Exit LabelsUseful labels to identify Profit/Loss and cumulative portfolio capital after each trade closes.\n\nAlso note that TradingView limits the max number of 'boxes' that can be displayed on a chart (max 500). This means when you lookback far enough on the chart you will not see the TP/SL boxes. However you can check this option to identify where trades exited. | false | bool | line 265 |
| Leading Indicator: Coral Trand Settings | |||
| Smoothing Period | 25 | int | di |
| Constant D | 0.4 | float · step 0.1 | c3 c4 c5 bfr |
| Confirmation Indicator: Indicator Selection | |||
| Entry Confirmation Method Select one of the possible confirmation indicator(s) which can be used to confirm entry signals from the main Coral Trend indicator conditions. See strategy conditions to understand the logic behind each confirmation indicator | ADX and DI | string · options ["None", "ADX and DI", "Absolute Strength Histogram + HawkEye Volume"] | line 302 line 307 line 313 |
| Confirmation Indicator: ADX and DI Settings | |||
| ADX Length | 14 | int | SmoothedTrueRange SmoothedDirectionalMovementPlus SmoothedDirectionalMovementMinus ADX |
| Mid Line Mid line on standard ADX and DI indicator. In this strategy the DI must be above this line for entry confirmation. | 20 | int | isAdxValid |
| Confirmation Indicator: Absolute Strength Histogram Settings | |||
| Period of Evaluation | 9 | int | Bulls1 Bears1 AvgBulls AvgBears |
| Period of Smoothing | 6 | int | SmthBulls SmthBears |
| Source | close | source | result ashWma ashSma Price |
| Indicator Method | RSI | string · options ["RSI", "STOCHASTIC", "ADX"] | Bulls Bears |
| MA | SMA | string · options ["ALMA", "EMA", "WMA", "SMA", "SMMA", "HMA"] | AvgBulls AvgBears SmthBulls SmthBears |
| * Arnaud Legoux (ALMA) Offset | 0.85 | float · min 0 · step 0.01 | result |
| * Arnaud Legoux (ALMA) Sigma | 6 | int · min 0 | result |
| Confirmation Indicator: HawkEye Volume Settings | |||
| Length | 200 | int | hevRangeAvg hevVolumeA |
| Divisor | 1.6 | float · step 0.1 | hevU1 hevD1 |
What it calculates
- SMADX, ADX Length (14)
ADX · line 159 - SMA / EMA / WMA / ALMASource (close), ashLen
result · line 166 - WMASource (close), ashLen
ashWma · line 175 - SMASource (close), ashLen
ashSma · line 176 - LowestPrice1, Period of Evaluation (9)
Bulls1 · line 193 - HighestPrice1, Period of Evaluation (9)
Bears1 · line 194 - SMAhevRange1, Length (200)
hevRangeAvg · line 209 - SMAvolume, Length (200)
hevVolumeA · line 210 - Barssince / Crossoverta.crossover(close, bfr)
sincePrePullbackBullBreakout · line 277 - Barssince / Crossunderta.crossunder(close, bfr)
sincePrePullbackBearBreakout · line 278 - Barssince / Crossunderta.crossunder(close, bfr)
barssinceBullPullbackStart · line 282 - Barssince / Crossoverta.crossover(close, bfr)
barssinceBearPullbackStart · line 283 - Barssince / Crossoverta.crossover(bfr, nz(bfr[1]))
sinceBullish · line 286 - Barssince / Crossunderta.crossunder(bfr, nz(bfr[1]))
sinceBearish · line 287 - LowestLocal High/Low Lookback (5)
longSlPrice · line 336 - HighestLocal High/Low Lookback (5)
shortSlPrice · line 337
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 136 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 | openLong | On | 348 |
| Open Short short | openShort | On | 356 |
| Exit TP/SL stop and limit | every bar | On | 366 |
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 | −1.0% | +102.5% | 1 | 0% | 0.00 | 1.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +2.3% | +5.5% | 5 | 60% | 2.08 | 2.1% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −1.5% | +9.8% | 4 | 25% | 0.49 | 3.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −4.2% | +8.4% | 4 | 0% | 0.00 | 4.2% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +1.5% | +16.7% | 1 | 100% | — | 0.9% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −1.0% | +21.5% | 1 | 0% | 0.00 | 1.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.5% | +148.3% | 2 | 50% | 1.44 | 1.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +1.5% | +17.1% | 1 | 100% | — | 0.1% | 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 | 0 | — | $0.00 |
| Sideways market | 1 | 0% | −$10.11 |
| 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?
1.0%
The 95th percentile of the worst drawdown when the same 1 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 1.0% to 1.0%; the tick is what actually happened, 1.0%. Order luck alone moves it this much.
All 1 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 21 Mar 2025 84,223.40 | 24 Mar 2025 87,453.70 | 3 | −$10.11 |
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 |
|---|---|---|---|---|---|
| Coral Trend Pullback Strategy (TradeIQ) this page | — | v5 strategy | −1.0% | 1 | 1.0% |
| Swing Multi Moving Averages Crypto and Stocks Strategy by exlux99 | ema wma highest lowest sma | v5 strategy | +60.2% | 22 | 13.1% |
| MACD Willy Strategy by PtGambler | sma ema highest lowest wma | v5 strategy | No trades on this market | ||
| TradingGroundhog - Strategy & Wavetrend V2 by UnknownUnicorn27666852 | wma highest lowest barssince sma | v5 strategy | −0.0% | 2 | 0.0% |
| Forex bot full strategy with risk management by exlux99 | lowest highest ema sma | v4 strategy | −26.4% | 11 | 38.9% |
| Lorentzian Classification Strategy by StrategiesForEveryone | ema sma barssince highest lowest | v5 strategy | does not run in Zeal Terminal | ||
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.
- No v6-only features. v6 is not needed to run this script.
Clean v5
VerifiedNothing to change.
Does it run in Pine Script v6?
Yes
Same 1 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.
⋯// ADX and DI by @BeikabuOyaji-//@version=5+//@version=6INITIAL_CAPITAL = 1000⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 137 ms | With a workaround 1,000 bars in 216 ms | Not measured |
| PineTS | Not tested | Not tested | Not 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/// © kevinmck100// @description//// Strategy is taken from the TradeIQ YouTube video called "I Finally Found 80% Win Rate Trading Strategy For Crypto"// Check out the full video for further details/clarification on strategy entry/exit conditions.//// It incorporates the following features://// - Risk management: Configurable X% loss per stop loss// Configurable R:R ratio//// - Trade entry: Conditions outlines below//// - Trade exit: Conditions outlined below//// - Backtesting: Configurable backtesting range by date//// - Trade drawings: TP/SL boxes drawn for all trades (can be turned on and off)// Trade exit information labels (can be turned on and off)// NOTE: Trade drawings will only be applicable when using overlay strategies//// - Debugging: Includes section with useful debugging techniques//// Strategy conditions://// - Trade entry: LONG: C1: Coral Trend is bullish// C2: At least 1 candle where low is above Coral Trend since last cross above Coral Trend// C3: Pullback happens and price closes below Coral Trend// C4: Coral Trend colour remains bullish for duration of pullback// C5: After valid pullback, price then closes above Coral Trend// C6: Optional confirmation indicators (choose either C6.1 or C6.2 or NONE):// C6.1: ADX and DI (Single indicator)// C6.1.1: Green line is above red line// C6.1.2: Blue line > 20// C6.1.3: Blue trending up over last 1 candle// C6.2: Absolute Strengeh Histogram + HawkEye Volume Indicator (Two indicators combined)// C6.2.1: Absolute Strengeh Histogram colour is blue// C6.2.2: HawkEye Volume Indicator colour is green// SHORT: C1: Coral Trend is bearish// C2: At least 1 candle where high is below Coral Trend since last cross below Coral Trend// C3: Pullback happens and price closes above Coral Trend// C4: Coral Trend colour remains bearish for duration of pullback// C5: After valid pullback, price then closes below Coral Trend// C6: Optional confirmation indicators (choose either C6.1 or C6.2 or NONE):// C6.1: ADX and DI (Single indicator)// C6.1.1: Red line is above green line// C6.1.2: Blue line > 20// C6.1.3: Blue trending up over last 1 candle// C6.2: Absolute Strengeh Histogram + HawkEye Volume Indicator (Two indicators combined)// C6.2.1: Absolute Strengeh Histogram colour is red// C6.2.2: HawkEye Volume Indicator colour is red// NOTE: All the optional confirmation indicators cannot be overlayed with Coral Trend so feel free to add each separately to the chart for visual purposes////// - Trade exit: Stop Loss: Calculated by recent swing low over previous X candles (configurable with "Local High/Low Lookback")// Take Profit: Calculated from R:R multiplier * Stop Loss size//// @credits//// Coral Trend Indicator [LazyBear] by @LazyBear// Absolute Strength Histogram | jh by @jiehonglim// Indicator: HawkEye Volume Indicator by @LazyBear// ADX and DI by @BeikabuOyaji//@version=5INITIAL_CAPITAL = 1000DEFAULT_COMMISSION = 0.02MAX_DRAWINGS = 500IS_OVERLAY = truestrategy("Coral Trend Pullback Strategy (TradeIQ)", "Coral Trend Pullback", overlay = IS_OVERLAY, initial_capital = INITIAL_CAPITAL, currency = currency.NONE, max_labels_count = MAX_DRAWINGS, max_boxes_count = MAX_DRAWINGS, max_lines_count = MAX_DRAWINGS, default_qty_type = strategy.cash, commission_type = strategy.commission.percent, commission_value = DEFAULT_COMMISSION)// =============================================================================// INPUTS// =============================================================================// ---------------// Risk Management// ---------------riskReward = input.float(1.5, "Risk : Reward 1 :", group = "Strategy: Risk Management", inline = "RM1", minval = 0, step = 0.1, tooltip = "Previous high or low (long/short dependant) is used to determine TP level. 'Risk : Reward' ratio is then used to calculate SL based of previous high/low level.\n\nIn short, the higher the R:R ratio, the smaller the SL since TP target is fixed by previous high/low price data.")accountRiskPercent = input.float(1, "Portfolio Risk % ", group = "Strategy: Risk Management", inline = "RM2", minval = 0, step = 0.1, tooltip = "Percentage of portfolio you lose if trade hits SL.\n\nYou then stand to gain\n Portfolio Risk % * Risk : Reward\nif trade hits TP.")localHlLookback = input.int (5, "Local High/Low Lookback ", group = "Strategy: Stop Loss Settings", inline = "SL1", minval = 1, tooltip = "This strategy calculates the Stop Loss value from the recent local high/low. This lookback period determines the number of candles to include for the local high/low.")// ----------// Date Range// ----------startYear = input.int (2010, "Start Date ", group = "Strategy: Date Range", inline = "DR1", minval = 1900, maxval = 2100)startMonth = input.int (1, "", group = "Strategy: Date Range", inline = "DR1", options = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])startDate = input.int (1, "", group = "Strategy: Date Range", inline = "DR1", options = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31])endYear = input.int (2100, "End Date ", group = "Strategy: Date Range", inline = "DR2", minval = 1900, maxval = 2100)endMonth = input.int (1, "", group = "Strategy: Date Range", inline = "DR2", options = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])endDate = input.int (1, "", group = "Strategy: Date Range", inline = "DR2", options = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31])// ----------------// Drawing Settings// ----------------showTpSlBoxes = input.bool(true, "Show TP / SL Boxes", group = "Strategy: Drawings", inline = "D1", tooltip = "Show or hide TP and SL position boxes.\n\nNote: TradingView limits the maximum number of boxes that can be displayed to 500 so they may not appear for all price data under test.")showLabels = input.bool(false, "Show Trade Exit Labels", group = "Strategy: Drawings", inline = "D2", tooltip = "Useful labels to identify Profit/Loss and cumulative portfolio capital after each trade closes.\n\nAlso note that TradingView limits the max number of 'boxes' that can be displayed on a chart (max 500). This means when you lookback far enough on the chart you will not see the TP/SL boxes. However you can check this option to identify where trades exited.")// ------------------// Indicator Settings// ------------------// Coral TrendctSm = input.int (25, "Smoothing Period ", group = "Leading Indicator: Coral Trand Settings", inline = "CT1")ctCd = input.float(0.4, "Constant D ", group = "Leading Indicator: Coral Trand Settings", inline = "CT2", step = 0.1)// Confirmation indicator inputsconfirmationInd = input.string("ADX and DI", "Entry Confirmation Method ", group = "Confirmation Indicator: Indicator Selection", inline = "IS1", options=["None", "ADX and DI", "Absolute Strength Histogram + HawkEye Volume"], tooltip = "Select one of the possible confirmation indicator(s) which can be used to confirm entry signals from the main Coral Trend indicator conditions. See strategy conditions to understand the logic behind each confirmation indicator")// ADX and DIadxLen = input.int(14, "ADX Length ", group = "Confirmation Indicator: ADX and DI Settings", inline = "AD1")midLine = input.int(20, "Mid Line ", group = "Confirmation Indicator: ADX and DI Settings", inline = "AD2", tooltip = "Mid line on standard ADX and DI indicator. In this strategy the DI must be above this line for entry confirmation.")// Absolute Strength HistogramashLength = input.int(9, "Period of Evaluation ", group = "Confirmation Indicator: Absolute Strength Histogram Settings", inline = "ASH1")ashSmooth = input.int(6, "Period of Smoothing ", group = "Confirmation Indicator: Absolute Strength Histogram Settings", inline = "ASH2")ashSrc = input.source(close, "Source ", group = "Confirmation Indicator: Absolute Strength Histogram Settings", inline = "ASH3")ashMode = input.string("RSI", "Indicator Method ", group = "Confirmation Indicator: Absolute Strength Histogram Settings", inline = "ASH4", options=["RSI", "STOCHASTIC", "ADX"])sahMaType = input.string("SMA", "MA ", group = "Confirmation Indicator: Absolute Strength Histogram Settings", inline = "ASH5", options=["ALMA", "EMA", "WMA", "SMA", "SMMA", "HMA"])ashAlmaOffset = input.float(0.85, "* Arnaud Legoux (ALMA) Offset", group = "Confirmation Indicator: Absolute Strength Histogram Settings", inline = "ASH6", minval=0, step=0.01)ashAlmaSigma = input.int(6, "* Arnaud Legoux (ALMA) Sigma", group = "Confirmation Indicator: Absolute Strength Histogram Settings", inline = "ASH7", minval=0)// HawkEye Volume IndicatorhevLength = input.int(200, "Length ", group = "Confirmation Indicator: HawkEye Volume Settings", inline = "HV1")hevDivisor = input.float(1.6, "Divisor ", group = "Confirmation Indicator: HawkEye Volume Settings", inline = "HV2", step=0.1)// =============================================================================// INDICATORS// =============================================================================// -----------// Coral Trend// -----------src = closedi = (ctSm - 1.0) / 2.0 + 1.0 c1 = 2 / (di + 1.0)c2 = 1 - c1c3 = 3.0 * (ctCd * ctCd + ctCd * ctCd * ctCd)c4 = -3.0 * (2.0 * ctCd * ctCd + ctCd + ctCd * ctCd * ctCd)c5 = 3.0 * ctCd + 1.0 + ctCd * ctCd * ctCd + 3.0 * ctCd * ctCdvar float i1 = navar float i2 = navar float i3 = navar float i4 = navar float i5 = navar float i6 = nai1 := c1 * src + c2 * nz(i1[1])i2 := c1 * i1 + c2 * nz(i2[1])i3 := c1 * i2 + c2 * nz(i3[1])i4 := c1 * i3 + c2 * nz(i4[1])i5 := c1 * i4 + c2 * nz(i5[1])i6 := c1 * i5 + c2 * nz(i6[1])bfr = -ctCd * ctCd * ctCd * i6 + c3 * i5 + c4 * i4 + c5 * i3bfrC = bfr > nz(bfr[1]) ? color.new(color.green, 50) : bfr < nz(bfr[1]) ? color.new(color.red, 50) : color.new(color.blue, 50)plot(bfr, "Trend", linewidth = 3, style = plot.style_stepline, color = bfrC)// ----------// ADX and DI// ----------TrueRange = math.max(math.max(high - low, math.abs(high - nz(close[1]))), math.abs(low - nz(close[1])))DirectionalMovementPlus = high - nz(high[1]) > nz(low[1]) - low ? math.max(high - nz(high[1]), 0) : 0DirectionalMovementMinus = nz(low[1]) - low > high - nz(high[1]) ? math.max(nz(low[1]) - low, 0) : 0SmoothedTrueRange = 0.0SmoothedTrueRange := nz(SmoothedTrueRange[1]) - nz(SmoothedTrueRange[1]) / adxLen + TrueRangeSmoothedDirectionalMovementPlus = 0.0SmoothedDirectionalMovementPlus := nz(SmoothedDirectionalMovementPlus[1]) - nz(SmoothedDirectionalMovementPlus[1]) / adxLen + DirectionalMovementPlusSmoothedDirectionalMovementMinus = 0.0SmoothedDirectionalMovementMinus := nz(SmoothedDirectionalMovementMinus[1]) - nz(SmoothedDirectionalMovementMinus[1]) / adxLen + DirectionalMovementMinusDIPlus = SmoothedDirectionalMovementPlus / SmoothedTrueRange * 100DIMinus = SmoothedDirectionalMovementMinus / SmoothedTrueRange * 100DX = math.abs(DIPlus - DIMinus) / (DIPlus + DIMinus) * 100ADX = ta.sma(DX, adxLen)// ---------------------------// Absolute Strength Histogram// ---------------------------ashMa(ashType, ashSrc, ashLen) => float result = 0 if ashType == 'SMA' // Simple result := ta.sma(ashSrc, ashLen) result if ashType == 'EMA' // Exponential result := ta.ema(ashSrc, ashLen) result if ashType == 'WMA' // Weighted result := ta.wma(ashSrc, ashLen) result if ashType == 'SMMA' // Smoothed ashWma = ta.wma(ashSrc, ashLen) ashSma = ta.sma(ashSrc, ashLen) result := na(ashWma[1]) ? ashSma : (ashWma[1] * (ashLen - 1) + ashSrc) / ashLen result if ashType == 'HMA' // Hull result := ta.wma(2 * ta.wma(ashSrc, ashLen / 2) - ta.wma(ashSrc, ashLen), math.round(math.sqrt(ashLen))) result if ashType == 'ALMA' // Arnaud Legoux result := ta.alma(ashSrc, ashLen, ashAlmaOffset, ashAlmaSigma) result resultPrice = ashSrcPrice1 = ashMa('SMA', Price, 1)Price2 = ashMa('SMA', Price[1], 1)//RSIBulls0 = 0.5 * (math.abs(Price1 - Price2) + Price1 - Price2)Bears0 = 0.5 * (math.abs(Price1 - Price2) - (Price1 - Price2))//STOCHASTICBulls1 = Price1 - ta.lowest(Price1, ashLength)Bears1 = ta.highest(Price1, ashLength) - Price1//ADXBulls2 = 0.5 * (math.abs(high - high[1]) + high - high[1])Bears2 = 0.5 * (math.abs(low[1] - low) + low[1] - low)Bulls = ashMode == 'RSI' ? Bulls0 : ashMode == 'STOCHASTIC' ? Bulls1 : Bulls2Bears = ashMode == 'RSI' ? Bears0 : ashMode == 'STOCHASTIC' ? Bears1 : Bears2AvgBulls = ashMa(sahMaType, Bulls, ashLength)AvgBears = ashMa(sahMaType, Bears, ashLength)SmthBulls = ashMa(sahMaType, AvgBulls, ashSmooth)SmthBears = ashMa(sahMaType, AvgBears, ashSmooth)isTrendBullish = SmthBulls > SmthBears ? true : false// ------------------------// HawkEye Volume Indicator// ------------------------hevRange1 = high - lowhevRangeAvg = ta.sma(hevRange1, hevLength)hevVolumeA = ta.sma(volume, hevLength)hevHigh1 = high[1]hevLow1 = low[1]hevMid1 = hl2[1]hevU1 = hevMid1 + (hevHigh1 - hevLow1) / hevDivisorhevD1 = hevMid1 - (hevHigh1 - hevLow1) / hevDivisorrEnabled1 = hevRange1 > hevRangeAvg and close < hevD1 and volume > hevVolumeArEnabled2 = close < hevMid1rEnabled = rEnabled1 or rEnabled2gEnabled1 = close > hevMid1gEnabled2 = hevRange1 > hevRangeAvg and close > hevU1 and volume > hevVolumeAgEnabled3 = high > hevHigh1 and hevRange1 < hevRangeAvg / 1.5 and volume < hevVolumeAgEnabled4 = low < hevLow1 and hevRange1 < hevRangeAvg / 1.5 and volume > hevVolumeAgEnabled = gEnabled1 or gEnabled2 or gEnabled3 or gEnabled4grEnabled1 = hevRange1 > hevRangeAvg and close > hevD1 and close < hevU1 and volume > hevVolumeA and volume < hevVolumeA * 1.5 and volume > volume[1]grEnabled2 = hevRange1 < hevRangeAvg / 1.5 and volume < hevVolumeA / 1.5grEnabled3 = close > hevD1 and close < hevU1grEnabled = grEnabled1 or grEnabled2 or grEnabled3// =============================================================================// STRATEGY LOGIC// =============================================================================// ---------// FUNCTIONS// ---------percentAsPoints(pcnt) => math.round(pcnt / 100 * close / syminfo.mintick) calcStopLossPrice(pointsOffset, isLong) => priceOffset = pointsOffset * syminfo.mintick if isLong close - priceOffset else close + priceOffsetcalcProfitTrgtPrice(pointsOffset, isLong) => calcStopLossPrice(-pointsOffset, isLong) printLabel(barIndex, msg) => label.new(barIndex, close, msg)printTpSlHitBox(left, right, slHit, tpHit, entryPrice, slPrice, tpPrice) => if showTpSlBoxes box.new (left = left, top = entryPrice, right = right, bottom = slPrice, bgcolor = slHit ? color.new(color.red, 60) : color.new(color.gray, 90), border_width = 0) box.new (left = left, top = entryPrice, right = right, bottom = tpPrice, bgcolor = tpHit ? color.new(color.green, 60) : color.new(color.gray, 90), border_width = 0) line.new(x1 = left, y1 = entryPrice, x2 = right, y2 = entryPrice, color = color.new(color.yellow, 20)) line.new(x1 = left, y1 = slPrice, x2 = right, y2 = slPrice, color = color.new(color.red, 20)) line.new(x1 = left, y1 = tpPrice, x2 = right, y2 = tpPrice, color = color.new(color.green, 20)) printTpSlNotHitBox(left, right, entryPrice, slPrice, tpPrice) => if showTpSlBoxes box.new (left = left, top = entryPrice, right = right, bottom = slPrice, bgcolor = color.new(color.gray, 90), border_width = 0) box.new (left = left, top = entryPrice, right = right, bottom = tpPrice, bgcolor = color.new(color.gray, 90), border_width = 0) line.new(x1 = left, y1 = entryPrice, x2 = right, y2 = entryPrice, color = color.new(color.yellow, 20)) line.new(x1 = left, y1 = slPrice, x2 = right, y2 = slPrice, color = color.new(color.red, 20)) line.new(x1 = left, y1 = tpPrice, x2 = right, y2 = tpPrice, color = color.new(color.green, 20)) printTradeExitLabel(x, y, posSize, entryPrice, pnl) => if showLabels labelStr = "Position Size: " + str.tostring(math.abs(posSize), "#.##") + "\nPNL: " + str.tostring(pnl, "#.##") + "\nCapital: " + str.tostring(strategy.equity, "#.##") + "\nEntry Price: " + str.tostring(entryPrice, "#.##") label.new(x = x, y = y, text = labelStr, color = pnl > 0 ? color.new(color.green, 60) : color.new(color.red, 60), textcolor = color.white, style = label.style_label_down)printVerticalLine(col) => line.new(bar_index, close, bar_index, close * 1.01, extend = extend.both, color = col)// ----------// CONDITIONS// ----------inDateRange = time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0) and time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0)// Condition 1: Coral Trend color matches trend direction (long=green, short=red)isCoralBullish = bfr > nz(bfr[1])isCoralBearish = bfr < nz(bfr[1])// Condition 2: At least 1 candle completely above/below (long/short) Coral Trend since last cross above/below (long/short) Coral Trend (could potentially try also with only close above)sincePrePullbackBullBreakout= ta.barssince(ta.crossover(close, bfr))sincePrePullbackBearBreakout= ta.barssince(ta.crossunder(close, bfr))prePullbackBullBreakout = ta.barssince(low > bfr and high > bfr) < sincePrePullbackBullBreakout[1]prePullbackBearBreakout = ta.barssince(low < bfr and high < bfr) < sincePrePullbackBearBreakout[1]// Condition 3: Pullback closes below/above (long/short) Coral TrendbarssinceBullPullbackStart = ta.barssince(ta.crossunder(close, bfr))barssinceBearPullbackStart = ta.barssince(ta.crossover(close, bfr))barssincePullbackStart = isCoralBullish ? barssinceBullPullbackStart : isCoralBearish ? barssinceBearPullbackStart : na// Condition 4: Coral Trend colour matched trend direction for duration of pullbacksinceBullish = ta.barssince(ta.crossover(bfr, nz(bfr[1])))sinceBearish = ta.barssince(ta.crossunder(bfr, nz(bfr[1])))barssinceCoralflip = isCoralBullish ? sinceBullish : isCoralBearish ? sinceBearish : naisPullbackValid = barssincePullbackStart < barssinceCoralflip// Condition 5: After valid pullback, price then closes above/below (long/short) Coral TrendentryBreakout = (isCoralBullish and ta.crossover(close, bfr)) or (isCoralBearish and ta.crossunder(close, bfr))// Condition 6: Confirmation indicators (6.1 or 6.2, optional depending on settings) confirms trade entry// 6.1: ADX and DI// 6.1.1: Green and red match trend (long=(green > red), short=(red > green)) // 6.1.2: Blue > 20// 6.1.3: Blue trending up over last 1 candle// 6.2: Absolute Strengeh Histogram + HawkEye Volume Indicator// 6.2.1: Absolute Strengeh Histogram colour matches trend (long=blue, short=red)// 6.2.2: HawkEye Volume Indicator colour matches trend (long=green, short=red)var longTradeConfirmed = falsevar shortTradeConfirmed = falseif confirmationInd == "ADX and DI" isAdxUp = ADX > ADX [1] isAdxValid = ADX > midLine and isAdxUp longTradeConfirmed := DIPlus > DIMinus and isAdxValid shortTradeConfirmed:= DIMinus > DIPlus and isAdxValidelse if confirmationInd == "Absolute Strength Histogram + HawkEye Volume" isAshBullish = SmthBulls > SmthBears ? true : false isHevBullish = not grEnabled and gEnabled ? true : false isHevBearish = not grEnabled and rEnabled ? true : false longTradeConfirmed := isAshBullish and isHevBullish shortTradeConfirmed:= not isAshBullish and isHevBearishelse if confirmationInd == "None" longTradeConfirmed := true shortTradeConfirmed:= true// Combine all entry conditionsgoLong = inDateRange and isCoralBullish and prePullbackBullBreakout and isPullbackValid and entryBreakout and longTradeConfirmedgoShort = inDateRange and isCoralBearish and prePullbackBearBreakout and isPullbackValid and entryBreakout and shortTradeConfirmed// Trade entry and exit variablesvar tradeEntryBar = bar_indexvar profitPoints = 0.var lossPoints = 0.var slPrice = 0.var tpPrice = 0.var inLong = falsevar inShort = falsevar entryPrice = 0.// Entry decisionsopenLong = (goLong and not inLong)openShort = (goShort and not inShort)flippingSides = (goLong and inShort) or (goShort and inLong)enteringTrade = openLong or openShortinTrade = inLong or inShort// Exit calculationsentryPrice := closelongSlPrice = ta.lowest(localHlLookback)shortSlPrice = ta.highest(localHlLookback)slAmount = isCoralBullish ? entryPrice - longSlPrice : shortSlPrice - entryPriceslPercent = math.abs((1 - (entryPrice - slAmount) / entryPrice) * 100)tpPercent = slPercent * riskReward// Risk calculationsriskAmt = strategy.equity * accountRiskPercent / 100entryQty = math.abs(riskAmt / slPercent * 100) / closeif openLong if strategy.position_size < 0 printTpSlNotHitBox(tradeEntryBar + 1, bar_index + 1, strategy.position_avg_price, slPrice, tpPrice) printTradeExitLabel(bar_index + 1, math.max(tpPrice, slPrice), strategy.position_size, strategy.position_avg_price, strategy.openprofit) strategy.entry("Long", strategy.long, qty = entryQty, alert_message = "Long Entry") enteringTrade := true inLong := true inShort := falseif openShort if strategy.position_size > 0 printTpSlNotHitBox(tradeEntryBar + 1, bar_index + 1, strategy.position_avg_price, slPrice, tpPrice) printTradeExitLabel(bar_index + 1, math.max(tpPrice, slPrice), strategy.position_size, strategy.position_avg_price, strategy.openprofit) strategy.entry("Short", strategy.short, qty = entryQty, alert_message = "Short Entry") enteringTrade := true inShort := true inLong := falseif enteringTrade profitPoints := percentAsPoints(tpPercent) lossPoints := percentAsPoints(slPercent) slPrice := calcStopLossPrice(lossPoints, openLong) tpPrice := calcProfitTrgtPrice(profitPoints, openLong) tradeEntryBar := bar_indexstrategy.exit("TP/SL", profit = profitPoints, loss = lossPoints, comment_profit = "TP Hit", comment_loss = "SL Hit", alert_profit = "TP Hit Alert", alert_loss = "SL Hit Alert")// =============================================================================// DRAWINGS// =============================================================================// -----------// TP/SL Boxes// -----------slHit = (inShort and high >= slPrice) or (inLong and low <= slPrice)tpHit = (inLong and high >= tpPrice) or (inShort and low <= tpPrice)exitTriggered = slHit or tpHitctEntryPrice = strategy.closedtrades.entry_price (strategy.closedtrades - 1)pnl = strategy.closedtrades.profit (strategy.closedtrades - 1)posSize = strategy.closedtrades.size (strategy.closedtrades - 1)// Print boxes for trades closed at profit or lossif (inTrade and exitTriggered) inShort := false inLong := false printTpSlHitBox(tradeEntryBar, bar_index, slHit, tpHit, ctEntryPrice, slPrice, tpPrice) printTradeExitLabel(bar_index, math.max(tpPrice, slPrice), posSize, ctEntryPrice, pnl)// Print TP/SL box for current open tradeif barstate.islastconfirmedhistory and strategy.position_size != 0 printTpSlNotHitBox(tradeEntryBar + 1, bar_index + 1, strategy.position_avg_price, slPrice, tpPrice) // // =============================================================================// // DEBUGGING// // =============================================================================// Data window plotsplotchar(prePullbackBullBreakout, "prePullbackBullBreakout", "")plotchar(prePullbackBearBreakout, "prePullbackBearBreakout", "")plotchar(barssincePullbackStart, "barssincePullbackStart", "")plotchar(isCoralBullish, "isCoralBullish", "")plotchar(isCoralBearish, "isCoralBearish", "")plotchar(barssinceCoralflip, "barssinceCoralflip", "")plotchar(isPullbackValid, "isPullbackValid", "")plotchar(entryBreakout, "entryBreakout", "")plotchar(slHit, "slHit", "")plotchar(tpHit, "tpHit", "")plotchar(slPrice, "slPrice", "")// Label plots// plotDebugLabels = false// if plotDebugLabels// if bar_index == tradeEntryBar // printLabel(bar_index, "Position size: " + str.tostring(entryQty * close, "#.##"))