Pine Script v5 · Strategy
Forex Fractal EMA Scalper
A Pine Script v5 strategy built on EMA (hl2, 10). It has 4 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. 7 settings; defaults include Period Fractals 2, Source for EMA's hl2 and Length EMA 1 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 Forex Fractal EMA Scalper repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 34 of 34 trades.
- How did Forex Fractal EMA Scalper do on BTCUSDT 1D with default settings?
- −0.00%
- From 26 Jan 2024 to 21 Oct 2026, over 97 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Forex Fractal EMA Scalper 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: 97 before, 70 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 Forex Fractal EMA Scalper use a stop loss?
- Yes
- strategy.exit sets a stop on line 54, 55.
- Does Forex Fractal EMA Scalper run in Zeal Terminal?
- Yes
- It compiles in 27 ms and runs 1,000 bars in 83 ms, in the browser.
BTCUSDT · 1D · default settings
- EMA
- EMA
- EMA
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −0.00%
- −$27.50
- Buy and hold
- +102.5%
- same period
- Closed trades
- 97
- 43 won · 54 lost
- Profitable
- 44.3%
- of closed trades
- Profit factor
- 0.80
- gross profit ÷ gross loss
- Max drawdown
- 0.00%
- −$30.00
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
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
-
Note
Uses an argument v6 removed
when = on line 50, 51. The upgraded version below moves each call inside an if block.
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 |
|---|---|---|---|
| Optimization Parameters | |||
| Period Fractals | 2 | int · min 2 | upflagDownFrontier upflagUpFrontier0 upflagUpFrontier1 upflagUpFrontier2 upflagUpFrontier3 upflagUpFrontier4 downflagDownFrontier downflagUpFrontier0 downflagUpFrontier1 downflagUpFrontier2 downflagUpFrontier3 downflagUpFrontier4 line 21 line 37 |
| Source for EMA's | hl2 | source | out1 out2 out3 |
| Length EMA 1 | 10 | int · min 1 | out1 |
| Length EMA 2 | 20 | int · min 1 | out2 |
| Length EMA 3 | 100 | int · min 1 | out3 |
| Risk Management | |||
| TP in PIPS | 25 | int | exit X_long exit x_short |
| SL in PIPS | 25 | int | exit X_long exit x_short |
What it calculates
- EMASource for EMA's (hl2), Length EMA 1 (10)
out1 · line 9 - EMASource for EMA's (hl2), Length EMA 2 (20)
out2 · line 11 - EMASource for EMA's (hl2), Length EMA 3 (100)
out3 · line 13
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 | shortout1 < out2 and out2<out3 and downFractal | On | 50 |
| Open short short | longout1 > out2 and out2>out3 and upFractal | On | 51 |
| Exit X_long stop and limit | every bar | On | 54 |
| Exit x_short stop and limit | every bar | On | 55 |
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 | −0.0% | +102.5% | 97 | 44% | 0.80 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +0.0% | +5.5% | 97 | 52% | 1.06 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +0.0% | +9.8% | 89 | 52% | 1.07 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.0% | +8.4% | 106 | 57% | 1.30 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −0.0% | +16.7% | 95 | 49% | 0.98 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 63 | 51% | 1.03 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | 0.0% | +148.3% | 92 | 50% | 1.00 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.0% | +17.1% | 100 | 45% | 0.82 | 0.0% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
Settings heatmap
Two settings that feed the entry signal, moved around their defaults. The best in-sample pair (Length EMA 1 12, Length EMA 2 10) made +0.0% before 26 Dec 2025 and +0.0% after it, against −0.0% for the defaults. 9% of the 64 combinations made money in-sample and 31% out-of-sample.
| Length EMA 2 ↓ · Length EMA 1 → | 5 | 6 | 7 | 9 | 10 | 12 | 14 | 17 |
|---|---|---|---|---|---|---|---|---|
| 10 | −0% | −0% | −0% | −0% | 0% | +0% | +0% | +0% |
| 12 | −0% | −0% | −0% | −0% | −0% | 0% | +0% | +0% |
| 14 | −0% | −0% | −0% | −0% | −0% | −0% | 0% | +0% |
| 17 | −0% | −0% | −0% | −0% | −0% | −0% | −0% | 0% |
| 20 | −0% | −0% | −0% | −0% | −0% | −0% | −0% | −0% |
| 24 | −0% | −0% | −0% | −0% | −0% | −0% | −0% | −0% |
| 28 | −0% | −0% | −0% | −0% | −0% | −0% | −0% | −0% |
| 34 | −0% | −0% | −0% | −0% | −0% | −0% | −0% | −0% |
| Length EMA 2 ↓ · Length EMA 1 → | 5 | 6 | 7 | 9 | 10 | 12 | 14 | 17 |
|---|---|---|---|---|---|---|---|---|
| 10 | +0% | +0% | +0% | +0% | 0% | +0% | +0% | +0% |
| 12 | +0% | +0% | +0% | +0% | +0% | 0% | +0% | +0% |
| 14 | 0% | 0% | +0% | 0% | +0% | +0% | 0% | +0% |
| 17 | +0% | 0% | 0% | +0% | 0% | −0% | −0% | 0% |
| 20 | −0% | −0% | −0% | −0% | −0% | −0% | −0% | −0% |
| 24 | −0% | −0% | −0% | −0% | −0% | −0% | −0% | −0% |
| 28 | −0% | −0% | −0% | −0% | −0% | −0% | −0% | −0% |
| 34 | −0% | −0% | −0% | −0% | −0% | −0% | −0% | −0% |
Net P&L of trades opened in each period, as a share of starting capital. marks the defaults and the best in-sample cell. Hover a cell for its trade count. 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 | 29 | 38% | −$17.50 |
| Sideways market | 41 | 49% | −$2.50 |
| Falling market | 27 | 44% | −$7.50 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
0.0%
The 95th percentile of the worst drawdown when the same 97 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 0.0% to 0.0%; the tick is what actually happened, 0.0%. Order luck alone moves it this much.
All 97 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 24 May 2024 67,969.70 | 24 May 2024 67,972.20 | 0 | −$2.50 |
| short | 30 May 2024 67,652.40 | 30 May 2024 67,649.90 | 0 | $2.50 |
| short | 10 Jun 2024 69,648.10 | 10 Jun 2024 69,645.60 | 0 | $2.50 |
| short | 13 Jun 2024 68,264.00 | 13 Jun 2024 68,266.50 | 0 | −$2.50 |
| long | 1 Jul 2024 62,772.00 | 1 Jul 2024 62,769.50 | 0 | −$2.50 |
| long | 8 Jul 2024 55,857.80 | 8 Jul 2024 55,855.30 | 0 | −$2.50 |
| long | 11 Jul 2024 57,725.80 | 11 Jul 2024 57,723.30 | 0 | −$2.50 |
| long | 15 Jul 2024 60,797.90 | 15 Jul 2024 60,795.40 | 0 | −$2.50 |
| short | 25 Jul 2024 65,376.00 | 25 Jul 2024 65,378.50 | 0 | −$2.50 |
| short | 1 Aug 2024 64,628.00 | 1 Aug 2024 64,630.50 | 0 | −$2.50 |
| long | 8 Aug 2024 55,133.80 | 8 Aug 2024 55,131.30 | 0 | −$2.50 |
| long | 15 Aug 2024 58,683.40 | 15 Aug 2024 58,685.90 | 0 | $2.50 |
| long | 18 Aug 2024 59,492.00 | 18 Aug 2024 59,494.50 | 0 | $2.50 |
| long | 22 Aug 2024 61,156.00 | 22 Aug 2024 61,158.50 | 0 | $2.50 |
| long | 9 Sep 2024 54,869.90 | 9 Sep 2024 54,867.40 | 0 | −$2.50 |
| short | 30 Sep 2024 65,602.00 | 30 Sep 2024 65,604.50 | 0 | −$2.50 |
| short | 10 Oct 2024 60,636.00 | 10 Oct 2024 60,638.50 | 0 | −$2.50 |
| short | 24 Oct 2024 66,668.60 | 24 Oct 2024 66,666.10 | 0 | $2.50 |
| short | 27 Oct 2024 67,092.80 | 27 Oct 2024 67,090.30 | 0 | $2.50 |
| short | 1 Nov 2024 70,292.00 | 1 Nov 2024 70,294.50 | 0 | −$2.50 |
| short | 16 Nov 2024 91,032.10 | 16 Nov 2024 91,034.60 | 0 | −$2.50 |
| short | 25 Nov 2024 97,900.10 | 25 Nov 2024 97,902.60 | 0 | −$2.50 |
| short | 2 Dec 2024 97,185.20 | 2 Dec 2024 97,187.70 | 0 | −$2.50 |
| short | 8 Dec 2024 99,832.00 | 8 Dec 2024 99,829.50 | 0 | $2.50 |
| short | 20 Dec 2024 97,461.90 | 20 Dec 2024 97,464.40 | 0 | −$2.50 |
| short | 23 Jan 2025 103,707.00 | 23 Jan 2025 103,704.00 | 0 | $2.50 |
| short | 27 Jan 2025 102,620.00 | 27 Jan 2025 102,623.00 | 0 | −$2.50 |
| short | 2 Feb 2025 100,636.00 | 2 Feb 2025 100,638.00 | 0 | −$2.50 |
| long | 3 Mar 2025 94,270.00 | 3 Mar 2025 94,272.50 | 0 | $2.50 |
| long | 7 Mar 2025 89,931.90 | 7 Mar 2025 89,934.40 | 0 | $2.50 |
| long | 14 Mar 2025 81,115.80 | 14 Mar 2025 81,113.30 | 0 | −$2.50 |
| long | 21 Mar 2025 84,223.40 | 21 Mar 2025 84,225.90 | 0 | $2.50 |
| long | 3 Apr 2025 82,516.30 | 3 Apr 2025 82,513.80 | 0 | −$2.50 |
| long | 6 Apr 2025 83,538.00 | 6 Apr 2025 83,540.50 | 0 | $2.50 |
| long | 10 Apr 2025 82,615.20 | 10 Apr 2025 82,617.70 | 0 | $2.50 |
| short | 28 Apr 2025 93,749.30 | 28 Apr 2025 93,746.80 | 0 | $2.50 |
| short | 1 May 2025 94,172.00 | 1 May 2025 94,169.50 | 0 | $2.50 |
| short | 5 May 2025 94,277.60 | 5 May 2025 94,275.10 | 0 | $2.50 |
| short | 15 May 2025 103,508.00 | 15 May 2025 103,510.00 | 0 | −$2.50 |
| short | 25 May 2025 107,762.00 | 25 May 2025 107,759.00 | 0 | $2.50 |
| short | 30 May 2025 105,590.00 | 30 May 2025 105,592.00 | 0 | −$2.50 |
| short | 6 Jun 2025 101,509.00 | 6 Jun 2025 101,506.00 | 0 | $2.50 |
| short | 12 Jun 2025 108,645.00 | 12 Jun 2025 108,648.00 | 0 | −$2.50 |
| short | 19 Jun 2025 104,887.00 | 19 Jun 2025 104,889.00 | 0 | −$2.50 |
| short | 29 Jun 2025 107,297.00 | 29 Jun 2025 107,294.00 | 0 | $2.50 |
| short | 6 Jul 2025 108,198.00 | 6 Jul 2025 108,196.00 | 0 | $2.50 |
| short | 17 Jul 2025 118,630.00 | 17 Jul 2025 118,628.00 | 0 | $2.50 |
| short | 20 Jul 2025 117,840.00 | 20 Jul 2025 117,843.00 | 0 | −$2.50 |
| short | 25 Jul 2025 118,341.00 | 25 Jul 2025 118,343.00 | 0 | −$2.50 |
| short | 31 Jul 2025 117,840.00 | 31 Jul 2025 117,843.00 | 0 | −$2.50 |
| short | 17 Aug 2025 117,381.00 | 17 Aug 2025 117,378.00 | 0 | $2.50 |
| short | 15 Sep 2025 115,268.00 | 15 Sep 2025 115,266.00 | 0 | $2.50 |
| short | 21 Sep 2025 115,686.00 | 21 Sep 2025 115,688.00 | 0 | −$2.50 |
| short | 9 Oct 2025 123,306.00 | 9 Oct 2025 123,309.00 | 0 | −$2.50 |
| long | 25 Oct 2025 111,005.00 | 25 Oct 2025 111,002.00 | 0 | −$2.50 |
| long | 2 Nov 2025 110,098.00 | 2 Nov 2025 110,096.00 | 0 | −$2.50 |
| long | 7 Nov 2025 101,346.00 | 7 Nov 2025 101,344.00 | 0 | −$2.50 |
| long | 24 Nov 2025 86,830.00 | 24 Nov 2025 86,827.50 | 0 | −$2.50 |
| long | 4 Dec 2025 93,429.90 | 4 Dec 2025 93,432.40 | 0 | $2.50 |
| long | 10 Dec 2025 92,678.80 | 10 Dec 2025 92,676.30 | 0 | −$2.50 |
| long | 14 Dec 2025 90,240.00 | 14 Dec 2025 90,242.50 | 0 | $2.50 |
| long | 18 Dec 2025 86,243.20 | 18 Dec 2025 86,240.70 | 0 | −$2.50 |
| long | 21 Dec 2025 88,360.90 | 21 Dec 2025 88,363.40 | 0 | $2.50 |
| long | 27 Dec 2025 87,369.60 | 27 Dec 2025 87,367.10 | 0 | −$2.50 |
| long | 1 Jan 2026 87,648.20 | 1 Jan 2026 87,645.70 | 0 | −$2.50 |
| long | 24 Jan 2026 89,600.30 | 24 Jan 2026 89,602.80 | 0 | $2.50 |
| long | 28 Jan 2026 89,250.00 | 28 Jan 2026 89,247.50 | 0 | −$2.50 |
| long | 9 Feb 2026 70,330.40 | 9 Feb 2026 70,332.90 | 0 | $2.50 |
| long | 15 Feb 2026 69,822.90 | 15 Feb 2026 69,825.40 | 0 | $2.50 |
| long | 22 Feb 2026 67,975.90 | 22 Feb 2026 67,978.40 | 0 | $2.50 |
| long | 27 Feb 2026 67,485.20 | 27 Feb 2026 67,487.70 | 0 | $2.50 |
| long | 3 Mar 2026 68,830.10 | 3 Mar 2026 68,832.60 | 0 | $2.50 |
| long | 11 Mar 2026 69,948.60 | 11 Mar 2026 69,946.10 | 0 | −$2.50 |
| long | 1 Apr 2026 68,284.50 | 1 Apr 2026 68,282.00 | 0 | −$2.50 |
| long | 5 Apr 2026 67,300.40 | 5 Apr 2026 67,297.90 | 0 | −$2.50 |
| short | 9 May 2026 80,193.20 | 9 May 2026 80,190.70 | 0 | $2.50 |
| short | 13 May 2026 80,504.50 | 13 May 2026 80,507.00 | 0 | −$2.50 |
| short | 17 May 2026 78,148.10 | 17 May 2026 78,150.60 | 0 | −$2.50 |
| long | 1 Jun 2026 73,674.40 | 1 Jun 2026 73,676.90 | 0 | $2.50 |
| long | 8 Jun 2026 63,332.00 | 8 Jun 2026 63,334.50 | 0 | $2.50 |
| long | 13 Jun 2026 63,580.00 | 13 Jun 2026 63,577.50 | 0 | −$2.50 |
| long | 21 Jun 2026 64,298.00 | 21 Jun 2026 64,300.50 | 0 | $2.50 |
| long | 28 Jun 2026 60,029.00 | 28 Jun 2026 60,031.50 | 0 | $2.50 |
| long | 4 Jul 2026 62,583.30 | 4 Jul 2026 62,580.80 | 0 | −$2.50 |
| long | 9 Jul 2026 62,290.00 | 9 Jul 2026 62,287.50 | 0 | −$2.50 |
| long | 4 Aug 2026 63,520.00 | 4 Aug 2026 63,517.50 | 0 | −$2.50 |
| long | 17 Aug 2026 62,900.00 | 17 Aug 2026 62,897.50 | 0 | −$2.50 |
| short | 24 Aug 2026 77,734.00 | 24 Aug 2026 77,731.50 | 0 | $2.50 |
| short | 28 Aug 2026 80,249.60 | 28 Aug 2026 80,252.10 | 0 | −$2.50 |
| short | 31 Aug 2026 77,682.00 | 31 Aug 2026 77,679.50 | 0 | $2.50 |
| short | 6 Sep 2026 79,831.80 | 6 Sep 2026 79,829.30 | 0 | $2.50 |
| short | 14 Sep 2026 76,842.00 | 14 Sep 2026 76,839.50 | 0 | $2.50 |
| short | 17 Sep 2026 76,206.00 | 17 Sep 2026 76,203.50 | 0 | $2.50 |
| short | 24 Sep 2026 84,397.60 | 24 Sep 2026 84,400.10 | 0 | −$2.50 |
| short | 5 Oct 2026 86,530.00 | 5 Oct 2026 86,532.50 | 0 | −$2.50 |
| short | 8 Oct 2026 83,321.80 | 8 Oct 2026 83,324.30 | 0 | −$2.50 |
| short | 15 Oct 2026 81,682.00 | 15 Oct 2026 81,684.50 | 0 | −$2.50 |
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 |
|---|---|---|---|---|---|
| Forex Fractal EMA Scalper this page | — | v5 strategy | −0.0% | 97 | 0.0% |
| EMA Slope AyE by fajardoarelys | ema | v4 strategy | No trades on this market | ||
| ROoT by realisticDove62527 | ema | v5 strategy | −4.7% | 225 | 9.4% |
| sachin5986 by mohitesachin78 | ema | v4 strategy | +32.1% | 35 | 17.6% |
| sonu1997 by Sonu1997 | ema | v4 strategy | +960.7% | 2 | 1,103.8% |
| Moving Average Crossover by Muh4mm4d | ema | v4 strategy | +19,990.1% | 30 | 1,274.2% |
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.
- 2 strategy calls use the when = argument (line 50, 51). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- 3 settings use the untyped input() (line 7, 52, 53). 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 97 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 7: input() → input.source()
- Line 50: when = short → if block
- Line 51: when = long → if block
- Line 52: input() → input.int()
- Line 53: input() → input.int()
⋯n = input.int(title="Period Fractals", defval=2, minval=2, group="Optimization Parameters")-src = input(hl2, title="Source for EMA's", group="Optimization Parameters")+src = input.source(hl2, title="Source for EMA's", group="Optimization Parameters")len1 = input.int(10, minval=1, title="Length EMA 1", group="Optimization Parameters")⋯short= out1 < out2 and out2<out3 and downFractal-strategy.entry("long",strategy.long,when= short)+if short+ strategy.entry("long",strategy.long)-strategy.entry("short",strategy.short,when=long)+if long+ strategy.entry("short",strategy.short)-tp=input(25, title="TP in PIPS", group="Risk Management")*10+tp=input.int(25, title="TP in PIPS", group="Risk Management")*10-sl=input(25, title="SL in PIPS", group="Risk Management")*10+sl=input.int(25, title="SL in PIPS", group="Risk Management")*10strategy.exit("X_long", "long", profit=tp, loss=sl )⋯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: 97 before, 70 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.
⋯// © exlux99-//@version=5+//@version=6strategy("Forex Fractal EMA Scalper", overlay=true)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 27 ms | Yes 1,000 bars in 83 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/// © exlux99//@version=5strategy("Forex Fractal EMA Scalper", overlay=true)// Define "n" as the number of periods and keep a minimum value of 2 for error handling.n = input.int(title="Period Fractals", defval=2, minval=2, group="Optimization Parameters")src = input(hl2, title="Source for EMA's", group="Optimization Parameters")len1 = input.int(10, minval=1, title="Length EMA 1", group="Optimization Parameters")out1 = ta.ema(src, len1)len2 = input.int(20, minval=1, title="Length EMA 2", group="Optimization Parameters")out2 = ta.ema(src, len2)len3 = input.int(100, minval=1, title="Length EMA 3", group="Optimization Parameters")out3 = ta.ema(src, len3)// UpFractalbool upflagDownFrontier = truebool upflagUpFrontier0 = truebool upflagUpFrontier1 = truebool upflagUpFrontier2 = truebool upflagUpFrontier3 = truebool upflagUpFrontier4 = truefor i = 1 to n upflagDownFrontier := upflagDownFrontier and (high[n-i] < high[n]) upflagUpFrontier0 := upflagUpFrontier0 and (high[n+i] < high[n]) upflagUpFrontier1 := upflagUpFrontier1 and (high[n+1] <= high[n] and high[n+i + 1] < high[n]) upflagUpFrontier2 := upflagUpFrontier2 and (high[n+1] <= high[n] and high[n+2] <= high[n] and high[n+i + 2] < high[n]) upflagUpFrontier3 := upflagUpFrontier3 and (high[n+1] <= high[n] and high[n+2] <= high[n] and high[n+3] <= high[n] and high[n+i + 3] < high[n]) upflagUpFrontier4 := upflagUpFrontier4 and (high[n+1] <= high[n] and high[n+2] <= high[n] and high[n+3] <= high[n] and high[n+4] <= high[n] and high[n+i + 4] < high[n])flagUpFrontier = upflagUpFrontier0 or upflagUpFrontier1 or upflagUpFrontier2 or upflagUpFrontier3 or upflagUpFrontier4upFractal = (upflagDownFrontier and flagUpFrontier)// downFractalbool downflagDownFrontier = truebool downflagUpFrontier0 = truebool downflagUpFrontier1 = truebool downflagUpFrontier2 = truebool downflagUpFrontier3 = truebool downflagUpFrontier4 = truefor i = 1 to n downflagDownFrontier := downflagDownFrontier and (low[n-i] > low[n]) downflagUpFrontier0 := downflagUpFrontier0 and (low[n+i] > low[n]) downflagUpFrontier1 := downflagUpFrontier1 and (low[n+1] >= low[n] and low[n+i + 1] > low[n]) downflagUpFrontier2 := downflagUpFrontier2 and (low[n+1] >= low[n] and low[n+2] >= low[n] and low[n+i + 2] > low[n]) downflagUpFrontier3 := downflagUpFrontier3 and (low[n+1] >= low[n] and low[n+2] >= low[n] and low[n+3] >= low[n] and low[n+i + 3] > low[n]) downflagUpFrontier4 := downflagUpFrontier4 and (low[n+1] >= low[n] and low[n+2] >= low[n] and low[n+3] >= low[n] and low[n+4] >= low[n] and low[n+i + 4] > low[n])flagDownFrontier = downflagUpFrontier0 or downflagUpFrontier1 or downflagUpFrontier2 or downflagUpFrontier3 or downflagUpFrontier4downFractal = (downflagDownFrontier and flagDownFrontier)// plotshape(downFractal, style=shape.triangledown, location=location.belowbar, offset=-n, color=#F44336, size = size.small)// plotshape(upFractal, style=shape.triangleup, location=location.abovebar, offset=-n, color=#009688, size = size.small)long= out1 > out2 and out2>out3 and upFractalshort= out1 < out2 and out2<out3 and downFractalstrategy.entry("long",strategy.long,when= short)strategy.entry("short",strategy.short,when=long)tp=input(25, title="TP in PIPS", group="Risk Management")*10sl=input(25, title="SL in PIPS", group="Risk Management")*10strategy.exit("X_long", "long", profit=tp, loss=sl )strategy.exit("x_short", "short",profit=tp, loss=sl )