Pine Script v5 · Strategy
Flying Dragon Trend Strategy
A Pine Script v5 strategy with no technical-analysis calculation. It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss. Each trade commits 5% of equity and pays 10 commission. 23 settings; defaults include Strategy Direction Both, Risk Level Medium and % 10.
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 Flying Dragon Trend Strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 63 of 63 trades.
- How did Flying Dragon Trend Strategy do on BTCUSDT 1D with default settings?
- +0.44%
- From 26 Jan 2024 to 21 Oct 2026, over 227 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- What alerts does Flying Dragon Trend Strategy have?
- 2
- alertMessage; alertMessage.
- Does Flying Dragon Trend Strategy run in Pine Script v6?
- Yes
- Same 227 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 Flying Dragon Trend Strategy use a stop loss?
- Yes
- strategy.exit sets a stop on line 80, 83.
BTCUSDT · 1D · default settings
- MA1
- MA2
- MA3
- MA4
- Up
- Down
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +0.44%
- $444.36
- Buy and hold
- +102.5%
- same period
- Closed trades
- 227
- 70 won · 157 lost
- Profitable
- 30.8%
- of closed trades
- Profit factor
- 1.02
- gross profit ÷ gross loss
- Max drawdown
- 6.32%
- −$6,319.95
One run with the author's default settings, $100,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.
-
Note
10 settings have no label
In the settings dialog ma1Type (line 33), ma1Length (line 34), ma1Source (line 35), ma1Color (line 36), ma2Color (line 39), ma3Color (line 42), ma4Type (line 45), ma4Length (line 46), ma4Source (line 47), ma4Color (line 48) 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 Options | |||
| Strategy Direction | Both | string · options ["Both", "Long", "Short"] | strSelection |
| Risk Level | Medium | string · options ["Highest", "High", "Medium", "Low", "Lowest"] | longCondition shortCondition |
| IndicatorsTurn on or off pivot indicators. Strategy execution criteria. When risk level Highest then Leading MA Offset1 crossover with price triggers the indicator and executes the strategy, when Low then Lagging MA crossover with price, when Lowest then all the Bands are the same color (Leading MA Offset1 crossover with Lagging MA). Alerts are enabled when indicators are on. Create Alert on selected equity and timeframe, select on Condition this strategy and alert criteria (for example: Alert () function calls only), Create. | true | bool | pivotUp pivotDown |
| Use Stop Loss | false | bool | stopLprice stopSprice |
| % | 10 | int · min 0 · max 100 · step 1 | stopLprice stopSprice |
| Leading Moving Average | |||
| Ma1Type (no label in the script) | HMA | string · options ["EMA", "HMA", "RMA", "SMA","SWMA", "VWMA", "WMA"] | ma1 |
| Ma1Length (no label in the script) | 35 | int · min 1 | ma1 |
| Ma1Source (no label in the script)For short timeframes, minutes to hours, instead of Default values try Lowest risk level and HMA75 with Offsets 0,1,4 and SMA12 with Offset 6. | close | source | ma1 longCondition shortCondition |
| Ma1Color (no label in the script) | color.purple | value | MA1 |
| Offset1 StepsThe Magic happens here! The offset to move the line to the right. | 0 | int · min 0 · max 10 · step 1 | ma1 |
| Ma2Color (no label in the script) | color.lime | value | MA2 |
| Offset2 StepsThe Magic happens here! The offset to move the line to the right. | 4 | int · min 0 · max 10 · step 1 | ma2 |
| Ma3Color (no label in the script) | color.aqua | value | MA3 |
| Offset3 StepsThe Magic happens here! The offset to move the line to the right. | 6 | int · min 0 · max 10 · step 1 | ma3 |
| Lagging Moving Average | |||
| Ma4Type (no label in the script) | SMA | string · options ["EMA", "HMA", "RMA", "SMA","SWMA", "VWMA", "WMA"] | ma4 |
| Ma4Length (no label in the script) | 22 | int · min 1 | ma4 |
| Ma4Source (no label in the script) | close | source | ma4 longCondition shortCondition |
| Ma4Color (no label in the script) | color.yellow | value | MA4 |
| Offset StepsThe Magic happens here! The offset to move the line to the right. | 2 | int · min 0 · max 10 · step 1 | ma4 |
| Banding | |||
| Band Transparency | 60 | int · min 20 · max 80 · step 10 | band1Transp band2Transp band3Transp |
| Band 1 | true | bool | band1Transp |
| Band 2 | true | bool | band2Transp |
| Band 3Up trend green, down trend red. Colors get reversed if MA1 lenght is greater than MA2 lenght, or they are different type and MA2 quicker. In that case, just reverse your selections for MA1 and MA2, or let it be as is. | true | bool | band3Transp |
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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | longCondition | On | 79 |
| Exit Long Stop stop | longCondition | On | 80 |
| Open Short short | shortCondition | On | 82 |
| Exit Short Stop stop | shortCondition | On | 83 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| (no title) | alert | alertMessage | 87 |
| (no title) | alert | alertMessage | 90 |
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 timingprocess_orders_on_close = true: orders fill at the signal bar's close.
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 | +0.4% | +102.5% | 227 | 31% | 1.02 | 6.3% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −3.8% | +5.5% | 265 | 22% | 0.73 | 6.3% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −1.3% | +9.8% | 246 | 28% | 0.97 | 14.5% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −1.9% | +8.4% | 248 | 20% | 0.89 | 6.1% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +13.1% | +16.7% | 200 | 43% | 1.31 | 10.8% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.6% | +21.5% | 218 | 32% | 1.04 | 4.4% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −11.7% | +148.3% | 243 | 30% | 0.64 | 16.7% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −1.1% | +17.1% | 228 | 27% | 0.91 | 4.3% | 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 | 100 | 20% | −$7,291.21 |
| Sideways market | 84 | 44% | $3,272.43 |
| Falling market | 43 | 30% | $4,473.14 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
8.0%
The 95th percentile of the worst drawdown when the same 227 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 3.5% to 8.0%; the tick is what actually happened, 5.6%. Order luck alone moves it this much.
The first 150 of 227 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 10 Mar 2024 68,955.90 | 16 Mar 2024 65,300.60 | 6 | −$285.04 |
| long | 11 Mar 2024 72,078.10 | 16 Mar 2024 65,300.60 | 5 | −$481.17 |
| long | 12 Mar 2024 71,452.00 | 16 Mar 2024 65,300.60 | 4 | −$440.96 |
| short | 16 Mar 2024 65,300.60 | 28 Mar 2024 70,780.60 | 12 | −$434.57 |
| short | 17 Mar 2024 68,393.50 | 28 Mar 2024 70,780.60 | 11 | −$181.98 |
| short | 18 Mar 2024 67,610.00 | 28 Mar 2024 70,780.60 | 10 | −$241.32 |
| long | 28 Mar 2024 70,780.60 | 2 Apr 2024 65,464.00 | 5 | −$387.85 |
| long | 29 Mar 2024 69,850.50 | 2 Apr 2024 65,464.00 | 4 | −$317.28 |
| long | 30 Mar 2024 69,582.20 | 2 Apr 2024 65,464.00 | 3 | −$299.45 |
| short | 2 Apr 2024 65,464.00 | 4 Apr 2024 68,487.80 | 2 | −$243.88 |
| short | 3 Apr 2024 65,963.30 | 4 Apr 2024 68,487.80 | 1 | −$195.39 |
| long | 4 Apr 2024 68,487.80 | 5 Apr 2024 67,820.60 | 1 | −$67.00 |
| short | 5 Apr 2024 67,820.60 | 6 Apr 2024 68,896.00 | 1 | −$96.45 |
| long | 6 Apr 2024 68,896.00 | 12 Apr 2024 67,116.50 | 6 | −$144.41 |
| long | 7 Apr 2024 69,360.40 | 12 Apr 2024 67,116.50 | 5 | −$165.85 |
| long | 8 Apr 2024 71,620.00 | 12 Apr 2024 67,116.50 | 4 | −$313.88 |
| short | 12 Apr 2024 67,116.50 | 4 May 2024 63,892.00 | 22 | $209.92 |
| short | 13 Apr 2024 63,924.50 | 4 May 2024 63,892.00 | 21 | −$7.56 |
| short | 14 Apr 2024 65,661.80 | 4 May 2024 63,892.00 | 20 | $118.91 |
| long | 4 May 2024 63,892.00 | 7 May 2024 62,312.10 | 3 | −$138.74 |
| long | 5 May 2024 64,012.00 | 7 May 2024 62,312.10 | 2 | −$137.50 |
| long | 6 May 2024 63,165.20 | 7 May 2024 62,312.10 | 1 | −$74.75 |
| short | 7 May 2024 62,312.10 | 9 May 2024 63,074.00 | 2 | −$78.50 |
| short | 8 May 2024 61,193.00 | 9 May 2024 63,074.00 | 1 | −$157.16 |
| long | 9 May 2024 63,074.00 | 10 May 2024 60,800.00 | 1 | −$192.06 |
| short | 10 May 2024 60,800.00 | 12 May 2024 61,484.00 | 2 | −$73.58 |
| short | 11 May 2024 60,826.00 | 12 May 2024 61,484.00 | 1 | −$61.51 |
| long | 12 May 2024 61,484.00 | 31 May 2024 67,540.00 | 19 | $448.46 |
| long | 13 May 2024 62,940.10 | 31 May 2024 67,540.00 | 18 | $337.93 |
| long | 14 May 2024 61,577.50 | 31 May 2024 67,540.00 | 17 | $449.92 |
| short | 31 May 2024 67,540.00 | 4 Jun 2024 70,537.80 | 4 | −$233.85 |
| short | 1 Jun 2024 67,766.90 | 4 Jun 2024 70,537.80 | 3 | −$206.93 |
| short | 2 Jun 2024 67,765.60 | 4 Jun 2024 70,537.80 | 2 | −$207.00 |
| long | 4 Jun 2024 70,537.80 | 7 Jun 2024 69,355.60 | 3 | −$100.21 |
| long | 5 Jun 2024 71,108.00 | 7 Jun 2024 69,355.60 | 2 | −$127.96 |
| long | 6 Jun 2024 70,799.10 | 7 Jun 2024 69,355.60 | 1 | −$107.53 |
| short | 7 Jun 2024 69,355.60 | 13 Jul 2024 59,204.00 | 36 | $677.99 |
| short | 8 Jun 2024 69,310.50 | 13 Jul 2024 59,204.00 | 35 | $685.22 |
| short | 9 Jun 2024 69,648.10 | 13 Jul 2024 59,204.00 | 34 | $704.54 |
| long | 13 Jul 2024 59,204.00 | 31 Jul 2024 64,628.00 | 18 | $426.36 |
| long | 14 Jul 2024 60,797.90 | 31 Jul 2024 64,628.00 | 17 | $297.28 |
| long | 15 Jul 2024 64,724.10 | 31 Jul 2024 64,628.00 | 16 | −$17.29 |
| short | 31 Jul 2024 64,628.00 | 17 Aug 2024 59,492.00 | 17 | $369.99 |
| short | 1 Aug 2024 65,354.00 | 17 Aug 2024 59,492.00 | 16 | $429.84 |
| short | 2 Aug 2024 61,498.30 | 17 Aug 2024 59,492.00 | 15 | $150.91 |
| long | 17 Aug 2024 59,492.00 | 30 Aug 2024 59,124.00 | 13 | −$50.65 |
| long | 18 Aug 2024 58,427.30 | 30 Aug 2024 59,124.00 | 12 | $49.01 |
| long | 19 Aug 2024 59,438.50 | 30 Aug 2024 59,124.00 | 11 | −$36.23 |
| short | 30 Aug 2024 59,124.00 | 13 Sep 2024 60,498.00 | 14 | −$135.11 |
| short | 31 Aug 2024 58,974.00 | 13 Sep 2024 60,498.00 | 13 | −$137.99 |
| short | 1 Sep 2024 57,301.90 | 13 Sep 2024 60,498.00 | 12 | −$287.00 |
| long | 13 Sep 2024 60,498.00 | 1 Oct 2024 60,805.80 | 18 | $5.06 |
| long | 14 Sep 2024 59,993.00 | 1 Oct 2024 60,805.80 | 17 | $56.68 |
| long | 15 Sep 2024 59,132.00 | 1 Oct 2024 60,805.80 | 16 | $129.11 |
| short | 1 Oct 2024 60,805.80 | 14 Oct 2024 66,084.00 | 13 | −$448.34 |
| short | 2 Oct 2024 60,649.30 | 14 Oct 2024 66,084.00 | 12 | −$452.15 |
| short | 3 Oct 2024 60,752.70 | 14 Oct 2024 66,084.00 | 11 | −$442.88 |
| long | 14 Oct 2024 66,084.00 | 3 Nov 2024 68,776.00 | 20 | $178.28 |
| long | 15 Oct 2024 67,074.10 | 3 Nov 2024 68,776.00 | 19 | $113.57 |
| long | 16 Oct 2024 67,620.00 | 3 Nov 2024 68,776.00 | 18 | $73.31 |
| short | 3 Nov 2024 68,776.00 | 6 Nov 2024 75,572.00 | 3 | −$502.77 |
| short | 4 Nov 2024 67,850.00 | 6 Nov 2024 75,572.00 | 2 | −$566.30 |
| short | 5 Nov 2024 69,372.00 | 6 Nov 2024 75,572.00 | 1 | −$445.83 |
| long | 6 Nov 2024 75,572.00 | 26 Nov 2024 91,965.20 | 20 | $1,023.37 |
| long | 7 Nov 2024 75,857.90 | 26 Nov 2024 91,965.20 | 19 | $1,011.29 |
| long | 8 Nov 2024 76,509.80 | 26 Nov 2024 91,965.20 | 18 | $962.35 |
| short | 26 Nov 2024 91,965.20 | 27 Nov 2024 95,863.10 | 1 | −$230.22 |
| long | 27 Nov 2024 95,863.10 | 28 Nov 2024 95,644.00 | 1 | −$31.31 |
| short | 28 Nov 2024 95,644.00 | 8 Dec 2024 101,110.00 | 10 | −$302.68 |
| short | 29 Nov 2024 97,460.00 | 8 Dec 2024 101,110.00 | 9 | −$195.03 |
| short | 30 Nov 2024 96,408.00 | 8 Dec 2024 101,110.00 | 8 | −$251.20 |
| long | 8 Dec 2024 101,110.00 | 9 Dec 2024 97,276.50 | 1 | −$206.11 |
| short | 9 Dec 2024 97,276.50 | 11 Dec 2024 101,125.00 | 2 | −$213.82 |
| short | 10 Dec 2024 96,593.00 | 11 Dec 2024 101,125.00 | 1 | −$239.88 |
| long | 11 Dec 2024 101,125.00 | 19 Dec 2024 97,461.90 | 8 | −$196.64 |
| long | 12 Dec 2024 100,004.00 | 19 Dec 2024 97,461.90 | 7 | −$133.88 |
| long | 13 Dec 2024 101,424.00 | 19 Dec 2024 97,461.90 | 6 | −$200.61 |
| short | 19 Dec 2024 97,461.90 | 3 Jan 2025 98,174.20 | 15 | −$55.45 |
| short | 20 Dec 2024 97,805.40 | 3 Jan 2025 98,174.20 | 14 | −$28.28 |
| short | 21 Dec 2024 97,292.00 | 3 Jan 2025 98,174.20 | 13 | −$53.98 |
| long | 3 Jan 2025 98,174.20 | 9 Jan 2025 92,552.50 | 6 | −$297.31 |
| long | 4 Jan 2025 98,220.50 | 9 Jan 2025 92,552.50 | 5 | −$289.41 |
| long | 5 Jan 2025 98,363.60 | 9 Jan 2025 92,552.50 | 4 | −$296.06 |
| short | 9 Jan 2025 92,552.50 | 10 Jan 2025 94,726.10 | 1 | −$132.70 |
| long | 10 Jan 2025 94,726.10 | 12 Jan 2025 94,545.10 | 2 | −$29.16 |
| long | 11 Jan 2025 94,600.00 | 12 Jan 2025 94,545.10 | 1 | −$12.78 |
| short | 12 Jan 2025 94,545.10 | 14 Jan 2025 96,560.90 | 2 | −$122.13 |
| short | 13 Jan 2025 94,536.10 | 14 Jan 2025 96,560.90 | 1 | −$112.57 |
| long | 14 Jan 2025 96,560.90 | 28 Jan 2025 101,336.00 | 14 | $216.27 |
| long | 15 Jan 2025 100,497.00 | 28 Jan 2025 101,336.00 | 13 | $29.92 |
| long | 16 Jan 2025 99,987.30 | 28 Jan 2025 101,336.00 | 12 | $54.51 |
| short | 28 Jan 2025 101,336.00 | 29 Jan 2025 103,733.00 | 1 | −$133.41 |
| long | 29 Jan 2025 103,733.00 | 31 Jan 2025 102,430.00 | 2 | −$80.16 |
| long | 30 Jan 2025 104,723.00 | 31 Jan 2025 102,430.00 | 1 | −$114.85 |
| short | 31 Jan 2025 102,430.00 | 19 Feb 2025 96,644.40 | 19 | $249.79 |
| short | 1 Feb 2025 100,636.00 | 19 Feb 2025 96,644.40 | 18 | $179.58 |
| short | 2 Feb 2025 97,700.60 | 19 Feb 2025 96,644.40 | 17 | $41.82 |
| long | 19 Feb 2025 96,644.40 | 24 Feb 2025 91,552.90 | 5 | −$272.90 |
| long | 20 Feb 2025 98,305.00 | 24 Feb 2025 91,552.90 | 4 | −$339.93 |
| long | 21 Feb 2025 96,182.00 | 24 Feb 2025 91,552.90 | 3 | −$240.66 |
| short | 24 Feb 2025 91,552.90 | 17 Mar 2025 84,010.00 | 21 | $371.98 |
| short | 25 Feb 2025 88,680.40 | 17 Mar 2025 84,010.00 | 20 | $240.91 |
| short | 26 Feb 2025 84,250.10 | 17 Mar 2025 84,010.00 | 19 | $3.64 |
| long | 17 Mar 2025 84,010.00 | 30 Mar 2025 82,390.00 | 13 | −$112.34 |
| long | 18 Mar 2025 82,715.00 | 30 Mar 2025 82,390.00 | 12 | −$28.80 |
| long | 19 Mar 2025 86,845.90 | 30 Mar 2025 82,390.00 | 11 | −$256.64 |
| short | 30 Mar 2025 82,390.00 | 1 Apr 2025 85,158.30 | 2 | −$180.23 |
| short | 31 Mar 2025 82,550.00 | 1 Apr 2025 85,158.30 | 1 | −$160.63 |
| long | 1 Apr 2025 85,158.30 | 2 Apr 2025 82,516.30 | 1 | −$167.42 |
| short | 2 Apr 2025 82,516.30 | 12 Apr 2025 85,276.90 | 10 | −$178.69 |
| short | 3 Apr 2025 83,213.10 | 12 Apr 2025 85,276.90 | 9 | −$127.56 |
| short | 4 Apr 2025 83,889.90 | 12 Apr 2025 85,276.90 | 8 | −$88.30 |
| long | 12 Apr 2025 85,276.90 | 28 May 2025 107,782.00 | 46 | $1,226.55 |
| long | 13 Apr 2025 83,760.00 | 28 May 2025 107,782.00 | 45 | $1,343.18 |
| long | 14 Apr 2025 84,591.60 | 28 May 2025 107,782.00 | 44 | $1,284.63 |
| short | 28 May 2025 107,782.00 | 9 Jun 2025 110,263.00 | 12 | −$133.18 |
| short | 29 May 2025 105,590.00 | 9 Jun 2025 110,263.00 | 11 | −$227.76 |
| short | 30 May 2025 103,985.00 | 9 Jun 2025 110,263.00 | 10 | −$307.45 |
| long | 9 Jun 2025 110,263.00 | 12 Jun 2025 105,672.00 | 3 | −$223.32 |
| long | 10 Jun 2025 110,274.00 | 12 Jun 2025 105,672.00 | 2 | −$213.76 |
| long | 11 Jun 2025 108,645.00 | 12 Jun 2025 105,672.00 | 1 | −$143.39 |
| short | 12 Jun 2025 105,672.00 | 13 Jun 2025 106,067.00 | 1 | −$38.14 |
| long | 13 Jun 2025 106,067.00 | 17 Jun 2025 104,551.00 | 4 | −$89.32 |
| long | 14 Jun 2025 105,415.00 | 17 Jun 2025 104,551.00 | 3 | −$49.72 |
| long | 15 Jun 2025 105,594.00 | 17 Jun 2025 104,551.00 | 2 | −$57.90 |
| short | 17 Jun 2025 104,551.00 | 25 Jun 2025 107,341.00 | 8 | −$149.19 |
| short | 18 Jun 2025 104,887.00 | 25 Jun 2025 107,341.00 | 7 | −$123.24 |
| short | 19 Jun 2025 104,659.00 | 25 Jun 2025 107,341.00 | 6 | −$134.05 |
| long | 25 Jun 2025 107,341.00 | 24 Jul 2025 118,341.00 | 29 | $474.13 |
| long | 26 Jun 2025 106,947.00 | 24 Jul 2025 118,341.00 | 28 | $503.49 |
| long | 27 Jun 2025 107,048.00 | 24 Jul 2025 118,341.00 | 27 | $498.48 |
| short | 24 Jul 2025 118,341.00 | 10 Aug 2025 119,294.00 | 17 | −$59.42 |
| short | 25 Jul 2025 117,614.00 | 10 Aug 2025 119,294.00 | 16 | −$79.92 |
| short | 26 Jul 2025 117,920.00 | 10 Aug 2025 119,294.00 | 15 | −$67.03 |
| long | 10 Aug 2025 119,294.00 | 19 Aug 2025 112,873.00 | 9 | −$282.95 |
| long | 11 Aug 2025 118,686.00 | 19 Aug 2025 112,873.00 | 8 | −$249.16 |
| long | 12 Aug 2025 120,134.00 | 19 Aug 2025 112,873.00 | 7 | −$305.46 |
| short | 19 Aug 2025 112,873.00 | 7 Sep 2025 111,137.00 | 19 | $54.47 |
| short | 20 Aug 2025 114,271.00 | 7 Sep 2025 111,137.00 | 18 | $122.72 |
| short | 21 Aug 2025 112,500.00 | 7 Sep 2025 111,137.00 | 17 | $48.70 |
| long | 7 Sep 2025 111,137.00 | 22 Sep 2025 112,651.00 | 15 | $46.12 |
| long | 8 Sep 2025 112,065.00 | 22 Sep 2025 112,651.00 | 14 | $15.38 |
| long | 9 Sep 2025 111,546.00 | 22 Sep 2025 112,651.00 | 13 | $38.06 |
| short | 22 Sep 2025 112,651.00 | 1 Oct 2025 118,595.00 | 9 | −$276.42 |
| short | 23 Sep 2025 111,999.00 | 1 Oct 2025 118,595.00 | 8 | −$296.23 |
| short | 24 Sep 2025 113,307.00 | 1 Oct 2025 118,595.00 | 7 | −$236.53 |
| long | 1 Oct 2025 118,595.00 | 10 Oct 2025 112,775.00 | 9 | −$256.52 |
| long | 2 Oct 2025 120,529.00 | 10 Oct 2025 112,775.00 | 8 | −$320.25 |
| long | 3 Oct 2025 122,232.00 | 10 Oct 2025 112,775.00 | 7 | −$383.59 |
| short | 10 Oct 2025 112,775.00 | 26 Oct 2025 114,559.00 | 16 | −$95.51 |
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.
- 11 settings use the untyped input() (line 29, 30, 35, 36, 39, 42, 47, 48, 52, 55, 58). 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 227 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 29: input() → input.bool()
- Line 30: input() → input.bool()
- Line 35: input() → input.source()
- Line 36: input() → input.color()
- Line 39: input() → input.color()
- Line 42: input() → input.color()
5 more edits
- Line 47: input() → input.source()
- Line 48: input() → input.color()
- Line 52: input() → input.bool()
- Line 55: input() → input.bool()
- Line 58: input() → input.bool()
⋯riskLevel = input.string(defval="Medium", title="Risk Level", options=["Highest", "High", "Medium", "Low", "Lowest"], inline="Options", group="Strategy Options")-indicatorsOn = input(defval=true, title="Indicators", inline="Options", tooltip="Turn on or off pivot indicators. Strategy execution criteria. When risk level Highest then Leading MA Offset1 crossover with price triggers the indicator and executes the strategy, when Low then Lagging MA crossover with price, when Lowest then all the Bands are the same color (Leading MA Offset1 crossover with Lagging MA). Alerts are enabled when indicators are on. Create Alert on selected equity and timeframe, select on Condition this strategy and alert criteria (for example: Alert () function calls only), Create.", group="Strategy Options")+indicatorsOn = input.bool(defval=true, title="Indicators", inline="Options", tooltip="Turn on or off pivot indicators. Strategy execution criteria. When risk level Highest then Leading MA Offset1 crossover with price triggers the indicator and executes the strategy, when Low then Lagging MA crossover with price, when Lowest then all the Bands are the same color (Leading MA Offset1 crossover with Lagging MA). Alerts are enabled when indicators are on. Create Alert on selected equity and timeframe, select on Condition this strategy and alert criteria (for example: Alert () function calls only), Create.", group="Strategy Options")-useStop = input(defval=false, title="Use Stop Loss", inline="SL", group="Strategy Options")+useStop = input.bool(defval=false, title="Use Stop Loss", inline="SL", group="Strategy Options")stopPrct = input.int(defval=10, title=" %", minval=0, maxval=100, step=1, inline="SL", group="Strategy Options") / 100⋯ma1Length = input.int(defval=35, title="",minval=1, inline="MA1", group="Leading Moving Average")-ma1Source = input(defval=close, title="", tooltip="For short timeframes, minutes to hours, instead of Default values try Lowest risk level and HMA75 with Offsets 0,1,4 and SMA12 with Offset 6.", inline="MA1", group="Leading Moving Average")+ma1Source = input.source(defval=close, title="", tooltip="For short timeframes, minutes to hours, instead of Default values try Lowest risk level and HMA75 with Offsets 0,1,4 and SMA12 with Offset 6.", inline="MA1", group="Leading Moving Average")-ma1Color = input(defval=color.purple, title="", inline="MA-1", group="Leading Moving Average")+ma1Color = input.color(defval=color.purple, title="", inline="MA-1", group="Leading Moving Average")ma1Offset = input.int(defval=0, title="Offset1 Steps", minval=0, maxval=10, step=1, tooltip="The Magic happens here! The offset to move the line to the right.", inline="MA-1", group="Leading Moving Average")ma1 = MA(ma1Source, ma1Length, ma1Type)[ma1Offset]-ma2Color = input(defval=color.lime, title="", inline="MA-2", group="Leading Moving Average")+ma2Color = input.color(defval=color.lime, title="", inline="MA-2", group="Leading Moving Average")ma2Offset = input.int(defval=4, title="Offset2 Steps", minval=0, maxval=10, step=1, tooltip="The Magic happens here! The offset to move the line to the right.", inline="MA-2", group="Leading Moving Average")ma2 = ma1[ma2Offset]-ma3Color = input(defval=color.aqua, title="", inline="MA-3", group="Leading Moving Average")+ma3Color = input.color(defval=color.aqua, title="", inline="MA-3", group="Leading Moving Average")ma3Offset = input.int(defval=6, title="Offset3 Steps", minval=0, maxval=10, step=1, tooltip="The Magic happens here! The offset to move the line to the right.", inline="MA-3", group="Leading Moving Average")⋯ma4Length = input.int(defval=22, title="",minval=1, inline="MA4", group="Lagging Moving Average")-ma4Source = input(defval=close, title="", inline="MA4", group="Lagging Moving Average")+ma4Source = input.source(defval=close, title="", inline="MA4", group="Lagging Moving Average")-ma4Color = input(defval=color.yellow, title="", inline="MA-4", group="Lagging Moving Average")+ma4Color = input.color(defval=color.yellow, title="", inline="MA-4", group="Lagging Moving Average")ma4Offset = input.int(defval=2, title="Offset Steps", minval=0, maxval=10, step=1, tooltip="The Magic happens here! The offset to move the line to the right.", inline="MA-4", group="Lagging Moving Average")⋯bandTransp = input.int(defval=60, title="Band Transparency", minval=20, maxval=80, step=10, group="Banding")-useBand1 = input(defval=true, title="Band 1", inline="Band", group="Banding")+useBand1 = input.bool(defval=true, title="Band 1", inline="Band", group="Banding")band1Transp = useBand1 ? bandTransp : 100band1clr = ma1 > ma2 ? color.new(#00ff00, transp=band1Transp) : color.new(#ff0000, transp=band1Transp)-useBand2 = input(defval=true, title="Band 2", inline="Band", group="Banding")+useBand2 = input.bool(defval=true, title="Band 2", inline="Band", group="Banding")band2Transp = useBand2 ? bandTransp : 100band2clr = ma1 > ma3 ? color.new(#00ff00, transp=band2Transp) : color.new(#ff0000, transp=band2Transp)-useBand3 = input(defval=true, title="Band 3", tooltip="Up trend green, down trend red. Colors get reversed if MA1 lenght is greater than MA2 lenght, or they are different type and MA2 quicker. In that case, just reverse your selections for MA1 and MA2, or let it be as is.", inline="Band", group="Banding")+useBand3 = input.bool(defval=true, title="Band 3", tooltip="Up trend green, down trend red. Colors get reversed if MA1 lenght is greater than MA2 lenght, or they are different type and MA2 quicker. In that case, just reverse your selections for MA1 and MA2, or let it be as is.", inline="Band", group="Banding")band3Transp = useBand3 ? bandTransp : 100⋯Does it run in Pine Script v6?
Yes
Same 227 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.
⋯// © MarkoP010 2023-//@version=5+//@version=6//The basic idea of the strategy is to select the best set of MAs, types, lenghts and offsets, which draws red trend bands for downtrend (and green for uptrend).⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 33 ms | With a workaround 1,000 bars in 74 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/// © MarkoP010 2023//@version=5//The basic idea of the strategy is to select the best set of MAs, types, lenghts and offsets, which draws red trend bands for downtrend (and green for uptrend).//Strategy executes by selected risk level either when there is MA crossover with price (Leading MA Offset1 on Highest risk level, Lagging MA on Low risk level) or three bands with the same color at the same time (on Lowest risk level, Leading MA Offset1 crossover with Lagging MA). //Strategy plots user selectable Moving Average lines, a colored trend band between the MA lines and pivot indicators. The trend bands can be turned off individually if required. Also pivot indicators can be turned off if required.//The Offset option shifts the selected MA with the set number of steps to the right. That is where the Magic happens and the Dragon roars!//Strategy version history://Version 1 - Initial script//Version 2 - Bug fix for Lowest risk level to show the indicator//Version 3 - Updated graph picture//Version 4 - Alert function and pivot indicators added, alerts are enabled when indicators are on. Inlining the code with the corresponding indicator.strategy("Flying Dragon Trend Strategy", shorttitle="Flying Dragon Trend Strategy", overlay=true, pyramiding=3, initial_capital=100000, default_qty_type=strategy.percent_of_equity, default_qty_value=5, commission_type=strategy.commission.cash_per_order, commission_value=10, calc_on_order_fills=false, process_orders_on_close=true)//Moving Averages functionMA(source, length, type) => type == "EMA" ? ta.ema(source, length) : type == "HMA" ? ta.hma(source, length) : type == "RMA" ? ta.rma(source, length) : type == "SMA" ? ta.sma(source, length) : type == "SWMA" ? ta.swma(source) : type == "VWMA" ? ta.vwma(source, length) : type == "WMA" ? ta.wma(source, length) : na//Strategy optionsstrDirection = input.string(defval="Both", title="Strategy Direction", options=["Both", "Long", "Short"], group="Strategy Options") //Strategy direction selector by DashTraderstrSelection = strDirection == "Long" ? strategy.direction.long : strDirection == "Short" ? strategy.direction.short : strategy.direction.all //Strategy direction selector by DashTraderstrategy.risk.allow_entry_in(strSelection)riskLevel = input.string(defval="Medium", title="Risk Level", options=["Highest", "High", "Medium", "Low", "Lowest"], inline="Options", group="Strategy Options")indicatorsOn = input(defval=true, title="Indicators", inline="Options", tooltip="Turn on or off pivot indicators. Strategy execution criteria. When risk level Highest then Leading MA Offset1 crossover with price triggers the indicator and executes the strategy, when Low then Lagging MA crossover with price, when Lowest then all the Bands are the same color (Leading MA Offset1 crossover with Lagging MA). Alerts are enabled when indicators are on. Create Alert on selected equity and timeframe, select on Condition this strategy and alert criteria (for example: Alert () function calls only), Create.", group="Strategy Options")useStop = input(defval=false, title="Use Stop Loss", inline="SL", group="Strategy Options")stopPrct = input.int(defval=10, title=" %", minval=0, maxval=100, step=1, inline="SL", group="Strategy Options") / 100//Inputsma1Type = input.string(defval="HMA", title="", inline="MA1", options=["EMA", "HMA", "RMA", "SMA","SWMA", "VWMA", "WMA"], group="Leading Moving Average") ma1Length = input.int(defval=35, title="",minval=1, inline="MA1", group="Leading Moving Average")ma1Source = input(defval=close, title="", tooltip="For short timeframes, minutes to hours, instead of Default values try Lowest risk level and HMA75 with Offsets 0,1,4 and SMA12 with Offset 6.", inline="MA1", group="Leading Moving Average")ma1Color = input(defval=color.purple, title="", inline="MA-1", group="Leading Moving Average")ma1Offset = input.int(defval=0, title="Offset1 Steps", minval=0, maxval=10, step=1, tooltip="The Magic happens here! The offset to move the line to the right.", inline="MA-1", group="Leading Moving Average")ma1 = MA(ma1Source, ma1Length, ma1Type)[ma1Offset]ma2Color = input(defval=color.lime, title="", inline="MA-2", group="Leading Moving Average")ma2Offset = input.int(defval=4, title="Offset2 Steps", minval=0, maxval=10, step=1, tooltip="The Magic happens here! The offset to move the line to the right.", inline="MA-2", group="Leading Moving Average")ma2 = ma1[ma2Offset]ma3Color = input(defval=color.aqua, title="", inline="MA-3", group="Leading Moving Average")ma3Offset = input.int(defval=6, title="Offset3 Steps", minval=0, maxval=10, step=1, tooltip="The Magic happens here! The offset to move the line to the right.", inline="MA-3", group="Leading Moving Average")ma3 = ma1[ma3Offset]ma4Type = input.string(defval="SMA", title="", inline="MA4", options=["EMA", "HMA", "RMA", "SMA","SWMA", "VWMA", "WMA"], group="Lagging Moving Average") ma4Length = input.int(defval=22, title="",minval=1, inline="MA4", group="Lagging Moving Average")ma4Source = input(defval=close, title="", inline="MA4", group="Lagging Moving Average")ma4Color = input(defval=color.yellow, title="", inline="MA-4", group="Lagging Moving Average")ma4Offset = input.int(defval=2, title="Offset Steps", minval=0, maxval=10, step=1, tooltip="The Magic happens here! The offset to move the line to the right.", inline="MA-4", group="Lagging Moving Average")ma4 = MA(ma4Source, ma4Length, ma4Type)[ma4Offset]bandTransp = input.int(defval=60, title="Band Transparency", minval=20, maxval=80, step=10, group="Banding")useBand1 = input(defval=true, title="Band 1", inline="Band", group="Banding")band1Transp = useBand1 ? bandTransp : 100band1clr = ma1 > ma2 ? color.new(#00ff00, transp=band1Transp) : color.new(#ff0000, transp=band1Transp)useBand2 = input(defval=true, title="Band 2", inline="Band", group="Banding")band2Transp = useBand2 ? bandTransp : 100band2clr = ma1 > ma3 ? color.new(#00ff00, transp=band2Transp) : color.new(#ff0000, transp=band2Transp)useBand3 = input(defval=true, title="Band 3", tooltip="Up trend green, down trend red. Colors get reversed if MA1 lenght is greater than MA2 lenght, or they are different type and MA2 quicker. In that case, just reverse your selections for MA1 and MA2, or let it be as is.", inline="Band", group="Banding")band3Transp = useBand3 ? bandTransp : 100band3clr = ma1 > ma4 ? color.new(#00ff00, transp=band3Transp) : color.new(#ff0000, transp=band3Transp)//Graphspiirto1 = plot(ma1, color = ma1Color, title="MA1")piirto2 = plot(ma2, color = ma2Color, title="MA2")piirto3 = plot(ma3, color = ma3Color, title="MA3")piirto4 = plot(ma4, color = ma4Color, title="MA4")fill(piirto1, piirto2, color=band1clr)fill(piirto1, piirto3, color=band2clr)fill(piirto1, piirto4, color=band3clr)//Strategy entry and stop conditions, indicator plot conditionslongCondition = riskLevel == "Highest" ? ma1Source > ma1 : riskLevel == "High" ? ma1Source > ma2 : riskLevel == "Medium" ? ma1Source > ma3 : riskLevel == "Low" ? ma4Source > ma4 : riskLevel == "Lowest" ? ma1 > ma4 : nashortCondition = riskLevel == "Highest" ? ma1Source < ma1 : riskLevel == "High" ? ma1Source < ma2 : riskLevel == "Medium" ? ma1Source < ma3 : riskLevel == "Low" ? ma4Source < ma4 : riskLevel == "Lowest" ? ma1 < ma4 : napivotUp = longCondition and shortCondition[1] and indicatorsOn ? true : napivotDown = shortCondition and longCondition[1] and indicatorsOn ? true : naplotshape(pivotUp, title="Up", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)plotshape(pivotDown, title="Down", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)stopLprice = useStop == true ? strategy.position_avg_price * (1-stopPrct) : nastopSprice = useStop == true ? strategy.position_avg_price * (1+stopPrct) : naif longCondition strategy.entry("Long",strategy.long) strategy.exit("Long Stop", "Long", stop=stopLprice) if shortCondition strategy.entry("Short",strategy.short) strategy.exit("Short Stop", "Short", stop=stopSprice)//Alertsif pivotUp alertMessage = syminfo.ticker + ' - ' + timeframe.period + ": Pivot Up!" alert(alertMessage, alert.freq_once_per_bar_close)if pivotDown alertMessage = syminfo.ticker + ' - ' + timeframe.period + ": Pivot Down!" alert(alertMessage, alert.freq_once_per_bar_close)//End