Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Moving Average Rainbow (Stormer)

A Pine Script v5 strategy with no technical-analysis calculation. It has 6 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade commits 10% of equity and pays 0.12% commission. 17 settings; defaults include Moving Average Type/Tipo de Média Móvel EMA, MA #1 3 and MA #2 5.

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 Moving Average Rainbow (Stormer) repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 12 of 12 trades.
How did Moving Average Rainbow (Stormer) do on BTCUSDT 1D with default settings?
+1.65%
From 26 Jan 2024 to 21 Oct 2026, over 58 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
What alerts does Moving Average Rainbow (Stormer) have?
4
{ "side/lado": "sell", "stop": ' + str.tostring(stopLossShort) + ', "target/alvo": ' + str.tostring(shortPositionLowestLow) + ', "new setup/nova definição": ' + str.tostring(isTurnoverTrendShortTrigger) + ' }; { "side/lado": "sell", "stop": ' + str.tostring(stopLossShort) + ', "target/alvo": ' + str.tostring(shortPositionLowestLow) + ', "new setup/nova definição": ' + str.tostring(isTurnoverTrendShortTrigger) + ' }; { "side/lado": "sell", "stop": ' + str.tostring(stopLossShort) + ', "target/alvo": ' + str.tostring(shortPositionLowestLow) + ', "new setup/nova definição": ' + str.tostring(isTurnoverTrendShortTrigger) + ' }; { "side/lado": "sell", "stop": ' + str.tostring(stopLossShort) + ', "target/alvo": ' + str.tostring(shortPositionLowestLow) + ', "new setup/nova definição": ' + str.tostring(isTurnoverTrendShortTrigger) + ' }.
Does Moving Average Rainbow (Stormer) run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L119:C0: a 'bool' cannot be 'na' in Pine Script v6 — declare it as true or false. The v6 version is shown for reference and is not offered as a download.
Does Moving Average Rainbow (Stormer) use a stop loss?
Yes
strategy.exit sets a stop on line 154, 172, 181, 190.

BTCUSDT · 1D · default settings

  • 1st Moving Average
  • 2nd Moving Average
  • 3rd Moving Average
  • 4th Moving Average
  • 5th Moving Average
  • 6th Moving Average
  • 7th Moving Average
  • 8th Moving Average
  • 9th Moving Average
  • 10th Moving Average
  • 11th Moving Average
  • 12th Moving Average
  • 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 (17)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$10,165$20,253Equity from $10,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.
Table drawn by the script, as it stood on the last bar
Entry Side/Lado da EntradaEntry Price/Preço da Entrada
NONE/NENHUMNONE/NENHUM
Take Profit Price/Preço Alvo LucroStop Loss Price/Preço Stop Loss
NONE/NENHUMNONE/NENHUM
New Target/Novo AlvoPossible Market Turnover/Possível Virada do Mercado
NONE/NENHUMNONE/NENHUM
Net profit
+1.65%
$164.57
Buy and hold
+102.5%
same period
Closed trades
58
27 won · 31 lost
Profitable
46.6%
of closed trades
Profit factor
1.11
gross profit ÷ gross loss
Max drawdown
4.21%
−$420.75

One run with the author's default settings, $10,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.

  • Note

    No slippage

    Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Moving Averages/Médias Móveis
