Pine Script v5 · Strategy
supertrend with multiple filter strategy
A Pine Script v5 strategy built on Supertrend (3.0, 10), Change or Highest (lengths) and Change or Lowest (lengths). It has 12 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 100% of equity and pays no commission. 87 settings; defaults include From Day 1, From Month 1 and From Year 2019.
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 supertrend with multiple filter strategy repaint?
- No
- No repainting patterns were found in the source.
- Does supertrend with multiple filter strategy run in Pine Script v6?
- Not tested
- The v5 script does not run in Zeal Terminal's engine (request.earnings: no data was supplied for 'SYMBOL|earnings_actual'. This engine cannot fetch it from TradingView — provide it with ctx.provideRequestData("earnings", "SYMBOL|earnings_actual", samples).), so this step could not be checked. The v6 version is shown for reference and is not offered as a download.
- Does supertrend with multiple filter strategy use a stop loss?
- Yes
- strategy.exit sets a stop on line 595, 597, 599, 601.
- Does supertrend with multiple filter strategy run in Zeal Terminal?
- No
- Not yet: request.earnings: no data was supplied for 'SYMBOL|earnings_actual'. This engine cannot fetch it from TradingView — provide it with ctx.provideRequestData("earnings", "SYMBOL|earnings_actual", samples).
Review
What a careful reader of this script would point out, found by checking the source.
-
Likely bug
ta.sma(stochastic_K, 3) ignores the settings line 142
Line 142 hard-codes 3 where line 131 uses “Trama lenght”. Changing those settings moves one band but not this one.
ta.sma(stochastic_K, 3)ta.sma(stochastic_K, lengths) -
Likely bug
ta.atr(20) ignores the settings line 319
Line 319 hard-codes 20 where line 175 uses “ CCI ATR Length”. Changing those settings moves one band but not this one.
ta.atr(20)ta.atr(atr_l) -
Likely bug
ta.highest(high, stochlenght) ignores the settings line 137
Line 137 hard-codes high where line 129 uses “Trama lenght”. Changing those settings moves one band but not this one.
ta.highest(high, stochlenght)ta.highest(lengths, stochlenght) -
Likely bug
ta.lowest(low, stochlenght) ignores the settings line 139
Line 139 hard-codes low where line 130 uses “Trama lenght”. Changing those settings moves one band but not this one.
ta.lowest(low, stochlenght)ta.lowest(lengths, stochlenght) -
Likely bug
ta.ema(close, 1) ignores the settings line 158
Line 158 hard-codes 1 where line 168 uses “mfi Signal Length”. Changing those settings moves one band but not this one.
ta.ema(close,1)ta.ema(close, signalLength) -
Likely bug
ta.ema(close, 200) ignores the settings line 159
Line 159 hard-codes 200 where line 168 uses “mfi Signal Length”. Changing those settings moves one band but not this one.
ta.ema(close,200)ta.ema(close, signalLength) -
Likely bug
ta.ema(close, 200) ignores the settings line 164
Line 164 hard-codes 200 where line 168 uses “mfi Signal Length”. Changing those settings moves one band but not this one.
ta.ema(close, 200)ta.ema(close, signalLength) -
Likely bug
ta.ema(st, 8) ignores the settings line 204
Line 204 hard-codes 8 where line 168 uses “mfi Signal Length”. Changing those settings moves one band but not this one.
ta.ema(st, 8)ta.ema(st, signalLength) -
Likely bug
ta.ema(st, 13) ignores the settings line 205
Line 205 hard-codes 13 where line 168 uses “mfi Signal Length”. Changing those settings moves one band but not this one.
ta.ema(st, 13)ta.ema(st, signalLength) -
Likely bug
ta.ema(st, 21) ignores the settings line 206
Line 206 hard-codes 21 where line 168 uses “mfi Signal Length”. Changing those settings moves one band but not this one.
ta.ema(st, 21)ta.ema(st, signalLength) -
Likely bug
ta.ema(st, 21) ignores the settings line 207
Line 207 hard-codes 21 where line 168 uses “mfi Signal Length”. Changing those settings moves one band but not this one.
ta.ema(st, 21)ta.ema(st, signalLength) -
Likely bug
ta.ema(st, 55) ignores the settings line 208
Line 208 hard-codes 55 where line 168 uses “mfi Signal Length”. Changing those settings moves one band but not this one.
ta.ema(st, 55)ta.ema(st, signalLength) -
Likely bug
ta.ema(st, 89) ignores the settings line 209
Line 209 hard-codes 89 where line 168 uses “mfi Signal Length”. Changing those settings moves one band but not this one.
ta.ema(st, 89)ta.ema(st, signalLength) -
Likely bug
ta.ema(st, 144) ignores the settings line 210
Line 210 hard-codes 144 where line 168 uses “mfi Signal Length”. Changing those settings moves one band but not this one.
ta.ema(st, 144)ta.ema(st, signalLength) -
Likely bug
ta.ema(st, 233) ignores the settings line 211
Line 211 hard-codes 233 where line 168 uses “mfi Signal Length”. Changing those settings moves one band but not this one.
ta.ema(st, 233)ta.ema(st, signalLength) -
Likely bug
ta.ema(volume, 5) ignores the settings line 422
Line 422 hard-codes 5 where line 168 uses “mfi Signal Length”. Changing those settings moves one band but not this one.
ta.ema(volume, 5)ta.ema(volume, signalLength) -
Likely bug
ta.ema(volume, 10) ignores the settings line 423
Line 423 hard-codes 10 where line 168 uses “mfi Signal Length”. Changing those settings moves one band but not this one.
ta.ema(volume, 10)ta.ema(volume, signalLength) -
Likely bug
ta.wma(close, 3) ignores the settings line 442
Line 442 hard-codes 3 where line 432 uses “mavilimw fast ma”. Changing those settings moves one band but not this one.
ta.wma(close, 3)ta.wma(close, fmal) -
Likely bug
ta.wma(M12, 5) ignores the settings line 443
Line 443 hard-codes 5 where line 432 uses “mavilimw fast ma”. Changing those settings moves one band but not this one.
ta.wma(M12, 5)ta.wma(M12, fmal) -
Likely bug
ta.wma(M22, 8) ignores the settings line 444
Line 444 hard-codes 8 where line 432 uses “mavilimw fast ma”. Changing those settings moves one band but not this one.
ta.wma(M22, 8)ta.wma(M22, fmal) -
Likely bug
ta.wma(M32, 13) ignores the settings line 445
Line 445 hard-codes 13 where line 432 uses “mavilimw fast ma”. Changing those settings moves one band but not this one.
ta.wma(M32, 13)ta.wma(M32, fmal) -
Likely bug
ta.wma(M42, 21) ignores the settings line 446
Line 446 hard-codes 21 where line 432 uses “mavilimw fast ma”. Changing those settings moves one band but not this one.
ta.wma(M42, 21)ta.wma(M42, fmal) -
Likely bug
ta.wma(M52, 34) ignores the settings line 447
Line 447 hard-codes 34 where line 432 uses “mavilimw fast ma”. Changing those settings moves one band but not this one.
ta.wma(M52, 34)ta.wma(M52, fmal) -
Check
1 setting does nothing
“Close position when oposite signal” is declared but never read.
-
Check
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
24 settings have no label
In the settings dialog long_only (line 24), short_only (line 25), use_supertrend_filter (line 28), use_stochastic_filter (line 31), use_supertrend2_filter (line 35), use_supertrend3_filter (line 38), use_cci_filter (line 41), use_vwap_filter (line 44), use_chaikin_money_flow_filter (line 47), use_ema_cross_filter (line 49), use_ichimoku_filter (line 52), use_luxcandlepatternchannel_filter (line 55), use_support_an_dresistance_break_filter (line 63), use_mavilimw_filter (line 66), use_mfi_filter (line 69), use_ift_cci_filter (line 72), use_LUX_trama_filter (line 76), use_macd_filter (line 78), use_ema200_filter (line 81), use_atr_bands_exits (line 85), use_trailing_atr_exits (line 89), use_bollinger_exits (line 93), use_percent_base_trailing_stop_exits (line 97), close_position_when_oposite_signal (line 107) show an empty name. The labels on this page come from the variable names.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
-
Note
Uses an argument v6 removed
when = on line 599, 601. The upgraded version below moves each call inside an if block.
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 |
|---|---|---|---|
| From Day | 1 | int · min 1 · max 31 | startDate |
| From Month | 1 | int · min 1 · max 12 | startDate |
| From Year | 2019 | int · min 1970 | startDate |
| from hour | 1 | int · min 0 · max 24 | startDate |
| from minute | 1 | int · min 0 · max 60 | startDate |
| from second | 1 | int · min 0 · max 60 | startDate |
| To Day | 1 | int · min 1 · max 31 | finishDate |
| To Month | 1 | int · min 1 · max 12 | finishDate |
| To Year | 2100 | int · min 1970 | finishDate |
| Long only (no label in the script) | false | bool | shortCondition |
| Short only (no label in the script) | false | bool | longCondition |
| Long Stop Loss (%) | 1 | float · min 0.0 · step 0.01 | longStopPrice |
| Short Stop Loss (%) | 1 | float · min 0.0 · step 0.01 | shortStopPrice |
| Use supertrend filter (no label in the script) | true | bool | Up Trend Down Trend long short |
| supertrend ATR Length | 10 | int | supertrend direction |
| supertrend Factor | 3.0 | float · step 0.01 | supertrend direction |
| Use stochastic filter (no label in the script) | false | bool | long short |
| stochlenght | 14 | int | highest lowest |
| stoch Oversold | 20 | int | long_stoch_filter |
| stoch Overbought | 80 | int | short_stoch_filter |
| Use supertrend2 filter (no label in the script) | false | bool | Up Trend Down Trend Up Trend Down Trend long short |
| supertrend2 ATR Length | 7 | int | supertrend2 direction2 |
| supertrend2 Factor | 3 | float · step 0.01 | supertrend2 direction2 |
| Use supertrend3 filter (no label in the script) | false | bool | long short |
| supertrend3 ATR Length | 11 | int | supertrend3 direction3 |
| supertrend3 Factor | 2 | float · step 0.01 | supertrend3 direction3 |
| Use cci filter (no label in the script) | false | bool | UpperS LowerS long short Basis |
| CCI Period Length | 50 | int | cci |
| CCI ATR Length | 5 | int | atr2 |
| Use vwap filter (no label in the script) | false | bool | long short VWAP |
| Use chaikin money flow filter (no label in the script) | false | bool | long short |
| chaikin lenght | 20 | int | mf2 |
| Use ema cross filter (no label in the script) | false | bool | long short plot |
| Short MA Length for cross filter | 9 | int · min 1 | ema4 |
| Long MA Length for cross filter | 21 | int · min 1 | ema5 |
| Use ichimoku filter (no label in the script) | false | bool | SenkouA SenkouB long short Tenkan Kijun Chikou |
| ichimoku convertion periods | 9 | int · min 1 | Tenkan |
| ichimoku base periods | 26 | int · min 1 | Kijun SenkouB |
| Use luxcandlepatternchannel filter (no label in the script) | false | bool | Upper Average Lower css1 css2 long short line 368 line 372 line 378 line 382 line 385 line 391 |
| lux candlestick pattern Trend Length | 14 | int · min 0 | stw |
| lux candlestick pattern Convergence | 50 | float · min 0 · max 100 | max min |
| lux candlestick pattern Smooth | 7 | int · min 1 | smooth_max smooth_min |
| Use support an dresistance break filter (no label in the script) | false | bool | Resistance Support long short |
| support and resistance Left Bars | 15 | int | highUsePivot lowUsePivot |
| support and resistance Right Bars | 15 | int | highUsePivot lowUsePivot Resistance Support |
| Use mavilimw filter (no label in the script) | false | bool | long short MAVW |
| mavilimw fast ma | 3 | int | tmal M1 |
| mavilimw slow ma | 5 | int | tmal Fmal M2 |
| Use mfi filter (no label in the script) | false | bool | long short |
| mfi Length | 14 | int · min 1 · max 2000 | mf |
| mfi Signal Length | 9 | int | signal |
| Use ift cci filter (no label in the script) | false | bool | long short |
| cci lenght | 5 | int | v11 |
| cci WMA lenght | 9 | int | v21 v22 v2 v23 |
| Show Lux TRAMA | false | bool | Plot |
| Use LUX trama filter (no label in the script) | false | bool | long short |
| Trama lenght | 99 | int | hh ll tc |
| Use macd filter (no label in the script) | false | bool | long short |
| ma fast for macd filter | 14 | int | long_macd_filter short_macd_filter |
| ma slowfor macd filter | 28 | int | long_macd_filter short_macd_filter |
| Use ema200 filter (no label in the script) | false | bool | long short |
| Plot EMA200 | true | bool | Exponential Average |
| use indicator exits (atr band, trailing atr or bollinger)? | false | bool | line 584 |
| Use atr bands exits (no label in the script) | false | bool | takelong takeshort plot take profit |
| ATR Stop Loss Factor | 2.0 | float | bottomline stopLoss |
| ATR Take Profit Factor | 1.5 | float | upline takeProfit |
| atr band period | 10 | int | upline bottomline stopLoss takeProfit st bulleng beareng wm bm |
| Use trailing atr exits (no label in the script) | false | bool | takelong takeshort ATR Trailing Stoploss |
| trailing Atr exit Period | 5 | int · min 1 · max 500 | Prev highest_1 highest_2 line 489 |
| trailing ATR exit HHV Period | 10 | int · min 1 · max 500 | Prev highest_1 highest_2 line 489 |
| trailing exit ATR Multiplier | 2.5 | float · min 0.1 | Prev highest_1 highest_2 line 489 |
| Use bollinger exits (no label in the script) | false | bool | Upper Lower takelong takeshort Basis take profit |
| bollinger lenght | 20 | int | basiss dev |
| bollinger StdDev | 2.0 | float · min 0.001 · max 50 | dev |
| bollinger Offset | 0 | int · min -500 · max 500 | Upper Lower Basis |
| Close position when oposite signal (no label in the script) | false | bool | unused |
| VWAP Settings | |||
| Anchor Period | Session | string · options ["Session", "Week", "Month", "Quarter", "Year", "Decade", "Century", "Earnings", "Dividends", "Splits"] | isNewPeriod isEsdAnchor |
| % trailing stop loss | |||
| Use percent base trailing stop exits (no label in the script) | false | bool | exit Close Long exit Close Short Long Trail Stop Short Trail Stop line 594 line 596 |
| traling Stop Loss (%) | 1 | float · min 0.0 · step 0.01 | longStopPricess shortStopPricess stopValue |
| % trailing Take Profit | |||
| Enable % take profit Trailing | false | bool | exit Long Take Profit exit Short Take Profit Long Take Profit Short Take Profit line 598 line 600 |
| Long trailing Take Profit % | 0.5 | float · min 0.01 · step 0.01 | longTakeProfitPrice2 |
| Short trailing Take Profit % | 0.5 | float · min 0.01 · step 0.01 | shortTakeProfitPrice2 |
| long Trailing Take Profit Deviation %The step to follow the price when the take profit limit is reached. | 1.0 | float · min 0.01 · max 100 · step 0.01 | longTrailingTakeProfitStepTicks |
| Short Trailing Take Profit Deviation %The step to follow the price when the take profit limit is reached. | 1.0 | float · min 0.01 · max 100 · step 0.01 | shortTrailingTakeProfitStepTicks |
| fixed % Take Profit | |||
| use a fix % take profit | false | bool | close Long Entry close Short Entry Long profit Short profit line 590 line 592 |
| fixed Long profit (%) if not using indicator exits | 1 | float · min 0.0 · step 0.01 | longprofitPrice |
| fixed Short profit (%) if not using indicator exits | 1 | float · min 0.0 · step 0.01 | shortprofitPrice |
What it calculates
- Supertrendsupertrend Factor (3.0), supertrend ATR Length (10)
supertrend · line 109 - Supertrendsupertrend Factor (3.0), supertrend ATR Length (10)
direction · line 109 - Supertrendsupertrend2 Factor (3), supertrend2 ATR Length (7)
supertrend2 · line 115 - Supertrendsupertrend2 Factor (3), supertrend2 ATR Length (7)
direction2 · line 115 - Supertrendsupertrend3 Factor (2), supertrend3 ATR Length (11)
supertrend3 · line 121 - Supertrendsupertrend3 Factor (2), supertrend3 ATR Length (11)
direction3 · line 121 - Change / Highestta.highest(lengths)
hh · line 129 - Change / Lowestta.lowest(lengths)
ll · line 130 - SMAhh or ll ? 1 : 0, Trama lenght (99)
tc · line 131 - Highesthigh, stochlenght (14)
highest · line 137 - Lowestlow, stochlenght (14)
lowest · line 139 - SMAstochastic_K, 3
stochastic_D · line 142 - MACDclose, 12, 26, 9
macdLine · line 154 - MACDclose, 12, 26, 9
signalLine · line 154 - MACDclose, 12, 26, 9
histLine · line 154 - EMAclose, 1
ema1 · line 158 - EMAclose, 200
ema2 · line 159 - MFIsrc1, mfi Length (14)
mf · line 167 - EMAmf, mfi Signal Length (9)
signal · line 168 - Crossovermf, signal
long_mfi_filter · line 169 - Crossundermf, signal
short_mfi_filter · line 170 - CCIsrc, CCI Period Length (50)
cci · line 174 - ATR CCI ATR Length (5)
atr2 · line 175 - EMAst, 8
avg_st8 · line 204 - EMAst, 13
avg_st13 · line 205 - EMAst, 21
avg_st21 · line 206 - EMAst, 21
avg_st34 · line 207 - EMAst, 55
avg_st55 · line 208 - EMAst, 89
avg_st89 · line 209 - EMAst, 144
avg_st144 · line 210 - EMAst, 233
avg_st233 · line 211 - SMAaverage_weighting, sd_length
basis · line 213 - Stdevaverage_weighting, sd_length
devs · line 214 - Crossoverclose, upperS
long_cci_filter · line 220 - Crossunderclose, lowerS
short_cci_filter · line 221 - VWAPsrc, isNewPeriod, 1
_vwap · line 253 - VWAPsrc, isNewPeriod, 1
_stdevUpper · line 253 - EMAclose, Short MA Length for cross filter (9)
ema4 · line 271 - EMAclose, Long MA Length for cross filter (21)
ema5 · line 272 - Crossoverema4, ema5
long_ema_cross_filter · line 273 - Crossunderema4, ema5
short_ema_cross_filter · line 274 - ATR20
atrw · line 319 - Stochc, c, c, lux candlestick pattern Trend Length (14)
stw · line 320 - EMAmax, lux candlestick pattern Smooth (7)
smooth_max · line 396 - EMAmin, lux candlestick pattern Smooth (7)
smooth_min · line 397 - Pivothighsupport and resistance Left Bars (15), support and resistance Right Bars (15)
highUsePivot · line 417 - Pivotlowsupport and resistance Left Bars (15), support and resistance Right Bars (15)
lowUsePivot · line 418 - EMAvolume, 5
shorts · line 422 - EMAvolume, 10
longs · line 423 - WMAclose, mavilimw fast ma (3)
M1 · line 432 - WMAM1, mavilimw slow ma (5)
M2 · line 433 - WMAM2, tmal
M3 · line 434 - WMAM3, Fmal
M4 · line 435 - WMAM4, Ftmal
M5 · line 436 - WMAM5, Smal
MAVW · line 437 - WMAclose, 3
M12 · line 442 - WMAM12, 5
M22 · line 443 - WMAM22, 8
M32 · line 444 - WMAM32, 13
M42 · line 445 - WMAM42, 21
M52 · line 446 - WMAM52, 34
MAVW2 · line 447 - CrossoverMAVW, MAVW[1]
long_mavilimw_filter · line 448 - CrossunderMAVW, MAVW[1]
short_mavilimw_filter · line 449 - CCIclose, cci lenght (5)
v11 · line 452 - WMAv11, cci WMA lenght (9)
v21 · line 453 - RSIclose, rsilength
v12 · line 456 - WMAv12, cci WMA lenght (9)
v22 · line 457 - Stochclose, high, low, stochlength
v1 · line 460 - WMAv1, cci WMA lenght (9)
v2 · line 461 - Changesourcse
up · line 468 - Changesourcse
lo · line 469 - WMAv13, cci WMA lenght (9)
v23 · line 472 - Highest / ATRhigh - Mult1 * ta.atr(Atr1), trailing ATR exit HHV Period (10)
Prev · line 488 - CUM1
cum_1 · line 490 - Highest / ATRhigh - Mult1 * ta.atr(Atr1), trailing ATR exit HHV Period (10)
highest_1 · line 491 - Highest / ATRhigh - Mult1 * ta.atr(Atr1), trailing ATR exit HHV Period (10)
highest_2 · line 492 - Crossoverclose, TS
short_trailing_atr_exits · line 498 - Crossunderclose, TS
long_trailing_atr_exits · line 499 - SMAsrc, bollinger lenght (20)
basiss · line 517 - Stdevsrc, bollinger lenght (20)
dev · line 518
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 304 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Close Long Entry | longstoploss | On | 575 |
| Close Short Entry | shortstoploss | On | 577 |
| Open Long Entry long | (longCondition and time_cond) | On | 580 |
| Open Short Entry short | (shortCondition and time_cond) | On | 583 |
| Close Long Entry | takelong and strategy.position_size > 0 and time_cond or time_cond and close < longStopPrice | On | 586 |
| Close Short Entry | takeshort and strategy.position_size < 0 and time_cond or time_cond and close >shortStopPrice | On | 588 |
| Close Long Entry | time_cond and close < longStopPrice or time_cond and close > longprofitPrice and use_fix_perc_take_profit | On | 591 |
| Close Short Entry | time_cond and close < shortprofitPrice or time_cond and close > shortStopPrice and use_fix_perc_take_profit | On | 593 |
| Exit Close Long stop | isLong and use_percent_base_trailing_stop_exits | On | 595 |
| Exit Close Short stop | isShort and use_percent_base_trailing_stop_exits | On | 597 |
| Exit Long Take Profit stop and limit | longIsActiveopenLongPosition or strategy.position_size > 0 | On | 599 |
| Exit Short Take Profit stop and limit | shortIsActiveopenShortPosition or strategy.position_size < 0 | On | 601 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
No
No repainting patterns in the source.
The live replay needs a run, and this script does not run in Zeal Terminal yet; the answer comes from the checks on the source alone.
- 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.
Similar scripts
Indicators and strategies built from the same calculations.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| HAERI 𝐍𝐄𝐓𝐖𝐎𝐑𝐊 by ahhanegin | ema supertrend wma rsi pivotlow pivothigh sma highest lowest stdev atr cci | v4 strategy | does not run in Zeal Terminal | ||
| VXD Supercycle by Vvaz_ | supertrend ema sma cum pivothigh pivotlow highest lowest rsi | v5 strategy | does not run in Zeal Terminal | ||
| Kifier's MFI-STOCH Hidden Divergence-Trend Beater by kifier | pivothigh pivotlow stoch sma ema mfi highest stdev | v4 strategy | −2.7% | 2 | 13.7% |
| X48 - Strategy - BreakOut & Consecutive (11in1) + Alert - V.1.2 by X4815162342 | sma ema highest lowest stdev pivothigh pivotlow atr rsi | v5 strategy | does not run in Zeal Terminal | ||
| Divergence for Many [Dimkud - v5] by dimkud | rsi sma cci mfi highest macd ema stdev pivothigh pivotlow atr | v5 strategy | −0.0% | 24 | 0.4% |
Upgrade and export
Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.
- 2 strategy calls use the when = argument (line 599, 601). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- 23 settings use the untyped input() (line 29, 32, 33, 34, 36, 39, 42, 43, 48, 64, 65, 67, 68, 71, 73, 74, 77, 79, 80, 86, 87, 88, 94). It still compiles in v6; input.int, input.float or input.source state the type.
- No v6-only features. v6 is not needed to run this script.
Clean v5
Not verifiedThe v5 script does not run in Zeal Terminal's engine (request.earnings: no data was supplied for 'SYMBOL|earnings_actual'. This engine cannot fetch it from TradingView — provide it with ctx.provideRequestData("earnings", "SYMBOL|earnings_actual", samples).), so this step could not be checked.
- Line 29: input() → input.int()
- Line 32: input() → input.int()
- Line 33: input() → input.int()
- Line 34: input() → input.int()
- Line 36: input() → input.int()
- Line 39: input() → input.int()
19 more edits
- Line 42: input() → input.int()
- Line 43: input() → input.int()
- Line 48: input() → input.int()
- Line 64: input() → input.int()
- Line 65: input() → input.int()
- Line 67: input() → input.int()
- Line 68: input() → input.int()
- Line 71: input() → input.int()
- Line 73: input() → input.int()
- Line 74: input() → input.int()
- Line 77: input() → input.int()
- Line 79: input() → input.int()
- Line 80: input() → input.int()
- Line 86: input() → input.float()
- Line 87: input() → input.float()
- Line 88: input() → input.int()
- Line 94: input() → input.int()
- Line 599: when = longIsActive → if block
- Line 601: when = shortIsActive → if block
⋯use_supertrend_filter=input.bool(true)-atrPeriod = input(10, "supertrend ATR Length")+atrPeriod = input.int(10, "supertrend ATR Length")factor = input.float(3.0, "supertrend Factor", step = 0.01)use_stochastic_filter = input.bool(false)-stochlenght= input(14,'stochlenght')+stochlenght= input.int(14,'stochlenght')-oversold_level = input(title = ' stoch Oversold', defval = 20)+oversold_level = input.int(title = ' stoch Oversold', defval = 20)-overbought_level = input(title = 'stoch Overbought', defval = 80)+overbought_level = input.int(title = 'stoch Overbought', defval = 80)use_supertrend2_filter=input.bool(false)-atrPeriod2 = input(7, "supertrend2 ATR Length")+atrPeriod2 = input.int(7, "supertrend2 ATR Length")factor2 = input.float(3, "supertrend2 Factor", step = 0.01)use_supertrend3_filter=input.bool(false)-atrPeriod3 = input(11, "supertrend3 ATR Length")+atrPeriod3 = input.int(11, "supertrend3 ATR Length")factor3 = input.float(2, "supertrend3 Factor", step = 0.01)use_cci_filter=input.bool(false)-cci_l = input(50, title='CCI Period Length')+cci_l = input.int(50, title='CCI Period Length')-atr_l = input(5, title=' CCI ATR Length')+atr_l = input.int(5, title=' CCI ATR Length')use_vwap_filter=input.bool(false)⋯use_chaikin_money_flow_filter=input.bool(false)-length = input(20, title='chaikin lenght')+length = input.int(20, title='chaikin lenght')use_ema_cross_filter=input.bool(false)⋯use_support_an_dresistance_break_filter=input.bool(false)-leftBars = input(15, title='support and resistance Left Bars ')+leftBars = input.int(15, title='support and resistance Left Bars ')-rightBars = input(15, title='support and resistance Right Bars')+rightBars = input.int(15, title='support and resistance Right Bars')use_mavilimw_filter=input.bool(false)-fmal = input(3,title = 'mavilimw fast ma') +fmal = input.int(3,title = 'mavilimw fast ma') -smal = input(5,title = 'mavilimw slow ma')+smal = input.int(5,title = 'mavilimw slow ma')use_mfi_filter=input.bool(false)length1 = input.int(title="mfi Length", defval=14, minval=1, maxval=2000)-signalLength = input(title='mfi Signal Length', defval=9)+signalLength = input.int(title='mfi Signal Length', defval=9)use_ift_cci_filter=input.bool(false)-ccilength = input(5, title = 'cci lenght')+ccilength = input.int(5, title = 'cci lenght')-wmalength =input(9, title = 'cci WMA lenght')+wmalength =input.int(9, title = 'cci WMA lenght')plottrama=input.bool(false, title="Show Lux TRAMA")use_LUX_trama_filter=input.bool(false)-lengths = input(99,title='Trama lenght')+lengths = input.int(99,title='Trama lenght')use_macd_filter=input.bool(false)-ma_fast=ta.sma(close,input(14,title='ma fast for macd filter'))+ma_fast=ta.sma(close,input.int(14,title='ma fast for macd filter'))-ma_slow=ta.sma(close,input(28, title='ma slowfor macd filter'))+ma_slow=ta.sma(close,input.int(28, title='ma slowfor macd filter'))use_ema200_filter= input.bool(false)⋯use_atr_bands_exits=input.bool(false)-stopLossFactor = input(2.0, "ATR Stop Loss Factor")+stopLossFactor = input.float(2.0, "ATR Stop Loss Factor")-takeProfitFactor = input(1.5, "ATR Take Profit Factor")+takeProfitFactor = input.float(1.5, "ATR Take Profit Factor")-atr = ta.atr(input(10, 'atr band period'))+atr = ta.atr(input.int(10, 'atr band period'))use_trailing_atr_exits=input.bool(false)⋯use_bollinger_exits=input.bool(false)-lengthss = input(20, title='bollinger lenght')+lengthss = input.int(20, title='bollinger lenght')mult = input.float(2.0, minval=0.001, maxval=50, title="bollinger StdDev")⋯if isLong and enableTrailing - strategy.exit(id = 'Long Take Profit', from_entry = 'Long Entry', limit = close < longStopPrice or enableTrailing ? na : longTakeProfitPrice2, trail_price = enableTrailing ? longTakeProfitPrice2 : na, trail_offset = enableTrailing ? longTrailingTakeProfitStepTicks : na, when = longIsActive, alert_message = 'Long(' + syminfo.ticker + '): Take Profit activated')+ if longIsActive+ strategy.exit(id = 'Long Take Profit', from_entry = 'Long Entry', limit = close < longStopPrice or enableTrailing ? na : longTakeProfitPrice2, trail_price = enableTrailing ? longTakeProfitPrice2 : na, trail_offset = enableTrailing ? longTrailingTakeProfitStepTicks : na, alert_message = 'Long(' + syminfo.ticker + '): Take Profit activated')if isShort and enableTrailing - strategy.exit(id = 'Short Take Profit', from_entry = 'Short Entry', limit = close > shortStopPrice or enableTrailing ? na : shortTakeProfitPrice2, trail_price = enableTrailing ? shortTakeProfitPrice2 : na, trail_offset = enableTrailing ? shortTrailingTakeProfitStepTicks : na, when = shortIsActive, alert_message = 'Short(' + syminfo.ticker + '): Take Profit activated')+ if shortIsActive+ strategy.exit(id = 'Short Take Profit', from_entry = 'Short Entry', limit = close > shortStopPrice or enableTrailing ? na : shortTakeProfitPrice2, trail_price = enableTrailing ? shortTakeProfitPrice2 : na, trail_offset = enableTrailing ? shortTrailingTakeProfitStepTicks : na, alert_message = 'Short(' + syminfo.ticker + '): Take Profit activated')Does it run in Pine Script v6?
Not tested
The v5 script does not run in Zeal Terminal's engine (request.earnings: no data was supplied for 'SYMBOL|earnings_actual'. This engine cannot fetch it from TradingView — provide it with ctx.provideRequestData("earnings", "SYMBOL|earnings_actual", samples).), so this step could not be checked. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © mathlabel-//@version=5+//@version=6strategy("My strategy", overlay=true, default_qty_type = strategy.percent_of_equity, default_qty_value=100,margin_long= 50, margin_short=50)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | No Request.earnings: no data was supplied for 'SYMBOL|earnings_actual'. This engine cannot fetch it from TradingView — provide it with ctx.provideRequestData("earnings", "SYMBOL|earnings_actual", samples). | 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/// © mathlabel//@version=5strategy("My strategy", overlay=true, default_qty_type = strategy.percent_of_equity, default_qty_value=100,margin_long= 50, margin_short=50)//////////////////////////////////////////////////////////////////////////////////// BACKTESTING RANGE// From Date InputsfromDay = input.int(defval=1, title='From Day', minval=1, maxval=31)fromMonth = input.int(defval=1, title='From Month', minval=1, maxval=12)fromYear = input.int(defval=2019, title='From Year', minval=1970)fromHour =input.int(defval = 1, title = 'from hour',minval = 0 ,maxval =24 )fromMinute=input.int(defval = 1, title = 'from minute',minval = 0 ,maxval =60 )fromSecond=input.int(defval = 1, title = 'from second',minval = 0 ,maxval =60 )// To Date InputstoDay = input.int(defval=1, title='To Day', minval=1, maxval=31)toMonth = input.int(defval=1, title='To Month', minval=1, maxval=12)toYear = input.int(defval=2100, title='To Year', minval=1970)// Calculate start/end date and time conditionstartDate = timestamp(fromYear, fromMonth, fromDay,fromHour, fromMinute,fromSecond)finishDate = timestamp(toYear, toMonth, toDay, 00, 00)time_cond = time >= startDate and time <= finishDate//////////////////////////////////////////////////long_only=input.bool(false)short_only=input.bool(false)longLossPerc = input.float(title='Long Stop Loss (%)', minval=0.0, step=0.01, defval=1) * 0.01shortLossPerc = input.float(title='Short Stop Loss (%)', minval=0.0, step=0.01, defval=1) * 0.01use_supertrend_filter=input.bool(true)atrPeriod = input(10, "supertrend ATR Length")factor = input.float(3.0, "supertrend Factor", step = 0.01)use_stochastic_filter = input.bool(false)stochlenght= input(14,'stochlenght')oversold_level = input(title = ' stoch Oversold', defval = 20)overbought_level = input(title = 'stoch Overbought', defval = 80)use_supertrend2_filter=input.bool(false)atrPeriod2 = input(7, "supertrend2 ATR Length")factor2 = input.float(3, "supertrend2 Factor", step = 0.01)use_supertrend3_filter=input.bool(false)atrPeriod3 = input(11, "supertrend3 ATR Length")factor3 = input.float(2, "supertrend3 Factor", step = 0.01)use_cci_filter=input.bool(false)cci_l = input(50, title='CCI Period Length')atr_l = input(5, title=' CCI ATR Length')use_vwap_filter=input.bool(false)var anchor = input.string(defval = "Session", title="Anchor Period", options=["Session", "Week", "Month", "Quarter", "Year", "Decade", "Century", "Earnings", "Dividends", "Splits"], group="VWAP Settings")use_chaikin_money_flow_filter=input.bool(false)length = input(20, title='chaikin lenght')use_ema_cross_filter=input.bool(false)shortlen = input.int(9, "Short MA Length for cross filter", minval=1)longlen = input.int(21, "Long MA Length for cross filter", minval=1)use_ichimoku_filter=input.bool(false)conversionPeriods = input.int(9, minval=1, title='ichimoku convertion periods')basePeriods = input.int(26, minval=1, title = 'ichimoku base periods')use_luxcandlepatternchannel_filter=input.bool(false)lengthw = input.int(14, 'lux candlestick pattern Trend Length' , minval = 0)alpha = input.float(50, 'lux candlestick pattern Convergence' , minval = 0 , maxval = 100)smooth = input.int(7, 'lux candlestick pattern Smooth' , minval = 1)use_support_an_dresistance_break_filter=input.bool(false)leftBars = input(15, title='support and resistance Left Bars ')rightBars = input(15, title='support and resistance Right Bars')use_mavilimw_filter=input.bool(false)fmal = input(3,title = 'mavilimw fast ma') smal = input(5,title = 'mavilimw slow ma')use_mfi_filter=input.bool(false)length1 = input.int(title="mfi Length", defval=14, minval=1, maxval=2000)signalLength = input(title='mfi Signal Length', defval=9)use_ift_cci_filter=input.bool(false)ccilength = input(5, title = 'cci lenght')wmalength =input(9, title = 'cci WMA lenght')plottrama=input.bool(false, title="Show Lux TRAMA")use_LUX_trama_filter=input.bool(false)lengths = input(99,title='Trama lenght')use_macd_filter=input.bool(false)ma_fast=ta.sma(close,input(14,title='ma fast for macd filter'))ma_slow=ta.sma(close,input(28, title='ma slowfor macd filter'))use_ema200_filter= input.bool(false)plotAverage = input.bool(true, title="Plot EMA200")//exitsuse_trailing_stop_loss=input.bool( false,title = 'use indicator exits (atr band, trailing atr or bollinger)?')use_atr_bands_exits=input.bool(false)stopLossFactor = input(2.0, "ATR Stop Loss Factor")takeProfitFactor = input(1.5, "ATR Take Profit Factor")atr = ta.atr(input(10, 'atr band period'))use_trailing_atr_exits=input.bool(false)Atr1 = input.int(defval=5, title='trailing Atr exit Period', minval=1, maxval=500)Hhv1 = input.int(defval=10, title='trailing ATR exit HHV Period', minval=1, maxval=500)Mult1 = input.float(defval=2.5, title='trailing exit ATR Multiplier', minval=0.1)use_bollinger_exits=input.bool(false)lengthss = input(20, title='bollinger lenght')mult = input.float(2.0, minval=0.001, maxval=50, title="bollinger StdDev")offset = input.int(0, "bollinger Offset", minval = -500, maxval = 500)use_percent_base_trailing_stop_exits=input.bool(false,group = '% trailing stop loss')trailStop = input.float(title=' traling Stop Loss (%)', minval=0.0, step=0.01, defval=1,group = '% trailing stop loss') * 0.01enableTrailing = input.bool(false, 'Enable % take profit Trailing',group = '% trailing Take Profit')longTakeProfitPerc2 = input.float(0.5, 'Long trailing Take Profit %', minval=0.01, step=0.01,group = '% trailing Take Profit') * 0.01shortTakeProfitPerc2 = input.float(0.5, 'Short trailing Take Profit %', minval=0.01, step=0.01,group = '% trailing Take Profit') * 0.01LtrailingTakeProfitDeviationPerc = input.float(defval = 1.0, title = 'long Trailing Take Profit Deviation %', minval = 0.01, maxval = 100, step = 0.01, tooltip = 'The step to follow the price when the take profit limit is reached.', group = '% trailing Take Profit') / 100StrailingTakeProfitDeviationPerc = input.float(defval = 1.0, title = 'Short Trailing Take Profit Deviation %', minval = 0.01, maxval = 100, step = 0.01, tooltip = 'The step to follow the price when the take profit limit is reached.', group ='% trailing Take Profit') / 100use_fix_perc_take_profit=input.bool(false, 'use a fix % take profit ',group = ' fixed % Take Profit')longprofitPerc = input.float(title='fixed Long profit (%) if not using indicator exits', minval=0.0, step=0.01, defval=1,group = ' fixed % Take Profit') * 0.01shortprofitPerc = input.float(title='fixed Short profit (%) if not using indicator exits', minval=0.0, step=0.01, defval=1,group = ' fixed % Take Profit') * 0.01close_position_when_oposite_signal=input.bool(false)// Calculate supertrend[supertrend, direction] = ta.supertrend(factor, atrPeriod)upTrend = plot(use_supertrend_filter? (direction < 0 ? supertrend : na) : na, "Up Trend", color = color.green, style=plot.style_linebr)downTrend = plot(use_supertrend_filter ? (direction < 0? na : supertrend):na, "Down Trend", color = color.red, style=plot.style_linebr)long_supertrend_filter= (direction < 0 ? supertrend : na)short_supertrend_filter= (direction < 0? na : supertrend)// Calculate supertrend 2[supertrend2, direction2] = ta.supertrend(factor2, atrPeriod2)upTrend2 = plot(use_supertrend2_filter? (direction2 < 0 ? supertrend2 : na) : na, "Up Trend", color = color.green, style=plot.style_linebr)downTrend2 = plot(use_supertrend2_filter ? (direction2 < 0? na : supertrend2):na, "Down Trend", color = color.red, style=plot.style_linebr)long_supertrend2_filter= (direction2 < 0 ? supertrend2 : na)short_supertrend2_filter= (direction2 < 0? na : supertrend2)// Calculate supertrend 3[supertrend3, direction3] = ta.supertrend(factor3, atrPeriod3)upTrend3 = plot(use_supertrend2_filter? (direction3 < 0 ? supertrend3 : na) : na, "Up Trend", color = color.green, style=plot.style_linebr)downTrend3 = plot(use_supertrend2_filter ? (direction3 < 0? na : supertrend3):na, "Down Trend", color = color.red, style=plot.style_linebr)long_supertrend3_filter= (direction3 < 0 ? supertrend3 : na)short_supertrend3_filter= (direction3 < 0? na : supertrend3)//--trama--src =(close)ama = 0.hh = math.max(math.sign(ta.change(ta.highest(lengths))), 0)ll = math.max(math.sign(ta.change(ta.lowest(lengths)) * -1), 0)tc = math.pow(ta.sma(hh or ll ? 1 : 0, lengths), 2)ama := nz(ama[1] + tc * (src - ama[1]), src)plot(plottrama?ama : na, 'Plot', color.new(#ff1100, 0), 2)long_LUX_trama_filter= (close > ama)short_LUX_trama_filter= (close < ama)// highest highhighest = ta.highest(high, stochlenght)// lowest lowlowest = ta.lowest(low, stochlenght)// stochastic oscillatorstochastic_K = ((close - lowest) / (highest - lowest)) * 100stochastic_D = ta.sma(stochastic_K, 3)long_stoch_filter =ta.crossover( stochastic_K , oversold_level) and stochastic_K[1] < oversold_levelshort_stoch_filter = ta.crossunder(stochastic_K , overbought_level) and stochastic_K[1] > overbought_level//ATR band upline and bottome line.upline = open + (atr* takeProfitFactor)bottomline = open -(atr*stopLossFactor)plot(use_atr_bands_exits ? upline : na, color=color.white)plot(use_atr_bands_exits ? bottomline:na, color=color.white)// Calculate stop loss and take profit levelsstopLoss = stopLossFactor * atrtakeProfit = takeProfitFactor * atr//input macd[macdLine, signalLine, histLine]= ta.macd(close,12,26,9)long_macd_filter= (macdLine > signalLine) and ta.crossover(ma_fast,ma_slow)short_macd_filter= (macdLine < signalLine) and ta.crossunder(ma_fast,ma_slow)// ema 200ema1= ta.ema(close,1)ema2= ta.ema(close,200)barsincecrossup =ta.barssince(close >ema2)barsincecrossdw=ta.barssince(close <ema2)long_ema_filter = (close > ema2 and close[1] > ema2 )short_ema_filter= (close<ema2 and close[1]<ema2)plot(plotAverage ? ta.ema(close, 200) : na, title="Exponential Average")// mfisrc1 = hlc3mf = ta.mfi(src1, length1)signal = ta.ema(mf, signalLength)long_mfi_filter= ta.crossover(mf, signal) ? mf : nashort_mfi_filter= ta.crossunder(mf, signal) ? mf : na//ccilevel = 0sd_length = 20cci = ta.cci(src, cci_l)atr2 = ta.atr(atr_l)var st = 0.if cci >= level st := low - atr stif cci <= level st := high + atr stvar tu = 0.var td = 0.var optimal_line = 0.if cci >= level and cci[1] < level tu := td[1] tuif cci <= level and cci[1] > level td := tu[1] tdif cci > level tu := low - atr2 if tu < tu[1] and cci[1] >= level tu := tu[1] tuif cci < level td := high + atr2 if td > td[1] and cci[1] <= level td := td[1] tdoptimal_line := math.max(tu, td)// Creating a Price Channel, avg_st8 = ta.ema(st, 8)avg_st13 = ta.ema(st, 13)avg_st21 = ta.ema(st, 21)avg_st34 = ta.ema(st, 21)avg_st55 = ta.ema(st, 55)avg_st89 = ta.ema(st, 89)avg_st144 = ta.ema(st, 144)avg_st233 = ta.ema(st, 233)average_weighting = (optimal_line + avg_st8 + avg_st13 + avg_st21 + avg_st34 + avg_st55 + avg_st89 + avg_st144 + avg_st233) / 9basis = ta.sma(average_weighting, sd_length)devs = ta.stdev(average_weighting, sd_length)upperS = basis + devslowerS = basis - devsplot(use_cci_filter ? basis: na, 'Basis', color=color.new(#872323, 0))p3 = plot(use_cci_filter ? upperS : na, 'UpperS', color=color.new(color.teal, 0))p4 = plot(use_cci_filter ? lowerS: na ,'LowerS', color=color.new(color.teal, 0))long_cci_filter= ta.crossover(close,upperS) short_cci_filter= ta.crossunder(close,lowerS) //wvapsrcv = hlc3stdevMult_1 = (0)if barstate.islast and ta.cum(volume) == 0 runtime.error("No volume is provided by the data vendor.")new_earnings = request.earnings(syminfo.tickerid, earnings.actual, barmerge.gaps_on, barmerge.lookahead_on, ignore_invalid_symbol=true)new_dividends = request.dividends(syminfo.tickerid, dividends.gross, barmerge.gaps_on, barmerge.lookahead_on, ignore_invalid_symbol=true)new_split = request.splits(syminfo.tickerid, splits.denominator, barmerge.gaps_on, barmerge.lookahead_on, ignore_invalid_symbol=true)isNewPeriod = switch anchor "Earnings" => not na(new_earnings) "Dividends" => not na(new_dividends) "Splits" => not na(new_split) "Session" => timeframe.change("D") "Week" => timeframe.change("W") "Month" => timeframe.change("M") "Quarter" => timeframe.change("3M") "Year" => timeframe.change("12M") "Decade" => timeframe.change("12M") and year % 10 == 0 "Century" => timeframe.change("12M") and year % 100 == 0 => falseisEsdAnchor = anchor == "Earnings" or anchor == "Dividends" or anchor == "Splits"if na(src[1]) and not isEsdAnchor isNewPeriod := truefloat vwapValue = nafloat upperBandValue1 = nafloat lowerBandValue1 = nafloat upperBandValue2 = nafloat lowerBandValue2 = nafloat upperBandValue3 = nafloat lowerBandValue3 = naif not (timeframe.isdwm) [_vwap, _stdevUpper, _] = ta.vwap(src, isNewPeriod, 1) vwapValue := _vwap stdevAbs = _stdevUpper - _vwap upperBandValue1 := _vwap + stdevAbs * stdevMult_1 lowerBandValue1 := _vwap - stdevAbs * stdevMult_1plot(use_vwap_filter ?vwapValue : na, title="VWAP", color=#2962FF)long_vwap_filter= close > vwapValueshort_vwap_filter = close < vwapValue//chaikin money flow var cumVol = 0.cumVol += nz(volume)if barstate.islast and cumVol == 0 runtime.error("No volume is provided by the data vendor.")ad = close==high and close==low or high==low ? 0 : ((2*close-low-high)/(high-low))*volumemf2 = math.sum(ad, length) / math.sum(volume, length)long_chaikin_money_flow_filter= mf2> 0short_chaikin_money_flow_filter = mf2<0// ema crossema4=ta.ema(close,shortlen)ema5=ta.ema(close,longlen)long_ema_cross_filter= ta.crossover(ema4,ema5)short_ema_cross_filter=ta.crossunder(ema4,ema5)plot(use_ema_cross_filter? ema4 : na)plot(use_ema_cross_filter ? ema5 : na)//ichimku cloudmiddleDonchian(Length) => lower = ta.lowest(Length) upper = ta.highest(Length) math.avg(upper, lower)laggingSpan2Periods = 52displacement = 26Tenkan = middleDonchian(conversionPeriods)Kijun = middleDonchian(basePeriods)xChikou = closeSenkouA = middleDonchian(laggingSpan2Periods)SenkouB = (Tenkan[basePeriods] + Kijun[basePeriods]) / 2plot(use_ichimoku_filter ? Tenkan : na, color=color.new(color.red, 0), title='Tenkan')plot(use_ichimoku_filter ? Kijun : na, color=color.new(color.blue, 0), title='Kijun')plot(use_ichimoku_filter ? xChikou : na, color=color.new(color.teal, 0), title='Chikou', offset=-displacement)A = plot(use_ichimoku_filter ? SenkouA[displacement]: na, color=color.new(color.purple, 0), title='SenkouA')B = plot(use_ichimoku_filter ? SenkouB : na, color=color.new(color.green, 0), title='SenkouB')long_ichimoku_filter= close > SenkouA[displacement] and close> SenkouB short_ichimoku_filter= close < SenkouA[displacement] and close< SenkouB // lux candlestick pattern//Settings//-----------------------------------------------------------------------------{//Patternsenable_hammer = trueenable_ihammer = trueenable_shooting =trueenable_hanging = trueenable_bulleng = falseenable_beareng = falseenable_wm = trueenable_bm = true //Stylebull_css = #0cb51aavg_css =#ff5d00bear_css = #ff1100fade = 200//-----------------------------------------------------------------------------}//Variables/Functions//-----------------------------------------------------------------------------{n = bar_indexo = open,h = high,l = low,c = closeatrw = ta.atr(20) / 2 stw = ta.stoch(c, c, c, lengthw)downtrendw = stw < 50uptrendw = stw > 50d = math.abs(c - o)lbl(y, txt, direction, tlt)=> label.new( n, y, txt , size = size.tiny , style = direction == 1 ? label.style_cross : label.style_cross , color = direction == 1 ? bull_css : bear_css , textcolor = color.white , tooltip = tlt )//-----------------------------------------------------------------------------}//Tooltips//-----------------------------------------------------------------------------{var hammer_tlt = "The hammer candlestick pattern is formed of a short body with a long lower wick, and is found at the bottom of a downward trend." + "\n" + "\nA hammer shows that although there were selling pressures during the day, ultimately a strong buying pressure drove the price back up." var ihammer_tlt = "The inverted hammer is a similar pattern than the hammer pattern. The only difference being that the upper wick is long, while the lower wick is short." + "\n" + "\nIt indicates a buying pressure, followed by a selling pressure that was not strong enough to drive the market price down. The inverse hammer suggests that buyers will soon have control of the market."var bulleng_tlt = "The bullish engulfing pattern is formed of two candlesticks. The first candle is a short red body that is completely engulfed by a larger green candle" + "\n" + "\nThough the second day opens lower than the first, the bullish market pushes the price up, culminating in an obvious win for buyers"var wm_tlt = "The white marubozu is a single candles formation formed after a downtrend and indicating a bullish reversal." + "\n" + "\nThis candlestick has a long bullish body with no upper or lower shadows, reflecting a strong buying pressure." var shooting_tlt = "The shooting star is the same shape as the inverted hammer, but is formed in an uptrend: it has a small lower body, and a long upper wick." + "\n" + "\nUsually, the market will gap slightly higher on opening and rally to an intra-day high before closing at a price just above the open – like a star falling to the ground."var hanging_tlt = "The hanging man is the bearish equivalent of a hammer; it has the same shape but forms at the end of an uptrend." + "\n" + "\nIt indicates that there was a significant sell-off during the day, but that buyers were able to push the price up again. The large sell-off is often seen as an indication that the bulls are losing control of the market."var beareng_tlt = "A bearish engulfing pattern occurs at the end of an uptrend. The first candle has a small green body that is engulfed by a subsequent long red candle." + "\n" + "\nIt signifies a peak or slowdown of price movement, and is a sign of an impending market downturn. The lower the second candle goes, the more significant the trend is likely to be."var bm_tlt = "The black marubozu is a single candles formation formed after an uptrend and indicating a bearish reversal." + "\n" + "\nThis candlestick has a long bearish body with no upper or lower shadows, reflecting a strong selling pressure."//-----------------------------------------------------------------------------}//Pattern Rules//-----------------------------------------------------------------------------{hammer = downtrendw and math.min(o, c) - l > 2 * d and h - math.max(c, o) < d / 4ihammer = downtrendw and h - math.max(o, c) > 2 * d and math.min(c, o) - l < d / 4shooting = uptrendw and h - math.max(o, c) > 2 * d and math.min(c, o) - l < d / 4hanging = uptrendw and math.min(o, c) - l > 2 * d and h - math.max(c, o) < d / 4bulleng = downtrendw and c > o and c[1] < o[1] and c > o[1] and d > atrbeareng = uptrendw and c < o and c[1] > o[1] and c < o[1] and d > atrwm = c > o and h - math.max(o, c) + math.min(o, c) - l < d / 10 and d > atr and downtrendw[1]bm = c < o and h - math.max(o, c) + math.min(o, c) - l < d / 10 and d > atr and uptrendw[1]//-----------------------------------------------------------------------------}//Channel//-----------------------------------------------------------------------------{var max = hvar min = l//Bullish Patternsif hammer and use_luxcandlepatternchannel_filter max += alpha / 100 * (c - max) lbl(low, 'H', 1, hammer_tlt) if ihammer and use_luxcandlepatternchannel_filter max += alpha / 100 * (c - max) lbl(low, 'IH', 1, ihammer_tlt)if bulleng and enable_bulleng max += alpha / 100 * (c - max) lbl(low, 'BE', 1, bulleng_tlt)if wm and use_luxcandlepatternchannel_filter max += alpha / 100 * (c - max) lbl(low, 'WM', 1, wm_tlt)//Bearish Patternsif shooting and use_luxcandlepatternchannel_filter min += alpha / 100 * (c - min) lbl(high, 'SS', 0, shooting_tlt)if hanging and use_luxcandlepatternchannel_filter min += alpha / 100 * (c - min) lbl(high, 'HM', 0, hanging_tlt)if beareng and enable_beareng min += alpha / 100 * (c - min) lbl(high, 'BE', 0, beareng_tlt)if bm and use_luxcandlepatternchannel_filter min += alpha / 100 * (c - min) lbl(high, 'BM', 0, bm_tlt)max := math.max(c, max)min := math.min(c, min)smooth_max = ta.ema(max, smooth)smooth_min = ta.ema(min, smooth)avg = math.avg(smooth_max, smooth_min)//-----------------------------------------------------------------------------}//Plots//-----------------------------------------------------------------------------{var os = 0os := c > smooth_max ? 1 : c < smooth_min ? 0 : osvar fade_max = 0fade_max := os == 0 ? fade_max + 1 : 0var fade_min = 0fade_min := os == 1 ? fade_min + 1 : 0plot_0 = plot(use_luxcandlepatternchannel_filter? smooth_max : na, 'Upper', bull_css)plot_1 = plot(use_luxcandlepatternchannel_filter? avg : na, 'Average', avg_css)plot_2 = plot(use_luxcandlepatternchannel_filter? smooth_min : na, 'Lower', bear_css)css1 = color.from_gradient(use_luxcandlepatternchannel_filter? fade_max : na, 0, fade, color.new(bull_css, 80), color.new(bull_css, 100))css2 = color.from_gradient(use_luxcandlepatternchannel_filter? fade_min : na, 0, fade, color.new(bear_css, 80), color.new(bear_css, 100))long_luxcandlepatternchannel_filter=hammer or ihammer or wm short_luxcandlepatternchannel_filter= shooting or hanging or bm//support and resistance luxvolumeThresh = 20highUsePivot = fixnan(ta.pivothigh(leftBars, rightBars)[1])lowUsePivot = fixnan(ta.pivotlow(leftBars, rightBars)[1])r1 = plot(use_support_an_dresistance_break_filter? highUsePivot : na, color=ta.change(highUsePivot) ? na : #FF0000, linewidth=3, offset=-(rightBars + 1), title='Resistance')s1 = plot(use_support_an_dresistance_break_filter? lowUsePivot : na, color=ta.change(lowUsePivot) ? na : #233dee, linewidth=3, offset=-(rightBars + 1), title='Support')//Volume %shorts = ta.ema(volume, 5)longs = ta.ema(volume, 10)osc = 100 * (shorts - longs) / longsshort_support_an_dresistance_break_filter=close[1] < lowUsePivot and close < lowUsePivot long_support_an_dresistance_break_filter=close[1]> highUsePivot and close > highUsePivot//mavilimwtmal = fmal + smalFmal = smal + tmalFtmal = tmal + FmalSmal = Fmal + FtmalM1 = ta.wma(close, fmal)M2 = ta.wma(M1, smal)M3 = ta.wma(M2, tmal)M4 = ta.wma(M3, Fmal)M5 = ta.wma(M4, Ftmal)MAVW = ta.wma(M5, Smal)col1 = MAVW > MAVW[1]col3 = MAVW < MAVW[1]colorM = col1 ? color.blue : col3 ? color.red : color.yellowplot(use_mavilimw_filter? MAVW : na, color=colorM, linewidth=2, title='MAVW')M12 = ta.wma(close, 3)M22 = ta.wma(M12, 5)M32 = ta.wma(M22, 8)M42 = ta.wma(M32, 13)M52 = ta.wma(M42, 21)MAVW2 = ta.wma(M52, 34)long_mavilimw_filter= ta.crossover(MAVW, MAVW[1])short_mavilimw_filter=ta.crossunder(MAVW, MAVW[1])//ift-cc1CCI = truev11 = 0.1 * (ta.cci(close, ccilength) / 4)v21 = ta.wma(v11, wmalength)INV1 = (math.exp(2 * v21) - 1) / (math.exp(2 * v21) + 1)rsilength = 5v12 = 0.1 * (ta.rsi(close, rsilength) - 50)v22 = ta.wma(v12, wmalength)INV2 = (math.exp(2 * v22) - 1) / (math.exp(2 * v22) + 1)stochlength = 5v1 = 0.1 * (ta.stoch(close, high, low, stochlength) - 50)v2 = ta.wma(v1, wmalength)INVLine = (math.exp(2 * v2) - 1) / (math.exp(2 * v2) + 1)long_ift_cci_filter=CCI and INV1 > 0.5short_ift_cci_filter=CCI and INV1 < -0.5//MFImfilength = 5sourcse = hlc3up = math.sum(volume * (ta.change(sourcse) <= 0 ? 0 : sourcse), mfilength)lo = math.sum(volume * (ta.change(sourcse) >= 0 ? 0 : sourcse), mfilength)mfii = 100.0 - 100.0 / (1.0 + up / lo)v13 = 0.1 * (mfii - 50)v23 = ta.wma(v13, wmalength)INV3 = (math.exp(2 * v23) - 1) / (math.exp(2 * v23) + 1)AVINV = (INV1 + INV2 + INVLine + INV3) / 4var isLong = falsevar isShort= falselong = ((not use_ema_cross_filter or long_ema_cross_filter) and (not use_LUX_trama_filter or long_LUX_trama_filter) and ( not use_supertrend_filter or long_supertrend_filter) and (not use_ema200_filter or long_ema_filter) and (not isLong) and (not use_stochastic_filter or long_stoch_filter) and (not use_macd_filter or long_macd_filter) and (not use_mfi_filter or long_mfi_filter) and (not use_cci_filter or long_cci_filter) and ( not use_vwap_filter or long_vwap_filter) and (not use_chaikin_money_flow_filter or long_chaikin_money_flow_filter)and (not use_ichimoku_filter or long_ichimoku_filter)and (not use_luxcandlepatternchannel_filter or long_luxcandlepatternchannel_filter) and ( not use_support_an_dresistance_break_filter or long_support_an_dresistance_break_filter) and (not use_mavilimw_filter or long_mavilimw_filter) and (not use_ift_cci_filter or long_ift_cci_filter) and (not use_supertrend2_filter or long_supertrend2_filter) and (not use_supertrend3_filter or long_supertrend3_filter) ) short= ((not use_ema_cross_filter or short_ema_cross_filter) and (not use_LUX_trama_filter or short_LUX_trama_filter) and (not use_supertrend_filter or short_supertrend_filter) and (not use_ema200_filter or short_ema_filter) and (not isShort) and ( not use_stochastic_filter or short_stoch_filter) and (not use_macd_filter or long_macd_filter) and (not use_mfi_filter or short_mfi_filter) and (not use_cci_filter or short_cci_filter) and (not use_vwap_filter or short_vwap_filter)and (not use_chaikin_money_flow_filter or short_chaikin_money_flow_filter) and (not use_ichimoku_filter or short_ichimoku_filter) and ( not use_luxcandlepatternchannel_filter or short_luxcandlepatternchannel_filter)and (not use_support_an_dresistance_break_filter or short_support_an_dresistance_break_filter)and ( not use_mavilimw_filter or short_mavilimw_filter)and (not use_ift_cci_filter or short_ift_cci_filter)and (not use_supertrend2_filter or short_supertrend2_filter) and ( not use_supertrend3_filter or short_supertrend3_filter))if long isLong := true isShort := falseif short isLong := false isShort := trueplotshape(long, title='Buy', text='Buy', style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0), textcolor=color.new(color.white, 0), size=size.tiny)plotshape(short, title='Sell', text='Sell', style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 0), textcolor=color.new(color.white, 0), size=size.tiny)// trailing atr exitsPrev = ta.highest(high - Mult1 * ta.atr(Atr1), Hhv1)ta.barssince(close > ta.highest(high - Mult1 * ta.atr(Atr1), Hhv1) and close > close[1])cum_1 = ta.cum(1)highest_1 = ta.highest(high - Mult1 * ta.atr(Atr1), Hhv1)highest_2 = ta.highest(high - Mult1 * ta.atr(Atr1), Hhv1)iff_1 = close > highest_1 and close > close[1] ? highest_2 : PrevTS = cum_1 < 16 ? close : iff_1iff_2 = close < TS ? color.red : color.blackColor = close > TS ? color.green : iff_2plot(use_trailing_atr_exits? TS : na, color=Color, linewidth=3, title='ATR Trailing Stoploss')short_trailing_atr_exits = ta.crossover(close, TS)long_trailing_atr_exits = ta.crossunder(close, TS)//traillongStopPricess = 0.0shortStopPricess = 0.0longStopPricess := if strategy.position_size > 0 stopValue = close * (1 - trailStop) math.max(stopValue, longStopPricess[1])else 0shortStopPricess := if strategy.position_size < 0 stopValue = close * (1 + trailStop) math.min(stopValue, shortStopPricess[1])else 999999//PLOT TSL LINESplot(series=strategy.position_size > 0 and use_percent_base_trailing_stop_exits ? longStopPricess : na, color=color.red, style=plot.style_linebr, linewidth=1, title="Long Trail Stop", offset=1, title="Long Trail Stop")plot(series=strategy.position_size < 0 and use_percent_base_trailing_stop_exits? shortStopPricess : na, color=color.red, style=plot.style_linebr, linewidth=1, title="Short Trail Stop", offset=1, title="Short Trail Stop")//bollingerbasiss = ta.sma(src, lengthss)dev = mult * ta.stdev(src, lengthss)upper = basiss + devlower = basiss - devplot(use_bollinger_exits ? basiss : na, "Basis", color=#FF6D00, offset = offset)p1 = plot(use_bollinger_exits ? upper : na, "Upper", color=#2962FF, offset = offset)p2 = plot(use_bollinger_exits ? lower: na, "Lower", color=#2962FF, offset = offset)long_atr_bands_exits = close > upline short_atr_bands_exits = close < bottomlinelong_bollinger_exits= close > uppershort_bollinger_exits=close < lowerlong_atr_exits = close > upline short_atr_exits = close < bottomlinetakelong = (not use_atr_bands_exits or long_atr_bands_exits) and (not use_bollinger_exits or long_bollinger_exits) and ( not use_trailing_atr_exits or long_trailing_atr_exits )takeshort = (not use_atr_bands_exits or short_atr_bands_exits) and (not use_bollinger_exits or short_bollinger_exits) and (not use_trailing_atr_exits or short_trailing_atr_exits)plotshape(use_atr_bands_exits? takelong : na,title = 'take profit',text='high SL/TP',style=shape.cross,location = location.abovebar, color=color.new(color.green,0) , size=size.tiny)plotshape(use_atr_bands_exits ? takeshort : na,title = 'take profit',text='low SL/TP',style=shape.cross,location = location.belowbar, color=color.new(color.green,0), size=size.tiny)plotshape(use_bollinger_exits ? takelong: na,title = 'take profit',text='high SL/TP',style=shape.cross,location = location.abovebar, color=color.new(color.green,0) , size=size.tiny)plotshape(use_bollinger_exits ? takeshort: na,title = 'take profit',text='low SL/TP',style=shape.cross,location = location.belowbar, color=color.new(color.green,0), size=size.tiny)// Determine stop loss pricelongStopPrice = strategy.position_avg_price * (1 - longLossPerc)shortStopPrice = strategy.position_avg_price * (1 + shortLossPerc)// Determine take profit pricelongprofitPrice = strategy.position_avg_price * (1 + longprofitPerc)shortprofitPrice = strategy.position_avg_price * (1 - shortprofitPerc)// Plot stop loss values for confirmationplot(series=strategy.position_size > 0 ? longStopPrice : na, color=color.new(color.red, 0), style=plot.style_cross, linewidth=1, title='Long Stop Loss')plot(series=strategy.position_size < 0 ? shortStopPrice : na, color=color.new(color.red, 0), style=plot.style_cross, linewidth=1, title='Short Stop Loss')plot(use_fix_perc_take_profit and strategy.position_size > 0 ? longprofitPrice : na, color=color.new(color.green, 0), style=plot.style_cross, linewidth=1, title='Long profit')plot(use_fix_perc_take_profit and strategy.position_size < 0 ? shortprofitPrice : na, color=color.new(color.green, 0), style=plot.style_cross, linewidth=1, title='Short profit')// trailing tpbool openLongPosition = longbool openShortPosition = shortbool longIsActive = openLongPosition or strategy.position_size > 0bool shortIsActive = openShortPosition or strategy.position_size < 0float longTakeProfitPrice2 = nalongTakeProfitPrice2 := if longIsActive if openLongPosition and not (strategy.position_size > 0) close * (1 + longTakeProfitPerc2) else nz(longTakeProfitPrice2[1], close * (1 + longTakeProfitPerc2))else nafloat shortTakeProfitPrice2 = nashortTakeProfitPrice2 := if shortIsActive if openShortPosition and not (strategy.position_size < 0) close * (1 - shortTakeProfitPerc2) else nz(shortTakeProfitPrice2[1], close * (1 - shortTakeProfitPrice2))else nafloat longTrailingTakeProfitStepTicks = longTakeProfitPrice2 * LtrailingTakeProfitDeviationPerc / syminfo.mintickfloat shortTrailingTakeProfitStepTicks = shortTakeProfitPrice2 * StrailingTakeProfitDeviationPerc / syminfo.mintickplot(enableTrailing? longTakeProfitPrice2:na, title='Long Take Profit', color = color.green, linewidth = 1, style = plot.style_cross, offset = 1)plot(enableTrailing? shortTakeProfitPrice2 :na, title='Short Take Profit', color = color.red, linewidth = 1, style = plot.style_cross, offset = 1)longstoploss= close <longStopPrice shortstoploss=close >shortStopPrice if longstoploss strategy.close("Long Entry")if shortstoploss strategy.close("Short Entry")longCondition = long and not short_onlyif (longCondition and time_cond) strategy.entry("Long Entry", strategy.long)shortCondition = short and not long_onlyif (shortCondition and time_cond) strategy.entry("Short Entry", strategy.short)if use_trailing_stop_loss if takelong and strategy.position_size > 0 and time_cond or time_cond and close < longStopPrice strategy.close("Long Entry") if takeshort and strategy.position_size < 0 and time_cond or time_cond and close >shortStopPrice strategy.close("Short Entry")else if time_cond and close < longStopPrice or time_cond and close > longprofitPrice and use_fix_perc_take_profit strategy.close("Long Entry") if time_cond and close < shortprofitPrice or time_cond and close > shortStopPrice and use_fix_perc_take_profit strategy.close("Short Entry")if isLong and use_percent_base_trailing_stop_exits strategy.exit(id="Close Long", stop=longStopPricess)if isShort and use_percent_base_trailing_stop_exits strategy.exit(id="Close Short", stop=shortStopPricess)if isLong and enableTrailing strategy.exit(id = 'Long Take Profit', from_entry = 'Long Entry', limit = close < longStopPrice or enableTrailing ? na : longTakeProfitPrice2, trail_price = enableTrailing ? longTakeProfitPrice2 : na, trail_offset = enableTrailing ? longTrailingTakeProfitStepTicks : na, when = longIsActive, alert_message = 'Long(' + syminfo.ticker + '): Take Profit activated')if isShort and enableTrailing strategy.exit(id = 'Short Take Profit', from_entry = 'Short Entry', limit = close > shortStopPrice or enableTrailing ? na : shortTakeProfitPrice2, trail_price = enableTrailing ? shortTakeProfitPrice2 : na, trail_offset = enableTrailing ? shortTrailingTakeProfitStepTicks : na, when = shortIsActive, alert_message = 'Short(' + syminfo.ticker + '): Take Profit activated')