Pine Script v5 · Strategy
EMA bands + leledc + bollinger bands trend following strategy v2
A Pine Script v5 strategy built on EMA (close, 34), SMA (close, 20) and Stdev (close, 20). It has 110 order rules, 24 entries among them, and trades long and short with the default settings; 4 entries are switched off until a setting enables them. Exits use a stop loss and a profit target. Each trade commits 100% of equity and pays 0.036 commission. 61 settings; defaults include EMA Length 34, Top middle band multiplier 1 and Bottom middle band multiplier 1.
Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.
- Does EMA bands + leledc + bollinger bands trend following strategy v2 repaint?
- Yes
- At least one pattern in the source can repaint: intrabar recalculation.
- How did EMA bands + leledc + bollinger bands trend following strategy v2 do on BTCUSDT 1D with default settings?
- +7.75%
- From 26 Jan 2024 to 21 Oct 2026, over 38 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does EMA bands + leledc + bollinger bands trend following strategy v2 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: 38 before, 38 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 EMA bands + leledc + bollinger bands trend following strategy v2 use a stop loss?
- Yes
- strategy.exit sets a stop on line 646, 648, 672, 674.
- Does EMA bands + leledc + bollinger bands trend following strategy v2 run in Zeal Terminal?
- Yes
- It compiles in 256 ms and runs 1,000 bars in 213 ms, in the browser.
BTCUSDT · 1D · default settings
- Char
- Char
- Winning trade
- Losing trade
- Equity
- Buy and hold
Needs BINANCE:BTCUSDT 360 data, not available: a lower timeframe than the chart; the engine does not evaluate intrabar data Values that depend on it are empty on this chart.
- Net profit
- +7.75%
- $77.53
- Buy and hold
- +102.5%
- same period
- Closed trades
- 38
- 10 won · 28 lost
- Profitable
- 26.3%
- of closed trades
- Profit factor
- 1.07
- gross profit ÷ gross loss
- Max drawdown
- 31.97%
- −$352.55
One run with the author's default settings, $1,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.
-
Likely bug
ta.sma(volume, 100) ignores the settings line 177
Line 177 hard-codes volume where line 95 uses “Source” and 100 where line 95 uses “Bollinger Bands SMA Period Length”. Changing those settings moves one band but not this one.
ta.sma(volume,100)ta.sma(i_srcBB, i_BBlength) -
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
1 setting has no label
In the settings dialog res (line 57) shows an empty name. The labels on this page come from the variable names.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
-
Note
The long side is off by default line 381
Its orders only fire after “Use slow EMA filter” is switched on. The figures on this page cover long and long and long and short and short and short and counter trend short and counter trend short and counter trend short and counter trend short and counter trend long and counter trend long and counter trend long and counter trend long and counter trend long and counter trend long and counter trend short and counter trend short and default long and default short trades only.
-
Note
The short side is off by default line 407
Its orders only fire after “Use slow EMA filter” is switched on. The figures on this page cover long and long and long and short and short and short and counter trend short and counter trend short and counter trend short and counter trend short and counter trend long and counter trend long and counter trend long and counter trend long and counter trend long and counter trend long and counter trend short and counter trend short and default long and default short trades only.
-
Note
The default long side is off by default line 686
Its orders only fire after “Use slow EMA filter” is switched on. The figures on this page cover long and long and long and short and short and short and counter trend short and counter trend short and counter trend short and counter trend short and counter trend long and counter trend long and counter trend long and counter trend long and counter trend long and counter trend long and counter trend short and counter trend short and default long and default short trades only.
-
Note
The default short side is off by default line 692
Its orders only fire after “Use slow EMA filter” is switched on. The figures on this page cover long and long and long and short and short and short and counter trend short and counter trend short and counter trend short and counter trend short and counter trend long and counter trend long and counter trend long and counter trend long and counter trend long and counter trend long and counter trend short and counter trend short and default long and default short trades only.
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 |
|---|---|---|---|
| EMA Length | 34 | int · min 1 · step 1 | EMA rangema highShortEMA lowShortEMA |
| Open Conditions | |||
| Enable middle EMA band breakout: Long | true | bool | line 358 |
| Enable middle EMA band breakdown: Short | true | bool | line 384 |
| Enable middle EMA band bounce re-entry: LongWorks best when early close conditions are used | false | bool | longBounce |
| Enable middle EMA band bounce re-entry: ShortWorks best when early close conditions are used | false | bool | shortBounce |
| Enable default positioning: LongDoes not work with "Enable default positioning: Short" also selected. Works best when early close conditions are used | false | bool | line 681 line 687 line 709 line 728 line 747 line 764 |
| Enable default positioning: ShortDoes not work with "Enable default positioning: Long" also selected. Works best when early close conditions are used | false | bool | line 681 line 687 line 704 line 723 line 742 line 759 |
| Top middle band multiplier | 1 | float · step 0.1 | middleBandTop shortbandsHigh phiExtensionHigh |
| Bottom middle band multiplier | 1 | float · step 0.1 | middleBandBot shortbandsLow phiExtensionLow |
| Use slow EMA filterCondition does not apply to counter-trend trades | false | bool | close Short close Counter Trend Short close Default Short entry Long close Long close Counter Trend Long close Default Long entry Short entry Default Long entry Default Short line 359 line 371 line 385 line 397 line 682 line 688 |
| Slow EMA Length | 200 | int · min 1 · step 1 | slowEMA |
| Close Conditions | |||
| Close on crosses through middle EMA bandsSelecting "Delayed bars inside" will closing positions after specified amount of candles close in between the middle EMA bands without breaking out | Opposite band | string · options ['Nearest band', 'Opposite band', 'Delayed bars inside'] | line 556 line 559 line 562 line 610 line 613 line 616 line 713 line 715 line 732 line 734 line 751 line 753 line 768 line 770 |
| Delayed close no. of bars | 4 | int · min 1 · max 10 · step 1 | close Long close Short line 509 line 566 line 620 |
| Close on Leledc bars | false | bool | line 422 line 435 line 538 line 547 line 592 line 601 |
| Which Leledc bar? | First | string · options ['First', 'Second', 'Third', 'Fourth', 'Fifth'] | numLele |
| Close on Bollinger Band exhaustion barsBollinger Band Exhaustion bars are candles that close back inside the Bollinger Bands when RSI is overbought or oversold. Settings for both can be changed under the -Bollinger Bands Exhaustion Bar Settings- header. | false | bool | line 458 line 471 line 520 line 529 line 574 line 583 |
| Which BB exhaustion bar? | First | string · options ['First', 'Second', 'Third'] | numBBs |
| Close on loss of Buy/Sell zone | false | bool | line 517 line 571 |
| Which Buy/Sell zone? | Inner | string · options ['Inner', 'Outer'] | line 488 |
| Counter Trade Settings | |||
| Enable counter-trend trades: LongDoes not work with "Enable default positioning: Short" selected | false | bool | line 577 line 586 line 595 line 604 line 628 line 709 line 728 line 747 line 764 |
| Trigger | Leledc | string · options ['Leledc', 'BB Exhaustion'] | line 577 line 586 line 595 line 604 line 629 |
| Enable counter-trend trades: ShortDoes not work with "Enable default positioning: Long" selected" | false | bool | line 523 line 532 line 541 line 550 line 654 line 704 line 723 line 742 line 759 |
| Trigger | Leledc | string · options ['Leledc', 'BB Exhaustion'] | line 523 line 532 line 541 line 550 line 655 |
| Leledc/BB must be outside which Buy/Sell zone to open | Inner | string · options ['Inner', 'Outer'] | line 271 |
| Closing conditions for counter-trend longs-Cross- type close conditions market close position on candle closes above selected region \n\n-Touch- type enable trailing limit orders that follow the selected region | Cross Top Middle Band | string · options ['Cross Outer Buy Zone', 'Cross Inner Buy Zone', 'Touch Inner Buy Zone', 'Cross Bottom Middle Band', 'Touch Bottom Middle Band', 'Cross Top Middle Band', 'Touch Top Middle Band', 'Cross Inner Sell Zone', 'Touch Inner Sell Zone', 'Cross Outer Sell Zone', 'Touch Outer Sell Zone', 'First Leledc', 'First BB Exhaustion'] | CTlongCloseCond CTlongTP |
| Closing conditions for counter-trend shorts-Cross- type close conditions market close position on candle closes below selected region \n\n-Touch- type enable trailing limit orders that follow the selected region | First Leledc | string · options ['Cross Outer Sell Zone', 'Cross Inner Sell Zone', 'Touch Inner Sell Zone', 'Cross Top Middle Band', 'Touch Top Middle Band', 'Cross Bottom Middle Band', 'Touch Bottom Middle Band', 'Cross Inner Buy Zone', 'Touch Inner Buy Zone', 'Cross Outer Buy Zone', 'Touch Outer Buy Zone', 'First Leledc', 'First BB Exhaustion'] | CTshortCloseCond CTshortTP |
| Flat stop-loss % for counter-trend longs | 10 | float | CTlongSL exit Counter Trend Long line 644 line 649 |
| Flat stop-loss % for counter-trend shorts | 10 | float | CTshortSL exit Counter Trend Short line 670 line 675 |
| Keltner Buy/Sell Zones | |||
| Use Keltner channel multiples for "Buy/Sell Zones"Enables inputting custom multiples and a different/smoother calculation of "Buy/Sell Zones". Default calculation is a multiple of EMA band highs and lows | false | bool | rangema shortbandsHigh shortbandsLow phiExtensionHigh phiExtensionLow |
| Outer MultiplierOnly for "Buy/Sell Zones" calculated by Keltner channels | 5.0 | float | upper lower |
| Inner MultiplierOnly for "Buy/Sell Zones" calculated by Keltner channels | 3.0 | float | inner_upper inner_lower |
| BB-Keltner squeze | |||
| Filter out trades during BB-Keltner squeezes | false | bool | longBounce shortBounce shortMidBreak longMidBreak line 149 line 628 line 654 |
| Bollinger Band Crossover Condition | At Least One | string · options ['Both', 'At Least One'] | line 150 line 153 line 156 |
| BB Length | 30 | int · min 1 | B2basis B2dev |
| Keltner Length | 18 | int · min 1 | Kma Krangema |
| Use current timeframe | false | bool | res line 150 line 153 |
| Res (no label in the script) | 360 | timeframe | srcClose srcHigh srcLow |
| BB Standard Deviation | 2 | float · min 0.001 · max 50 | B2dev |
| Keltner Range | 1.5 | float | Kupper Klower |
| Bollinger Bands Exhaustion Bar Settings | |||
| Bollinger Bands SMA Period Length | 20 | int · min 1 | BBbasis BBdev |
| Bollinger Bands Standard Deviation | 1.8 | float · min 0.001 · max 50 | BBdev |
| RSI Period Length | 8 | int · min 1 · step 1 | vrsi |
| RSI Oversold Value | 30 | int · min 0 · max 50 · step 1 | RSIoverSold |
| RSI Overbought value | 70 | int · min 50 · max 100 · step 1 | RSIoverBought |
| Source | close | source | BBbasis BBdev vrsi OSOBcolor |
| Leledc Exhaustion Bar Settings | |||
| Require Volume breakout for Leledc bars | false | bool | line 191 |
| Volume Multiplier | 1.5 | float | leleVol |
| Highest / Lowest | 30 | int | major |
| Bar count no | 6 | int | major |
| Close | 4 | int | line 184 line 187 |
| bindexSindex | 1 | int | bindex sindex |
| Visual Elements | |||
| Enable Trend Bar ColorColor bars green when above mid bands, red when below, and gray when inside. Dark green and dark red bars signal a position is kept open from the delayed close settings. | false | bool | line 696 |
| Show "Buy/Sell Zones" | true | bool | Lower sell zone Higher buy zone Top sell zone Bottom buy zone |
| Show EMA | false | bool | EMA |
| Show middle EMA bands | true | bool | Top median zone Bottom median zone |
| Show Slow EMA | false | bool | plot |
| Show Leledc Exhausion Bars | true | bool | plotchar |
| Enable Bollinger Bands exhaustion bar coloring | true | bool | line 697 line 774 |
| Enable Bollinger bands exhaustion bar background coloringEnabling this can help visualize when dialing in Bollinger Bands and RSI settings | false | bool | bgcolor |
| Enable Buy/Sell zone failure bar coloring | false | bool | line 698 line 738 line 775 line 787 |
| Enable volatility squeeze (BB-Keltner) background coloring | true | bool | bgcolor |
What it calculates
- EMAclose, EMA Length (34)
EMA · line 87 - EMAclose, Slow EMA Length (200)
slowEMA · line 88 - SMASource (close), Bollinger Bands SMA Period Length (20)
BBbasis · line 95 - StdevSource (close), Bollinger Bands SMA Period Length (20)
BBdev · line 96 - RSISource (close), RSI Period Length (8)
vrsi · line 100 - RMAhigh - low, EMA Length (34)
rangema · line 111 - SMAsrcClose, BB Length (30)
B2basis · line 137 - StdevsrcClose, BB Length (30)
B2dev · line 138 - EMAsrcClose, Keltner Length (18)
Kma · line 142 - EMAKrange, Keltner Length (18)
Krangema · line 144 - Barssincenot srcClose == barstate.isrealtime
squeezing · line 151 - EMAhigh, EMA Length (34)
highShortEMA · line 226 - EMAlow, EMA Length (34)
lowShortEMA · line 227 - WMAshortbandsHigh, 8
shortbandsHighEMA · line 239 - WMAshortbandsLow, 8
shortbandsLowEMA · line 240 - WMAphiExtensionHigh, 8
phiExtensionHighEMA · line 246 - WMAphiExtensionLow, 8
phiExtensionLowEMA · line 247
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 129 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 |
|---|---|---|---|
| Close Short | longMidBreak and close > slowEMA and open < middleBandTop | On | 361 |
| Close Counter Trend Short | longMidBreak and close > slowEMA and open < middleBandTop | On | 362 |
| Close Default Short | longMidBreak and close > slowEMA and open < middleBandTop | On | 363 |
| Open Long long | longMidBreak and close > slowEMA and open < middleBandTop | On | 364 |
| Close Short | longMidBreak | On | 366 |
| Close Counter Trend Short | longMidBreak | On | 367 |
| Close Default Short | longMidBreak | On | 368 |
| Open Long long | longMidBreak | On | 369 |
| Close Short | close > slowEMA | On | 373 |
| Close Counter Trend Short | close > slowEMA | On | 374 |
| Close Default Short | close > slowEMA | On | 375 |
| Open Long long | close > slowEMA | On | 376 |
| Close Short | s_useSlowEMA | Off “Use slow EMA filter” | 378 |
| Close Counter Trend Short | s_useSlowEMA | Off “Use slow EMA filter” | 379 |
| Close Default Short | s_useSlowEMA | Off “Use slow EMA filter” | 380 |
| Open Long long | s_useSlowEMA | Off “Use slow EMA filter” | 381 |
| Close Long | shortMidBreak and close < slowEMA and open > middleBandBot | On | 387 |
| Close Counter Trend Long | shortMidBreak and close < slowEMA and open > middleBandBot | On | 388 |
| Close Default Long | shortMidBreak and close < slowEMA and open > middleBandBot | On | 389 |
| Open Short short | shortMidBreak and close < slowEMA and open > middleBandBot | On | 390 |
| Close Long | shortMidBreak | On | 392 |
| Close Counter Trend Long | shortMidBreak | On | 393 |
| Close Default Long | shortMidBreak | On | 394 |
| Open Short short | shortMidBreak | On | 395 |
| Close Long | close < slowEMA | On | 399 |
| Close Counter Trend Long | close < slowEMA | On | 400 |
| Close Default Long | close < slowEMA | On | 401 |
| Open Short short | close < slowEMA | On | 402 |
| Close Long | s_useSlowEMA | Off “Use slow EMA filter” | 404 |
| Close Counter Trend Long | s_useSlowEMA | Off “Use slow EMA filter” | 405 |
| Close Default Long | s_useSlowEMA | Off “Use slow EMA filter” | 406 |
| Open Short short | s_useSlowEMA | Off “Use slow EMA filter” | 407 |
| Close Long | reverBarColor == color.orange | On | 519 |
| Close Long | OSOBcolor == color.yellow | On | 522 |
| Close Long | open > CTbandTop | On | 525 |
| Close Counter Trend Long | open > CTbandTop | On | 526 |
| Close Default Long | open > CTbandTop | On | 527 |
| Open Counter Trend Short short | open > CTbandTop | On | 528 |
| Close Long | countLongBBs == numBBs | On | 531 |
| Close Long | open > CTbandTop | On | 534 |
| Close Counter Trend Long | open > CTbandTop | On | 535 |
| Close Default Long | open > CTbandTop | On | 536 |
| Open Counter Trend Short short | open > CTbandTop | On | 537 |
| Close Long | major == -1 | On | 540 |
| Close Long | high > CTbandTop | On | 543 |
| Close Counter Trend Long | high > CTbandTop | On | 544 |
| Close Default Long | high > CTbandTop | On | 545 |
| Open Counter Trend Short short | high > CTbandTop | On | 546 |
| Close Long | countLongLele == numLele | On | 549 |
| Close Long | high > CTbandTop | On | 552 |
| Close Counter Trend Long | high > CTbandTop | On | 553 |
| Close Default Long | high > CTbandTop | On | 554 |
| Open Counter Trend Short short | high > CTbandTop | On | 555 |
| Close Long | crossDownTopMB or wiggleDownTopMB | On | 558 |
| Close Long | crossDownBotMB or wiggleDownBotMB | On | 561 |
| Close Long | crossDownBotMB or wiggleDownBotMB | On | 564 |
| Close Long | open[i_numBars] > middleBandTop and close[i_numBars] < middleBandTop and inMid | On | 567 |
| Close Short | reverBarColor == color.purple | On | 573 |
| Close Short | OSOBcolor == color.blue | On | 576 |
| Close Short | open < CTbandBottom | On | 579 |
| Close Counter Trend Short | open < CTbandBottom | On | 580 |
| Close Default Short | open < CTbandBottom | On | 581 |
| Open Counter Trend Long long | open < CTbandBottom | On | 582 |
| Close Short | countShortBBs == numBBs | On | 585 |
| Close Short | open < CTbandBottom | On | 588 |
| Close Counter Trend Short | open < CTbandBottom | On | 589 |
| Close Default Short | open < CTbandBottom | On | 590 |
| Open Counter Trend Long long | open < CTbandBottom | On | 591 |
| Close Short | major == 1 | On | 594 |
| Close Short | low < CTbandBottom | On | 597 |
| Close Counter Trend Short | low < CTbandBottom | On | 598 |
| Close Default Short | low < CTbandBottom | On | 599 |
| Open Counter Trend Long long | low < CTbandBottom | On | 600 |
| Close Short | countShortLele == numLele | On | 603 |
| Close Short | low < CTbandBottom | On | 606 |
| Close Counter Trend Short | low < CTbandBottom | On | 607 |
| Close Default Short | low < CTbandBottom | On | 608 |
| Open Counter Trend Long long | low < CTbandBottom | On | 609 |
| Close Short | crossUpBotMB or wiggleUpBotMB | On | 612 |
| Close Short | crossUpTopMB or wiggleUpTopMB | On | 615 |
| Close Short | crossUpTopMB or wiggleUpTopMB | On | 618 |
| Close Short | open[i_numBars] < middleBandBot and close[i_numBars] > middleBandBot and inMid | On | 621 |
| Close Short | low < CTbandBottom | On | 632 |
| Close Counter Trend Short | low < CTbandBottom | On | 633 |
| Close Default Short | low < CTbandBottom | On | 634 |
| Open Counter Trend Long long | low < CTbandBottom | On | 635 |
| Close Short | OSOBcolor == color.blue | On | 638 |
| Close Counter Trend Short | OSOBcolor == color.blue | On | 639 |
| Close Default Short | OSOBcolor == color.blue | On | 640 |
| Open Counter Trend Long long | OSOBcolor == color.blue | On | 641 |
| Exit Counter Trend Long stop | na(CTlongTP) | On | 646 |
| Exit Counter Trend Long stop and limit | na(CTlongTP) | On | 648 |
| Exit Counter Trend Long limit | i_CTlongSL == 0 | On | 650 |
| Close Counter Trend Long | CTlongCloseCond | On | 652 |
| Close Long | high > CTbandTop | On | 658 |
| Close Counter Trend Long | high > CTbandTop | On | 659 |
| Close Default Long | high > CTbandTop | On | 660 |
| Open Counter Trend Short short | high > CTbandTop | On | 661 |
| Close Long | OSOBcolor == color.yellow | On | 664 |
| Close Counter Trend Long | OSOBcolor == color.yellow | On | 665 |
| Close Default Long | OSOBcolor == color.yellow | On | 666 |
| Open Counter Trend Short short | OSOBcolor == color.yellow | On | 667 |
| Exit Counter Trend Short stop | na(CTshortTP) | On | 672 |
| Exit Counter Trend Short stop and limit | na(CTshortTP) | On | 674 |
| Exit Counter Trend Short limit | i_CTshortSL == 0 | On | 676 |
| Close Counter Trend Short | CTshortCloseCond | On | 678 |
| Open Default Long long | close > slowEMA | On | 684 |
| Open Default Long long | s_useSlowEMA | Off “Use slow EMA filter” | 686 |
| Open Default Short short | close < slowEMA | On | 690 |
| Open Default Short short | s_useSlowEMA | Off “Use slow EMA filter” | 692 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
Yes
At least one pattern in the source can repaint; it is marked Check below.
- ClearHigher-timeframe data1 request.security call(s), none with lookahead on.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- CheckIntrabar recalculationreads realtime-only state. Live values can differ from history.
- 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
Not run on other markets: the script requests BINANCE:BTCUSDT 360, and that data is not available here (a lower timeframe than the chart; the engine does not evaluate intrabar data). Its results would rest on empty values.
The trades
By market direction
| At entry, last 90 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 13 | 15% | −$321.24 |
| Sideways market | 18 | 33% | $351.10 |
| Falling market | 7 | 29% | $48.07 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
51.2%
The 95th percentile of the worst drawdown when the same 38 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 26.6% to 51.2%; the tick is what actually happened, 26.9%. Order luck alone moves it this much.
All 38 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 21 Mar 2024 67,840.50 | 14 Apr 2024 63,924.50 | 24 | −$58.40 |
| short | 14 Apr 2024 63,924.50 | 16 May 2024 66,206.50 | 32 | −$34.30 |
| long | 16 May 2024 66,206.50 | 15 Jun 2024 66,044.00 | 30 | −$2.88 |
| short | 15 Jun 2024 66,044.00 | 16 Jul 2024 64,724.10 | 31 | $17.43 |
| long | 16 Jul 2024 64,724.10 | 3 Aug 2024 61,498.30 | 18 | −$46.59 |
| short | 3 Aug 2024 61,498.30 | 24 Aug 2024 64,037.20 | 21 | −$36.78 |
| long | 24 Aug 2024 64,037.20 | 28 Aug 2024 59,415.00 | 4 | −$61.11 |
| short | 28 Aug 2024 59,415.00 | 14 Sep 2024 60,498.00 | 17 | −$14.73 |
| long | 14 Sep 2024 60,498.00 | 10 Oct 2024 60,636.00 | 26 | $1.19 |
| short | 10 Oct 2024 60,636.00 | 13 Oct 2024 63,206.20 | 3 | −$32.94 |
| long | 13 Oct 2024 63,206.20 | 30 Dec 2024 93,738.20 | 78 | $352.42 |
| short | 30 Dec 2024 93,738.20 | 4 Jan 2025 98,174.20 | 5 | −$52.06 |
| long | 4 Jan 2025 98,174.20 | 10 Jan 2025 92,552.50 | 6 | −$59.77 |
| short | 10 Jan 2025 92,552.50 | 16 Jan 2025 100,497.00 | 6 | −$84.12 |
| long | 16 Jan 2025 100,497.00 | 3 Feb 2025 97,700.60 | 18 | −$25.33 |
| short | 3 Feb 2025 97,700.60 | 22 Apr 2025 87,516.20 | 78 | $89.27 |
| long | 22 Apr 2025 87,516.20 | 6 Jun 2025 101,509.00 | 45 | $151.35 |
| short | 6 Jun 2025 101,509.00 | 8 Jun 2025 105,552.00 | 2 | −$44.73 |
| long | 8 Jun 2025 105,552.00 | 22 Jun 2025 102,120.00 | 14 | −$35.15 |
| short | 22 Jun 2025 102,120.00 | 25 Jun 2025 106,083.00 | 3 | −$40.44 |
| long | 25 Jun 2025 106,083.00 | 2 Aug 2025 113,298.00 | 38 | $66.08 |
| short | 2 Aug 2025 113,298.00 | 8 Aug 2025 117,472.00 | 6 | −$39.39 |
| long | 8 Aug 2025 117,472.00 | 20 Aug 2025 112,873.00 | 12 | −$40.22 |
| short | 20 Aug 2025 112,873.00 | 12 Sep 2025 115,483.00 | 23 | −$23.10 |
| long | 12 Sep 2025 115,483.00 | 23 Sep 2025 112,651.00 | 11 | −$23.86 |
| short | 23 Sep 2025 112,651.00 | 2 Oct 2025 118,595.00 | 9 | −$49.32 |
| long | 2 Oct 2025 118,595.00 | 11 Oct 2025 112,774.00 | 9 | −$43.44 |
| short | 11 Oct 2025 112,774.00 | 5 Jan 2026 91,529.70 | 86 | $155.64 |
| long | 5 Jan 2026 91,529.70 | 21 Jan 2026 88,427.70 | 16 | −$34.07 |
| short | 21 Jan 2026 88,427.70 | 16 Mar 2026 72,815.30 | 54 | $167.22 |
| long | 16 Mar 2026 72,815.30 | 22 Mar 2026 68,918.10 | 6 | −$60.61 |
| short | 22 Mar 2026 68,918.10 | 8 Apr 2026 71,924.20 | 17 | −$46.89 |
| long | 8 Apr 2026 71,924.20 | 23 May 2026 75,539.50 | 45 | $50.04 |
| short | 23 May 2026 75,539.50 | 15 Jul 2026 65,044.00 | 53 | $146.62 |
| long | 15 Jul 2026 65,044.00 | 1 Aug 2026 62,887.90 | 17 | −$40.86 |
| short | 1 Aug 2026 62,887.90 | 9 Aug 2026 64,962.60 | 8 | −$39.33 |
| long | 9 Aug 2026 64,962.60 | 13 Aug 2026 63,480.00 | 4 | −$26.52 |
| short | 13 Aug 2026 63,480.00 | 19 Aug 2026 64,725.40 | 6 | −$22.39 |
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 |
|---|---|---|---|---|---|
| EMA bands + leledc + bollinger bands trend following strategy v2 this page | — | v5 strategy | +7.8% | 38 | 32.0% |
| Contrarian Scalping Counter Trend Bb Envelope Adx and Stochastic by exlux99 | sma stdev ema rma | v5 strategy | +1.9% | 15 | 3.2% |
| Forex Scalping 1min Bollinger Bands, RSI and ADX Trading System by exlux99 | rsi sma stdev rma | v4 strategy | −0.0% | 3 | 0.0% |
| Take Profit On Trend (by BHD_Trade_Bot) by BHD_Trade_Bot | ema rsi stdev sma | v4 strategy | +54.8% | 9 | 13.1% |
| DRSI DMA Scalping Strategy No Repaint by allenlk | sma wma ema rsi | v4 strategy | −99.5% | 44 | 137.7% |
| Best TradingView Strategy - For NASDAQ and DOW30 and other Index by The_Bigger_Bull | sma stdev rma ema | v5 strategy | +2.2% | 17 | 3.4% |
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?
No
The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 38 before, 38 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.
⋯// backtesting results when considering for slippage and fees, readability adjustments-//@version=5+//@version=6strategy(title='EMA bands + leledc + bollinger bands trend catching strategy w/ countertrend scalp', ⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 256 ms | With a workaround 1,000 bars in 213 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
Zeal Terminal's engine currently reads an order side written as direction = strategy.short, direction = strategy.long as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 528, 537, 546, 555, 582, 591 and more) so the engine trades the way the script says.
“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/// © danielx888// Credits to Joy_Bangla for the Leledc exhaustion bar code// Credits to VishvaP for the 34 EMA bands code// Credits to SlumdogTrader for the BB exhaustion code (edited for functionality)// Credits to Juanc2316 for his code for BB Keltner Squeeze//// Update Notes : added strategy close conditions before every entry for more accurate// backtesting results when considering for slippage and fees, readability adjustments//@version=5strategy(title='EMA bands + leledc + bollinger bands trend catching strategy w/ countertrend scalp', shorttitle='Trend Pooristics', overlay=true, initial_capital = 1000, commission_value= 0.036, pyramiding= 0, default_qty_type= strategy.percent_of_equity, default_qty_value= 100, margin_long=0, margin_short=0, max_bars_back=200)//USER INPUTS {//INPUT: OPENi_EMAlength = input.int (34, 'EMA Length', minval=1, step=1)s_needLong = input.bool (true, title = "Enable middle EMA band breakout: Long", group="Open Conditions")s_needShort = input.bool (true, title = "Enable middle EMA band breakdown: Short", group="Open Conditions")s_longBounce = input.bool (false, 'Enable middle EMA band bounce re-entry: Long', tooltip='Works best when early close conditions are used', group= 'Open Conditions')s_shortBounce = input.bool (false, 'Enable middle EMA band bounce re-entry: Short', tooltip='Works best when early close conditions are used', group= 'Open Conditions')s_alwaysLong = input.bool (false, title = "Enable default positioning: Long", tooltip='Does not work with "Enable default positioning: Short" also selected. Works best when early close conditions are used', group = 'Open Conditions')s_alwaysShort = input.bool (false, title = "Enable default positioning: Short", tooltip='Does not work with "Enable default positioning: Long" also selected. Works best when early close conditions are used', group = 'Open Conditions')i_topMBmult = input.float (1, 'Top middle band multiplier', 0.1,3,step=0.1,group='Open Conditions')i_botMBmult = input.float (1, 'Bottom middle band multiplier',0.1,3,step=0.1,group='Open Conditions')s_useSlowEMA = input.bool (false, title='Use slow EMA filter',tooltip='Condition does not apply to counter-trend trades', group='Open Conditions')i_slowEMAlen = input.int (200, title='Slow EMA Length', step=1, minval=1, group='Open Conditions')//INPUT: CLOSEi_midClose = input.string('Opposite band', 'Close on crosses through middle EMA bands', tooltip='Selecting "Delayed bars inside" will closing positions after specified amount of candles close in between the middle EMA bands without breaking out', options=['Nearest band', 'Opposite band', 'Delayed bars inside'], group='Close Conditions')i_numBars = input.int (4, 'Delayed close no. of bars', minval=1, maxval=10, step=1, group='Close Conditions')s_useLele = input.bool (false, 'Close on Leledc bars', group='Close Conditions')i_whichLele = input.string('First', 'Which Leledc bar?', options=['First', 'Second', 'Third', 'Fourth', 'Fifth'], group='Close Conditions')s_useBBExtend = input.bool (false, 'Close on Bollinger Band exhaustion bars', tooltip='Bollinger Band Exhaustion bars are candles that close back inside the Bollinger Bands when RSI is overbought or oversold. Settings for both can be changed under the -Bollinger Bands Exhaustion Bar Settings- header.', group='Close Conditions')i_whichBBext = input.string('First', 'Which BB exhaustion bar?', options=['First', 'Second', 'Third'], group='Close Conditions')s_buySellClose = input.bool (false, 'Close on loss of Buy/Sell zone', group='Close Conditions')s_whichBuySellBars = input.string('Inner', 'Which Buy/Sell zone?', options=['Inner', 'Outer'], group='Close Conditions')//INPUT: COUNTER-TREND TRADESs_needCTlong = input.bool (false, "Enable counter-trend trades: Long", tooltip='Does not work with "Enable default positioning: Short" selected', group="Counter Trade Settings")i_CTlongType = input.string('Leledc', title = 'Trigger', options=['Leledc', 'BB Exhaustion'], group='Counter Trade Settings')s_needCTshort = input.bool (false, "Enable counter-trend trades: Short", tooltip='Does not work with "Enable default positioning: Long" selected"', group="Counter Trade Settings")i_CTshortType = input.string('Leledc', 'Trigger', options=['Leledc', 'BB Exhaustion'], group='Counter Trade Settings')i_ctLeleBuySell = input.string('Inner', 'Leledc/BB must be outside which Buy/Sell zone to open', options=['Inner', 'Outer'], group="Counter Trade Settings")i_CTlongCloseCond = input.string('Cross Top Middle Band','Closing conditions for counter-trend longs', tooltip='-Cross- type close conditions market close position on candle closes above selected region \n\n-Touch- type enable trailing limit orders that follow the selected region', options=['Cross Outer Buy Zone', 'Cross Inner Buy Zone', 'Touch Inner Buy Zone', 'Cross Bottom Middle Band', 'Touch Bottom Middle Band', 'Cross Top Middle Band', 'Touch Top Middle Band', 'Cross Inner Sell Zone', 'Touch Inner Sell Zone', 'Cross Outer Sell Zone', 'Touch Outer Sell Zone', 'First Leledc', 'First BB Exhaustion'], group='Counter Trade Settings')i_CTshortCloseCond = input.string('First Leledc','Closing conditions for counter-trend shorts', tooltip='-Cross- type close conditions market close position on candle closes below selected region \n\n-Touch- type enable trailing limit orders that follow the selected region',options=['Cross Outer Sell Zone', 'Cross Inner Sell Zone', 'Touch Inner Sell Zone', 'Cross Top Middle Band', 'Touch Top Middle Band', 'Cross Bottom Middle Band', 'Touch Bottom Middle Band', 'Cross Inner Buy Zone', 'Touch Inner Buy Zone', 'Cross Outer Buy Zone', 'Touch Outer Buy Zone', 'First Leledc', 'First BB Exhaustion'], group='Counter Trade Settings')i_CTlongSL = input.float (10, 'Flat stop-loss % for counter-trend longs', 0, 100, 0.1, 'Input 0 to disable stop-loss for counter-trend trades. Enabling stop-loss will not apply to middle band breakout, bounce, or default positional trades',group='Counter Trade Settings')i_CTshortSL = input.float (10, 'Flat stop-loss % for counter-trend shorts', 0, 100, 0.1, 'Input 0 to disable stop-loss for counter-trend trades. Enabling stop-loss will not apply to middle band breakout, bounce, or default positional trades',group='Counter Trade Settings')//INPUT: KELTNER BUY/SELL ZONESs_keltnerBuySell = input.bool (false, 'Use Keltner channel multiples for "Buy/Sell Zones"',tooltip='Enables inputting custom multiples and a different/smoother calculation of "Buy/Sell Zones". Default calculation is a multiple of EMA band highs and lows', group='Keltner Buy/Sell Zones')i_mult = input.float (5.0, "Outer Multiplier", tooltip='Only for "Buy/Sell Zones" calculated by Keltner channels', group='Keltner Buy/Sell Zones')i_innerMult = input.float (3.0, "Inner Multiplier", tooltip='Only for "Buy/Sell Zones" calculated by Keltner channels', group='Keltner Buy/Sell Zones')//INPUT: VOLATILITY SQUEEZE FILTERs_squeezeFilter = input.bool (false, 'Filter out trades during BB-Keltner squeezes', group= 'BB-Keltner squeze')i_bbCondition = input.string('At Least One', title='Bollinger Band Crossover Condition', options=['Both', 'At Least One'], group= 'BB-Keltner squeze')i_bbSqueezeLength = input.int (30, minval=1, title='BB Length', group= 'BB-Keltner squeze')i_ktSqueezeLength = input.int (18, minval=1, title='Keltner Length', group= 'BB-Keltner squeze')s_useRes = input.bool (false, 'Use current timeframe', group= 'BB-Keltner squeze')res = (s_useRes ? '' :input.timeframe('360', 'Resolution for BB-Keltner squeeze', group= 'BB-Keltner squeze'))i_B2mult = input.float (2, minval=0.001, maxval=50, title='BB Standard Deviation', group= 'BB-Keltner squeze')i_Kmult = input.float (1.5, title='Keltner Range', group= 'BB-Keltner squeze')//INPUT: BOLLINGER BANDS EXHAUSTION BARSi_BBlength = input.int (20, minval=1, title='Bollinger Bands SMA Period Length', group='Bollinger Bands Exhaustion Bar Settings')i_BBmult = input.float (1.8, minval=0.001, maxval=50, title='Bollinger Bands Standard Deviation', group='Bollinger Bands Exhaustion Bar Settings')i_RSIlength = input.int (8, minval=1, step=1, title='RSI Period Length', group='Bollinger Bands Exhaustion Bar Settings')i_RSIos = input.int (30, minval=0, maxval=50, step=1,title='RSI Oversold Value', group='Bollinger Bands Exhaustion Bar Settings')i_RSIob = input.int (70, minval=50, maxval=100, step=1, title='RSI Overbought value', group='Bollinger Bands Exhaustion Bar Settings')i_srcBB = input.source(close, title='Source', group='Bollinger Bands Exhaustion Bar Settings')//INPUT: LELEDCi_leleVol = input.bool (false, 'Require Volume breakout for Leledc bars', group='Leledc Exhaustion Bar Settings')i_volMult = input.float (1.5,'Volume Multiplier', 0.1,20,0.1, group='Leledc Exhaustion Bar Settings')i_majLen = input.int (30, 'Highest / Lowest', group='Leledc Exhaustion Bar Settings')i_majQual = input.int (6, 'Bar count no', group='Leledc Exhaustion Bar Settings')i_closeVal = input.int (4, 'Close', group='Leledc Exhaustion Bar Settings')i_bindexSindex = input.int (1, 'bindexSindex', group='Leledc Exhaustion Bar Settings')//INPUT: VISUAL ELEMENTSs_trendColor = input.bool (false, 'Enable Trend Bar Color', tooltip='Color bars green when above mid bands, red when below, and gray when inside. Dark green and dark red bars signal a position is kept open from the delayed close settings.', group='Visual Elements')s_showBuySell = input.bool (true, 'Show "Buy/Sell Zones"', group='Visual Elements')s_showEMA = input.bool (false, 'Show EMA', group='Visual Elements')s_showMiddleBands = input.bool (true, 'Show middle EMA bands', group='Visual Elements')s_showSlowEMA = input.bool (false, 'Show Slow EMA', group='Visual Elements')s_showMaj = input.bool (true, 'Show Leledc Exhausion Bars', group='Visual Elements')s_switch1 = input.bool (true, 'Enable Bollinger Bands exhaustion bar coloring', group='Visual Elements')s_switch2 = input.bool (false, 'Enable Bollinger bands exhaustion bar background coloring', tooltip='Enabling this can help visualize when dialing in Bollinger Bands and RSI settings', group='Visual Elements')s_colorBuySellBars = input.bool (false, 'Enable Buy/Sell zone failure bar coloring', group='Visual Elements')s_squeezeBG = input.bool (true, 'Enable volatility squeeze (BB-Keltner) background coloring', group='Visual Elements')//}//VARIABLES: EMA and slowEMA CALC {EMA = ta.ema(close, i_EMAlength)slowEMA = ta.ema(close, i_slowEMAlen)plot(s_showSlowEMA ? slowEMA : na)//}//*****************************// SlumdogTrader's Bollinger Bands + RSI Double Strategy - Profit Trailer//====================================================================================================//{//BB VARIABLESBBbasis = ta.sma(i_srcBB, i_BBlength)BBdev = i_BBmult * ta.stdev(i_srcBB, i_BBlength)BBupper = BBbasis + BBdevBBlower = BBbasis - BBdev//RSI VARIABLESvrsi = ta.rsi(i_srcBB, i_RSIlength)RSIoverSold = vrsi < i_RSIosRSIoverBought = vrsi > i_RSIob//BB EXHAUSTION BAR COLOR VARIABLEOSOBcolor = RSIoverBought and i_srcBB[1] > BBupper and i_srcBB < BBupper ? color.yellow : RSIoverSold and i_srcBB[1] < BBlower and i_srcBB > BBlower ? color.blue : na//====================================================================================================////}//KELTNER SELL ZONE {rangema = s_keltnerBuySell ? ta.rma(high - low, i_EMAlength) : 0.0kt_outersell(_ma) => upper = EMA + _ma * i_mult upperkt_innersell(_ma) => inner_upper = EMA + _ma * i_innerMult inner_upperkt_outerbuy(_ma) => lower = EMA - _ma * i_mult lowerkt_innerbuy(_ma) => inner_lower = EMA - _ma * i_innerMult inner_lower//}//*****************************// BB-Keltner Squeeze-FVBO-2.0// Modified by Juan C for FVBO Strategy, some source code from Trader-Elisa//====================================================================================================//{//VARIABLES FOR HTF SOURCESrp_security(_sym, _res, _src) => request.security(_sym, _res, _src[barstate.ishistory ? 0 : 1], gaps=barmerge.gaps_on) srcClose = rp_security(syminfo.tickerid, res, close)srcHigh = rp_security(syminfo.tickerid, res, high)srcLow = rp_security(syminfo.tickerid, res, low)//SQUEEZE BOLLINGER BANDSB2basis = ta.sma(srcClose, i_bbSqueezeLength)B2dev = i_B2mult * ta.stdev(srcClose, i_bbSqueezeLength)B2upper = B2basis + B2devB2lower = B2basis - B2dev//SQUEEZE KELTNER CHANNELSKma = ta.ema(srcClose, i_ktSqueezeLength)Krange = srcHigh - srcLowKrangema = ta.ema(Krange, i_ktSqueezeLength)Kupper = Kma + Krangema * i_KmultKlower = Kma - Krangema * i_Kmult//DEFINE SQUEEZEvar bool squeezing = falseif s_squeezeFilter if i_bbCondition == 'Both' and s_useRes squeezing := B2upper <= Kupper and B2lower >= Klower ? true : false squeezing else if i_bbCondition == 'At Least One' and s_useRes squeezing := B2upper <= Kupper or B2lower >= Klower ? true : false squeezing else if i_bbCondition == 'Both' squeezing := B2upper[ta.barssince(not srcClose == barstate.isrealtime)] <= Kupper[ta.barssince(not srcClose == barstate.isrealtime)] and B2lower[ta.barssince(not srcClose == barstate.isrealtime)] >= Klower[ta.barssince(not srcClose == barstate.isrealtime)] ? true : false squeezing else squeezing := B2upper[ta.barssince(not srcClose == barstate.isrealtime)] <= Kupper[ta.barssince(not srcClose == barstate.isrealtime)] or B2lower[ta.barssince(not srcClose == barstate.isrealtime)] >= Klower[ta.barssince(not srcClose == barstate.isrealtime)] ? true : false squeezing//VISUALcross_over_color = (squeezing ? color.new(color.aqua, 90) : na)bgcolor(s_squeezeBG ? cross_over_color : na)bgcolor(s_switch2 ? color.new(OSOBcolor,70) : na)//}//*****************************// © Joy_Bangla Leledc Exhaustion V4//====================================================================================================//{//min = input(false, 'Minor Leledc Exhaustion Bar :: Show')//min_qual = input(5, 'Minor Leledc Exhausion Bar :: Bar count no')//min_len = input(5, 'Minor Leledc Exhausion Bar :: Bar count no')leleVol = volume > ta.sma(volume,100)*i_volMultlele(qual, len) => bindex = 0 sindex = 0 bindex := nz(bindex[i_bindexSindex], 0) sindex := nz(sindex[i_bindexSindex], 0) ret = 0 if close > close[i_closeVal] bindex += 1 bindex if close < close[i_closeVal] sindex += 1 sindex if i_leleVol and not leleVol ret := 0 ret else if bindex > qual and close < open and high >= ta.highest(high, len) bindex := 0 ret := -1 ret if sindex > qual and close > open and low <= ta.lowest(low, len) sindex := 0 ret := 1 ret return_1 = ret return_1major = lele(i_majQual, i_majLen)//minor = lele(min_qual, min_len)plotchar(s_showMaj ? major == -1 ? high : na : na, char='•', location=location.absolute, color=color.new(color.red, 0), size=size.small)plotchar(s_showMaj ? major == 1 ? low : na : na, char='•', location=location.absolute, color=color.new(color.lime, 0), size=size.small)//plotchar(min ? minor == 1 ? high : na : na, char='x', location=location.absolute, color=color.new(color.red, 0), size=size.small)//plotchar(min ? minor == -1 ? low : na : na, char='x', location=location.absolute, color=color.new(color.lime, 0), size=size.small)//leledcMajorBullish = major == 1 ? low : na//leledcMajorBearish = major == -1 ? high : na//leledcMinorBullish = minor == 1 ? low : na//leledcMinorBearish = minor == -1 ? high : na//==============================================////alertcondition(leledcMajorBullish, title='Major Bullish Leledc', message='Major Bullish Leledc')//alertcondition(leledcMajorBearish, title='Major Bearish Leledc', message='Major Bearish Leledc')//alertcondition(leledcMinorBullish, title='Minor Bullish Leledc', message='Minor Bullish Leledc')//alertcondition(leledcMinorBearish, title='Minor Bearish Leledc', message='Minor Bearish Leledc')//====================================================================================================////}//*****************************// © VishvaP 34 EMA Bands v2//====================================================================================================//{//BUILD EMA MIDDLE BANDShighShortEMA = ta.ema(high, i_EMAlength)lowShortEMA = ta.ema(low, i_EMAlength)middleBandTop = (highShortEMA - EMA) * i_topMBmult + EMAmiddleBandBot = (lowShortEMA - EMA) * i_botMBmult + EMA//==============================================////1D Bands [Not Used]//bandsHigh = highShortEMA * math.phi//bandsLow = lowShortEMA * math.rphi//==============================================////INNER BUY/SELL ZONESshortbandsHigh = s_keltnerBuySell ? kt_innersell(rangema) : ((highShortEMA - EMA) * math.phi * i_topMBmult) * math.pi + EMAshortbandsLow = s_keltnerBuySell ? kt_innerbuy(rangema) : (-(EMA - lowShortEMA) * math.phi * i_botMBmult) * math.pi + EMA//SMOOTH INNERshortbandsHighEMA = ta.wma(shortbandsHigh, 8)shortbandsLowEMA = ta.wma(shortbandsLow, 8)//==============================================////OUTER BUY/SELL ZONESphiExtensionHigh = s_keltnerBuySell ? kt_outersell(rangema) : ((highShortEMA - EMA) * math.phi * i_topMBmult) * (math.phi + 4) + EMAphiExtensionLow = s_keltnerBuySell ? kt_outerbuy(rangema) : (-(EMA - lowShortEMA) * math.phi * i_botMBmult) * (math.phi + 4) + EMA//SMOOTH OUTERphiExtensionHighEMA = ta.wma(phiExtensionHigh, 8)phiExtensionLowEMA = ta.wma(phiExtensionLow, 8)//==============================================////PLOT MIDDLE BANDS AND EMAhighP1 = plot(s_showMiddleBands ? middleBandTop : na, color = color.new(color.blue, 100), title = "Top median zone")lowP1 = plot(s_showMiddleBands ? middleBandBot : na, color = color.new(color.blue, 100), title = "Bottom median zone")plot(s_showEMA ? EMA : na, color = color.new(color.gray, 0), title = "EMA")//1D bands [not used]//highP2 = plot(bandsHigh)//lowP2 = plot(bandsLow)//PLOT BUY/SELL ZONEShighP3 = plot(s_showBuySell ? shortbandsHighEMA : na, color = color.new(color.yellow, 100), title = "Lower sell zone")lowP3 = plot(s_showBuySell ? shortbandsLowEMA : na, color = color.new(color.teal, 100), title = "Higher buy zone")phiPlotHigh = plot(s_showBuySell ? phiExtensionHighEMA : na, color = color.new(color.red, 100), title = "Top sell zone")phiPlotLow = plot(s_showBuySell ? phiExtensionLowEMA : na, color = color.new(color.green, 100), title = "Bottom buy zone")//==============================================////BUY/SELL ZONE AND MIDDLE BAND COLOR FILLSfill(phiPlotHigh, highP3, color.new(color.red, 85), title = "Sell zone")fill(lowP3, phiPlotLow, color.new(color.green, 85), title = "Buy zone")fill(highP1, lowP1, color.new(color.gray, 70), title = "Median zone")//====================================================================================================////}//ASSIGN BANDS FOR COUNTERTREND ENTRIES {float CTbandTop = nafloat CTbandBottom = na if i_ctLeleBuySell == 'Inner' CTbandTop := shortbandsHighEMA CTbandBottom := shortbandsLowEMAelse CTbandTop := phiExtensionHighEMA CTbandBottom := phiExtensionLowEMA//}//BUILD VARIABLES FOR CROSSES {crossUpTopMB = open < middleBandTop and close > middleBandTopwiggleUpTopMB = open > middleBandTop and close > middleBandTop and close[1] <= middleBandTop[1]crossDownTopMB = open > middleBandTop and close < middleBandTopwiggleDownTopMB = open < middleBandTop and close < middleBandTop and close[1] >= middleBandTop[1]crossUpBotMB = open < middleBandBot and close > middleBandBotwiggleUpBotMB = open > middleBandBot and close > middleBandBot and close[1] <= middleBandBot[1]crossDownBotMB = open > middleBandBot and close < middleBandBotwiggleDownBotMB = open < middleBandBot and close < middleBandBot and close[1] >= middleBandBot[1]crossUpBotInnerRB = open < shortbandsLowEMA and close > shortbandsLowEMAwiggleUpBotInnerRB = open > shortbandsLowEMA and close > shortbandsLowEMA and close[1] <= shortbandsLowEMA[1]crossUpBotOuterRB = open < phiExtensionLowEMA and close > phiExtensionLowEMAwiggleUpBotOuterRB = open > phiExtensionLowEMA and close > phiExtensionLowEMA and close[1] <= phiExtensionLowEMA[1]crossUpTopInnerRB = open < shortbandsHighEMA and close > shortbandsHighEMAwiggleUpTopInnerRB = open > shortbandsHighEMA and close > shortbandsHighEMA and close[1] <= shortbandsHighEMA[1]crossUpTopOuterRB = open < phiExtensionHighEMA and close > phiExtensionHighEMAwiggleUpTopOuterRB = open > phiExtensionHighEMA and close > phiExtensionHighEMA and close[1] <= phiExtensionHighEMA[1]crossDownBotInnerRB = open > shortbandsLowEMA and close < shortbandsLowEMAwiggleDownBotInnerRB = open < shortbandsLowEMA and close < shortbandsLowEMA and close[1] >= shortbandsLowEMA[1]crossDownBotOuterRB = open > phiExtensionLowEMA and close < phiExtensionLowEMAwiggleDownBotOuterRB = open < phiExtensionLowEMA and close < phiExtensionLowEMA and close[1] >= phiExtensionLowEMA[1]crossDownTopInnerRB = open > shortbandsHighEMA and close < shortbandsHighEMAwiggleDownTopInnerRB = open < shortbandsHighEMA and close < shortbandsHighEMA and close[1] >= shortbandsHighEMA[1]crossDownTopOuterRB = open > phiExtensionHighEMA and close < phiExtensionHighEMAwiggleDownTopOuterRB = open < phiExtensionHighEMA and close < phiExtensionHighEMA and close[1] >= phiExtensionHighEMA[1]//}//VARIABLES FOR BOUNCES {longBounce = not s_longBounce ? false : s_squeezeFilter ? open > middleBandTop and close > middleBandTop and low < middleBandTop and squeezing == false : open > middleBandTop and close > middleBandTop and low < middleBandTopshortBounce = not s_shortBounce ? false : s_squeezeFilter ? open < middleBandBot and close < middleBandBot and high > middleBandBot and squeezing == false : open < middleBandBot and close < middleBandBot and high > middleBandBot//}//BUILD VARIABLES FOR CLOSING CONDITIONS {CTlongCloseCond = i_CTlongCloseCond == 'Cross Inner Sell Zone' ? (crossUpTopInnerRB or wiggleUpTopInnerRB) : i_CTlongCloseCond == 'Cross Outer Sell Zone' ? (crossUpTopOuterRB or wiggleUpTopOuterRB) : i_CTlongCloseCond == 'Cross Top Middle Band' ? (crossUpTopMB or wiggleUpTopMB) : i_CTlongCloseCond == 'Cross Bottom Middle Band' ? (crossUpBotMB or wiggleUpBotMB) : i_CTlongCloseCond == 'Cross Inner Buy Zone' ? (crossUpBotInnerRB or wiggleUpBotInnerRB) : i_CTlongCloseCond == 'Cross Outer Buy Zone' ? (crossUpBotOuterRB or crossUpBotOuterRB) : i_CTlongCloseCond == 'First Leledc' ? major == -1 : i_CTlongCloseCond == 'First BB Exhaustion' ? OSOBcolor == color.yellow : naCTlongTP = i_CTlongCloseCond == 'Touch Inner Buy Zone' ? shortbandsLowEMA : i_CTlongCloseCond == 'Touch Top Middle Band' ? middleBandTop : i_CTlongCloseCond == 'Touch Bottom Middle Band' ? middleBandBot : i_CTlongCloseCond == 'Touch Inner Sell Zone' ? shortbandsHighEMA : i_CTlongCloseCond == 'Touch Outer Sell Zone' ? phiExtensionHighEMA : naCTshortCloseCond = i_CTshortCloseCond == 'Cross Inner Buy Zone' ? (crossDownBotInnerRB or wiggleDownBotInnerRB) : i_CTshortCloseCond == 'Cross Outer Buy Zone' ? (crossDownBotOuterRB or wiggleDownBotOuterRB) : i_CTshortCloseCond == 'Cross Bottom Middle Band' ? (crossDownBotMB or wiggleDownBotMB) : i_CTshortCloseCond == 'Cross Top Middle Band' ? (crossDownTopMB or wiggleDownTopMB) : i_CTshortCloseCond == 'Cross Inner Sell Zone' ? (crossDownTopInnerRB or wiggleDownTopInnerRB) : i_CTshortCloseCond == 'Cross Outer Sell Zone' ? (crossDownTopOuterRB or crossDownTopOuterRB) : i_CTshortCloseCond == 'First Leledc' ? major == 1 : i_CTshortCloseCond == 'First BB Exhaustion' ? OSOBcolor == color.blue : naCTshortTP = i_CTshortCloseCond == 'Touch Inner Sell Zone' ? shortbandsHighEMA : i_CTshortCloseCond == 'Touch Bottom Middle Band' ? middleBandBot : i_CTshortCloseCond == 'Touch Top Middle Band' ? middleBandTop : i_CTshortCloseCond == 'Touch Inner Buy Zone' ? shortbandsLowEMA : i_CTshortCloseCond == 'Touch Outer Buy Zone' ? phiExtensionLowEMA : nashortMidBreak = s_squeezeFilter ? (crossDownBotMB or wiggleDownBotMB) and squeezing == false : crossDownBotMB or wiggleDownBotMBlongMidBreak = s_squeezeFilter ? (crossUpTopMB or wiggleUpTopMB) and squeezing == false : crossUpTopMB or wiggleUpTopMB//}//BASIC STRATEGY POSITIONS OPEN//LONGS OPEN {if s_needLong if s_useSlowEMA if longMidBreak and close > slowEMA and open < middleBandTop strategy.close('Short', comment='Close Short') strategy.close('Counter Trend Short', comment='Close CT Short') strategy.close('Default Short', comment='Close Default Short') strategy.entry('Long', strategy.long) else if longMidBreak strategy.close('Short', comment='Close Short') strategy.close('Counter Trend Short', comment='Close CT Short') strategy.close('Default Short', comment='Close Default Short') strategy.entry('Long', strategy.long)if strategy.position_size == 0 and longBounce if s_useSlowEMA if close > slowEMA strategy.close('Short', comment='Close Short') strategy.close('Counter Trend Short', comment='Close CT Short') strategy.close('Default Short', comment='Close Default Short') strategy.entry('Long', strategy.long) else strategy.close('Short', comment='Close Short') strategy.close('Counter Trend Short', comment='Close CT Short') strategy.close('Default Short', comment='Close Default Short') strategy.entry('Long', strategy.long)//}//SHORTS OPEN {if s_needShort if s_useSlowEMA if shortMidBreak and close < slowEMA and open > middleBandBot strategy.close('Long', comment='Close Long') strategy.close('Counter Trend Long', comment='Close CT Long') strategy.close('Default Long', comment='Close Default Long') strategy.entry('Short', strategy.short) else if shortMidBreak strategy.close('Long', comment='Close Long') strategy.close('Counter Trend Long', comment='Close CT Long') strategy.close('Default Long', comment='Close Default Long') strategy.entry('Short', strategy.short)if strategy.position_size == 0 and shortBounce if s_useSlowEMA if close < slowEMA strategy.close('Long', comment='Close Long') strategy.close('Counter Trend Long', comment='Close CT Long') strategy.close('Default Long', comment='Close Default Long') strategy.entry('Short', strategy.short) else strategy.close('Long', comment='Close Long') strategy.close('Counter Trend Long', comment='Close CT Long') strategy.close('Default Long', comment='Close Default Long') strategy.entry('Short', strategy.short)//}//COUNT LELEDC BARS BETWEEN CURRENT BAR AND POSITION OPEN {//VARIABLESint countLongLele = 0int countShortLele = 0int numLele = switch i_whichLele 'First' => 1 'Second' => 2 'Third' => 3 'Fourth' => 4 'Fifth' => 5int i = 0//COUNT LELES FOR LONGSif strategy.position_size > 0 if s_useLele and numLele > 1 while i <= 200 if strategy.position_size[i] <= 0 break if bar_index[i] == 0 break if major[i] == -1 countLongLele += 1 if countLongLele == numLele break i += 1//COUNT LELES FOR SHORTSif strategy.position_size < 0 if s_useLele and numLele > 1 while i <= 200 if strategy.position_size[i] >= 0 break if bar_index[i] == 0 break if major[i] == 1 countShortLele += 1 if countShortLele == numLele break i += 1//}//COUNT BB EXHAUSTION BARS BETWEEN CURRENT BAR AND POSITION OPEN {//VARIABLESint countLongBBs = 0int countShortBBs = 0int numBBs = switch i_whichBBext 'First' => 1 'Second' => 2 'Third' => 3int n = 0//COUNT BB BARS FOR LONGSif strategy.position_size > 0 if s_useBBExtend and numBBs > 1 while n <= 200 if strategy.position_size[n] <= 0 break if bar_index[n] == 0 break if OSOBcolor[n] == color.yellow countLongBBs += 1 if countLongBBs == numBBs break n+= 1//COUNT BB BARS FOR SHORTSif strategy.position_size < 0 if s_useBBExtend and numBBs > 1 while n <= 200 if strategy.position_size[n] >= 0 break if bar_index[n] == 0 break if OSOBcolor[n] == color.blue countShortBBs += 1 if countShortBBs == numBBs break n+= 1//}//VARIABLES: CONDITIONS OF LOSS OF BUY/SELL ZONES {var bool crossUpRB = falsevar bool wiggleUpRB = falsevar bool crossDownRB = falsevar bool wiggleDownRB = falseif s_whichBuySellBars == 'Inner' crossUpRB := crossUpBotInnerRB wiggleUpRB := wiggleUpBotInnerRB crossDownRB := crossDownTopInnerRB wiggleDownRB := wiggleDownTopInnerRBelse crossUpRB := crossUpBotOuterRB wiggleUpRB := wiggleUpBotOuterRB crossDownRB := crossDownTopOuterRB wiggleDownRB := wiggleDownTopOuterRB//}//VARIABLES: reverBarColor {reverBarColor = crossDownRB or (wiggleDownRB and not crossDownRB[1]) ? color.orange : crossUpRB or (wiggleUpRB and not crossUpRB[1]) ? color.purple : na//}//FUNCTION: isAllMid() {//return true after specified number of bars (i_numBars) closes inside the mid bands but no breakoutinMid = close > middleBandBot and close < middleBandTop and open > middleBandBot and open < middleBandTopisAllMid() => AllMid = true for t = 0 to i_numBars by 1 if longMidBreak[t] or shortMidBreak[t] AllMid := false AllMid//}//BASIC STRATEGY POSITIONS CLOSE//LONGS CLOSE {if strategy.position_size > 0 if s_buySellClose if reverBarColor == color.orange strategy.close('Long', comment = 'Close Long') if s_useBBExtend and numBBs == 1 if OSOBcolor == color.yellow strategy.close('Long', comment = 'Close Long') if s_needCTshort and i_CTshortType == 'BB Exhaustion' if open > CTbandTop strategy.close('Long', comment='Close Long') strategy.close('Counter Trend Long', comment='Close CT Long') strategy.close('Default Long', comment='Close Default Long') strategy.entry('Counter Trend Short', comment = 'CT Short', direction=strategy.short) if s_useBBExtend and numBBs > 1 if countLongBBs == numBBs strategy.close('Long', comment = 'Close Long') if s_needCTshort and i_CTshortType == 'BB Exhaustion' if open > CTbandTop strategy.close('Long', comment='Close Long') strategy.close('Counter Trend Long', comment='Close CT Long') strategy.close('Default Long', comment='Close Default Long') strategy.entry('Counter Trend Short', comment = 'CT Short', direction=strategy.short) if s_useLele and numLele == 1 if major == -1 strategy.close('Long', comment = 'Close Long') if s_needCTshort and i_CTshortType == 'Leledc' if high > CTbandTop strategy.close('Long', comment='Close Long') strategy.close('Counter Trend Long', comment='Close CT Long') strategy.close('Default Long', comment='Close Default Long') strategy.entry('Counter Trend Short', comment = 'CT Short', direction=strategy.short) if s_useLele and numLele > 1 if countLongLele == numLele strategy.close('Long', comment = 'Close Long') if s_needCTshort and i_CTshortType == 'Leledc' if high > CTbandTop strategy.close('Long', comment='Close Long') strategy.close('Counter Trend Long', comment='Close CT Long') strategy.close('Default Long', comment='Close Default Long') strategy.entry('Counter Trend Short', comment = 'CT Short', direction=strategy.short) if i_midClose == 'Nearest band' if crossDownTopMB or wiggleDownTopMB strategy.close('Long', comment = 'Close Long') if i_midClose == 'Opposite band' if crossDownBotMB or wiggleDownBotMB strategy.close('Long', comment = 'Close Long') if i_midClose == 'Delayed bars inside' if crossDownBotMB or wiggleDownBotMB strategy.close('Long', comment = 'Close Long') if isAllMid() if open[i_numBars] > middleBandTop and close[i_numBars] < middleBandTop and inMid strategy.close('Long', comment = 'Close Long')//}//SHORTS CLOSE {if strategy.position_size < 0 if s_buySellClose if reverBarColor == color.purple strategy.close('Short', comment = 'Close Short') if s_useBBExtend and numBBs == 1 if OSOBcolor == color.blue strategy.close('Short', comment = 'Close Short') if s_needCTlong and i_CTlongType == 'BB Exhaustion' if open < CTbandBottom strategy.close('Short', comment='Close Short') strategy.close('Counter Trend Short', comment='Close CT Short') strategy.close('Default Short', comment='Close Default Short') strategy.entry('Counter Trend Long', comment = 'CT Long', direction=strategy.long) if s_useBBExtend and numBBs > 1 if countShortBBs == numBBs strategy.close('Short', comment = 'Close Short') if s_needCTlong and i_CTlongType == 'BB Exhaustion' if open < CTbandBottom strategy.close('Short', comment='Close Short') strategy.close('Counter Trend Short', comment='Close CT Short') strategy.close('Default Short', comment='Close Default Short') strategy.entry(id='Counter Trend Long', comment = 'CT Long', direction=strategy.long) if s_useLele and numLele == 1 if major == 1 strategy.close('Short', comment = 'Close Short') if s_needCTlong and i_CTlongType == 'Leledc' if low < CTbandBottom strategy.close('Short', comment='Close Short') strategy.close('Counter Trend Short', comment='Close CT Short') strategy.close('Default Short', comment='Close Default Short') strategy.entry(id='Counter Trend Long', comment= 'CT Long', direction=strategy.long) if s_useLele and numLele > 1 if countShortLele == numLele strategy.close('Short', comment = 'Close Short') if s_needCTlong and i_CTlongType == 'Leledc' if low < CTbandBottom strategy.close('Short', comment='Close Short') strategy.close('Counter Trend Short', comment='Close CT Short') strategy.close('Default Short', comment='Close Default Short') strategy.entry(id='Counter Trend Long', comment= 'CT Long', direction=strategy.long) if i_midClose == 'Nearest band' if crossUpBotMB or wiggleUpBotMB strategy.close('Short', comment = 'Close Short') if i_midClose == 'Opposite band' if crossUpTopMB or wiggleUpTopMB strategy.close('Short', comment = 'Close Short') if i_midClose == 'Delayed bars inside' if crossUpTopMB or wiggleUpTopMB strategy.close('Short', comment = 'Close Short') if isAllMid() if open[i_numBars] < middleBandBot and close[i_numBars] > middleBandBot and inMid strategy.close('Short', comment = 'Close Short')//}//COUNTER TREND STRATEGY POSITIONS OPEN AND CLOSE {//VARIABLES FOR CT STOP LOSSESCTlongSL = strategy.position_avg_price * (1 - i_CTlongSL / 100)CTshortSL = strategy.position_avg_price * (1 + i_CTshortSL / 100)//CT LONGS OPENif s_needCTlong and strategy.position_size == 0 and (not s_squeezeFilter or not squeezing) if i_CTlongType == 'Leledc' if major == 1 if low < CTbandBottom strategy.close('Short', comment='Close Short') strategy.close('Counter Trend Short', comment='Close CT Short') strategy.close('Default Short', comment='Close Default Short') strategy.entry('Counter Trend Long', comment = 'CT Long', direction = strategy.long) else if OSOBcolor == color.blue strategy.close('Short', comment='Close Short') strategy.close('Counter Trend Short', comment='Close CT Short') strategy.close('Default Short', comment='Close Default Short') strategy.entry('Counter Trend Long', comment = 'CT Long', direction = strategy.long)//CT LONGS CLOSEDif strategy.position_size > 0 and strategy.opentrades.entry_id(strategy.opentrades - 1) == 'Counter Trend Long' if i_CTlongSL > 0 if na(CTlongTP) strategy.exit(id='Counter Trend Long', stop=CTlongSL, comment = 'CT Long SL') else strategy.exit(id='Counter Trend Long', stop=CTlongSL, limit=CTlongTP, comment = 'CT Long TP/SL') else if i_CTlongSL == 0 strategy.exit(id='Counter Trend Long', limit=CTlongTP, comment = 'CT Long TP') if CTlongCloseCond strategy.close(id='Counter Trend Long', comment = 'Close CT Long')//CT SHORTS OPENif s_needCTshort and strategy.position_size == 0 and (not s_squeezeFilter or not squeezing) if i_CTshortType == 'Leledc' if major == -1 if high > CTbandTop strategy.close('Long', comment='Close Long') strategy.close('Counter Trend Long', comment='Close CT Long') strategy.close('Default Long', comment='Close Default Long') strategy.entry('Counter Trend Short', comment = 'CT Short', direction=strategy.short) else if OSOBcolor == color.yellow strategy.close('Long', comment='Close Long') strategy.close('Counter Trend Long', comment='Close CT Long') strategy.close('Default Long', comment='Close Default Long') strategy.entry('Counter Trend Short', comment= 'CT Short', direction=strategy.short)//CT SHORTS CLOSEif strategy.position_size < 0 and strategy.opentrades.entry_id(strategy.opentrades - 1) == 'Counter Trend Short' if i_CTshortSL > 0 if na(CTshortTP) strategy.exit(id='Counter Trend Short', stop=CTshortSL, comment = 'CT Short SL') else strategy.exit(id='Counter Trend Short', stop=CTshortSL, limit=CTshortTP, comment = 'CT Short TP/SL') else if i_CTshortSL == 0 strategy.exit(id='Counter Trend Short', limit=CTshortTP, comment = 'CT Short TP') if CTshortCloseCond strategy.close(id='Counter Trend Short', comment = "Close CT Short")//}//DEFAULT POSITIONING STRATEGY OPENS {if s_alwaysLong and not s_alwaysShort and strategy.position_size == 0 if s_useSlowEMA if close > slowEMA strategy.entry(id='Default Long', comment = 'Default Long', direction=strategy.long) else strategy.entry(id='Default Long', comment='Default Long', direction=strategy.long)if s_alwaysShort and not s_alwaysLong and strategy.position_size == 0 if s_useSlowEMA if close < slowEMA strategy.entry(id='Default Short', comment = 'Default Short', direction=strategy.short) else strategy.entry(id='Default Short', comment='Default Short', direction=strategy.short)//}//SET BAR COLORS {var colorBar = color.new(color.white, 50)if s_trendColor if s_switch1 if s_colorBuySellBars if reverBarColor == color.purple or reverBarColor == color.orange colorBar := reverBarColor else if OSOBcolor == color.yellow or OSOBcolor == color.blue colorBar := OSOBcolor else if close > middleBandTop if (s_alwaysShort or s_needCTshort) and strategy.position_size < 0 colorBar := color.new(color.red, 0) else colorBar := color.new(color.green, 0) else if close < middleBandBot if (s_alwaysLong or s_needCTlong) and strategy.position_size > 0 colorBar := color.new(color.green, 0) else colorBar := color.new(color.red, 0) else if strategy.position_size > 0 and (i_midClose == 'Delayed bars inside' or i_midClose == 'Opposite band') colorBar := color.new(#0a6136, 20) else if strategy.position_size < 0 and (i_midClose == 'Delayed bars inside' or i_midClose == 'Opposite band') colorBar := color.new(#600008, 20) else colorBar := color.new(color.gray, 0) else if OSOBcolor == color.yellow or OSOBcolor == color.blue colorBar := OSOBcolor else if close > middleBandTop if (s_alwaysShort or s_needCTshort) and strategy.position_size < 0 colorBar := color.new(color.red, 0) else colorBar := color.new(color.green, 0) else if close < middleBandBot if (s_alwaysLong or s_needCTlong) and strategy.position_size > 0 colorBar := color.new(color.green, 0) else colorBar := color.new(color.red, 0) else if strategy.position_size > 0 and (i_midClose == 'Delayed bars inside' or i_midClose == 'Opposite band') colorBar := color.new(#0a6136, 20) else if strategy.position_size < 0 and (i_midClose == 'Delayed bars inside' or i_midClose == 'Opposite band') colorBar := color.new(#600008, 20) else colorBar := color.new(color.gray, 0) else if s_colorBuySellBars if reverBarColor == color.purple or reverBarColor == color.orange colorBar := reverBarColor else if close > middleBandTop if (s_alwaysShort or s_needCTshort) and strategy.position_size < 0 colorBar := color.new(color.red, 0) else colorBar := color.new(color.green, 0) else if close < middleBandBot if (s_alwaysLong or s_needCTlong) and strategy.position_size > 0 colorBar := color.new(color.green, 0) else colorBar := color.new(color.red, 0) else if strategy.position_size > 0 and (i_midClose == 'Delayed bars inside' or i_midClose == 'Opposite band') colorBar := color.new(#0a6136, 20) else if strategy.position_size < 0 and (i_midClose == 'Delayed bars inside' or i_midClose == 'Opposite band') colorBar := color.new(#600008, 20) else colorBar := color.new(color.gray, 0) else if close > middleBandTop if (s_alwaysShort or s_needCTshort) and strategy.position_size < 0 colorBar := color.new(color.red, 0) else colorBar := color.new(color.green, 0) else if close < middleBandBot if (s_alwaysLong or s_needCTlong) and strategy.position_size > 0 colorBar := color.new(color.green, 0) else colorBar := color.new(color.red, 0) else if strategy.position_size > 0 and (i_midClose == 'Delayed bars inside' or i_midClose == 'Opposite band') colorBar := color.new(#0a6136, 20) else if strategy.position_size < 0 and (i_midClose == 'Delayed bars inside' or i_midClose == 'Opposite band') colorBar := color.new(#600008, 20) else colorBar := color.new(color.gray, 0)else if s_switch1 if s_colorBuySellBars if reverBarColor == color.purple or reverBarColor == color.orange colorBar := reverBarColor else if OSOBcolor == color.yellow or OSOBcolor == color.blue colorBar := OSOBcolor else colorBar := na else if OSOBcolor == color.yellow or OSOBcolor == color.blue colorBar := OSOBcolor else colorBar := naelse if s_colorBuySellBars if reverBarColor == color.purple or reverBarColor == color.orange colorBar := reverBarColor else colorBar := naelse colorBar := nabarcolor(colorBar)//}