Moving Average Type/Tipo de Média MóvelThis option is to select the type of Moving Average that the Rainbow will use./Esta opção é para selecionar o tipo de Média Móvel que o Rainbow utilizará.EMAstring · options ['EMA', 'SMA', 'RMA', 'WMA', 'HMA', 'VWMA']ma1 ma2 ma3 ma4 ma5 ma6 ma7 ma8 ma9 ma10 ma11 ma12 line 23 line 25 line 27 line 29 line 31
MA #1First MA length./Comprimento da primeira MA.3int · min 1 · step 1ma1 ma2 ma3 ma4 ma5 ma6 ma7 ma8 ma9 ma10 ma11 ma12 line 24 line 26 line 28 line 30 line 32 line 34
MA #2Second MA length./Comprimento da segunda MA.5int · min 1 · step 1ma1 ma2 ma3 ma4 ma5 ma6 ma7 ma8 ma9 ma10 ma11 ma12 line 24 line 26 line 28 line 30 line 32 line 34
MA #3Third MA length./Comprimento da terceira MA.8int · min 1 · step 1ma1 ma2 ma3 ma4 ma5 ma6 ma7 ma8 ma9 ma10 ma11 ma12 line 24 line 26 line 28 line 30 line 32 line 34
MA #4Fourth MA length./Comprimento da quarta MA.13int · min 1 · step 1ma1 ma2 ma3 ma4 ma5 ma6 ma7 ma8 ma9 ma10 ma11 ma12 line 24 line 26 line 28 line 30 line 32 line 34
MA #5Fifth MA length./Comprimento da quinta MA.20int · min 1 · step 1ma1 ma2 ma3 ma4 ma5 ma6 ma7 ma8 ma9 ma10 ma11 ma12 line 24 line 26 line 28 line 30 line 32 line 34
MA #6Sixth MA length./Comprimento da sexta MA.25int · min 1 · step 1ma1 ma2 ma3 ma4 ma5 ma6 ma7 ma8 ma9 ma10 ma11 ma12 line 24 line 26 line 28 line 30 line 32 line 34
MA #7Seventh MA length./Comprimento da sétima MA.30int · min 1 · step 1ma1 ma2 ma3 ma4 ma5 ma6 ma7 ma8 ma9 ma10 ma11 ma12 line 24 line 26 line 28 line 30 line 32 line 34
MA #8Eighth MA length./Comprimento da oitava MA.35int · min 1 · step 1ma1 ma2 ma3 ma4 ma5 ma6 ma7 ma8 ma9 ma10 ma11 ma12 line 24 line 26 line 28 line 30 line 32 line 34
MA #9Nineth MA length./Comprimento da nona MA.40int · min 1 · step 1ma1 ma2 ma3 ma4 ma5 ma6 ma7 ma8 ma9 ma10 ma11 ma12 line 24 line 26 line 28 line 30 line 32 line 34
MA #10Tenth MA length./Comprimento da décima MA.45int · min 1 · step 1ma1 ma2 ma3 ma4 ma5 ma6 ma7 ma8 ma9 ma10 ma11 ma12 line 24 line 26 line 28 line 30 line 32 line 34
MA #11Eleventh MA length./Comprimento da décima primeira MA.50int · min 1 · step 1ma1 ma2 ma3 ma4 ma5 ma6 ma7 ma8 ma9 ma10 ma11 ma12 line 24 line 26 line 28 line 30 line 32 line 34
MA #12Twelveth MA length./Comprimento da décima segunda MA.55int · min 1 · step 1ma1 ma2 ma3 ma4 ma5 ma6 ma7 ma8 ma9 ma10 ma11 ma12 line 24 line 26 line 28 line 30 line 32 line 34
Risk Management/Gerenciamento de Risco
Target Take Profit/Objetivo de Lucro AlvoCalculate the take profit factor when entry position./Calcula o fator do alvo lucro ao entrar na posição.1.6float · min 0.1 · step 0.1targetLong targetShort
Turnover Trend/Rotatividade Tendência
Verify Turnover Trend/Verificar Tendência de RotatividadeThis option checks for a supposedly turnover trend and setup new target (for long is the highest high and for short is the lowest low identified)./Esta opção verifica uma suposta tendência de rotatividade e estabelece um novo objetivo (para long é a máxima mais alta, para short é a mínima mais baixa identificados).trueboolline 173 line 182 line 221 line 223
Turnover Signal/Rotatividade Sinal
Verify Turnover Signal/Verificar Sinal de RotatividadeThis option checks for a supposedly turnover signal, closing the current position and opening a new one (for long it will close and open a new for short, for short it will close and open a new for long)./Essa opção verifica um sinal de possível reversão, fechando a posição atual e abrindo uma nova (para long fechará e abrirá uma nova para short, para short fechará e abrirá uma nova para long).falseboollongTurnoverExit shortTurnoverExit
Verify Price Exit Turnover Signal/Verificar Saída de Preço Sinal de RotatividadeThis option complements "turnover signal" by veryfing the price if profitable before exiting the current position./Esta opção complementa o "sinal de rotatividade" verificando o preço do lucro antes de sair da posição atual.falseboollongTurnoverExit shortTurnoverExit

What it calculates

No technical-analysis calculation: the script works on prices and settings directly.

Signal flow

How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.

The script has 74 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.

Order rules

OrderFires whenBy defaultLine
Open Long long(targetLong > 0 and stopLossLong > 0)On153
Exit Exit Long stop and limit(targetLong > 0 and stopLossLong > 0)On154
Open Short short(targetShort > 0 and stopLossShort > 0)On171
Exit Exit Short stop and limit(targetShort > 0 and stopLossShort > 0)On172
Exit Exit Long stop and limit(isMa1To4Below and isCloseLesserMaMean and longPositionHighestHigh > positionEntryPrice)On181
Exit Exit Short stop and limit(isMa1To4Above and isCloseGreaterMaMean and shortPositionLowestLow < positionEntryPrice)On190

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

Alerts

AlertCallMessageLine
(no title)alert{ "side/lado": "sell", "stop": ' + str.tostring(stopLossShort) + ', "target/alvo": ' + str.tostring(shortPositionLowestLow) + ', "new setup/nova definição": ' + str.tostring(isTurnoverTrendShortTrigger) + ' }152
(no title)alert{ "side/lado": "sell", "stop": ' + str.tostring(stopLossShort) + ', "target/alvo": ' + str.tostring(shortPositionLowestLow) + ', "new setup/nova definição": ' + str.tostring(isTurnoverTrendShortTrigger) + ' }170
(no title)alert{ "side/lado": "sell", "stop": ' + str.tostring(stopLossShort) + ', "target/alvo": ' + str.tostring(shortPositionLowestLow) + ', "new setup/nova definição": ' + str.tostring(isTurnoverTrendShortTrigger) + ' }180
(no title)alert{ "side/lado": "sell", "stop": ' + str.tostring(stopLossShort) + ', "target/alvo": ' + str.tostring(shortPositionLowestLow) + ', "new setup/nova definição": ' + str.tostring(isTurnoverTrendShortTrigger) + ' }189

