Pine Script v4 · Strategy
MA Divergences Strategy
A Pine Script v4 strategy built on WMA (close, 14), Pivotlow (osc, 5) and Pivothigh (osc, 5). It has 2 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 16 settings; defaults include Backtest Start Year 2021, Backtest Start Month 1 and Backtest Start Day 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 MA Divergences Strategy repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did MA Divergences Strategy do on BTCUSDT 1D with default settings?
- Not measured
- It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its code limits trading to a date window, which can leave this period out. It closed no trades on the other markets either. A backtest, not investment advice.
- Can MA Divergences Strategy be converted to Pine Script v5?
- Not tested
- The steps are shown below, but neither version placed a trade on any market tested, so there was nothing to compare and no download is offered.
- What alerts does MA Divergences Strategy have?
- 7
- MA value crosses over 100.0; MA value crosses under 100.0; MA value crosses over -100.0; MA value crosses under -100.0; and more.
- Does MA Divergences Strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
BTCUSDT · 1D · default settings
- MA
- Regular Bullish
- Hidden Bullish
- Regular Bearish
- Hidden Bearish
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- 0.00%
- $0.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 0
- 0 won · 0 lost
- Profitable
- 0.0%
- of closed trades
- Profit factor
- —
- gross profit ÷ gross loss
- Max drawdown
- 0.00%
- $0.00
One run with the author's default settings, $100,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 stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
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 transp =, which v5 removed line 55
transp = on line 55, 63, 82, 90, 109, 117, 136, 144. v5 folds the transparency into the colour with color.new(c, transp).
Upgrade and export
Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.
- Upgrading to v5 renames wma → ta.wma, pivotlow → ta.pivotlow, pivothigh → ta.pivothigh, barssince → ta.barssince, valuewhen → ta.valuewhen.
v4 → v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 4: //@version=4 → //@version=5
- Line 37: wma → ta.wma
- Line 39: pivotlow → ta.pivotlow
- Line 40: pivothigh → ta.pivothigh
- Line 42: barssince → ta.barssince
- Line 51: valuewhen → ta.valuewhen
15 more edits
- Line 53: valuewhen → ta.valuewhen
- Line 55: transp = 0 → color.new((bullCond ? bullColor : noneColor), 0)
- Line 63: transp = 0 → color.new(bullColor, 0)
- Line 78: valuewhen → ta.valuewhen
- Line 80: valuewhen → ta.valuewhen
- Line 82: transp = 0 → color.new((hiddenBullCond ? hiddenBullColor : noneColor), 0)
- Line 90: transp = 0 → color.new(bullColor, 0)
- Line 105: valuewhen → ta.valuewhen
- Line 107: valuewhen → ta.valuewhen
- Line 109: transp = 0 → color.new((bearCond ? bearColor : noneColor), 0)
- Line 117: transp = 0 → color.new(bearColor, 0)
- Line 132: valuewhen → ta.valuewhen
- Line 134: valuewhen → ta.valuewhen
- Line 136: transp = 0 → color.new((hiddenBearCond ? hiddenBearColor : noneColor), 0)
- Line 144: transp = 0 → color.new(bearColor, 0)
⋯//https://www.tradingview.com/u/tista/#published-scripts-//@version=4+//@version=5strategy(title="MA Divergences", format=format.price)⋯noneColor = color.new(color.white, 100)-osc = wma(src, len)+osc = ta.wma(src, len)plot(osc, title="MA", linewidth=2, color=color.yellow)-plFound = na(pivotlow(osc, lbL, lbR)) ? false : true+plFound = na(ta.pivotlow(osc, lbL, lbR)) ? false : true-phFound = na(pivothigh(osc, lbL, lbR)) ? false : true+phFound = na(ta.pivothigh(osc, lbL, lbR)) ? false : true_inRange(cond) =>- bars = barssince(cond == true)+ bars = ta.barssince(cond == true) rangeLower <= bars and bars <= rangeUpper⋯// Osc: Higher Low-oscHL = osc[lbR] > valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])+oscHL = osc[lbR] > ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])// Price: Lower Low-priceLL = low[lbR] < valuewhen(plFound, low[lbR], 1)+priceLL = low[lbR] < ta.valuewhen(plFound, low[lbR], 1)bullCond = plotBull and priceLL and oscHL and plFound⋯ linewidth=2,- color=(bullCond ? bullColor : noneColor),- transp=0+ color=color.new((bullCond ? bullColor : noneColor), 0) )⋯ location=location.absolute,- color=bullColor,+ color=color.new(bullColor, 0),- textcolor=textColor,- transp=0+ textcolor=textColor )⋯// Osc: Lower Low-oscLL = osc[lbR] < valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])+oscLL = osc[lbR] < ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])// Price: Higher Low-priceHL = low[lbR] > valuewhen(plFound, low[lbR], 1)+priceHL = low[lbR] > ta.valuewhen(plFound, low[lbR], 1)hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound⋯ linewidth=2,- color=(hiddenBullCond ? hiddenBullColor : noneColor),- transp=0+ color=color.new((hiddenBullCond ? hiddenBullColor : noneColor), 0) )⋯ location=location.absolute,- color=bullColor,+ color=color.new(bullColor, 0),- textcolor=textColor,- transp=0+ textcolor=textColor )⋯// Osc: Lower High-oscLH = osc[lbR] < valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])+oscLH = osc[lbR] < ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])// Price: Higher High-priceHH = high[lbR] > valuewhen(phFound, high[lbR], 1)+priceHH = high[lbR] > ta.valuewhen(phFound, high[lbR], 1)bearCond = plotBear and priceHH and oscLH and phFound⋯ linewidth=2,- color=(bearCond ? bearColor : noneColor),- transp=0+ color=color.new((bearCond ? bearColor : noneColor), 0) )⋯ location=location.absolute,- color=bearColor,+ color=color.new(bearColor, 0),- textcolor=textColor,- transp=0+ textcolor=textColor )⋯// Osc: Higher High-oscHH = osc[lbR] > valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])+oscHH = osc[lbR] > ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])// Price: Lower High-priceLH = high[lbR] < valuewhen(phFound, high[lbR], 1)+priceLH = high[lbR] < ta.valuewhen(phFound, high[lbR], 1)hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound⋯ linewidth=2,- color=(hiddenBearCond ? hiddenBearColor : noneColor),- transp=0+ color=color.new((hiddenBearCond ? hiddenBearColor : noneColor), 0) )⋯ location=location.absolute,- color=bearColor,+ color=color.new(bearColor, 0),- textcolor=textColor,- transp=0+ textcolor=textColor )⋯Clean v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 10: input() → input.int()
- Line 11: input() → input.int()
- Line 12: input() → input.int()
- Line 14: input() → input.int()
- Line 15: input() → input.int()
- Line 16: input() → input.int()
10 more edits
- Line 21: input() → input.int()
- Line 22: input() → input.source()
- Line 23: input() → input.int()
- Line 24: input() → input.int()
- Line 25: input() → input.int()
- Line 26: input() → input.int()
- Line 27: input() → input.bool()
- Line 28: input() → input.bool()
- Line 29: input() → input.bool()
- Line 30: input() → input.bool()
⋯//* Modifications made *//-testStartYear = input(2021, "Backtest Start Year") +testStartYear = input.int(2021, "Backtest Start Year") -testStartMonth = input(1, "Backtest Start Month")+testStartMonth = input.int(1, "Backtest Start Month")-testStartDay = input(1, "Backtest Start Day")+testStartDay = input.int(1, "Backtest Start Day")testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)-testStopYear = input(999999, "Backtest Stop Year")+testStopYear = input.int(999999, "Backtest Stop Year")-testStopMonth = input(9, "Backtest Stop Month")+testStopMonth = input.int(9, "Backtest Stop Month")-testStopDay = input(26, "Backtest Stop Day")+testStopDay = input.int(26, "Backtest Stop Day")testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)⋯/////////////// END - Backtesting Period Selector | Component ///////////////-len = input(title="MA Period", minval=1, defval=14)+len = input.int(title="MA Period", minval=1, defval=14)-src = input(title="MA Source", defval=close)+src = input.source(title="MA Source", defval=close)-lbR = input(title="Pivot Lookback Right", defval=5)+lbR = input.int(title="Pivot Lookback Right", defval=5)-lbL = input(title="Pivot Lookback Left", defval=5)+lbL = input.int(title="Pivot Lookback Left", defval=5)-rangeUpper = input(title="Max of Lookback Range", defval=600)+rangeUpper = input.int(title="Max of Lookback Range", defval=600)-rangeLower = input(title="Min of Lookback Range", defval=2)+rangeLower = input.int(title="Min of Lookback Range", defval=2)-plotBull = input(title="Plot Bullish", defval=true)+plotBull = input.bool(title="Plot Bullish", defval=true)-plotHiddenBull = input(title="Plot Hidden Bullish", defval=true)+plotHiddenBull = input.bool(title="Plot Hidden Bullish", defval=true)-plotBear = input(title="Plot Bearish", defval=true)+plotBear = input.bool(title="Plot Bearish", defval=true)-plotHiddenBear = input(title="Plot Hidden Bearish", defval=true)+plotHiddenBear = input.bool(title="Plot Hidden Bearish", defval=true)bearColor = color.red⋯Does it run in Pine Script v6?
Not tested
Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯//https://www.tradingview.com/u/tista/#published-scripts-//@version=5+//@version=6strategy(title="MA Divergences", format=format.price)⋯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 |
|---|---|---|---|
| Backtest Start Year | 2021 | int | testPeriodStart |
| Backtest Start Month | 1 | int | testPeriodStart |
| Backtest Start Day | 1 | int | testPeriodStart |
| Backtest Stop Year | 999999 | int | testPeriodStop |
| Backtest Stop Month | 9 | int | testPeriodStop |
| Backtest Stop Day | 26 | int | testPeriodStop |
| MA Period | 14 | int · min 1 | osc |
| MA Source | close | source | osc |
| Pivot Lookback Right | 5 | int | plFound phFound oscHL priceLL oscLL priceHL oscLH priceHH oscHH priceLH Regular Bullish Regular Bullish Label Hidden Bullish Hidden Bullish Label Regular Bearish Regular Bearish Label Hidden Bearish Hidden Bearish Label |
| Pivot Lookback Left | 5 | int | plFound phFound |
| Max of Lookback Range | 600 | int | line 43 |
| Min of Lookback Range | 2 | int | line 43 |
| Plot Bullish | true | bool | bullCond |
| Plot Hidden Bullish | true | bool | hiddenBullCond |
| Plot Bearish | true | bool | bearCond |
| Plot Hidden Bearish | true | bool | hiddenBearCond |
What it calculates
- WMA (
wma,ta.wmain v5)MA Source (close), MA Period (14)osc · line 37 - Pivotlow (
pivotlow,ta.pivotlowin v5)osc, Pivot Lookback Left (5), Pivot Lookback Right (5)plFound · line 39 - Pivothigh (
pivothigh,ta.pivothighin v5)osc, Pivot Lookback Left (5), Pivot Lookback Right (5)phFound · line 40
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 Buy long | bullCond or hiddenBullCond | On | 163 |
| Open Sell short | bearCond or hiddenBearCond | On | 165 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| MA value crosses over 100.0 | alertcondition | Check charts for a MA cross over 100.0 | 44 |
| MA value crosses under 100.0 | alertcondition | Check charts for a MA cross under 100.0 | 45 |
| MA value crosses over -100.0 | alertcondition | Check charts for a MA cross over -100.0 | 46 |
| MA value crosses under -100.0 | alertcondition | Check charts for a MA cross under -100.0 | 47 |
| Regular bullish divergence in MA found | alertcondition | Check charts for a regular bullish divergence found with MA | 74 |
| Hidden bullish divergence in MA found | alertcondition | Check charts for a hidden bullish divergence found with MA | 101 |
| Regular bearish divergence in MA found | alertcondition | Check charts for a regular bearish divergence found with MA | 128 |
Does it repaint?
No
No repainting patterns in the source.
- ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
- ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.
The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.
Other markets
The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | 0.0% | +102.5% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | +9.8% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | 0.0% | +8.4% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | 0.0% | +16.7% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | 0.0% | +21.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | 0.0% | +148.3% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | 0.0% | +17.1% | 0 | 0% | — | 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 (MA Period 7, Pivot Lookback Right 3) made 0.0% before 26 Dec 2025 and 0.0% after it, against 0.0% for the defaults. 0% of the 48 combinations made money in-sample and 0% out-of-sample.
| Pivot Lookback Right ↓ · MA Period → | 7 | 8 | 10 | 12 | 14 | 17 | 20 | 24 |
|---|---|---|---|---|---|---|---|---|
| 3 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 4 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 5 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 6 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 7 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 9 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| Pivot Lookback Right ↓ · MA Period → | 7 | 8 | 10 | 12 | 14 | 17 | 20 | 24 |
|---|---|---|---|---|---|---|---|---|
| 3 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 4 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 5 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 6 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 7 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 9 | 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.
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 |
|---|---|---|---|---|---|
| MA Divergences Strategy this page | — | v4 strategy | 0.0% | 0 | 0.0% |
| Pivot Point Breakout by EduardoMattje | pivotlow pivothigh | v5 strategy | +93.0% | 25 | 32.3% |
| Monthly Returns of a Strategy in a Chart by QuantNomad | pivothigh pivotlow | v5 strategy | +21.0% | 76 | 13.0% |
| ZigZag by Zeal Terminal | pivothigh pivotlow | v5 indicator | indicator | ||
| RSI Centered Pivots by OztheWoz | pivotlow pivothigh | v4 strategy | +98.0% | 4 | 160.2% |
| ABCD Strategy by kerok3g | pivothigh pivotlow | v5 strategy | −2.7% | 4 | 3.0% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 27 ms | Yes 1,000 bars in 80 ms | Not measured |
| PineTS | No v5 and v6 only | — | 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. PineTS runs Pine Script v5 and v6 only.
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/// © tista //https://www.tradingview.com/u/tista/#published-scripts//@version=4strategy(title="MA Divergences", format=format.price)//* Backtesting Period Selector | Component *////* https://www.tradingview.com/script/eCC1cvxQ-Backtesting-Period-Selector-Component *////* https://www.tradingview.com/u/pbergden/ *////* Modifications made *//testStartYear = input(2021, "Backtest Start Year") testStartMonth = input(1, "Backtest Start Month")testStartDay = input(1, "Backtest Start Day")testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)testStopYear = input(999999, "Backtest Stop Year")testStopMonth = input(9, "Backtest Stop Month")testStopDay = input(26, "Backtest Stop Day")testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)testPeriod() => time >= testPeriodStart and time <= testPeriodStop ? true : false/////////////// END - Backtesting Period Selector | Component ///////////////len = input(title="MA Period", minval=1, defval=14)src = input(title="MA Source", defval=close)lbR = input(title="Pivot Lookback Right", defval=5)lbL = input(title="Pivot Lookback Left", defval=5)rangeUpper = input(title="Max of Lookback Range", defval=600)rangeLower = input(title="Min of Lookback Range", defval=2)plotBull = input(title="Plot Bullish", defval=true)plotHiddenBull = input(title="Plot Hidden Bullish", defval=true)plotBear = input(title="Plot Bearish", defval=true)plotHiddenBear = input(title="Plot Hidden Bearish", defval=true)bearColor = color.redbullColor = color.greenhiddenBullColor = color.greenhiddenBearColor = color.redtextColor = color.whitenoneColor = color.new(color.white, 100)osc = wma(src, len)plot(osc, title="MA", linewidth=2, color=color.yellow)plFound = na(pivotlow(osc, lbL, lbR)) ? false : truephFound = na(pivothigh(osc, lbL, lbR)) ? false : true_inRange(cond) => bars = barssince(cond == true) rangeLower <= bars and bars <= rangeUpperalertcondition(osc[1] > 100.0 and osc[2] < 100.0, title="MA value crosses over 100.0", message="Check charts for a MA cross over 100.0")alertcondition(osc[1] < 100.0 and osc[2] > 100.0, title="MA value crosses under 100.0", message="Check charts for a MA cross under 100.0")alertcondition(osc[1] > -100. and osc[2] < -100.0, title="MA value crosses over -100.0", message="Check charts for a MA cross over -100.0")alertcondition(osc[1] < -100.0 and osc[2] > -100.0, title="MA value crosses under -100.0", message="Check charts for a MA cross under -100.0")//------------------------------------------------------------------------------// Regular Bullish// Osc: Higher LowoscHL = osc[lbR] > valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])// Price: Lower LowpriceLL = low[lbR] < valuewhen(plFound, low[lbR], 1)bullCond = plotBull and priceLL and oscHL and plFoundplot( plFound ? osc[lbR] : na, offset=-lbR, title="Regular Bullish", linewidth=2, color=(bullCond ? bullColor : noneColor), transp=0 )plotshape( bullCond ? osc[lbR] : na, offset=-lbR, title="Regular Bullish Label", text=" Bull ", style=shape.labelup, location=location.absolute, color=bullColor, textcolor=textColor, transp=0 )alertcondition(bullCond, title="Regular bullish divergence in MA found", message="Check charts for a regular bullish divergence found with MA")//------------------------------------------------------------------------------// Hidden Bullish// Osc: Lower LowoscLL = osc[lbR] < valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])// Price: Higher LowpriceHL = low[lbR] > valuewhen(plFound, low[lbR], 1)hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFoundplot( plFound ? osc[lbR] : na, offset=-lbR, title="Hidden Bullish", linewidth=2, color=(hiddenBullCond ? hiddenBullColor : noneColor), transp=0 )plotshape( hiddenBullCond ? osc[lbR] : na, offset=-lbR, title="Hidden Bullish Label", text=" H Bull ", style=shape.labelup, location=location.absolute, color=bullColor, textcolor=textColor, transp=0 )alertcondition(hiddenBullCond, title="Hidden bullish divergence in MA found", message="Check charts for a hidden bullish divergence found with MA")//------------------------------------------------------------------------------// Regular Bearish// Osc: Lower HighoscLH = osc[lbR] < valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])// Price: Higher HighpriceHH = high[lbR] > valuewhen(phFound, high[lbR], 1)bearCond = plotBear and priceHH and oscLH and phFoundplot( phFound ? osc[lbR] : na, offset=-lbR, title="Regular Bearish", linewidth=2, color=(bearCond ? bearColor : noneColor), transp=0 )plotshape( bearCond ? osc[lbR] : na, offset=-lbR, title="Regular Bearish Label", text=" Bear ", style=shape.labeldown, location=location.absolute, color=bearColor, textcolor=textColor, transp=0 )alertcondition(bearCond, title="Regular bearish divergence in MA found", message="Check charts for a regular bearish divergence found with MA")//------------------------------------------------------------------------------// Hidden Bearish// Osc: Higher HighoscHH = osc[lbR] > valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])// Price: Lower HighpriceLH = high[lbR] < valuewhen(phFound, high[lbR], 1)hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFoundplot( phFound ? osc[lbR] : na, offset=-lbR, title="Hidden Bearish", linewidth=2, color=(hiddenBearCond ? hiddenBearColor : noneColor), transp=0 )plotshape( hiddenBearCond ? osc[lbR] : na, offset=-lbR, title="Hidden Bearish Label", text=" H Bear ", style=shape.labeldown, location=location.absolute, color=bearColor, textcolor=textColor, transp=0 )// Alerts//alertcondition(bearCond or hiddenBearCond, title='Bear div', message='Bear div')//alertcondition(bullCond or hiddenBullCond, title='Bull div', message='Bull div')//alertcondition(bearCond or bullCond, title='Bull or beal div', message='Bull or bear div') //alertcondition(hiddenBearCond or hiddenBullCond, title='Bull or beal div', message='Hidden Bull or bear div') //alertcondition(hiddenBearCond or hiddenBullCond or bearCond or bullCond, title='Bull or beal div', message='Any Bull or bear div') if testPeriod() if bullCond or hiddenBullCond strategy.entry("Buy", strategy.long) if bearCond or hiddenBearCond strategy.entry("Sell", strategy.short)