Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (16)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctMA$100,000$202,527Equity from $100,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots.
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 verified

Neither 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 verified

Neither 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.

SettingDefaultType and rangeFeeds
Backtest Start Year2021inttestPeriodStart
Backtest Start Month1inttestPeriodStart
Backtest Start Day1inttestPeriodStart
Backtest Stop Year999999inttestPeriodStop
Backtest Stop Month9inttestPeriodStop
Backtest Stop Day26inttestPeriodStop
MA Period14int · min 1osc
MA Sourceclosesourceosc
Pivot Lookback Right5intplFound 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 Left5intplFound phFound
Max of Lookback Range600intline 43
Min of Lookback Range2intline 43
Plot BullishtrueboolbullCond
Plot Hidden BullishtrueboolhiddenBullCond
Plot BearishtrueboolbearCond
Plot Hidden BearishtrueboolhiddenBearCond

What it calculates

  • WMA (wma, ta.wma in v5)MA Source (close), MA Period (14)osc · line 37
  • Pivotlow (pivotlow, ta.pivotlow in v5)osc, Pivot Lookback Left (5), Pivot Lookback Right (5)plFound · line 39
  • Pivothigh (pivothigh, ta.pivothigh in 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.

closecloseprice datalenMA Periodsetting · 14lbRPivot Lookback Rightsetting · 5lbLPivot Lookback Leftsetting · 5testStartYearBacktest Start Yearsetting · 2021testStartMonthBacktest Start Monthsetting · 1testStartDayBacktest Start Daysetting · 1testStopYearBacktest Stop Yearsetting · 999999testStopMonthBacktest Stop Monthsetting · 9testStopDayBacktest Stop Daysetting · 26lowlowprice datahighhighprice dataoscWMA→ oscplFoundPivotlow→ plFoundphFoundPivothigh→ phFoundtestPeriodStarttestPeriodStartvaluetestPeriodStoptestPeriodStopvaluebullCondbullCondconditionhiddenBullCondhiddenBullCondconditionbearCondbearCondconditionhiddenBearCondhiddenBearCondconditionbarsbarsconditionoscHL, oscLLoscHL · oscLL2 conditionspriceLL, priceHLpriceLL · priceHL2 conditionsoscLH, oscHHoscLH · oscHH2 conditionspriceHH, priceLHpriceHH · priceLH2 conditionsbearColor, bullColor, hiddenBullColor, hiddenBearColor, textColor, noneColorColourbearColor · bullColor +4entry:BuyOpen Buystrategy.entryentry:SellOpen Sellstrategy.entryplot:38MAplotalertcondition:44MA value crosses over 1…alertconditionalertcondition:45MA value crosses under …alertconditionalertcondition:46MA value crosses over -…alertconditionalertcondition:47MA value crosses under …alertconditionplot:55Regular Bullishplotplotshape:63Regular Bullish Labelplotshapealertcondition:74Regular bullish diverge…alertconditionplot:82Hidden Bullishplotplotshape:90Hidden Bullish Labelplotshapealertcondition:101Hidden bullish divergen…alertconditionplot:109Regular Bearishplotplotshape:117Regular Bearish Labelplotshapealertcondition:128Regular bearish diverge…alertconditionplot:136Hidden Bearishplotplotshape:144Hidden Bearish Labelplotshape

Order rules

OrderFires whenBy defaultLine
Open Buy longbullCond or hiddenBullCondOn163
Open Sell shortbearCond or hiddenBearCondOn165

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Alerts

AlertCallMessageLine
MA value crosses over 100.0alertconditionCheck charts for a MA cross over 100.044
MA value crosses under 100.0alertconditionCheck charts for a MA cross under 100.045
MA value crosses over -100.0alertconditionCheck charts for a MA cross over -100.046
MA value crosses under -100.0alertconditionCheck charts for a MA cross under -100.047
Regular bullish divergence in MA foundalertconditionCheck charts for a regular bullish divergence found with MA74
Hidden bullish divergence in MA foundalertconditionCheck charts for a hidden bullish divergence found with MA101
Regular bearish divergence in MA foundalertconditionCheck charts for a regular bearish divergence found with MA128

Does it repaint?

No

No repainting patterns in the source.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D0.0%+102.5%00%—0.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h0.0%+5.5%00%—0.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D0.0%+9.8%00%—0.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h0.0%+8.4%00%—0.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D0.0%+16.7%00%—0.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h0.0%+21.5%00%—0.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D0.0%+148.3%00%—0.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h0.0%+17.1%00%—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.

Before 26 Dec 2025 · in-sample
Pivot Lookback Right ↓ · MA Period →78101214172024
30%0%0%0%0%0%0%0%
40%0%0%0%0%0%0%0%
50%0%0%0%0%0%0%0%
60%0%0%0%0%0%0%0%
70%0%0%0%0%0%0%0%
90%0%0%0%0%0%0%0%
From 26 Dec 2025 · out-of-sample
Pivot Lookback Right ↓ · MA Period →78101214172024
30%0%0%0%0%0%0%0%
40%0%0%0%0%0%0%0%
50%0%0%0%0%0%0%0%
60%0%0%0%0%0%0%0%
70%0%0%0%0%0%0%0%
90%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.

ScriptSharesTypeNetTradesMax drawdown
MA Divergences Strategy this page—v4 strategy0.0%00.0%
Pivot Point Breakout by EduardoMattjepivotlow pivothighv5 strategy+93.0%2532.3%
Monthly Returns of a Strategy in a Chart by QuantNomadpivothigh pivotlowv5 strategy+21.0%7613.0%
ZigZag by Zeal Terminalpivothigh pivotlowv5 indicatorindicator
RSI Centered Pivots by OztheWozpivotlow pivothighv4 strategy+98.0%4160.2%
ABCD Strategy by kerok3gpivothigh pivotlowv5 strategy−2.7%43.0%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 27 msYes 1,000 bars in 80 msNot measured
PineTSNo 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)