Does it repaint?

No

No repainting patterns in the source, and the live replay matched history.

12/12trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
  • ClearFuture-bar referencesNo negative history offsets such as close[-1].
  • ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
  • ClearOrder timingprocess_orders_on_close = true: orders fill at the signal bar's close.

The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.

Other markets

The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D+1.6%+102.5%5847%1.114.2%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−2.2%+5.5%6038%0.663.5%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−1.9%+9.8%6737%0.937.5%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−1.7%+8.4%6639%0.814.2%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+1.1%+16.7%6538%1.0311.2%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.8%+21.5%6941%1.094.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−1.3%+148.3%7441%0.946.1%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−3.9%+17.1%5834%0.484.2%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market1850%$118.38
Sideways market2642%$40.20
Falling market1450%$5.99

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

6.6%

The 95th percentile of the worst drawdown when the same 58 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 2.8% to 6.6%; the tick is what actually happened, 4.0%. Order luck alone moves it this much.

0%8%
All 58 trades
SideEntryExitBarsP&L
long21 Mar 2024 65,501.3017 Apr 2024 59,897.5027−$87.74
short9 May 2024 63,074.0010 May 2024 62,420.301$7.90
long21 May 2024 70,148.3014 Jun 2024 65,420.8024−$69.07
short24 Jun 2024 60,293.3015 Jul 2024 64,829.2021−$76.47
long27 Jul 2024 67,896.5031 Jul 2024 65,221.504−$40.76
short11 Aug 2024 58,712.6023 Aug 2024 62,035.8012−$57.43
short30 Aug 2024 59,124.004 Sep 2024 55,775.905$52.48
short6 Sep 2024 53,963.0013 Sep 2024 58,783.407−$89.24
long23 Sep 2024 63,340.0026 Sep 2024 65,594.803$31.92
long27 Sep 2024 65,769.901 Oct 2024 62,405.804−$51.67
long6 Oct 2024 62,819.909 Oct 2024 61,603.803−$20.88
long14 Oct 2024 66,084.0029 Oct 2024 72,559.4015$91.53
long4 Nov 2024 67,850.005 Nov 2024 69,544.601$21.82
long6 Nov 2024 75,572.0011 Nov 2024 88,702.705$166.02
long12 Nov 2024 87,952.005 Dec 2024 103,616.0023$173.14
long8 Dec 2024 101,110.009 Dec 2024 98,582.101−$27.48
long11 Dec 2024 101,125.0020 Dec 2024 92,831.309−$84.42
long21 Dec 2024 97,292.0025 Dec 2024 99,540.604$20.53
long3 Jan 2025 98,174.208 Jan 2025 94,228.305−$42.32
long16 Jan 2025 99,987.3017 Jan 2025 105,694.001$54.10
long19 Jan 2025 101,332.0020 Jan 2025 104,674.001$30.42
long23 Jan 2025 103,910.0027 Jan 2025 100,308.004−$36.99
long28 Jan 2025 101,336.002 Feb 2025 97,407.005−$40.93
short16 Feb 2025 96,118.1020 Feb 2025 98,317.904−$25.09
short23 Feb 2025 96,258.0024 Feb 2025 94,404.901$16.68
short25 Feb 2025 88,680.407 Apr 2025 76,606.0041$132.64
short9 Apr 2025 82,615.2010 Apr 2025 80,606.101$22.03
long25 Apr 2025 94,638.708 May 2025 99,863.8013$53.05
long9 May 2025 102,972.009 Jul 2025 111,980.0061$85.92
long10 Jul 2025 116,010.0013 Aug 2025 123,218.0034$60.84
long14 Aug 2025 118,295.0015 Aug 2025 117,112.001−$12.71
long17 Aug 2025 117,405.0018 Aug 2025 116,756.001−$8.12
short30 Aug 2025 108,816.005 Sep 2025 113,003.006−$41.89
long18 Sep 2025 117,074.0022 Sep 2025 114,520.004−$24.65
short26 Sep 2025 109,643.0029 Sep 2025 113,622.003−$39.39
long6 Oct 2025 124,659.007 Oct 2025 121,040.001−$31.80
short3 Nov 2025 106,583.004 Nov 2025 99,034.601$69.19
short7 Nov 2025 103,339.008 Nov 2025 101,922.001$11.52
short9 Nov 2025 104,723.0010 Nov 2025 105,868.001−$13.59
short11 Nov 2025 103,059.0014 Nov 2025 95,866.803$68.60
short16 Nov 2025 94,261.4020 Nov 2025 87,879.004$66.93
short21 Nov 2025 85,129.403 Dec 2025 93,304.6012−$101.53
short4 Dec 2025 92,078.107 Dec 2025 88,051.803$42.21
short9 Dec 2025 92,678.8014 Dec 2025 88,557.405$43.15
short15 Dec 2025 86,432.1022 Dec 2025 90,565.507−$51.72
short23 Dec 2025 87,486.004 Jan 2026 91,243.3012−$46.46
short29 Jan 2026 84,650.202 Feb 2026 74,955.604$114.37
short3 Feb 2026 75,770.205 Feb 2026 67,989.002$103.45
short6 Feb 2026 70,580.3017 Mar 2026 75,636.1039−$77.13
short21 Mar 2026 68,918.1023 Mar 2026 71,552.502−$42.01
short27 Mar 2026 66,407.307 Apr 2026 71,540.4011−$82.08
long16 Apr 2026 75,154.304 May 2026 79,570.1018$57.44
long5 May 2026 80,905.5016 May 2026 78,142.1011−$37.47
short2 Jun 2026 66,760.8021 Aug 2026 74,882.7080−$126.99
long24 Aug 2026 78,992.8021 Sep 2026 85,617.3028$82.16
long25 Sep 2026 84,100.008 Oct 2026 81,677.9013−$31.73
long11 Oct 2026 83,773.1012 Oct 2026 82,232.801−$21.07
long19 Oct 2026 81,938.4021 Oct 2026 84,190.802$25.37

