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
| Entry Side/Lado da Entrada | Entry Price/Preço da Entrada |
| NONE/NENHUM | NONE/NENHUM |
| Take Profit Price/Preço Alvo Lucro | Stop Loss Price/Preço Stop Loss |
| NONE/NENHUM | NONE/NENHUM |
| New Target/Novo Alvo | Possible Market Turnover/Possível Virada do Mercado |
| NONE/NENHUM | NONE/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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| 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á. | EMA | string · 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. | 3 | int · min 1 · step 1 | ma1 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. | 5 | int · min 1 · step 1 | ma1 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. | 8 | int · min 1 · step 1 | ma1 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. | 13 | int · min 1 · step 1 | ma1 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. | 20 | int · min 1 · step 1 | ma1 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. | 25 | int · min 1 · step 1 | ma1 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. | 30 | int · min 1 · step 1 | ma1 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. | 35 | int · min 1 · step 1 | ma1 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. | 40 | int · min 1 · step 1 | ma1 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. | 45 | int · min 1 · step 1 | ma1 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. | 50 | int · min 1 · step 1 | ma1 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. | 55 | int · min 1 · step 1 | ma1 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.6 | float · min 0.1 · step 0.1 | targetLong 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). | true | bool | line 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). | false | bool | longTurnoverExit 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. | false | bool | longTurnoverExit 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
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | (targetLong > 0 and stopLossLong > 0) | On | 153 |
| Exit Exit Long stop and limit | (targetLong > 0 and stopLossLong > 0) | On | 154 |
| Open Short short | (targetShort > 0 and stopLossShort > 0) | On | 171 |
| Exit Exit Short stop and limit | (targetShort > 0 and stopLossShort > 0) | On | 172 |
| Exit Exit Long stop and limit | (isMa1To4Below and isCloseLesserMaMean and longPositionHighestHigh > positionEntryPrice) | On | 181 |
| Exit Exit Short stop and limit | (isMa1To4Above and isCloseGreaterMaMean and shortPositionLowestLow < positionEntryPrice) | On | 190 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| (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.
- 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | +1.6% | +102.5% | 58 | 47% | 1.11 | 4.2% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −2.2% | +5.5% | 60 | 38% | 0.66 | 3.5% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −1.9% | +9.8% | 67 | 37% | 0.93 | 7.5% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −1.7% | +8.4% | 66 | 39% | 0.81 | 4.2% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +1.1% | +16.7% | 65 | 38% | 1.03 | 11.2% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.8% | +21.5% | 69 | 41% | 1.09 | 4.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −1.3% | +148.3% | 74 | 41% | 0.94 | 6.1% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −3.9% | +17.1% | 58 | 34% | 0.48 | 4.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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 18 | 50% | $118.38 |
| Sideways market | 26 | 42% | $40.20 |
| Falling market | 14 | 50% | $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.
All 58 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 21 Mar 2024 65,501.30 | 17 Apr 2024 59,897.50 | 27 | −$87.74 |
| short | 9 May 2024 63,074.00 | 10 May 2024 62,420.30 | 1 | $7.90 |
| long | 21 May 2024 70,148.30 | 14 Jun 2024 65,420.80 | 24 | −$69.07 |
| short | 24 Jun 2024 60,293.30 | 15 Jul 2024 64,829.20 | 21 | −$76.47 |
| long | 27 Jul 2024 67,896.50 | 31 Jul 2024 65,221.50 | 4 | −$40.76 |
| short | 11 Aug 2024 58,712.60 | 23 Aug 2024 62,035.80 | 12 | −$57.43 |
| short | 30 Aug 2024 59,124.00 | 4 Sep 2024 55,775.90 | 5 | $52.48 |
| short | 6 Sep 2024 53,963.00 | 13 Sep 2024 58,783.40 | 7 | −$89.24 |
| long | 23 Sep 2024 63,340.00 | 26 Sep 2024 65,594.80 | 3 | $31.92 |
| long | 27 Sep 2024 65,769.90 | 1 Oct 2024 62,405.80 | 4 | −$51.67 |
| long | 6 Oct 2024 62,819.90 | 9 Oct 2024 61,603.80 | 3 | −$20.88 |
| long | 14 Oct 2024 66,084.00 | 29 Oct 2024 72,559.40 | 15 | $91.53 |
| long | 4 Nov 2024 67,850.00 | 5 Nov 2024 69,544.60 | 1 | $21.82 |
| long | 6 Nov 2024 75,572.00 | 11 Nov 2024 88,702.70 | 5 | $166.02 |
| long | 12 Nov 2024 87,952.00 | 5 Dec 2024 103,616.00 | 23 | $173.14 |
| long | 8 Dec 2024 101,110.00 | 9 Dec 2024 98,582.10 | 1 | −$27.48 |
| long | 11 Dec 2024 101,125.00 | 20 Dec 2024 92,831.30 | 9 | −$84.42 |
| long | 21 Dec 2024 97,292.00 | 25 Dec 2024 99,540.60 | 4 | $20.53 |
| long | 3 Jan 2025 98,174.20 | 8 Jan 2025 94,228.30 | 5 | −$42.32 |
| long | 16 Jan 2025 99,987.30 | 17 Jan 2025 105,694.00 | 1 | $54.10 |
| long | 19 Jan 2025 101,332.00 | 20 Jan 2025 104,674.00 | 1 | $30.42 |
| long | 23 Jan 2025 103,910.00 | 27 Jan 2025 100,308.00 | 4 | −$36.99 |
| long | 28 Jan 2025 101,336.00 | 2 Feb 2025 97,407.00 | 5 | −$40.93 |
| short | 16 Feb 2025 96,118.10 | 20 Feb 2025 98,317.90 | 4 | −$25.09 |
| short | 23 Feb 2025 96,258.00 | 24 Feb 2025 94,404.90 | 1 | $16.68 |
| short | 25 Feb 2025 88,680.40 | 7 Apr 2025 76,606.00 | 41 | $132.64 |
| short | 9 Apr 2025 82,615.20 | 10 Apr 2025 80,606.10 | 1 | $22.03 |
| long | 25 Apr 2025 94,638.70 | 8 May 2025 99,863.80 | 13 | $53.05 |
| long | 9 May 2025 102,972.00 | 9 Jul 2025 111,980.00 | 61 | $85.92 |
| long | 10 Jul 2025 116,010.00 | 13 Aug 2025 123,218.00 | 34 | $60.84 |
| long | 14 Aug 2025 118,295.00 | 15 Aug 2025 117,112.00 | 1 | −$12.71 |
| long | 17 Aug 2025 117,405.00 | 18 Aug 2025 116,756.00 | 1 | −$8.12 |
| short | 30 Aug 2025 108,816.00 | 5 Sep 2025 113,003.00 | 6 | −$41.89 |
| long | 18 Sep 2025 117,074.00 | 22 Sep 2025 114,520.00 | 4 | −$24.65 |
| short | 26 Sep 2025 109,643.00 | 29 Sep 2025 113,622.00 | 3 | −$39.39 |
| long | 6 Oct 2025 124,659.00 | 7 Oct 2025 121,040.00 | 1 | −$31.80 |
| short | 3 Nov 2025 106,583.00 | 4 Nov 2025 99,034.60 | 1 | $69.19 |
| short | 7 Nov 2025 103,339.00 | 8 Nov 2025 101,922.00 | 1 | $11.52 |
| short | 9 Nov 2025 104,723.00 | 10 Nov 2025 105,868.00 | 1 | −$13.59 |
| short | 11 Nov 2025 103,059.00 | 14 Nov 2025 95,866.80 | 3 | $68.60 |
| short | 16 Nov 2025 94,261.40 | 20 Nov 2025 87,879.00 | 4 | $66.93 |
| short | 21 Nov 2025 85,129.40 | 3 Dec 2025 93,304.60 | 12 | −$101.53 |
| short | 4 Dec 2025 92,078.10 | 7 Dec 2025 88,051.80 | 3 | $42.21 |
| short | 9 Dec 2025 92,678.80 | 14 Dec 2025 88,557.40 | 5 | $43.15 |
| short | 15 Dec 2025 86,432.10 | 22 Dec 2025 90,565.50 | 7 | −$51.72 |
| short | 23 Dec 2025 87,486.00 | 4 Jan 2026 91,243.30 | 12 | −$46.46 |
| short | 29 Jan 2026 84,650.20 | 2 Feb 2026 74,955.60 | 4 | $114.37 |
| short | 3 Feb 2026 75,770.20 | 5 Feb 2026 67,989.00 | 2 | $103.45 |
| short | 6 Feb 2026 70,580.30 | 17 Mar 2026 75,636.10 | 39 | −$77.13 |
| short | 21 Mar 2026 68,918.10 | 23 Mar 2026 71,552.50 | 2 | −$42.01 |
| short | 27 Mar 2026 66,407.30 | 7 Apr 2026 71,540.40 | 11 | −$82.08 |
| long | 16 Apr 2026 75,154.30 | 4 May 2026 79,570.10 | 18 | $57.44 |
| long | 5 May 2026 80,905.50 | 16 May 2026 78,142.10 | 11 | −$37.47 |
| short | 2 Jun 2026 66,760.80 | 21 Aug 2026 74,882.70 | 80 | −$126.99 |
| long | 24 Aug 2026 78,992.80 | 21 Sep 2026 85,617.30 | 28 | $82.16 |
| long | 25 Sep 2026 84,100.00 | 8 Oct 2026 81,677.90 | 13 | −$31.73 |
| long | 11 Oct 2026 83,773.10 | 12 Oct 2026 82,232.80 | 1 | −$21.07 |
| long | 19 Oct 2026 81,938.40 | 21 Oct 2026 84,190.80 | 2 | $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
VerifiedNothing 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
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 142 ms | Yes 1,000 bars in 161 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report.
Source
Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © 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)