Similar scripts

No other indicator or strategy here shares enough of its calculations.

Upgrade and export

Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.

  • No v6-only features. v6 is not needed to run this script.

Clean v5

Verified

Nothing to change.

Does it run in Pine Script v6?

No

The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L119:C0: a 'bool' cannot be 'na' in Pine Script v6 — declare it as true or false. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// © AugustoErni-//@version=5+//@version=6strategy('Moving Average Rainbow (Stormer)', overlay=true, process_orders_on_close=true, calc_on_every_tick=false, calc_on_order_fills=false, initial_capital=10000, currency=currency.USD, default_qty_type=strategy.percent_of_equity, default_qty_value=10, pyramiding=0, commission_type=strategy.commission.percent, commission_value=0.12)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 142 msYes 1,000 bars in 161 msNot measured
PineTSNot testedNot testedNot measured

“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report.

Source

Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © AugustoErni//@version=5strategy('Moving Average Rainbow (Stormer)', overlay=true, process_orders_on_close=true, calc_on_every_tick=false, calc_on_order_fills=false, initial_capital=10000, currency=currency.USD, default_qty_type=strategy.percent_of_equity, default_qty_value=10, pyramiding=0, commission_type=strategy.commission.percent, commission_value=0.12)maType                        = input.string('EMA', title='Moving Average Type/Tipo de Média Móvel', options=['EMA', 'SMA', 'RMA', 'WMA', 'HMA', 'VWMA'], tooltip='This option is to select the type of Moving Average that the Rainbow will use./Esta opção é para selecionar o tipo de Média Móvel que o Rainbow utilizará.', group='Moving Averages/Médias Móveis')maLengthFirst                 = input.int(3, title='MA #1', minval=1, step=1, tooltip='First MA length./Comprimento da primeira MA.', group='Moving Averages/Médias Móveis')maLengthSecond                = input.int(5, title='MA #2', minval=1, step=1, tooltip='Second MA length./Comprimento da segunda MA.', group='Moving Averages/Médias Móveis')maLengthThird                 = input.int(8, title='MA #3', minval=1, step=1, tooltip='Third MA length./Comprimento da terceira MA.', group='Moving Averages/Médias Móveis')maLengthFourth                = input.int(13, title='MA #4', minval=1, step=1, tooltip='Fourth MA length./Comprimento da quarta MA.', group='Moving Averages/Médias Móveis')maLengthFifth                 = input.int(20, title='MA #5', minval=1, step=1, tooltip='Fifth MA length./Comprimento da quinta MA.', group='Moving Averages/Médias Móveis')maLengthSixth                 = input.int(25, title='MA #6', minval=1, step=1, tooltip='Sixth MA length./Comprimento da sexta MA.', group='Moving Averages/Médias Móveis')maLengthSeventh               = input.int(30, title='MA #7', minval=1, step=1, tooltip='Seventh MA length./Comprimento da sétima MA.', group='Moving Averages/Médias Móveis')maLengthEighth                = input.int(35, title='MA #8', minval=1, step=1, tooltip='Eighth MA length./Comprimento da oitava MA.', group='Moving Averages/Médias Móveis')maLengthNineth                = input.int(40, title='MA #9', minval=1, step=1, tooltip='Nineth MA length./Comprimento da nona MA.', group='Moving Averages/Médias Móveis')maLengthTenth                 = input.int(45, title='MA #10', minval=1, step=1, tooltip='Tenth MA length./Comprimento da décima MA.', group='Moving Averages/Médias Móveis')maLengthEleventh              = input.int(50, title='MA #11', minval=1, step=1, tooltip='Eleventh MA length./Comprimento da décima primeira MA.', group='Moving Averages/Médias Móveis')maLengthTwelveth              = input.int(55, title='MA #12', minval=1, step=1, tooltip='Twelveth MA length./Comprimento da décima segunda MA.', group='Moving Averages/Médias Móveis')targetFactor                  = input.float(1.6, title='Target Take Profit/Objetivo de Lucro Alvo', minval=0.1, step=0.1, tooltip='Calculate the take profit factor when entry position./Calcula o fator do alvo lucro ao entrar na posição.', group='Risk Management/Gerenciamento de Risco')verifyTurnoverTrend           = input.bool(true, title='Verify Turnover Trend/Verificar Tendência de Rotatividade', tooltip='This option checks for a supposedly turnover trend and setup new target (for long is the highest high and for short is the lowest low identified)./Esta opção verifica uma suposta tendência de rotatividade e estabelece um novo objetivo (para long é a máxima mais alta, para short é a mínima mais baixa identificados).', group='Turnover Trend/Rotatividade Tendência')verifyTurnoverSignal          = input.bool(false, title='Verify Turnover Signal/Verificar Sinal de Rotatividade', tooltip='This option checks for a supposedly turnover signal, closing the current position and opening a new one (for long it will close and open a new for short, for short it will close and open a new for long)./Essa opção verifica um sinal de possível reversão, fechando a posição atual e abrindo uma nova (para long fechará e abrirá uma nova para short, para short fechará e abrirá uma nova para long).', group='Turnover Signal/Rotatividade Sinal')verifyTurnoverSignalPriceExit = input.bool(false, title='Verify Price Exit Turnover Signal/Verificar Saída de Preço Sinal de Rotatividade', tooltip='This option complements "turnover signal" by veryfing the price if profitable before exiting the current position./Esta opção complementa o "sinal de rotatividade" verificando o preço do lucro antes de sair da posição atual.', group='Turnover Signal/Rotatividade Sinal')mas(maType, maLengthFirst, maLengthSecond, maLengthThird, maLengthFourth, maLengthFifth, maLengthSixth, maLengthSeventh, maLengthEighth, maLengthNineth, maLengthTenth, maLengthEleventh, maLengthTwelveth) =>    if (maType == 'SMA')        [ta.sma(close, maLengthFirst), ta.sma(close, maLengthSecond), ta.sma(close, maLengthThird), ta.sma(close, maLengthFourth), ta.sma(close, maLengthFifth), ta.sma(close, maLengthSixth), ta.sma(close, maLengthSeventh), ta.sma(close, maLengthEighth), ta.sma(close, maLengthNineth), ta.sma(close, maLengthTenth), ta.sma(close, maLengthEleventh), ta.sma(close, maLengthTwelveth)]    else if (maType == 'RMA')        [ta.rma(close, maLengthFirst), ta.rma(close, maLengthSecond), ta.rma(close, maLengthThird), ta.rma(close, maLengthFourth), ta.rma(close, maLengthFifth), ta.rma(close, maLengthSixth), ta.rma(close, maLengthSeventh), ta.rma(close, maLengthEighth), ta.rma(close, maLengthNineth), ta.rma(close, maLengthTenth), ta.rma(close, maLengthEleventh), ta.rma(close, maLengthTwelveth)]    else if (maType == 'WMA')        [ta.wma(close, maLengthFirst), ta.wma(close, maLengthSecond), ta.wma(close, maLengthThird), ta.wma(close, maLengthFourth), ta.wma(close, maLengthFifth), ta.wma(close, maLengthSixth), ta.wma(close, maLengthSeventh), ta.wma(close, maLengthEighth), ta.wma(close, maLengthNineth), ta.wma(close, maLengthTenth), ta.wma(close, maLengthEleventh), ta.wma(close, maLengthTwelveth)]    else if (maType == 'HMA')        [ta.hma(close, maLengthFirst), ta.hma(close, maLengthSecond), ta.hma(close, maLengthThird), ta.hma(close, maLengthFourth), ta.hma(close, maLengthFifth), ta.hma(close, maLengthSixth), ta.hma(close, maLengthSeventh), ta.hma(close, maLengthEighth), ta.hma(close, maLengthNineth), ta.hma(close, maLengthTenth), ta.hma(close, maLengthEleventh), ta.hma(close, maLengthTwelveth)]    else if (maType == 'VWMA')        [ta.vwma(close, maLengthFirst), ta.vwma(close, maLengthSecond), ta.vwma(close, maLengthThird), ta.vwma(close, maLengthFourth), ta.vwma(close, maLengthFifth), ta.vwma(close, maLengthSixth), ta.vwma(close, maLengthSeventh), ta.vwma(close, maLengthEighth), ta.vwma(close, maLengthNineth), ta.vwma(close, maLengthTenth), ta.vwma(close, maLengthEleventh), ta.vwma(close, maLengthTwelveth)]    else        [ta.ema(close, maLengthFirst), ta.ema(close, maLengthSecond), ta.ema(close, maLengthThird), ta.ema(close, maLengthFourth), ta.ema(close, maLengthFifth), ta.ema(close, maLengthSixth), ta.ema(close, maLengthSeventh), ta.ema(close, maLengthEighth), ta.ema(close, maLengthNineth), ta.ema(close, maLengthTenth), ta.ema(close, maLengthEleventh), ta.ema(close, maLengthTwelveth)][ma1, ma2, ma3, ma4, ma5, ma6, ma7, ma8, ma9, ma10, ma11, ma12] = mas(maType, maLengthFirst, maLengthSecond, maLengthThird, maLengthFourth, maLengthFifth, maLengthSixth, maLengthSeventh, maLengthEighth, maLengthNineth, maLengthTenth, maLengthEleventh, maLengthTwelveth)maTouchPriceTrend(ma1, ma2, ma3, ma4, ma5, ma6, ma7, ma8, ma9, ma10, ma11, ma12, trend) =>    var float touchPrice = na    if (trend == 'UPTREND')        if (low <= ma1 and low >= ma2)            touchPrice := ma2        else if (low <= ma2 and low >= ma3)            touchPrice := ma3        else if (low <= ma3 and low >= ma4)            touchPrice := ma4        else if (low <= ma4 and low >= ma5)            touchPrice := ma5        else if (low <= ma5 and low >= ma6)            touchPrice := ma6        else if (low <= ma6 and low >= ma7)            touchPrice := ma7        else if (low <= ma7 and low >= ma8)            touchPrice := ma8        else if (low <= ma8 and low >= ma9)            touchPrice := ma9        else if (low <= ma9 and low >= ma10)            touchPrice := ma10        else if (low <= ma10 and low >= ma11)            touchPrice := ma11        else if (low <= ma11 and low >= ma12)            touchPrice := ma12        else            touchPrice := na    else if (trend == 'DOWNTREND')        if (high >= ma1 and high <= ma2)            touchPrice := ma2        else if (high >= ma2 and high <= ma3)            touchPrice := ma3        else if (high >= ma3 and high <= ma4)            touchPrice := ma4        else if (high >= ma4 and high <= ma5)            touchPrice := ma5        else if (high >= ma5 and high <= ma6)            touchPrice := ma6        else if (high >= ma6 and high <= ma7)            touchPrice := ma7        else if (high >= ma7 and high <= ma8)            touchPrice := ma8        else if (high >= ma8 and high <= ma9)            touchPrice := ma9        else if (high >= ma9 and high <= ma10)            touchPrice := ma10        else if (high >= ma10 and high <= ma11)            touchPrice := ma11        else if (high >= ma11 and high <= ma12)            touchPrice := ma12        else            touchPrice := namaMean = ((ma1 + ma2 + ma3 + ma4 + ma5 + ma6 + ma7 + ma8 + ma9 + ma10 + ma11 + ma12) / 12)isMa1To4Above            = ma1 > ma2 and ma2 > ma3 and ma3 > ma4 ? 1 : 0isMa1To4Below            = ma1 < ma2 and ma2 < ma3 and ma3 < ma4 ? 1 : 0isMa5To8Above            = ma5 > ma6 and ma6 > ma7 and ma7 > ma8 ? 1 : 0isMa5To8Below            = ma5 < ma6 and ma6 < ma7 and ma7 < ma8 ? 1 : 0isCloseGreaterMaMean     = close > maMean ? 1 : 0isCloseLesserMaMean      = close < maMean ? 1 : 0isCurHighGreaterPrevHigh = high > high[1] ? 1 : 0isCurLowLesserPrevLow    = low < low[1] ? 1 : 0isMaUptrend              = isCloseGreaterMaMean and isMa5To8Above ? 1 : 0isMaDowntrend            = isCloseLesserMaMean and isMa5To8Below ? 1 : 0isUptrend                = isMaUptrend ? 'UPTREND' : naisDowntrend              = isMaDowntrend ? 'DOWNTREND' : nacurTouchPriceUptrend    = maTouchPriceTrend(ma1, ma2, ma3, ma4, ma5, ma6, ma7, ma8, ma9, ma10, ma11, ma12, isUptrend)prevTouchPriceUptrend   = curTouchPriceUptrend[1]curTouchPriceDowntrend  = maTouchPriceTrend(ma1, ma2, ma3, ma4, ma5, ma6, ma7, ma8, ma9, ma10, ma11, ma12, isDowntrend)prevTouchPriceDowntrend = curTouchPriceDowntrend[1]isPrevTouchPriceUptrendTouched   = prevTouchPriceUptrend > 0.0 or not na(prevTouchPriceUptrend) ? 1 : 0isPrevTouchPriceDowntrendTouched = prevTouchPriceDowntrend > 0.0 or not na(prevTouchPriceDowntrend) ? 1 : 0isPrevTouchedPriceUptrend        = isPrevTouchPriceUptrendTouched and isMaUptrend ? 1 : 0isPrevTouchedPriceDowntrend      = isPrevTouchPriceDowntrendTouched and isMaDowntrend ? 1 : 0isPositionFlat  = strategy.position_size == 0 ? 1 : 0var float positionEntryPrice         = navar bool positionIsEntryLong         = falsevar bool positionIsEntryShort        = falsevar float longPositionHighestHigh    = navar float shortPositionLowestLow     = navar float stopLossLong               = navar float stopLossShort              = navar float targetLong                 = navar float targetShort                = navar bool isTurnoverTrendLongTrigger  = navar bool isTurnoverTrendShortTrigger = naisPositionLongClose  = na(positionEntryPrice) and not positionIsEntryLong ? 1 : 0isPositionShortClose = na(positionEntryPrice) and not positionIsEntryShort ? 1 : 0isLongCondition      = isMaUptrend and isCurHighGreaterPrevHigh and isPrevTouchedPriceUptrend ? 1 : 0isShortCondition     = isMaDowntrend and isCurLowLesserPrevLow and isPrevTouchedPriceDowntrend ? 1 : 0longTurnoverExit     = verifyTurnoverSignal and verifyTurnoverSignalPriceExit ? (verifyTurnoverSignal and isLongCondition and positionIsEntryShort and close < positionEntryPrice) : verifyTurnoverSignal ? (verifyTurnoverSignal and isLongCondition and positionIsEntryShort) : nashortTurnoverExit    = verifyTurnoverSignal and verifyTurnoverSignalPriceExit ? (verifyTurnoverSignal and isShortCondition and positionIsEntryLong and close > positionEntryPrice) : verifyTurnoverSignal ? (verifyTurnoverSignal and isShortCondition and positionIsEntryLong) : naif (isPositionFlat)    positionEntryPrice          := na    positionIsEntryLong         := false    positionIsEntryShort        := false    stopLossLong                := na    targetLong                  := na    stopLossShort               := na    targetShort                 := na    isTurnoverTrendLongTrigger  := na    isTurnoverTrendShortTrigger := naif ((isLongCondition and isPositionLongClose) or longTurnoverExit)    positionEntryPrice          := close    positionIsEntryLong         := true    positionIsEntryShort        := false    longPositionHighestHigh     := na    shortPositionLowestLow      := na    isTurnoverTrendLongTrigger  := na    isTurnoverTrendShortTrigger := na    stopLossLong                := prevTouchPriceUptrend    if (isCurLowLesserPrevLow)        curLowToucedPrice = na(curTouchPriceUptrend) ? low : curTouchPriceUptrend        stopLossLong      := na(curTouchPriceUptrend) ? ((stopLossLong + curLowToucedPrice) / 2) : curLowToucedPrice    targetLong := (positionEntryPrice + (math.abs(positionEntryPrice - stopLossLong) * targetFactor))    if (targetLong > 0 and stopLossLong > 0)        alertMessage = '{ "side/lado": "buy", "entry/entrada": ' + str.tostring(positionEntryPrice) + ', "stop": ' + str.tostring(stopLossLong) + ', "target/alvo": ' + str.tostring(targetLong) + ' }'        alert(alertMessage)        strategy.entry('Long', strategy.long)        strategy.exit('Exit Long', 'Long', stop=stopLossLong, limit=targetLong)if ((isShortCondition and isPositionShortClose) or shortTurnoverExit)    positionEntryPrice          := close    positionIsEntryLong         := false    positionIsEntryShort        := true    longPositionHighestHigh     := na    shortPositionLowestLow      := na    isTurnoverTrendLongTrigger  := na    isTurnoverTrendShortTrigger := na    stopLossShort               := prevTouchPriceDowntrend    if (isCurHighGreaterPrevHigh)        curHighToucedPrice = na(curTouchPriceDowntrend) ? high : curTouchPriceDowntrend        stopLossShort      := na(curTouchPriceDowntrend) ? ((stopLossShort + curHighToucedPrice) / 2) : curHighToucedPrice    targetShort := (positionEntryPrice - (math.abs(positionEntryPrice - stopLossShort) * targetFactor))    if (targetShort > 0 and stopLossShort > 0)        alertMessage = '{ "side/lado": "sell", "entry/entrada": ' + str.tostring(positionEntryPrice) + ', "stop": ' + str.tostring(stopLossShort) + ', "target/alvo": ' + str.tostring(targetShort) + ' }'        alert(alertMessage)        strategy.entry('Short', strategy.short)        strategy.exit('Exit Short', 'Short', stop=stopLossShort, limit=targetShort)if (verifyTurnoverTrend and positionIsEntryLong)    curHighestHigh = high    if (curHighestHigh > longPositionHighestHigh or na(longPositionHighestHigh))        longPositionHighestHigh := curHighestHigh    if (isMa1To4Below and isCloseLesserMaMean and longPositionHighestHigh > positionEntryPrice)        isTurnoverTrendLongTrigger := true        alertMessage = '{ "side/lado": "buy", "stop": ' + str.tostring(stopLossLong) + ', "target/alvo": ' + str.tostring(longPositionHighestHigh) + ', "new setup/nova definição": ' + str.tostring(isTurnoverTrendLongTrigger) + ' }'        alert(alertMessage)        strategy.exit('Exit Long', 'Long', stop=stopLossLong, limit=longPositionHighestHigh)if (verifyTurnoverTrend and positionIsEntryShort)    curLowestLow = low    if (curLowestLow < shortPositionLowestLow or na(shortPositionLowestLow))        shortPositionLowestLow := curLowestLow    if (isMa1To4Above and isCloseGreaterMaMean and shortPositionLowestLow < positionEntryPrice)        isTurnoverTrendShortTrigger := true        alertMessage = '{ "side/lado": "sell", "stop": ' + str.tostring(stopLossShort) + ', "target/alvo": ' + str.tostring(shortPositionLowestLow) + ', "new setup/nova definição": ' + str.tostring(isTurnoverTrendShortTrigger) + ' }'        alert(alertMessage)        strategy.exit('Exit Short', 'Short', stop=stopLossShort, limit=shortPositionLowestLow)plot(ma1, title='1st Moving Average', color=color.rgb(240, 240, 240))plot(ma2, title='2nd Moving Average', color=color.rgb(220, 220, 220))plot(ma3, title='3rd Moving Average', color=color.rgb(200, 200, 200))plot(ma4, title='4th Moving Average', color=color.rgb(180, 180, 180))plot(ma5, title='5th Moving Average', color=color.rgb(160, 160, 160))plot(ma6, title='6th Moving Average', color=color.rgb(140, 140, 140))plot(ma7, title='7th Moving Average', color=color.rgb(120, 120, 120))plot(ma8, title='8th Moving Average', color=color.rgb(100, 120, 120))plot(ma9, title='9th Moving Average', color=color.rgb(80, 120, 120))plot(ma10, title='10th Moving Average', color=color.rgb(60, 120, 120))plot(ma11, title='11th Moving Average', color=color.rgb(40, 120, 120))plot(ma12, title='12th Moving Average', color=color.rgb(20, 120, 120))tablePosition    = position.bottom_righttableColumns     = 2tableRows        = 7tableFrameWidth  = 1tableBorderColor = color.graytableBorderWidth = 1tableInfoTrade   = table.new(position=tablePosition, columns=tableColumns, rows=tableRows, frame_width=tableFrameWidth, border_color=tableBorderColor, border_width=tableBorderWidth)table.cell(table_id=tableInfoTrade, column=0, row=0)table.cell(table_id=tableInfoTrade, column=1, row=0)table.cell(table_id=tableInfoTrade, column=0, row=1, text='Entry Side/Lado da Entrada', text_color=color.white)table.cell(table_id=tableInfoTrade, column=0, row=2, text=positionIsEntryLong ? 'LONG' : positionIsEntryShort ? 'SHORT' : 'NONE/NENHUM', text_color=color.yellow)table.cell(table_id=tableInfoTrade, column=1, row=1, text='Entry Price/Preço da Entrada', text_color=color.white)table.cell(table_id=tableInfoTrade, column=1, row=2, text=not na(positionEntryPrice) ? str.tostring(positionEntryPrice) : 'NONE/NENHUM', text_color=color.blue)table.cell(table_id=tableInfoTrade, column=0, row=3, text='Take Profit Price/Preço Alvo Lucro', text_color=color.white)table.cell(table_id=tableInfoTrade, column=0, row=4, text=positionIsEntryLong ? str.tostring(targetLong) : positionIsEntryShort ? str.tostring(targetShort) : 'NONE/NENHUM', text_color=color.green)table.cell(table_id=tableInfoTrade, column=1, row=3, text='Stop Loss Price/Preço Stop Loss', text_color=color.white)table.cell(table_id=tableInfoTrade, column=1, row=4, text=positionIsEntryLong ? str.tostring(stopLossLong) : positionIsEntryShort ? str.tostring(stopLossShort) : 'NONE/NENHUM', text_color=color.red)table.cell(table_id=tableInfoTrade, column=0, row=5, text='New Target/Novo Alvo', text_color=color.white)table.cell(table_id=tableInfoTrade, column=0, row=6, text=verifyTurnoverTrend and positionIsEntryLong and isTurnoverTrendLongTrigger ? str.tostring(longPositionHighestHigh) : verifyTurnoverTrend and positionIsEntryShort and isTurnoverTrendShortTrigger ? str.tostring(shortPositionLowestLow) : 'NONE/NENHUM', text_color=color.green)table.cell(table_id=tableInfoTrade, column=1, row=5, text='Possible Market Turnover/Possível Virada do Mercado', text_color=color.white)table.cell(table_id=tableInfoTrade, column=1, row=6, text=verifyTurnoverTrend and positionIsEntryLong and isTurnoverTrendLongTrigger ? 'YES/SIM (Possible long going short/Possível long indo short)' : verifyTurnoverTrend and positionIsEntryShort and isTurnoverTrendShortTrigger ? 'YES/SIM (Possible short going long/Possível short indo long)' : 'NONE/NENHUM', text_color=color.red)