├── 40in1.md ├── README.md ├── indicators ├── 3 MA + Cross.pine ├── 3 MTF EMA:SMA.pine ├── 5 EMA SMA + Cross.pine ├── BB + 3EMA.pine ├── BB Winner.pine ├── Candle Percent Volatility [Alorse].pine ├── DMI + RSI Cross.pine ├── DMI.pine ├── KDJ.pine ├── MACD Divergence.pine ├── MACD.pine ├── MTF+MACD.pine ├── PivotHighLow.pine ├── RSI Divergence.pine ├── SuperTrend FromScrash.pine ├── TTM Squeeze + MACD Line.pine ├── TTM Squeeze.pine ├── Untitled-1.pine └── Williams Vix Fix + Inverse.pine ├── multi ├── Alert BB + RSI.pine ├── Futuros Binance.txt ├── Multi Alert Long:Short.pine ├── Multi MACD + BB + RSI.pine ├── Multi MTF + MACD.pine ├── Multi RSI Divergence.pine ├── Multi Supertrend.pine └── RSI Multi Alerts.pine └── strategies ├── 1P.pine ├── 2 EMA:SMA + RSI.pine ├── 3 EMA:SMA + Cross.pine ├── BB + Aroon.pine ├── BB Divergence.pine ├── BB Winner LITE 1.0.2.pine ├── BB Winner LITE.pine ├── BB Winner PRO 2.03.pine ├── BB Winner PRO.pine ├── Bollinger Breakout [kodify].pine ├── DMI Winner.pine ├── Double RSI.pine ├── Double Supertrend.pine ├── EMA Moving away Strategy [Alorse].pine ├── Exceeded candle.pine ├── Flawless Victory.pine ├── Full Candle.pine ├── GridBotDir [Alorse].pine ├── HA UnivLong&Short Futures.pine ├── Heikin Ashi Strategy V2 [FAKE].pine ├── Improvisando [Alorse].pine ├── Javo v1 [Repinta].pine ├── MA Cross + DMI.pine ├── MACD + BB + RSI.pine ├── MACD + DMI.pine ├── MACD Long Strategy [Bunghole].pine ├── MACD+RSI.pine ├── MEMA + BB + RSI [Alorse].pine ├── MTF BB.pine ├── MTF RSI.pine ├── MTF+MACD.pine ├── MacdNew.pine ├── Multi BB.pine ├── Omar Edited WF.pine ├── Omar MMR [Alorse].pine ├── Password protected.pine ├── Pin Bar Magic v1.pine ├── QQE signals.pine ├── RSI + 1200.pine ├── RSI + EMA.pine ├── Stoch RSI Crossover Strat + EMA - YT-Trade Pro.pine ├── StochRSI + Supertrend Strategy.pine ├── StratBase.pine ├── Strategy Tester [Lupown].pine ├── Supertrend + EMA rebound [Alorse].pine ├── Supertrend + RSI.pine ├── Supertrend.pine ├── TTM Squeeze.pine ├── Tendency EMA + RSI.pine ├── Williams Vix Fix.pine ├── estrategia10:20ema copy.pine └── velaSuperada.pine /40in1.md: -------------------------------------------------------------------------------- 1 | # 40 ALERTAS EN 1 2 | He creado un Indicador en Tradingview que permite agregar hasta **40 ALERTAS EN 1** sola para diferentes pares, nos va a ser muy util. 3 | 4 | Este indicador lo puede usar cualquier persona que tenga TradingView, pero recueden que la versión gratuita solo permite 1 alerta y no permite hacer la conexión con nuestro canal de Telegram. 5 | 6 | Si alguien lo quiere usar debe seguir estos pasos: 7 | 8 | 1. **Instalar el Indicador** 9 | - Ir a `https://www.tradingview.com/script/L1hS7zUw-Multi-Alert-MACD-Divergence-Alorse/` 10 | - Lo marcas como favorito. 11 | - Vas a tu gráfica de Tradingview y actualizas/recargas la página. 12 | - Ahora veras el indicador en tus Favoritos. 13 | - Lo agregas y listo. 14 | 15 | 2. **Configurar el Indicador** 16 | - Abres la configuración del Indicador ☸ 17 | - Elije los pares a los que les quieres hacer seguimiento. 18 | - Si son menos de 40, mejor deshabilita los que te sobren. 19 | - Revisa que los pares no esten ya en nuestra lista así evitamos alertas repetidas. 20 | 21 | 3. **Crear la alerta** (Ver la imagen adjunta) 22 | - Crea una nueva alerta. 23 | - En "Condición" seleccionas el nombre del indicador (Multi Alert MACD Diveregences) 24 | - Vencimiento: Indefinido (Si no te permite esta opción, selecciona la fecha más lejana, generalmente 2 meses después de hoy) 25 | - Webhook URL: `https://api.telegram.org/bot1835816922:AAHLinKRLewpOuusvSB1Fv1l_O-VzFELr0E/sendMessage?chat_id=-1001449948584` 26 | - Presiona el boton "Crear" 27 | 28 | 4. **Notificar de los nuevos pares** 29 | - Avisame al privado (@Alorse) para que agregue los pares a la lista. 30 | 31 | Espero que estas alertas nos sirvan y le saquemos dinero al mercado. 32 | 33 | 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 34 | 35 | Recuerdas el canal de las divergencias del MACD? https://t.me/DivergenciasMACD 36 | Si estas interesado en recibir alertas como estas o de cualquier otro tipo 37 | 38 | - RSI sobrevendido/sobrecomprado 39 | - Divergencias (MACD, RSI) 40 | - Bandas de Bollinger 41 | - Nube Ichumochu 42 | - Cruce de EMAs 43 | - Supertrend 44 | - ADX 45 | - etc... 46 | 47 | Incluso de tu propia estrategia, el costo $$$ dependerá de la dificultad. 48 | 49 | - Tendras tu propio canal para que lo compartas con tus amigos. 50 | - Un único pago si tienes alertas de Tradingview disponibles (Plan PRO en adelante), hasta 40 Monedas/Pares en 1 sola alerta. 51 | - Si tienes el plan FREE o no cuentas con alertas, podemos rentartelas. 52 | 53 | Contactar a @alorse para más información. 54 | 55 | 🟡 🟡 🟡 🟡 🟡 🟡 🟡 🟡 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Pinescript Repository 2 | 3 | This repository contains 3 folders with Pinescript files that have been created or modified by me. All files can be executed in Tradingview. 4 | 5 | ## Folders 6 | 7 | ### /indicators 8 | This folder includes the indicators that have been created or modified by me. These indicators can be used to analyze price movement, volume, and momentum. 9 | 10 | ### /multi 11 | This folder includes scripts that allow for up to 40 alerts. These alerts can be set based on a variety of conditions, including price movement, volume, and technical indicators. 12 | 13 | ### /strategies 14 | This folder includes over 50 alerts that have been created or improved by me. These alerts can be used as part of a trading strategy to help identify potential entry and exit points. 15 | 16 | ## Tradingview Profile 17 | For more information about me and my trading strategies, please visit my [Tradingview profile](https://www.tradingview.com/u/alorse/). -------------------------------------------------------------------------------- /indicators/3 MA + Cross.pine: -------------------------------------------------------------------------------- 1 | //@version=4 2 | study(title="3 EMA/SMA + Cross [Alorse]", shorttitle="3 MA + Cross [Alorse]", overlay=true) 3 | 4 | src = input(title="Source", type=input.source, defval=close) 5 | ma_type1 = input(title="Type", type=input.string, defval="EMA", options=["EMA", "SMA"], group="Moving Average 1 (Fast)") 6 | lenFast = input(10, minval=1, title="Periods", group="Moving Average 1 (Fast)") 7 | ma_type2 = input(title="Type", type=input.string, defval="EMA", options=["EMA", "SMA"], group="Moving Average 2 (Slow)") 8 | lenSlow = input(20, minval=1, title="Periods", group="Moving Average 2 (Slow)") 9 | ma_type3 = input(title="Type", type=input.string, defval="EMA", options=["EMA", "SMA"], group="Moving Average 3 (Tendence)") 10 | lenTend = input(100, minval=1, title="Periods", group="Moving Average 3 (Tendence)") 11 | 12 | // Calculate moving averages 13 | maFast = ma_type1 == "EMA" ? ema(src, lenFast) : sma(src, lenFast) 14 | maSlow = ma_type2 == "EMA" ? ema(src, lenSlow) : sma(src, lenSlow) 15 | maTend = ma_type3 == "EMA" ? ema(src, lenTend) : sma(src, lenTend) 16 | 17 | // Plot moving averages 18 | plot(maFast, color=color.purple, title="Fast MA") 19 | plot(maSlow, color=color.orange, title="Slow MA") 20 | plot(maTend, color=color.white, title="Tendence MA", linewidth=2) 21 | 22 | // Calculate trading conditions 23 | plot(cross(maFast, maSlow) ? maFast : na, style=plot.style_cross, title="Cross", linewidth=2, color=color.white) 24 | -------------------------------------------------------------------------------- /indicators/3 MTF EMA:SMA.pine: -------------------------------------------------------------------------------- 1 | // 2 | //@author Alorse 3 | //@version=5 4 | indicator(title='3 Multi Timeframe EMA/SMA', shorttitle='3 MTF EMA/SMA', overlay=true) 5 | 6 | // SMA or EMA 7 | mtf_type = input.string(title='MultiTimeframe MA Type', defval='EMA', options=['EMA', 'SMA'], group='MTF MA Type') 8 | 9 | //Get MA Values 10 | resA = input.timeframe(title='Timeframe', defval='15', group='Moving Average 1') 11 | maA = input.int(title='MA Periods', minval=1, defval=50, group='Moving Average 1') 12 | resB = input.timeframe(title='Timeframe', defval='60', group='Moving Average 2') 13 | maB = input.int(title='MA Periods', minval=1, defval=50, group='Moving Average 2') 14 | resC = input.timeframe(title='Timeframe', defval='240', group='Moving Average 3') 15 | maC = input.int(title='MA Periods', minval=1, defval=50, group='Moving Average 3') 16 | 17 | //Set resolutions 18 | 19 | //get data 20 | dataA = request.security(syminfo.tickerid, resA, mtf_type == 'EMA' ? ta.ema(close, maA) : ta.sma(close, maA)) 21 | dataB = request.security(syminfo.tickerid, resB, mtf_type == 'EMA' ? ta.ema(close, maB) : ta.sma(close, maB)) 22 | dataC = request.security(syminfo.tickerid, resC, mtf_type == 'EMA' ? ta.ema(close, maC) : ta.sma(close, maC)) 23 | 24 | //Plotting 25 | plot(dataA, color=color.new(color.purple, 0), linewidth=1) 26 | plot(dataB, color=color.new(color.white, 0), linewidth=1) 27 | plot(dataC, color=color.green, linewidth=1, color=na) 28 | -------------------------------------------------------------------------------- /indicators/5 EMA SMA + Cross.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | //@author Alorse 3 | //@version=5 4 | indicator(title='5 EMA SMA WMA + Cross [Alorse]', shorttitle='5 MA + Cross [Alorse]', overlay=true) 5 | 6 | src = input(title='Source', defval=close) 7 | ma_type1 = input.string(title='Type', defval='EMA', options=['EMA', 'SMA', 'WMA'], group='Moving Average 1') 8 | ma1 = input.int(10, minval=1, title='Periods', group='Moving Average 1') 9 | ma_type2 = input.string(title='Type', defval='EMA', options=['EMA', 'SMA', 'WMA'], group='Moving Average 2') 10 | ma2 = input.int(55, minval=1, title='Periods', group='Moving Average 2') 11 | ma_type3 = input.string(title='Type', defval='EMA', options=['EMA', 'SMA', 'WMA'], group='Moving Average 3') 12 | ma3 = input.int(200, minval=1, title='Periods', group='Moving Average 3') 13 | ma_type4 = input.string(title='Type', defval='SMA', options=['EMA', 'SMA', 'WMA'], group='Moving Average 4') 14 | ma4 = input.int(20, minval=1, title='Periods', group='Moving Average 4') 15 | ma_type5 = input.string(title='Type', defval='WMA', options=['EMA', 'SMA', 'WMA'], group='Moving Average 5') 16 | ma5 = input.int(100, minval=1, title='Periods', group='Moving Average 5') 17 | 18 | // Calculate moving averages 19 | maPlot1 = ma_type1 == 'EMA' ? ta.ema(src, ma1) : ma_type1 == 'SMA' ? ta.sma(src, ma1) : ta.wma(src, ma1) 20 | maPlot2 = ma_type2 == 'EMA' ? ta.ema(src, ma2) : ma_type2 == 'SMA' ? ta.sma(src, ma2) : ta.wma(src, ma2) 21 | maPlot3 = ma_type3 == 'EMA' ? ta.ema(src, ma3) : ma_type3 == 'SMA' ? ta.sma(src, ma3) : ta.wma(src, ma3) 22 | maPlot4 = ma_type4 == 'EMA' ? ta.ema(src, ma4) : ma_type4 == 'SMA' ? ta.sma(src, ma4) : ta.wma(src, ma4) 23 | maPlot5 = ma_type5 == 'EMA' ? ta.ema(src, ma5) : ma_type5 == 'SMA' ? ta.sma(src, ma5) : ta.wma(src, ma5) 24 | 25 | // Plot moving averages 26 | plot(maPlot1, color=color.new(color.purple, 0), title='Moving Average 1') 27 | plot(maPlot2, color=color.new(color.blue, 0), title='Moving Average 2') 28 | plot(maPlot3, color=color.new(color.yellow, 0), title='Moving Average 3', linewidth=2) 29 | plot(maPlot4, color=color.new(color.green, 0), title='Moving Average 4') 30 | plot(maPlot5, color=color.new(color.red, 0), title='Moving Average 5', linewidth=2) 31 | 32 | // Crosses 33 | plot(ta.cross(maPlot1, maPlot2) ? maPlot1 : na, style=plot.style_cross, title='Cross MA1-MA2', linewidth=2, color=color.new(color.aqua, 0)) 34 | plot(ta.cross(maPlot1, maPlot3) ? maPlot1 : na, style=plot.style_cross, title='Cross MA1-MA3', linewidth=2, color=color.new(color.aqua, 0)) 35 | plot(ta.cross(maPlot1, maPlot4) ? maPlot1 : na, style=plot.style_cross, title='Cross MA1-MA4', linewidth=2, color=color.new(color.aqua, 0)) 36 | plot(ta.cross(maPlot1, maPlot5) ? maPlot1 : na, style=plot.style_cross, title='Cross MA1-MA5', linewidth=2, color=color.new(color.aqua, 0)) 37 | 38 | plot(ta.cross(maPlot2, maPlot3) ? maPlot2 : na, style=plot.style_cross, title='Cross MA2-MA3', linewidth=2, color=color.new(color.fuchsia, 0)) 39 | plot(ta.cross(maPlot2, maPlot4) ? maPlot2 : na, style=plot.style_cross, title='Cross MA2-MA4', linewidth=2, color=color.new(color.fuchsia, 0)) 40 | plot(ta.cross(maPlot2, maPlot5) ? maPlot2 : na, style=plot.style_cross, title='Cross MA2-MA5', linewidth=2, color=color.new(color.fuchsia, 0)) 41 | 42 | plot(ta.cross(maPlot3, maPlot4) ? maPlot3 : na, style=plot.style_cross, title='Cross MA3-MA4', linewidth=2, color=color.new(color.teal, 0)) 43 | plot(ta.cross(maPlot3, maPlot5) ? maPlot3 : na, style=plot.style_cross, title='Cross MA3-MA5', linewidth=2, color=color.new(color.teal, 0)) 44 | 45 | plot(ta.cross(maPlot4, maPlot5) ? maPlot4 : na, style=plot.style_cross, title='Cross MA4-MA5', linewidth=2, color=color.new(color.yellow, 0)) 46 | -------------------------------------------------------------------------------- /indicators/BB + 3EMA.pine: -------------------------------------------------------------------------------- 1 | // 2 | //@author Alorse 3 | //@version=4 4 | study(title="Simple Bollinger Bands + 3 EMA/SMA [Alorse]", shorttitle="BB + 3 EMA/SMA [Alorse]", overlay=true) 5 | txtVer = "1.0.2" 6 | version = input(title="Version", type=input.string, defval=txtVer, options=[txtVer], tooltip="This is informational only, nothing will change.") 7 | 8 | src = input(title="Source", type=input.source, defval=close) 9 | 10 | // Bollinger Bands 11 | bbGroup = "Bollindger Bands" 12 | isBB = input(true, title="╔═════ Show Bollinger Bands ═════╗", group=bbGroup, tooltip="If you don't want to see Bollinger Bands") 13 | length = input(20, title="Period Bollindger Bands", group=bbGroup) 14 | mult = input(2.0, minval=0.001, maxval=5, group=bbGroup) 15 | 16 | basis = sma(src, length) 17 | dev = mult * stdev(src, length) 18 | upper = basis + dev 19 | lower = basis - dev 20 | offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500) 21 | 22 | plot(isBB ? basis : na, "Basis", color=color.new(color.orange, 75), offset = offset) 23 | pb1 = plot(isBB ? upper : na, color=color.new(color.lime, 75), title="Upper") 24 | pb2 = plot(isBB ? lower : na, color=color.new(color.lime, 75), title="Lower") 25 | fill(pb1, pb2, color=color.new(color.lime, 99), title="Background") 26 | 27 | //EMA 28 | ma_type = input(title="Moving Average Type", type=input.string, defval="EMA", options=["EMA", "SMA"], group="Moving Averages") 29 | lenFast = input(10, minval=1, title="Fast EMA", group="Moving Averages") 30 | lenSlow = input(55, minval=1, title="Slow EMA", group="Moving Averages") 31 | lenTend = input(200, minval=1, title="Tend EMA", group="Moving Averages") 32 | showCross = input(title="Show MA Cross", defval=true, group="Moving Averages") 33 | 34 | emaFast = ma_type == "EMA" ? ema(src, lenFast) : sma(src, lenFast) 35 | emaSlow = ma_type == "EMA" ? ema(src, lenSlow) : sma(src, lenSlow) 36 | emaTend = ma_type == "EMA" ? ema(src, lenTend) : sma(src, lenTend) 37 | 38 | plot(emaFast, title="Fast MA", linewidth=1, color=color.new(color.blue, 10)) 39 | plot(emaSlow, title="Slow MA", linewidth=1, color=color.new(color.orange, 10)) 40 | plot(emaTend, title="Tend MA", linewidth=2, color=color.new(color.white, 10)) 41 | 42 | // Cross detect 43 | cross_up = crossover(emaFast , emaSlow) 44 | cross_down = crossunder(emaFast , emaSlow) 45 | plot(showCross and cross_up or showCross and cross_down ? emaFast : na, style=plot.style_cross, title="Cross", linewidth=2, color=color.white) 46 | -------------------------------------------------------------------------------- /indicators/BB Winner.pine: -------------------------------------------------------------------------------- 1 | // 2 | //@author Alorse 3 | //@version=4 4 | study("Bollinger Bands Winner IND [Alorse]", shorttitle="BB Winner IND [Alorse]", overlay=true) 5 | 6 | txtVer = "2.0.8" 7 | version = input(title="Version", type=input.string, defval=txtVer, options=[txtVer], tooltip="This is informational only, nothing will change.") 8 | 9 | // Bollinger Bands 10 | bbGroup = "Bollindger Bands" 11 | src = input(title="Source", type=input.source, defval=close, group=bbGroup) 12 | length = input(20, title="Length", group=bbGroup) 13 | mult = input(2.0, title="StdDev", minval=0.001, maxval=5, group=bbGroup) 14 | 15 | basis = sma(src, length) 16 | dev = mult * stdev(src, length) 17 | upper = basis + dev 18 | lower = basis - dev 19 | 20 | // RSI 21 | rsiGroup = "RSI Filter" 22 | hasRSI = input(true, title="╔══════   Use RSI   ══════╗", group=rsiGroup, tooltip="Long: Only when RSI is below 45\nShort: Only when RSI is above 55") 23 | aboveRSI = input(45, title="Above", inline="Above", group=rsiGroup) 24 | srcRSI = input(close, title="Source", type=input.source, group=rsiGroup) 25 | lenRSI = input(14, title="Length", minval=1, group=rsiGroup) 26 | belowRSI = input(55, title="Below", inline="Above", group=rsiGroup) 27 | RSI = rsi(srcRSI, lenRSI) 28 | 29 | // Aroon 30 | aroonGroup = "Aroon Filter" 31 | hasAroon = input(false, title="╔══════ Use Aroon ══════╗", group=aroonGroup, tooltip="Aroon plays a key role in this strategy. It acts as a confirmation that the asset is currently in an uptrend. On the other hand, it acts as a stop if market conditions deteriorate. The strategy uses an Aroon Indicator set to 288 periods to provide a longer-term view on market conditions, not being heavily dependent on short-term volatility.") 32 | lengthAr = input(288, title="Periods", minval=1, group=aroonGroup) 33 | Confirmation = input(90, title="Confirmation", group=aroonGroup, inline="Above") 34 | Stop = input(70, title="Stop", group=aroonGroup, inline="Above") 35 | AroonUP = 100 * (highestbars(high, lengthAr+1) + lengthAr)/lengthAr 36 | // AroonDown = 100 * (lowestbars(low, lengthAr+1) + lengthAr)/lengthAr 37 | buyAroonFilter = hasAroon ? AroonUP > Confirmation : true 38 | sellAroonFilter = hasAroon ? AroonUP < Stop : true 39 | 40 | // Moving Average 41 | maGroup = "Moving Average" 42 | hasMa = input(true, title="╔══════   Use MA   ══════╗", group=maGroup, tooltip="asd") 43 | maType = input(title="Moving Average Type", type=input.string, defval="EMA", options=["EMA", "SMA"], group=maGroup) 44 | maLen = input(200, minval=1, title="Moving Average length", group=maGroup) 45 | ma = maType == "EMA" ? ema(src, maLen) : sma(src, maLen) 46 | // plot(hasMa ? ma : na, title="Moving Average", linewidth=1, color=color.new(color.blue, 10)) 47 | buyMaFilter = hasMa ? close > ma : true 48 | sellMaFilter = hasMa ? close < ma : true 49 | 50 | // Strategy Conditions 51 | stratGroup = "Strategy" 52 | candleper = input(title="Candle %", type=input.integer, minval=0, maxval=100, defval=30, group=stratGroup, tooltip="When the candle's body passes the Bollinger Bands in this percentage, a new entry will open in the opposite direction.") * 0.01 53 | cbSize = input(false, title="Include shadow as part of the body", group=stratGroup) 54 | showLong = input(true, title="Long entries", group=stratGroup) 55 | showShort = input(false, title="Short entries", group=stratGroup) 56 | // secureEntry = input(false, title="Only secure entries", group=stratGroup, tooltip="With this option the profit is almost guaranteed, but you will greatly limit the field of action of the strategy.") 57 | closeEarly = input(true, title="Close position early", group=stratGroup, tooltip="The position will be closed when the price touches the Bollinger Bands in the opposite direction and trade is in profit.") 58 | candle_size = cbSize ? high-low : close > open ? close - open : open - close 59 | buyzone = (candle_size*candleper) + low 60 | sellzone = high - (candle_size*candleper) 61 | 62 | body_size = close > open ? close - open : open - close 63 | bs60 = body_size*0.6 64 | bsBuy = low + bs60 65 | bsSell = high - bs60 66 | seBuy = true //secureEntry ? not (bsBuy < lower) : true 67 | seSell = true //secureEntry ? not (bsSell > upper) : true 68 | 69 | buyRSIFilter = hasRSI ? RSI < aboveRSI : true 70 | sellRSIFilter = hasRSI ? RSI > belowRSI : true 71 | 72 | // bought = strategy.opentrades[0] == 1 and strategy.position_size[0] > strategy.position_size[1] 73 | // entry_price = valuewhen(bought, open, 0) 74 | 75 | // closeLongEarly = close > entry_price and closeEarly 76 | // closeShortEarly = close < entry_price and closeEarly 77 | 78 | buy = buyzone < lower and close < open and buyRSIFilter and buyAroonFilter and buyMaFilter and seBuy 79 | sell = sellzone > upper and close > open and sellRSIFilter and sellAroonFilter and sellMaFilter and seSell 80 | 81 | // // Stop Loss 82 | // slGroup = "Stop Loss" 83 | // useSL = input(true, title="╔══════   Enable   ══════╗", group=slGroup, tooltip="If you are using this strategy for Scalping or Futures market, we do not recommend using Stop Loss.") 84 | // SLbased = input(title="Based on", type=input.string, defval="Percent", options=["ATR", "Percent"], group=slGroup, tooltip="ATR: Average True Range\nPercent: eg. 5%.") 85 | // multiATR = input(7.0, title="ATR   Mult", type=input.float, group=slGroup, inline="atr") 86 | // lengthATR = input(14, title="Length", type=input.integer, group=slGroup, inline="atr") 87 | // SLPercent = input(7, title="Percent", type=input.float, group=slGroup) * 0.01 88 | // plotSL = input(true, title="Show SL", group=slGroup) 89 | 90 | // longStop = 0.0 91 | // shortStop = 0.0 92 | 93 | // if SLbased == "ATR" 94 | // longStop := valuewhen(buy, low, 0) - (valuewhen(buy, rma(tr(true), lengthATR), 0) * multiATR) 95 | // longStopPrev = nz(longStop[1], longStop) 96 | // longStop := close[1] > longStopPrev ? max(longStop, longStopPrev) : longStop 97 | 98 | // shortStop := (valuewhen(sell, rma(tr(true), lengthATR), 0) * multiATR) + valuewhen(sell, high, 0) 99 | // shortStopPrev = nz(shortStop[1], shortStop) 100 | // shortStop := close[1] > shortStopPrev ? max(shortStop, shortStopPrev) : shortStop 101 | // if SLbased == "Percent" 102 | // longStop := strategy.position_avg_price * (1 - SLPercent) 103 | // shortStop := strategy.position_avg_price * (1 + SLPercent) 104 | 105 | // // Print Stop Loss 106 | // plotshape(plotSL and useSL and strategy.position_size > 0 ? longStop : na, title = "Long Stop Loss", color=color.green, location=location.absolute) 107 | // plotshape(plotSL and useSL and strategy.position_size < 0 ? shortStop : na, title = "Short Stop Loss", color=color.red, location=location.absolute) 108 | 109 | 110 | buyExit = RSI < 70 and buyzone > upper ? false : buyzone > upper 111 | sellExit = RSI > 30 and sellzone < lower ? false : sellzone < lower 112 | // if showLong 113 | // strategy.entry("Long", true, when=buy) 114 | plotshape(showLong and buy, location=location.belowbar, text="Long", style=shape.arrowup, color=color.blue) 115 | // if closeLongEarly and useSL 116 | // strategy.exit("Exit", "Long", limit=upper, stop=longStop) 117 | // if not useSL and closeLongEarly 118 | // strategy.exit("Exit", "Long", limit=upper) 119 | // if not showShort 120 | // strategy.close("Long", when=buyExit, comment="Exit") 121 | plotshape(showLong and not showShort and buyExit, location=location.abovebar, text="Exit", style=shape.arrowdown, color=color.fuchsia) 122 | // if showShort 123 | // strategy.entry("Short", false, when=sell) 124 | plotshape(showShort and buy, location=location.abovebar, text="Exit", style=shape.arrowdown, color=color.red) 125 | // if closeShortEarly and useSL 126 | // strategy.exit("Exit", "Short", limit=lower, stop=shortStop) 127 | // if not useSL and closeLongEarly 128 | // strategy.exit("Exit", "Short", limit=lower) 129 | // if not showLong 130 | // strategy.close("Short", when=sellExit, comment="Exit") 131 | plotshape(showShort and not showLong and sellExit, location=location.belowbar, text="Exit", style=shape.arrowdown, color=color.fuchsia) 132 | -------------------------------------------------------------------------------- /indicators/Candle Percent Volatility [Alorse].pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © Alorse 3 | //@version=5 4 | indicator(title='Percent & Volatility [Alorse]', shorttitle='P&V', overlay=false) 5 | 6 | change = input.int(5, minval=1, title='Change %', tooltip='Show strong color if candle percent greater than this number') 7 | 8 | percent_volatility = ((high - low) * 100) / low 9 | percent_change = ((close - open) * 100) / open 10 | 11 | plot(percent_volatility, color=color.new(color.teal, percent_volatility > change ? 0 : 70), title='Low/High', style=plot.style_columns) 12 | plot(percent_change, color=color.new(color.orange, math.abs(percent_change) > change ? 0 : 70), title='Open/Close', style=plot.style_columns) 13 | if math.abs(percent_change) > change 14 | alert('{"text": "' + cleanTicker + ': Cambió ' + timeframe.period + ' minutos"}', alert.freq_once_per_bar_close) 15 | -------------------------------------------------------------------------------- /indicators/DMI + RSI Cross.pine: -------------------------------------------------------------------------------- 1 | //@version=4 2 | study("Directional Movement Index [Alorse]", shorttitle="DMI [Alorse]", max_labels_count=500) 3 | len = input(14, minval=1, title="DI Length") 4 | lensig = input(14, title="ADX Smoothing", minval=1, maxval=50) 5 | keyLevel = input(25, title="Key level") 6 | showCross = input(title="Show RSI labels", defval=false) 7 | [diplus,diminus,adx] = dmi(len, lensig) 8 | colo = diplus > diminus ? color.teal : color.maroon 9 | plot(adx, color=colo, title="ADX", linewidth=2) 10 | hline(keyLevel) 11 | cond = adx > keyLevel 12 | bgcolor(cond ? color.silver : na) 13 | 14 | // RSI 15 | src = input(close, "Source", type = input.source, group="RSI") 16 | UpL = input(title="Up level", defval=64, group="RSI") 17 | DownL = input(title="down level", defval=36, group="RSI") 18 | up = rma(max(change(src), 0), len) 19 | down = rma(-min(change(src), 0), len) 20 | rsi = rsi(src, len) 21 | color = rsi > UpL or rsi < DownL ? color.gray : color.orange 22 | if adx >= keyLevel-1 and adx <= keyLevel+1 and adx[1] < keyLevel and showCross 23 | label.new(bar_index, keyLevel-5, tostring(rsi[0], '#.##'), color=color, style=label.style_label_up, textcolor=color.white, size=size.small) 24 | -------------------------------------------------------------------------------- /indicators/DMI.pine: -------------------------------------------------------------------------------- 1 | //@version=5 2 | indicator('DMI Trade Zone [Alorse]', shorttitle='DMI TZ [Alorse]') 3 | len = input.int(14, minval=1, title='DI Length') 4 | lensig = input.int(14, title='ADX Smoothing', minval=1, maxval=50) 5 | keyLevel = input(23, title='key level') 6 | pl = input(false, title='Plot DI- & DI+') 7 | [diplus, diminus, adx] = ta.dmi(len, lensig) 8 | cond = diplus > diminus 9 | colo = cond ? color.green : color.red 10 | plot(adx, color=color.new(color.white, 50), title='Shadow', linewidth=3) 11 | plot(adx, color=colo, title='ADX', linewidth=2) 12 | plot(pl ? diminus : na, color=color.new(color.red, 0), title='DI-') 13 | plot(pl ? diplus : na, color=color.new(color.green, 0), title='DI+') 14 | hline(keyLevel) 15 | bgcolor(cond ? color.new(color.silver, 92) : na) 16 | -------------------------------------------------------------------------------- /indicators/KDJ.pine: -------------------------------------------------------------------------------- 1 | //@version=4 2 | study(title="KDJ + MACD Cross [Alorse]", shorttitle = "KDJ + MACD Cross", format=format.price) 3 | ilong = input(9, title="period", type=input.integer, group="KDJ") 4 | isig = input(3, title="signal", type=input.integer, group="KDJ") 5 | 6 | bcwsma(s,l,m) => 7 | _bcwsma = float(na) 8 | _s = s 9 | _l = l 10 | _m = m 11 | _bcwsma := (_m*_s+(_l-_m)*nz(_bcwsma[1]))/_l 12 | _bcwsma 13 | 14 | c = close 15 | h = highest(high, ilong) 16 | l = lowest(low,ilong) 17 | RSV = 100*((c-l)/(h-l)) 18 | pK = bcwsma(RSV, isig, 1) 19 | pD = bcwsma(pK, isig, 1) 20 | pJ = 3 * pK-2 * pD 21 | 22 | plot(pK, color=#1E88E5) 23 | plot(pD, color=#FF6F00) 24 | plot(pJ, color=#000000) 25 | bgcolor(pJ>pD? color.green : color.red, transp=85) 26 | 27 | // Getting inputs 28 | fast_length = input(title="Fast Length", type=input.integer, defval=12, group="MACD") 29 | slow_length = input(title="Slow Length", type=input.integer, defval=26, group="MACD") 30 | src = input(title="Source", type=input.source, defval=close, group="MACD") 31 | signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9, group="MACD") 32 | sma_source = input(title="Oscillator MA Type", type=input.string, defval="EMA", options=["SMA", "EMA"], group="MACD") 33 | sma_signal = input(title="Signal Line MA Type", type=input.string, defval="EMA", options=["SMA", "EMA"], group="MACD") 34 | 35 | // Calculating 36 | fast_ma = sma_source == "SMA" ? sma(src, fast_length) : ema(src, fast_length) 37 | slow_ma = sma_source == "SMA" ? sma(src, slow_length) : ema(src, slow_length) 38 | macd = fast_ma - slow_ma 39 | signal = sma_signal == "SMA" ? sma(macd, signal_length) : ema(macd, signal_length) 40 | 41 | if (crossover(pJ, pD) and crossover(macd, signal)) 42 | line.new(bar_index, 0, bar_index, 100, xloc.bar_index, extend.both, color.new(color.green, 0), line.style_solid, 2) 43 | alert("KDJ Cross + MACD Cross ⬆") 44 | if (crossunder(pJ, pD) and crossunder(macd, signal)) 45 | line.new(bar_index, 0, bar_index, 100, xloc.bar_index, extend.both, color.new(color.red, 0), line.style_solid, 2) 46 | alert("KDJ Cross + MACD Cross ⬇") -------------------------------------------------------------------------------- /indicators/MACD Divergence.pine: -------------------------------------------------------------------------------- 1 | //@version=5 2 | // Based on Divergence MACD [mado] 3 | // URL: https://es.tradingview.com/script/ABhNVSWq/ 4 | indicator(title='MACD + Divergences [Alorse]', shorttitle='MACD Divergence', format=format.price) 5 | // Getting inputs 6 | src = input(title='Source', defval=close) 7 | fast_length = input(title='Fast Length', defval=12) 8 | slow_length = input(title='Slow Length', defval=26) 9 | signal_length = input.int(title='Signal Smoothing', minval=1, maxval=50, defval=9) 10 | sma_source = input.string(title='Oscillator MA Type', defval='EMA', options=['SMA', 'EMA']) 11 | sma_signal = input.string(title='Signal Line MA Type', defval='EMA', options=['SMA', 'EMA']) 12 | 13 | col_macd = input.color(#2962FF, 'MACD Line  ', group='Color Settings', inline='MACD') 14 | col_signal = input.color(#FF6D00, 'Signal Line  ', group='Color Settings', inline='Signal') 15 | showCross = input.bool(title='Show Signals&MACD Cross', defval=true, group='Color Settings') 16 | col_grow_above = input.color(#00796b, 'Above   Grow', group='Histogram', inline='Above') 17 | col_fall_above = input.color(#26a69a, 'Fall', group='Histogram', inline='Above') 18 | col_grow_below = input.color(#ef5350, 'Below Grow', group='Histogram', inline='Below') 19 | col_fall_below = input.color(#b71c1c, 'Fall', group='Histogram', inline='Below') 20 | 21 | fast_ma = sma_source == 'SMA' ? ta.sma(src, fast_length) : ta.ema(src, fast_length) 22 | slow_ma = sma_source == 'SMA' ? ta.sma(src, slow_length) : ta.ema(src, slow_length) 23 | macd = fast_ma - slow_ma 24 | signal = sma_signal == 'SMA' ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length) 25 | hist = macd - signal 26 | osc = macd 27 | 28 | plot(hist, title='Histogram', style=plot.style_columns, color=color.new(hist >= 0 ? hist[1] < hist ? col_grow_above : col_fall_above : hist[1] < hist ? col_grow_below : col_fall_below, 0)) 29 | plot(macd, title='MACD', color=color.new(col_macd, 10)) 30 | plot(signal, title='Signal', color=color.new(col_signal, 10)) 31 | 32 | //Divergences 33 | lbR = input.int(title='Pivot Lookback Right', defval=5, group='Divergences') 34 | lbL = input.int(title='Pivot Lookback Left', defval=5, group='Divergences') 35 | rangeUpper = input.int(title='Max of Lookback Range', defval=60, group='Divergences') 36 | rangeLower = input.int(title='Min of Lookback Range', defval=5, group='Divergences') 37 | plotBull = input.bool(title='Plot Bullish', defval=true, group='Divergences') 38 | plotBear = input.bool(title='Plot Bearish', defval=true, group='Divergences') 39 | plotHiddenBull = input.bool(title='Plot Hidden Bullish', defval=false, group='Divergences') 40 | plotHiddenBear = input.bool(title='Plot Hidden Bearish', defval=false, group='Divergences') 41 | 42 | bearColor = color.red 43 | bullColor = color.green 44 | hiddenBullColor = color.new(color.yellow, 50) 45 | hiddenBearColor = color.new(color.yellow, 50) 46 | textColor = color.white 47 | noneColor = color.new(color.white, 100) 48 | 49 | plFound = na(ta.pivotlow(osc, lbL, lbR)) ? false : true 50 | phFound = na(ta.pivothigh(osc, lbL, lbR)) ? false : true 51 | 52 | _inRange(cond) => 53 | bars = ta.barssince(cond == true) 54 | rangeLower <= bars and bars <= rangeUpper 55 | 56 | //------------------------------------------------------------------------------ 57 | // Regular Bullish 58 | 59 | // Osc: Higher Low 60 | oscHL = osc[lbR] > ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1]) 61 | 62 | // Price: Lower Low 63 | priceLL = low[lbR] < ta.valuewhen(plFound, low[lbR], 1) 64 | 65 | bullCond = plotBull and priceLL and oscHL and plFound 66 | 67 | plot(plFound ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=2, color=bullCond ? bullColor : noneColor) 68 | // plotshape(bullCond ? osc[lbR] : na,offset=-lbR,title="Regular Bullish Label",text="D",style=shape.labelup,location=location.absolute,color=bullColor,textcolor=textColor,transp=0) 69 | 70 | //------------------------------------------------------------------------------ 71 | // Hidden Bullish 72 | 73 | // Osc: Lower Low 74 | oscLL = osc[lbR] < ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1]) 75 | 76 | // Price: Higher Low 77 | priceHL = low[lbR] > ta.valuewhen(plFound, low[lbR], 1) 78 | 79 | hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound 80 | 81 | plot(plFound ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=2, color=hiddenBullCond ? hiddenBullColor : noneColor) 82 | plotshape(hiddenBullCond ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish Label', text='H', style=shape.labelup, location=location.absolute, color=bullColor, textcolor=textColor) 83 | 84 | //------------------------------------------------------------------------------ 85 | // Regular Bearish 86 | 87 | // Osc: Lower High 88 | oscLH = osc[lbR] < ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1]) 89 | 90 | // Price: Higher High 91 | priceHH = high[lbR] > ta.valuewhen(phFound, high[lbR], 1) 92 | 93 | bearCond = plotBear and priceHH and oscLH and phFound 94 | 95 | plot(phFound ? osc[lbR] : na, offset=-lbR, title='Regular Bearish', linewidth=2, color=bearCond ? bearColor : noneColor) 96 | // plotshape(bearCond ? osc[lbR] : na, offset=-lbR, title="Regular Bearish Label", text="⬇", style=shape.labeldown, location=location.absolute, color=color.new(bearColor,100), textcolor=color.new(bearColor, trendBear ? 0 : 50)) 97 | 98 | //------------------------------------------------------------------------------ 99 | // Hidden Bearish 100 | 101 | // Osc: Higher High 102 | oscHH = osc[lbR] > ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1]) 103 | 104 | // Price: Lower High 105 | priceLH = high[lbR] < ta.valuewhen(phFound, high[lbR], 1) 106 | 107 | hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound 108 | 109 | plot(phFound ? osc[lbR] : na, offset=-lbR, title='Hidden Bearish', linewidth=2, color=hiddenBearCond ? hiddenBearColor : noneColor) 110 | plotshape(hiddenBearCond ? osc[lbR] : na, offset=-lbR, title='Hidden Bearish Label', text='H', style=shape.labeldown, location=location.absolute, color=bearColor, textcolor=textColor) 111 | 112 | plot(showCross and ta.cross(osc, signal) ? osc : na, style=plot.style_cross, color=color.new(color.silver, 0), linewidth=2) 113 | 114 | alertcondition((bullCond ? macd[lbR] : na) or (bearCond ? macd[lbR] : na), 'Divergence', '{"text": "{{ticker}}: Divergence in {{interval}} minutes"}') 115 | 116 | -------------------------------------------------------------------------------- /indicators/MACD.pine: -------------------------------------------------------------------------------- 1 | //@version=4 2 | study(title="MACD", shorttitle="MACD", resolution="") 3 | // Getting inputs 4 | fast_length = input(title="Fast Length", type=input.integer, defval=12) 5 | slow_length = input(title="Slow Length", type=input.integer, defval=26) 6 | src = input(title="Source", type=input.source, defval=close) 7 | signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9) 8 | sma_source = input(title="Oscillator MA Type", type=input.string, defval="EMA", options=["SMA", "EMA"]) 9 | sma_signal = input(title="Signal Line MA Type", type=input.string, defval="EMA", options=["SMA", "EMA"]) 10 | // Plot colors 11 | col_macd = input(#2962FF, "MACD Line  ", input.color, group="Color Settings", inline="MACD") 12 | col_signal = input(#FF6D00, "Signal Line  ", input.color, group="Color Settings", inline="Signal") 13 | col_grow_above = input(#26A69A, "Above   Grow", input.color, group="Histogram", inline="Above") 14 | col_fall_above = input(#B2DFDB, "Fall", input.color, group="Histogram", inline="Above") 15 | col_grow_below = input(#FFCDD2, "Below Grow", input.color, group="Histogram", inline="Below") 16 | col_fall_below = input(#FF5252, "Fall", input.color, group="Histogram", inline="Below") 17 | // Calculating 18 | fast_ma = sma_source == "SMA" ? sma(src, fast_length) : ema(src, fast_length) 19 | slow_ma = sma_source == "SMA" ? sma(src, slow_length) : ema(src, slow_length) 20 | macd = fast_ma - slow_ma 21 | signal = sma_signal == "SMA" ? sma(macd, signal_length) : ema(macd, signal_length) 22 | hist = macd - signal 23 | plot(hist, title="Histogram", style=plot.style_columns, color=color.new((hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below) ),0)) 24 | plot(macd, title="MACD", color=color.new(col_macd, 0)) 25 | plot(signal, title="Signal", color=color.new(col_signal, 0)) 26 | 27 | 28 | // {{ticker}}: Divergence in {{interval}} minutes 29 | // https://tradingview.to/telegram/YRucmuUY0jUijwVf3lEg -------------------------------------------------------------------------------- /indicators/MTF+MACD.pine: -------------------------------------------------------------------------------- 1 | //@version=5 2 | indicator(title='MTF + MACD [Alorse]', shorttitle='MTF + MACD', format=format.price, overlay=false, timeframe='') 3 | 4 | txtVer = '2.0.0' 5 | version = input.string(title='Version', defval=txtVer, options=[txtVer], tooltip='This is informational only, nothing will change.') 6 | src = input(title='Source', defval=close) 7 | // Getting inputs 8 | macdGroup = 'MACD Settings' 9 | fast_length = input.int(title='Length   Fast', defval=12, group=macdGroup, inline='macdLength') 10 | slow_length = input.int(title='Slow', defval=26, group=macdGroup, inline='macdLength') 11 | signal_length = input.int(title='Signal Smoothing', minval=1, maxval=50, defval=9, group=macdGroup) 12 | sma_source = input.string(title='Oscillator', defval='EMA', options=['SMA', 'EMA'], group=macdGroup, inline='macdMa', tooltip='Moving Average Type') 13 | sma_signal = input.string(title='Signal Line', defval='EMA', options=['SMA', 'EMA'], group=macdGroup, inline='macdMa', tooltip='Moving Average Type') 14 | // Plot colors 15 | col_macd = input.color(#2962FF, 'MACD Line  ', group='Color Settings', inline='MACD') 16 | col_signal = input.color(#FF6D00, 'Signal Line  ', group='Color Settings', inline='Signal') 17 | showCross = input.bool(title='Show Signals&MACD Cross', defval=true, group='Color Settings') 18 | col_grow_above = input.color(#00796b, 'Above   Grow', group='Histogram', inline='Above') 19 | col_fall_above = input.color(#26a69a, 'Fall', group='Histogram', inline='Above') 20 | col_grow_below = input.color(#ef5350, 'Below Grow', group='Histogram', inline='Below') 21 | col_fall_below = input.color(#b71c1c, 'Fall', group='Histogram', inline='Below') 22 | // Calculating 23 | fast_ma = sma_source == 'SMA' ? ta.sma(src, fast_length) : ta.ema(src, fast_length) 24 | slow_ma = sma_source == 'SMA' ? ta.sma(src, slow_length) : ta.ema(src, slow_length) 25 | macd = fast_ma - slow_ma 26 | signal = sma_signal == 'SMA' ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length) 27 | hist = macd - signal 28 | plot(hist, title='Histogram', style=plot.style_columns, color=color.new(hist >= 0 ? hist[1] < hist ? col_grow_above : col_fall_above : hist[1] < hist ? col_grow_below : col_fall_below, 0)) 29 | plot(macd, title='MACD', color=color.new(col_macd, 10)) 30 | plot(signal, title='Signal', color=color.new(col_signal, 10)) 31 | 32 | //Divergences 33 | lbR = input.int(title='Pivot Lookback   Right', defval=2, group='Divergences', inline='pivot') 34 | lbL = input.int(title='Left', defval=2, group='Divergences', inline='pivot') 35 | rangeUpper = input.int(title='Lookback Range   Max', defval=60, group='Divergences', inline='range') 36 | rangeLower = input.int(title='Min', defval=6, group='Divergences', inline='range') 37 | plotBull = input.bool(title='Plot Bullish', defval=true, group='Divergences') 38 | plotHiddenBull = input.bool(title='Plot Hidden Bullish', defval=false, group='Divergences') 39 | plotBear = input.bool(title='Plot Bearish', defval=true, group='Divergences') 40 | plotHiddenBear = input.bool(title='Plot Hidden Bearish', defval=false, group='Divergences') 41 | 42 | bearColor = color.red 43 | bullColor = color.green 44 | hiddenBullColor = color.new(color.yellow, 50) 45 | hiddenBearColor = color.new(color.yellow, 50) 46 | textColor = color.white 47 | noneColor = color.new(color.white, 100) 48 | 49 | plFound = na(ta.pivotlow(macd, lbL, lbR)) ? false : true 50 | phFound = na(ta.pivothigh(macd, lbL, lbR)) ? false : true 51 | 52 | _inRange(cond) => 53 | bars = ta.barssince(cond == true) 54 | rangeLower <= bars and bars <= rangeUpper 55 | 56 | //Get MA Values 57 | maA = input.int(title='Periods', minval=1, defval=50, group='MTF EMA 1', inline='ma1') 58 | resA = input.timeframe(title='Resolution', defval='15', group='MTF EMA 1', inline='ma1') 59 | maB = input.int(title='Periods', minval=1, defval=50, group='MTF EMA 2', inline='ma2') 60 | resB = input.timeframe(title='Resolution', defval='60', group='MTF EMA 2', inline='ma2') 61 | 62 | //get data 63 | dataA = request.security(syminfo.tickerid, resA, ta.ema(src, maA)) 64 | dataB = request.security(syminfo.tickerid, resB, ta.ema(src, maB)) 65 | trendBull = dataA > dataB and macd[lbR] < 0 66 | trendBear = dataA < dataB and macd[lbR] > 0 67 | 68 | //------------------------------------------------------------------------------ 69 | // Regular Bullish 70 | 71 | // Osc: Higher Low 72 | oscHL = macd[lbR] > ta.valuewhen(plFound, macd[lbR], 1) and _inRange(plFound[1]) 73 | // Price: Lower Low 74 | priceLL = low[lbR] < ta.valuewhen(plFound, low[lbR], 1) 75 | bullCond = plotBull and priceLL and oscHL and plFound 76 | plot(plFound ? macd[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=2, color=bullCond ? color.new(bullColor, trendBull ? 0 : 50) : noneColor) 77 | plotshape(bullCond ? macd[lbR] : na, offset=-lbR, title='Regular Bullish Label', text='⬆', style=shape.labelup, location=location.absolute, color=color.new(bullColor, 100), textcolor=color.new(bullColor, trendBull ? 0 : 50)) 78 | 79 | //------------------------------------------------------------------------------ 80 | // Hidden Bullish 81 | 82 | // Osc: Lower Low 83 | oscLL = macd[lbR] < ta.valuewhen(plFound, macd[lbR], 1) and _inRange(plFound[1]) 84 | // Price: Higher Low 85 | priceHL = low[lbR] > ta.valuewhen(plFound, low[lbR], 1) 86 | hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound 87 | plot(plFound ? macd[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=2, color=hiddenBullCond ? hiddenBullColor : noneColor) 88 | plotshape(hiddenBullCond ? macd[lbR] : na, offset=-lbR, title='Hidden Bullish Label', text='⬆', style=shape.labelup, location=location.absolute, color=color.new(bullColor, 100), textcolor=hiddenBullColor) 89 | 90 | //------------------------------------------------------------------------------ 91 | // Regular Bearish 92 | 93 | // Osc: Lower High 94 | oscLH = macd[lbR] < ta.valuewhen(phFound, macd[lbR], 1) and _inRange(phFound[1]) 95 | // Price: Higher High 96 | priceHH = high[lbR] > ta.valuewhen(phFound, high[lbR], 1) 97 | bearCond = plotBear and priceHH and oscLH and phFound 98 | plot(phFound ? macd[lbR] : na, offset=-lbR, title='Regular Bearish', linewidth=2, color=bearCond ? color.new(bearColor, trendBear ? 0 : 50) : noneColor) 99 | plotshape(bearCond ? macd[lbR] : na, offset=-lbR, title='Regular Bearish Label', text='⬇', style=shape.labeldown, location=location.absolute, color=color.new(bearColor, 100), textcolor=color.new(bearColor, trendBear ? 0 : 50)) 100 | 101 | //------------------------------------------------------------------------------ 102 | // Hidden Bearish 103 | // Osc: Higher High 104 | oscHH = macd[lbR] > ta.valuewhen(phFound, macd[lbR], 1) and _inRange(phFound[1]) 105 | // Price: Lower High 106 | priceLH = high[lbR] < ta.valuewhen(phFound, high[lbR], 1) 107 | hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound 108 | plot(phFound ? macd[lbR] : na, offset=-lbR, title='Hidden Bearish', linewidth=2, color=hiddenBearCond ? hiddenBearColor : noneColor) 109 | plotshape(hiddenBearCond ? macd[lbR] : na, offset=-lbR, title='Hidden Bearish Label', text='⬇', style=shape.labeldown, location=location.absolute, color=color.new(bearColor, 100), textcolor=hiddenBearColor) 110 | 111 | plot(showCross and ta.crossunder(macd, signal) and trendBear ? macd : na, style=plot.style_cross, color=color.new(color.red, 0), linewidth=3) 112 | plot(showCross and ta.crossover(macd, signal) and trendBull ? macd : na, style=plot.style_cross, color=color.new(color.green, 0), linewidth=3) 113 | 114 | alertcondition((bullCond and trendBull ? macd[lbR] : na) or (bearCond and trendBear ? macd[lbR] : na), 'Divergence', '{"text": "{{ticker}}: Divergence in {{interval}} minutes"}') 115 | 116 | -------------------------------------------------------------------------------- /indicators/PivotHighLow.pine: -------------------------------------------------------------------------------- 1 | //@version=4 2 | study("PivotHighLow", overlay=true) 3 | leftBars = input(10) 4 | rightBars = input(10) 5 | ph = pivothigh(close, leftBars, rightBars) 6 | plot(ph, style=plot.style_line, linewidth=1, color= color.yellow, offset=-rightBars) 7 | plot(ph, style=plot.style_cross, linewidth=3, color= color.yellow, offset=-rightBars) 8 | pl = pivotlow(close, leftBars, rightBars) 9 | plot(pl, style=plot.style_line, linewidth=1, color= color.white, offset=-rightBars) 10 | plot(pl, style=plot.style_cross, linewidth=3, color= color.white, offset=-rightBars) 11 | 12 | //@version=3 13 | study(title="Better MACD", shorttitle="Better MACD") 14 | source = close 15 | fastLength = input(12, minval=1), slowLength=input(26,minval=1) 16 | signalLength=input(9,minval=1) 17 | fastMA = ema(source, fastLength) 18 | slowMA = ema(source, slowLength) 19 | macd = fastMA - slowMA 20 | signal = ema(macd, signalLength) 21 | hist = macd - signal 22 | histcolor = abs(hist[1]) < abs(hist) ? red:white 23 | 24 | hline(0,color=yellow, linestyle=dotted,title="Zero line") 25 | plot(hist, color=histcolor, style=columns,transp =50, title="Histogram") 26 | plot(signal, color=orange,linewidth=2, transp = 0, title="Signal") 27 | plot(macd, color=aqua, linewidth=2, transp = 0, title="MACD") 28 | plot(cross(macd,signal)? macd:na, style=circles,linewidth=3,transp=0,title="Crossing",color=white) 29 | -------------------------------------------------------------------------------- /indicators/RSI Divergence.pine: -------------------------------------------------------------------------------- 1 | //@version=5 2 | //RSI 3 | indicator(title='Relative Strength Index Divergence [Alorse]', shorttitle='RSI Divergence [Alorse]', format=format.price, precision=2, timeframe='') 4 | len = input.int(14, minval=1, title='Length', group='RSI') 5 | src = input.source(close, 'Source', group='RSI') 6 | up = ta.rma(math.max(ta.change(src), 0), len) 7 | down = ta.rma(-math.min(ta.change(src), 0), len) 8 | rsi = ta.rsi(src, len) 9 | osc = rsi 10 | plot(rsi, 'RSI', color=color.new(#7E57C2, 0)) 11 | band1 = hline(70, 'Upper Band', color=#787B86) 12 | bandm = hline(50, 'Middle Band', color=color.new(#787B86, 50)) 13 | band0 = hline(30, 'Lower Band', color=#787B86) 14 | fill(band1, band0, color=color.rgb(126, 87, 194, 90), title='Background') 15 | 16 | //Divergences 17 | lbR = input.int(title='Pivot Lookback Right', defval=5, group='Divergences') 18 | lbL = input.int(title='Pivot Lookback Left', defval=5, group='Divergences') 19 | rangeUpper = input.int(title='Max of Lookback Range', defval=60, group='Divergences') 20 | rangeLower = input.int(title='Min of Lookback Range', defval=5, group='Divergences') 21 | plotBull = input.bool(title='Plot Bullish', defval=true, group='Divergences') 22 | plotHiddenBull = input.bool(title='Plot Hidden Bullish', defval=true, group='Divergences') 23 | plotBear = input.bool(title='Plot Bearish', defval=true, group='Divergences') 24 | plotHiddenBear = input.bool(title='Plot Hidden Bearish', defval=true, group='Divergences') 25 | 26 | bearColor = color.red 27 | bullColor = color.green 28 | hiddenBullColor = color.new(color.yellow, 50) 29 | hiddenBearColor = color.new(color.yellow, 50) 30 | textColor = color.white 31 | noneColor = color.new(color.white, 100) 32 | 33 | plFound = na(ta.pivotlow(osc, lbL, lbR)) ? false : true 34 | phFound = na(ta.pivothigh(osc, lbL, lbR)) ? false : true 35 | 36 | _inRange(cond) => 37 | bars = ta.barssince(cond == true) 38 | rangeLower <= bars and bars <= rangeUpper 39 | 40 | //------------------------------------------------------------------------------ 41 | // Regular Bullish 42 | 43 | // Osc: Higher Low 44 | oscHL = osc[lbR] > ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1]) 45 | 46 | // Price: Lower Low 47 | priceLL = low[lbR] < ta.valuewhen(plFound, low[lbR], 1) 48 | 49 | bullCond = plotBull and priceLL and oscHL and plFound 50 | 51 | plot(plFound ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=2, color=bullCond ? color.new(bullColor, 0) : noneColor) 52 | // plotshape(bullCond ? osc[lbR] : na,offset=-lbR,title="Regular Bullish Label",text="⬆",style=shape.labelup,location=location.absolute,color=bullColor,textcolor=textColor,transp=0) 53 | 54 | //------------------------------------------------------------------------------ 55 | // Hidden Bullish 56 | 57 | // Osc: Lower Low 58 | oscLL = osc[lbR] < ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1]) 59 | 60 | // Price: Higher Low 61 | priceHL = low[lbR] > ta.valuewhen(plFound, low[lbR], 1) 62 | 63 | hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound 64 | 65 | plot(plFound ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=2, color=hiddenBullCond ? hiddenBullColor : noneColor) 66 | // plotshape(hiddenBullCond ? osc[lbR] : na,offset=-lbR,title="Hidden Bullish Label",text="⬆",style=shape.labelup,location=location.absolute,color=bullColor,textcolor=textColor,transp=0) 67 | 68 | //------------------------------------------------------------------------------ 69 | // Regular Bearish 70 | 71 | // Osc: Lower High 72 | oscLH = osc[lbR] < ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1]) 73 | 74 | // Price: Higher High 75 | priceHH = high[lbR] > ta.valuewhen(phFound, high[lbR], 1) 76 | 77 | bearCond = plotBear and priceHH and oscLH and phFound 78 | 79 | plot(phFound ? osc[lbR] : na, offset=-lbR, title='Regular Bearish', linewidth=2, color=bearCond ? color.new(bearColor, 0) : noneColor) 80 | // plotshape(bearCond ? osc[lbR] : na, offset=-lbR, title="Regular Bearish Label", text="⬇", style=shape.labeldown, location=location.absolute, color=color.new(bearColor,100), textcolor=color.new(bearColor, 0)) 81 | 82 | //------------------------------------------------------------------------------ 83 | // Hidden Bearish 84 | 85 | // Osc: Higher High 86 | oscHH = osc[lbR] > ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1]) 87 | 88 | // Price: Lower High 89 | priceLH = high[lbR] < ta.valuewhen(phFound, high[lbR], 1) 90 | 91 | hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound 92 | 93 | plot(phFound ? osc[lbR] : na, offset=-lbR, title='Hidden Bearish', linewidth=2, color=hiddenBearCond ? hiddenBearColor : noneColor) 94 | // plotshape(hiddenBearCond ? osc[lbR] : na,offset=-lbR,title="Hidden Bearish Label",text="⬇",style=shape.labeldown,location=location.absolute,color=bearColor,textcolor=textColor,transp=0) 95 | 96 | alertcondition((bullCond ? rsi[lbR] : na) or (bearCond ? rsi[lbR] : na), 'Divergence', '{"text": "{{ticker}}: Divergence in {{interval}} minutes"}') 97 | 98 | -------------------------------------------------------------------------------- /indicators/SuperTrend FromScrash.pine: -------------------------------------------------------------------------------- 1 | //@version=5 2 | indicator('Supertrend From Scratch [Alorse]', overlay=true, format=format.price, precision=2, timeframe='') 3 | 4 | Periods = input(title='ATR Period', defval=10) 5 | src = input(hl2, title='Source') 6 | Multiplier = input.float(title='ATR Multiplier', step=0.1, defval=3.0) 7 | atr = ta.atr(Periods) 8 | up = src - Multiplier * atr 9 | up1 = nz(up[1], up) 10 | up := close[1] > up1 ? math.max(up, up1) : up 11 | dn = src + Multiplier * atr 12 | dn1 = nz(dn[1], dn) 13 | dn := close[1] < dn1 ? math.min(dn, dn1) : dn 14 | trend = 1 15 | trend := nz(trend[1], trend) 16 | trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend 17 | upPlot = plot(trend == 1 ? up : na, title='Up Trend', style=plot.style_linebr, color=color.new(color.green, 0)) 18 | buySignal = trend == 1 and trend[1] == -1 19 | dnPlot = plot(trend == 1 ? na : dn, title='Down Trend', style=plot.style_linebr, color=color.new(color.red, 0)) 20 | sellSignal = trend == -1 and trend[1] == 1 21 | mPlot = plot(ohlc4, title='', style=plot.style_circles, linewidth=0) 22 | fill(mPlot, upPlot, title='UpTrend Highligter', color=color.new(color.green, 90)) 23 | fill(mPlot, dnPlot, title='DownTrend Highligter', color=color.new(color.red, 90)) 24 | 25 | -------------------------------------------------------------------------------- /indicators/TTM Squeeze + MACD Line.pine: -------------------------------------------------------------------------------- 1 | // 2 | //@author Alorse 3 | //@version=5 4 | indicator(title='TTM Squeeze + MACD line [Alorse]') 5 | length = input.int(title='Length', defval=20, minval=0) 6 | bband(length, mult) => 7 | ta.sma(close, length) + mult * ta.stdev(close, length) 8 | keltner(length, mult) => 9 | ta.ema(close, length) + mult * ta.ema(ta.tr, length) 10 | 11 | e1 = (ta.highest(high, length) + ta.lowest(low, length)) / 2 + ta.sma(close, length) 12 | ttm_osc = ta.linreg(close - e1 / 2, length, 0) 13 | diff = bband(length, 2) - keltner(length, 1) 14 | ttm_osc_color = ttm_osc[1] < ttm_osc[0] ? ttm_osc[0] >= 0 ? color.lime : color.maroon : ttm_osc[0] >= 0 ? color.green : color.red 15 | mid_color = diff >= 0 ? color.white : color.black 16 | 17 | plot(ttm_osc, color=ttm_osc_color, style=plot.style_area, linewidth=1) 18 | plot(0, color=mid_color, style=plot.style_circles, linewidth=1) 19 | 20 | // MACD Line 21 | src = input(title='Source', defval=close) 22 | fast_length = input(title='Fast Length', defval=12) 23 | slow_length = input(title='Slow Length', defval=26) 24 | sma_source = input.string(title='Oscillator MA Type', defval='EMA', options=['SMA', 'EMA']) 25 | 26 | 27 | fast_ma = sma_source == 'SMA' ? ta.sma(src, fast_length) : ta.ema(src, fast_length) 28 | slow_ma = sma_source == 'SMA' ? ta.sma(src, slow_length) : ta.ema(src, slow_length) 29 | macd = fast_ma - slow_ma 30 | osc = macd 31 | 32 | plot(macd, title='MACD', color=color.new(#2962FF, 10)) 33 | 34 | //Divergences 35 | lbR = input.int(title='Pivot Lookback Right', defval=5, group='Divergences') 36 | lbL = input.int(title='Pivot Lookback Left', defval=5, group='Divergences') 37 | rangeUpper = input.int(title='Max of Lookback Range', defval=60, group='Divergences') 38 | rangeLower = input.int(title='Min of Lookback Range', defval=5, group='Divergences') 39 | plotBull = input.bool(title='Plot Bullish', defval=true, group='Divergences') 40 | plotBear = input.bool(title='Plot Bearish', defval=true, group='Divergences') 41 | plotHiddenBull = input.bool(title='Plot Hidden Bullish', defval=false, group='Divergences') 42 | plotHiddenBear = input.bool(title='Plot Hidden Bearish', defval=false, group='Divergences') 43 | 44 | bearColor = color.red 45 | bullColor = color.green 46 | hiddenBullColor = color.new(color.yellow, 50) 47 | hiddenBearColor = color.new(color.yellow, 50) 48 | textColor = color.white 49 | noneColor = color.new(color.white, 100) 50 | 51 | plFound = na(ta.pivotlow(osc, lbL, lbR)) ? false : true 52 | phFound = na(ta.pivothigh(osc, lbL, lbR)) ? false : true 53 | 54 | _inRange(cond) => 55 | bars = ta.barssince(cond == true) 56 | rangeLower <= bars and bars <= rangeUpper 57 | 58 | //------------------------------------------------------------------------------ 59 | // Regular Bullish 60 | 61 | // Osc: Higher Low 62 | oscHL = osc[lbR] > ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1]) 63 | 64 | // Price: Lower Low 65 | priceLL = low[lbR] < ta.valuewhen(plFound, low[lbR], 1) 66 | 67 | bullCond = plotBull and priceLL and oscHL and plFound 68 | 69 | plot(plFound ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=2, color=bullCond ? bullColor : noneColor) 70 | // plotshape(bullCond ? osc[lbR] : na,offset=-lbR,title="Regular Bullish Label",text="D",style=shape.labelup,location=location.absolute,color=bullColor,textcolor=textColor,transp=0) 71 | 72 | //------------------------------------------------------------------------------ 73 | // Hidden Bullish 74 | 75 | // Osc: Lower Low 76 | oscLL = osc[lbR] < ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1]) 77 | 78 | // Price: Higher Low 79 | priceHL = low[lbR] > ta.valuewhen(plFound, low[lbR], 1) 80 | 81 | hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound 82 | 83 | plot(plFound ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=2, color=hiddenBullCond ? hiddenBullColor : noneColor) 84 | plotshape(hiddenBullCond ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish Label', text='H', style=shape.labelup, location=location.absolute, color=bullColor, textcolor=textColor) 85 | 86 | //------------------------------------------------------------------------------ 87 | // Regular Bearish 88 | 89 | // Osc: Lower High 90 | oscLH = osc[lbR] < ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1]) 91 | 92 | // Price: Higher High 93 | priceHH = high[lbR] > ta.valuewhen(phFound, high[lbR], 1) 94 | 95 | bearCond = plotBear and priceHH and oscLH and phFound 96 | 97 | plot(phFound ? osc[lbR] : na, offset=-lbR, title='Regular Bearish', linewidth=2, color=bearCond ? bearColor : noneColor) 98 | // plotshape(bearCond ? osc[lbR] : na, offset=-lbR, title="Regular Bearish Label", text="⬇", style=shape.labeldown, location=location.absolute, color=color.new(bearColor,100), textcolor=color.new(bearColor, trendBear ? 0 : 50)) 99 | 100 | //------------------------------------------------------------------------------ 101 | // Hidden Bearish 102 | 103 | // Osc: Higher High 104 | oscHH = osc[lbR] > ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1]) 105 | 106 | // Price: Lower High 107 | priceLH = high[lbR] < ta.valuewhen(phFound, high[lbR], 1) 108 | 109 | hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound 110 | 111 | plot(phFound ? osc[lbR] : na, offset=-lbR, title='Hidden Bearish', linewidth=2, color=hiddenBearCond ? hiddenBearColor : noneColor) 112 | plotshape(hiddenBearCond ? osc[lbR] : na, offset=-lbR, title='Hidden Bearish Label', text='H', style=shape.labeldown, location=location.absolute, color=bearColor, textcolor=textColor) 113 | 114 | alertcondition((bullCond ? macd[lbR] : na) or (bearCond ? macd[lbR] : na), 'Divergence', '{"text": "{{ticker}}: Divergence in {{interval}} minutes"}') 115 | 116 | -------------------------------------------------------------------------------- /indicators/TTM Squeeze.pine: -------------------------------------------------------------------------------- 1 | // 2 | //@author Alorse 3 | //@version=5 4 | indicator(title='TTM Squeeze [Alorse]') 5 | length = input.int(title='Length', defval=20, minval=0) 6 | bband(length, mult) => 7 | ta.sma(close, length) + mult * ta.stdev(close, length) 8 | keltner(length, mult) => 9 | ta.ema(close, length) + mult * ta.ema(ta.tr, length) 10 | 11 | e1 = (ta.highest(high, length) + ta.lowest(low, length)) / 2 + ta.sma(close, length) 12 | osc = ta.linreg(close - e1 / 2, length, 0) 13 | diff = bband(length, 2) - keltner(length, 1) 14 | osc_color = osc[1] < osc[0] ? osc[0] >= 0 ? color.lime : color.maroon : osc[0] >= 0 ? color.green : color.red 15 | mid_color = diff >= 0 ? color.white : color.black 16 | 17 | plot(osc, color=osc_color, style=plot.style_area, linewidth=1) 18 | plot(0, color=mid_color, style=plot.style_circles, linewidth=1) -------------------------------------------------------------------------------- /indicators/Untitled-1.pine: -------------------------------------------------------------------------------- 1 | //@version=5 2 | indicator(title='Range Filter', overlay=true) 3 | 4 | // Source 5 | src = input(defval=close, title='Source') 6 | per = input.int(defval=100, minval=1, title='Sampling Period') 7 | mult = input.float(defval=3.0, minval=0.1, title='Range Multiplier') 8 | 9 | // Smooth Average Range 10 | smoothrng(x, t, m) => 11 | wper = t * 2 - 1 12 | avrng = ta.ema(math.abs(x - x[1]), t) 13 | smoothrng = ta.ema(avrng, wper) * m 14 | smoothrng 15 | smrng = smoothrng(src, per, mult) 16 | 17 | // Range Filter 18 | rngfilt(x, r) => 19 | rngfilt = x 20 | rngfilt := x > nz(rngfilt[1]) ? x - r < nz(rngfilt[1]) ? nz(rngfilt[1]) : x - r : x + r > nz(rngfilt[1]) ? nz(rngfilt[1]) : x + r 21 | rngfilt 22 | filt = rngfilt(src, smrng) 23 | 24 | // Filter Direction 25 | upward = 0.0 26 | upward := filt > filt[1] ? nz(upward[1]) + 1 : filt < filt[1] ? 0 : nz(upward[1]) 27 | downward = 0.0 28 | downward := filt < filt[1] ? nz(downward[1]) + 1 : filt > filt[1] ? 0 : nz(downward[1]) 29 | 30 | // Target Bands 31 | hband = filt + smrng 32 | lband = filt - smrng 33 | 34 | // Colors 35 | filtcolor = upward > 0 ? color.lime : downward > 0 ? color.red : na 36 | filtplot = plot(filt, color=filtcolor, linewidth=3, title='Range Filter') 37 | 38 | // Target 39 | hbandplot = plot(hband, color=color.new(color.aqua, 100), title='High Target') 40 | lbandplot = plot(lband, color=color.new(color.fuchsia, 100), title='Low Target') 41 | 42 | // Fills 43 | fill(hbandplot, filtplot, color=color.new(color.fuchsia, 90), title='High Target Range') 44 | fill(lbandplot, filtplot, color=color.new(color.fuchsia, 90), title='Low Target Range') 45 | -------------------------------------------------------------------------------- /indicators/Williams Vix Fix + Inverse.pine: -------------------------------------------------------------------------------- 1 | //@version=4 2 | study("Williams Vix Fix + Inverse [Alorse]", shorttitle="WVF + Inverse [Alorse]", overlay=false) 3 | 4 | // Bollinger Bands 5 | bbGroup = "Bollindger Bands" 6 | bbl = input(20, title="Length", group=bbGroup) 7 | mult = input(2.0, minval=1, maxval=5, title="Standard Deviation", group=bbGroup) 8 | 9 | // Williams Vix Fix 10 | wvfGroup = "Williams Vix Fix" 11 | pd = input(20, title="LookBack Period StdDev", tooltip="LookBack Period Standard Deviation", group=wvfGroup) 12 | lb = input(50, title="LookBack Period Percentile", group=wvfGroup) 13 | ph = input(85, title="Highest Percentile", group=wvfGroup) * 0.01 14 | pl = input(99, title="Lowest Percentile", group=wvfGroup) * 0.01 15 | 16 | wvf = ((highest(close, pd)-low)/(highest(close, pd)))*100 17 | sDev = mult * stdev(wvf, bbl) 18 | midLine = sma(wvf, bbl) 19 | upperBand = midLine + sDev 20 | rangeHigh = highest(wvf, lb) * ph 21 | 22 | colNormal = wvf >= upperBand or wvf >= rangeHigh ? color.lime : color.new(color.silver, 20) 23 | 24 | plot(wvf, title="Williams Vix Fix", style=plot.style_columns, color=colNormal) 25 | plot(upperBand, title="Normal StdDev line", style=plot.style_line, linewidth=1,color=color.blue) 26 | 27 | plot(0, title="Cero line", color=color.white, style=plot.style_line) 28 | 29 | wvfInv = ((high-lowest(close, pd))/lowest(close, pd))*100 30 | sDevInv = mult * stdev(wvfInv, bbl) 31 | midLineInv = sma(wvfInv, bbl) 32 | upperBandInv = midLineInv + sDevInv 33 | rangeHighInv = lowest(wvfInv, lb) * pl 34 | 35 | colInv = wvfInv <= upperBandInv or wvfInv <= rangeHighInv ? color.new(color.silver, 20) : color.orange 36 | 37 | plot(wvfInv*-1, title="Williams Vix Fix Inverted", style=plot.style_columns, color=colInv) 38 | plot(upperBandInv*-1, title="Inverted StdDev line", style=plot.style_line, linewidth=1,color=color.blue) -------------------------------------------------------------------------------- /multi/Alert BB + RSI.pine: -------------------------------------------------------------------------------- 1 | // 2 | //@author Alorse 3 | //@version=4 4 | strategy("Alert BB + RSI [Alorse]", shorttitle="Alert BB + RSI [Alorse]", overlay=true, pyramiding=20, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=1000, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.01) 5 | 6 | txtVer = "0.0.1" 7 | version = input(title="Version", type=input.string, defval=txtVer, options=[txtVer], tooltip="This is informational only, nothing will change.\n\nEntry conditions:\nThe MACD line crosses over the signal line.\nRSI less than 50.\nPrice below the BB baseline.\n\nExit conditions:\nRSI greater than 70.\nClosing price higher than upper BB.") 8 | src = input(title="Source", type=input.source, defval=close) 9 | 10 | // Bollinger Bands 11 | bbGroup = "Bollindger Bands" 12 | length = input(20, title="Length", group=bbGroup) 13 | mult = input(2.0, title="StdDev", minval=0.001, maxval=5, group=bbGroup) 14 | 15 | // RSI 16 | rsiGroup = "RSI" 17 | lenRSI = input(14, title="Length", minval=1, group=rsiGroup) 18 | // lessThan = input(50, title="Less than", minval=1 , maxval=100, group=rsiGroup) 19 | 20 | 21 | screenerFunc(_ticker) => 22 | [rsi, basis, cl, dev] = security(_ticker, timeframe.period, [rsi(src, lenRSI), sma(src, length), close, mult * stdev(src, length)]) 23 | [upper, lower] = security(_ticker, timeframe.period, [basis + dev, basis - dev]) 24 | 25 | cleanTicker = str.replace_all(_ticker, "BINANCE:", "") 26 | 27 | strategy.entry(cleanTicker, true, when=rsi < 30 and cl < basis, alert_message='612e425361de9e0072e37083|RSIBB_|buy|' + cleanTicker + '|long') 28 | strategy.close(cleanTicker, when=rsi > 70 and cl > upper, alert_message='612e425361de9e0072e37083|RSIBB_|sell|' + cleanTicker + '|flat') 29 | 30 | [rsi, cl] 31 | 32 | // Symbols 33 | // There is a limit of 40 security calls so only 40 symbols at the same time is possible 34 | s01 = input('ADAUSDT', title="Symbol 1", type=input.symbol) 35 | s02 = input('ALPHAUSDT', title="Symbol 2", type=input.symbol) 36 | s03 = input('ALICEUSDT', title="Symbol 3", type=input.symbol) 37 | s04 = input('ANKRUSDT', title="Symbol 4", type=input.symbol) 38 | s05 = input('ARPAUSDT', title="Symbol 5", type=input.symbol) 39 | s06 = input('AVAXUSDT', title="Symbol 6", type=input.symbol) 40 | s07 = input('AXSUSDT', title="Symbol 7", type=input.symbol) 41 | s08 = input('BAKEUSDT', title="Symbol 8", type=input.symbol) 42 | s09 = input('BELUSDT', title="Symbol 9", type=input.symbol) 43 | s10 = input('BLZUSDT', title="Symbol 10", type=input.symbol) 44 | s11 = input('BTCUSDT', title="Symbol 11", type=input.symbol) 45 | s12 = input('CHZUSDT', title="Symbol 12", type=input.symbol) 46 | s13 = input('CTKUSDT', title="Symbol 13", type=input.symbol) 47 | s14 = input('CTSIUSDT', title="Symbol 14", type=input.symbol) 48 | s15 = input('CVCUSDT', title="Symbol 15", type=input.symbol) 49 | s16 = input('EGLDUSDT', title="Symbol 16", type=input.symbol) 50 | s17 = input('ENJUSDT', title="Symbol 17", type=input.symbol) 51 | s18 = input('ETCUSDT', title="Symbol 18", type=input.symbol) 52 | s19 = input('FILUSDT', title="Symbol 19", type=input.symbol) 53 | s20 = input('GRTUSDT', title="Symbol 20", type=input.symbol) 54 | // s21 = input('HOTUSDT ', title="Symbol 21", type=input.symbol) 55 | // s22 = input('ICPUSDT', title="Symbol 22", type=input.symbol) 56 | // s23 = input('KNCUSDT', title="Symbol 23", type=input.symbol) 57 | // s24 = input('LITUSDT', title="Symbol 24", type=input.symbol) 58 | // s25 = input('MANAUSDT', title="Symbol 25", type=input.symbol) 59 | // s26 = input('MATICUSDT', title="Symbol 26", type=input.symbol) 60 | // s27 = input('NEOUSDT', title="Symbol 27", type=input.symbol) 61 | // s28 = input('NKNUSDT', title="Symbol 28", type=input.symbol) 62 | // s29 = input('OGNUSDT', title="Symbol 29", type=input.symbol) 63 | // s30 = input('REEFUSDT', title="Symbol 30", type=input.symbol) 64 | // s31 = input('ROSEUSDT', title="Symbol 31", type=input.symbol) 65 | // s32 = input('SFPUSDT', title="Symbol 32", type=input.symbol) 66 | // s33 = input('SNXUSDT', title="Symbol 33", type=input.symbol) 67 | // s34 = input('SXPUSDT', title="Symbol 34", type=input.symbol) 68 | // s35 = input('TLMUSDT', title="Symbol 35", type=input.symbol) 69 | // s36 = input('TRBUSDT', title="Symbol 36", type=input.symbol) 70 | // s37 = input('UNFIUSDT', title="Symbol 37", type=input.symbol) 71 | // s38 = input('WAVESUSDT', title="Symbol 38", type=input.symbol) 72 | // s39 = input('XRPUSDT', title="Symbol 39", type=input.symbol) 73 | // s40 = input('ZECUSDT', title="Symbol 40", type=input.symbol) 74 | 75 | /////////////////////////////////////// 76 | // Running Functions for all sybmols // 77 | 78 | [v01, c01] = screenerFunc(s01) 79 | [v02, c02] = screenerFunc(s02) 80 | [v03, c03] = screenerFunc(s03) 81 | [v04, c04] = screenerFunc(s04) 82 | [v05, c05] = screenerFunc(s05) 83 | [v06, c06] = screenerFunc(s06) 84 | [v07, c07] = screenerFunc(s07) 85 | [v08, c08] = screenerFunc(s08) 86 | [v09, c09] = screenerFunc(s09) 87 | [v10, c10] = screenerFunc(s10) 88 | [v11, c11] = screenerFunc(s11) 89 | [v12, c12] = screenerFunc(s12) 90 | [v13, c13] = screenerFunc(s13) 91 | [v14, c14] = screenerFunc(s14) 92 | [v15, c15] = screenerFunc(s15) 93 | [v16, c16] = screenerFunc(s16) 94 | [v17, c17] = screenerFunc(s17) 95 | [v18, c18] = screenerFunc(s18) 96 | [v19, c19] = screenerFunc(s19) 97 | [v20, c20] = screenerFunc(s20) 98 | // [v21, c21] = screenerFunc(s21) 99 | // [v22, c22] = screenerFunc(s22) 100 | // [v23, c23] = screenerFunc(s23) 101 | // [v24, c24] = screenerFunc(s24) 102 | // [v25, c25] = screenerFunc(s25) 103 | // [v26, c26] = screenerFunc(s26) 104 | // [v27, c27] = screenerFunc(s27) 105 | // [v28, c28] = screenerFunc(s28) 106 | // [v29, c29] = screenerFunc(s29) 107 | // [v30, c30] = screenerFunc(s30) 108 | // [v31, c31] = screenerFunc(s31) 109 | // [v32, c32] = screenerFunc(s32) 110 | // [v33, c33] = screenerFunc(s33) 111 | // [v34, c34] = screenerFunc(s34) 112 | // [v35, c35] = screenerFunc(s35) 113 | // [v36, c36] = screenerFunc(s36) 114 | // [v37, c37] = screenerFunc(s37) 115 | // [v38, c38] = screenerFunc(s38) 116 | // [v39, c39] = screenerFunc(s39) 117 | // [v40, c40] = screenerFunc(s40) 118 | -------------------------------------------------------------------------------- /multi/Futuros Binance.txt: -------------------------------------------------------------------------------- 1 | 1INCHUSDT 2 | AAVEUSDT 3 | ADAUSDT 4 | AKROUSDT 5 | ALGOUSDT 6 | ALICEUSDT 7 | ALPHAUSDT 8 | ANKRUSDT 9 | ARUSDT 10 | ATAUSDT 11 | ATOMUSDT 12 | AUDIOUSDT 13 | AVAXUSDT 14 | AXSUSDT 15 | BAKEUSDT 16 | BALUSDT 17 | BANDUSDT 18 | BATUSDT 19 | BCHUSDT 20 | BELUSDT 21 | BLZUSDT 22 | BNBUSDT 23 | BTCUSDT 24 | BTSUSDT 25 | BTTUSDT 26 | BZRXUSDT 27 | C98USDT 28 | CELOUSDT 29 | CELRUSDT 30 | CHRUSDT 31 | CHZUSDT 32 | COMPUSDT 33 | COTIUSDT 34 | CRVUSDT 35 | CTKUSDT 36 | CVCUSDT 37 | DASHUSDT 38 | DEFIUSDT 39 | DENTUSDT 40 | DGBUSDT 41 | DODOUSDT 42 | DOGEUSDT 43 | DOTUSDT 44 | DYDXUSDT 45 | EGLDUSDT 46 | ENJUSDT 47 | EOSUSDT 48 | ETCUSDT 49 | ETHUSDT 50 | FILUSDT 51 | FLMUSDT 52 | FTMUSDT 53 | GALAUSDT 54 | GRTUSDT 55 | GTCUSDT 56 | HBARUSDT 57 | HNTUSDT 58 | HOTUSDT 59 | ICPUSDT 60 | ICXUSDT 61 | IOSTUSDT 62 | IOTAUSDT 63 | IOTXUSDT 64 | KAVAUSDT 65 | KEEPUSDT 66 | KLAYUSDT 67 | KNCUSDT 68 | KSMUSDT 69 | LINAUSDT 70 | LINKUSDT 71 | LITUSDT 72 | LRCUSDT 73 | LTCUSDT 74 | LUNAUSDT 75 | MANAUSDT 76 | MASKUSDT 77 | MATICUSDT 78 | MKRUSDT 79 | MTLUSDT 80 | NEARUSDT 81 | NEOUSDT 82 | NKNUSDT 83 | OCEANUSDT 84 | OGNUSDT 85 | OMGUSDT 86 | ONEUSDT 87 | ONTUSDT 88 | QTUMUSDT 89 | RAYUSDT 90 | REEFUSDT 91 | RENUSDT 92 | RLCUSDT 93 | RSRUSDT 94 | RUNEUSDT 95 | RVNUSDT 96 | SANDUSDT 97 | SCUSDT 98 | SFPUSDT 99 | SHIBUSDT 100 | SKLUSDT 101 | SNXUSDT 102 | SOLUSDT 103 | SRMUSDT 104 | STMXUSDT 105 | STORJUSDT 106 | SUSHIUSDT 107 | SXPUSDT 108 | THETAUSDT 109 | TLMUSDT 110 | TOMOUSDT 111 | TRBUSDT 112 | TRXUSDT 113 | UNFIUSDT 114 | UNIUSDT 115 | VETUSDT 116 | WAVESUSDT 117 | XEMUSDT 118 | XLMUSDT 119 | XMRUSDT 120 | XRPUSDT 121 | XTZUSDT 122 | YFIIUSDT 123 | YFIUSDT 124 | ZECUSDT 125 | ZENUSDT 126 | ZILUSDT 127 | ZRXUSDT -------------------------------------------------------------------------------- /multi/Multi RSI Divergence.pine: -------------------------------------------------------------------------------- 1 | //@version=5 2 | //RSI 3 | indicator(title='Multi RSI Divergence&Over [Alorse]', overlay=true) 4 | 5 | _inRange(cond, rangeUpper, rangeLower) => 6 | bars = ta.barssince(cond == true) 7 | rangeLower <= bars and bars <= rangeUpper 8 | 9 | RSI_Over(_ticker, rsi_overbought, rsi_oversold, rsi_time) => 10 | rsi = request.security(_ticker, rsi_time, ta.rsi(close, 14)) 11 | 12 | cond = rsi > rsi_overbought or rsi < rsi_oversold 13 | cleanTicker = str.replace_all(_ticker, 'BINANCE:', '') 14 | if ta.crossunder(rsi, rsi_oversold) 15 | alert('{"text": "🚨 ALERTA 🟢 ' + cleanTicker + ': RSI Sobre vendido en ' + rsi_time + ' minutos"}', alert.freq_once_per_bar_close) 16 | if ta.crossover(rsi, rsi_overbought) 17 | alert('{"text": "🚨 ALERTA 🔴 ' + cleanTicker + ': RSI Sobre comprado en ' + rsi_time + ' minutos"}', alert.freq_once_per_bar_close) 18 | 19 | [cond, rsi] 20 | 21 | screenerFunc(_ticker, lbR, lbL, rangeUpper, rangeLower, overbought, oversold, alert, rsi_time) => 22 | [cl, lo, hi] = request.security(_ticker, timeframe.period, [close, low, high]) 23 | rsi = ta.rsi(cl, 14) 24 | plFound = na(ta.pivotlow(rsi, lbL, lbR)) ? false : true 25 | phFound = na(ta.pivothigh(rsi, lbL, lbR)) ? false : true 26 | // Regular Bullish 27 | rsiHL = rsi[lbR] > ta.valuewhen(plFound, rsi[lbR], 1) and _inRange(plFound[1], rangeUpper, rangeLower) 28 | priceLL = low[lbR] < ta.valuewhen(plFound, low[lbR], 1) 29 | bullCond = priceLL and rsiHL and plFound 30 | // Regular Bearish 31 | rsiLH = rsi[lbR] < ta.valuewhen(phFound, rsi[lbR], 1) and _inRange(phFound[1], rangeUpper, rangeLower) 32 | priceHH = high[lbR] > ta.valuewhen(phFound, high[lbR], 1) 33 | bearCond = priceHH and rsiLH and phFound 34 | cleanTicker = str.replace_all(_ticker, 'BINANCE:', '') 35 | if bullCond 36 | alert('{"text": "🟢 ' + cleanTicker + ': Divergencia alcista en ' + timeframe.period + ' minutos"}', alert.freq_once_per_bar_close) 37 | if bearCond 38 | alert('{"text": "🔴 ' + cleanTicker + ': Divergencia bajista en ' + timeframe.period + ' minutos"}', alert.freq_once_per_bar_close) 39 | if alert 40 | RSI_Over(_ticker, overbought, oversold, rsi_time) 41 | 42 | [rsi, bullCond, bearCond] 43 | 44 | //Divergencias 45 | lbR = input.int(title='Pivot Lookback   Right', defval=2, group='Divergencias', inline='pivot') 46 | lbL = input.int(title='Left', defval=5, group='Divergencias', inline='pivot') 47 | rangeUpper = input.int(title='Lookback Range   Max', defval=60, group='Divergencias', inline='range') 48 | rangeLower = input.int(title='Min', defval=6, group='Divergencias', inline='range') 49 | 50 | overbought = input(70, title='Sobre   Comprado', group='RSI', inline='rsi') 51 | oversold = input(30, title='Vendido', group='RSI', inline='rsi') 52 | rsi_time = input.timeframe(title='Timeframe', defval='15', group='RSI') 53 | alert = input.bool(true, title='Noticar sobre compra/venta', group='RSI', tooltip='Se enviará una alerta al canal cuando el RSI este sobre comprado/vendido según el parametro anterior.') 54 | 55 | // Symbols 56 | // There is a limit of 40 security calls so only 40 symbols at the same time is possible 57 | 58 | e01 = input.bool(title='', defval=true, group='Symbol 1', inline='s01') 59 | s01 = input.symbol('BTCUSDT', title='', group='Symbol 1', inline='s01') 60 | 61 | e02 = input.bool(title='', defval=true, group='Symbol 2', inline='s02') 62 | s02 = input.symbol('ETHUSDT', title='', group='Symbol 2', inline='s02') 63 | 64 | e03 = input.bool(title='', defval=true, group='Symbol 3', inline='s03') 65 | s03 = input.symbol('BNBUSDT', title='', group='Symbol 3', inline='s03') 66 | 67 | e04 = input.bool(title='', defval=true, group='Symbol 4', inline='s04') 68 | s04 = input.symbol('ADAUSDT', title='', group='Symbol 4', inline='s04') 69 | 70 | e05 = input.bool(title='', defval=true, group='Symbol 5', inline='s05') 71 | s05 = input.symbol('XRPUSDT', title='', group='Symbol 5', inline='s05') 72 | 73 | e06 = input.bool(title='', defval=true, group='Symbol 6', inline='s06') 74 | s06 = input.symbol('SOLUSDT', title='', group='Symbol 6', inline='s06') 75 | 76 | e07 = input.bool(title='', defval=true, group='Symbol 7', inline='s07') 77 | s07 = input.symbol('DOTUSDT', title='', group='Symbol 7', inline='s07') 78 | 79 | e08 = input.bool(title='', defval=true, group='Symbol 8', inline='s08') 80 | s08 = input.symbol('DOGEUSDT', title='', group='Symbol 8', inline='s08') 81 | 82 | e09 = input.bool(title='', defval=true, group='Symbol 9', inline='s09') 83 | s09 = input.symbol('UNIUSDT', title='', group='Symbol 9', inline='s09') 84 | 85 | e10 = input.bool(title='', defval=true, group='Symbol 10', inline='s10') 86 | s10 = input.symbol('LUNAUSDT', title='', group='Symbol 10', inline='s10') 87 | 88 | if e01 89 | [rsi01, bullCond01, bearCond01] = screenerFunc(s01, lbR, lbL, rangeUpper, rangeLower, overbought, oversold, alert, rsi_time) 90 | 91 | if e02 92 | [rsi02, bullCond02, bearCond02] = screenerFunc(s02, lbR, lbL, rangeUpper, rangeLower, overbought, oversold, alert, rsi_time) 93 | 94 | if e03 95 | [rsi03, bullCond03, bearCond03] = screenerFunc(s03, lbR, lbL, rangeUpper, rangeLower, overbought, oversold, alert, rsi_time) 96 | 97 | if e04 98 | [rsi04, bullCond04, bearCond04] = screenerFunc(s04, lbR, lbL, rangeUpper, rangeLower, overbought, oversold, alert, rsi_time) 99 | 100 | if e05 101 | [rsi05, bullCond05, bearCond05] = screenerFunc(s05, lbR, lbL, rangeUpper, rangeLower, overbought, oversold, alert, rsi_time) 102 | 103 | if e06 104 | [rsi06, bullCond06, bearCond06] = screenerFunc(s06, lbR, lbL, rangeUpper, rangeLower, overbought, oversold, alert, rsi_time) 105 | 106 | if e07 107 | [rsi07, bullCond07, bearCond07] = screenerFunc(s07, lbR, lbL, rangeUpper, rangeLower, overbought, oversold, alert, rsi_time) 108 | 109 | if e08 110 | [rsi08, bullCond08, bearCond08] = screenerFunc(s08, lbR, lbL, rangeUpper, rangeLower, overbought, oversold, alert, rsi_time) 111 | 112 | if e09 113 | [rsi09, bullCond09, bearCond09] = screenerFunc(s09, lbR, lbL, rangeUpper, rangeLower, overbought, oversold, alert, rsi_time) 114 | 115 | if e10 116 | [rsi10, bullCond10, bearCond10] = screenerFunc(s10, lbR, lbL, rangeUpper, rangeLower, overbought, oversold, alert, rsi_time) -------------------------------------------------------------------------------- /strategies/1P.pine: -------------------------------------------------------------------------------- 1 | //@version=5 2 | strategy('Improvisando [Alorse]', overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=1000, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.1) 3 | 4 | txtVer = '0.0.1' 5 | version = input.string(title='Version', defval=txtVer, options=[txtVer], tooltip='This is informational only, nothing will change.\n\nEntry conditions:\n') 6 | src = input(title='Source', defval=close) 7 | 8 | // Moving Averages 9 | len_a = input.int(125, minval=1, title='EMA A Length', group='Moving Averages') 10 | out_a = ta.ema(close, len_a) 11 | plot(out_a, title='EMA A', color=color.purple) 12 | 13 | len_b = input.int(680, minval=1, title='EMA B Length', group='Moving Averages') 14 | out_b = ta.ema(close, len_b) 15 | plot(out_b, title='EMA B', color=color.orange) 16 | 17 | len_c = input.int(2500, minval=1, title='EMA C Length', group='Moving Averages') 18 | out_c = ta.ema(close, len_c) 19 | plot(out_c, title='EMA C', color=color.green) 20 | 21 | // TTM Squeeze 22 | length = input.int(title='Length', defval=20, minval=0, group="TTM Squeeze") 23 | bband(length, mult) => 24 | ta.sma(close, length) + mult * ta.stdev(close, length) 25 | keltner(length, mult) => 26 | ta.ema(close, length) + mult * ta.ema(ta.tr, length) 27 | 28 | e1 = (ta.highest(high, length) + ta.lowest(low, length)) / 2 + ta.sma(close, length) 29 | osc = ta.linreg(close - e1 / 2, length, 0) 30 | diff = bband(length, 2) - keltner(length, 1) 31 | 32 | 33 | // Strategy 34 | stratGroup = 'Strategy' 35 | showLong = input.bool(true, title='Long entries', group=stratGroup) 36 | showShort = input.bool(false, title='Short entries', group=stratGroup) 37 | 38 | buy = osc < 0 and osc[1] < osc and osc[2] < osc 39 | sell = osc > 0 and osc[1] > osc and osc[2] > osc 40 | 41 | entryLong = close > out_a and close > out_b and close > out_c and buy 42 | entryShort = close < out_a and close < out_b and close < out_c and sell 43 | 44 | tpGroup = 'Take Profit' 45 | useTP = input.bool(false, title='╔══════   Enable   ══════╗', group=tpGroup) 46 | TPPercent = input.float(1.2, step=0.1, title='Percent', group=tpGroup) * 0.01 47 | qtyPercent = input.float(100, step=1, title='Percent to sell', group=tpGroup) 48 | 49 | longTP = strategy.position_avg_price * (1 + TPPercent) 50 | shortTP = strategy.position_avg_price * (1 - TPPercent) 51 | 52 | trailLongLevel = strategy.position_avg_price * (1 + 0.002) 53 | trailShortLevel = strategy.position_avg_price * (1 - 0.002) 54 | 55 | exitLong = close < out_c 56 | exitShort = close > out_c 57 | 58 | ifLongTP = useTP ? close > longTP or exitLong : exitLong 59 | ifShortTP = useTP ? close < shortTP or exitShort : exitShort 60 | 61 | 62 | closeLongBeforeTP = close > longTP and osc[1] > osc 63 | closeShortBeforeTP = close < shortTP and osc[1] < osc 64 | // closeAfterXBars = input.bool(false, title='Close after X # bars', group=stratGroup, tooltip='If trade is in profit') 65 | // xBars = input.int(20, title='# bars', group=stratGroup) 66 | 67 | // bought = strategy.opentrades[0] == 1 and strategy.position_size[0] > strategy.position_size[1] 68 | // entry_price = ta.valuewhen(bought, open, 0) 69 | 70 | // var int nPastBars = 0 71 | // if strategy.position_size > 0 72 | // nPastBars := nPastBars + 1 73 | // nPastBars 74 | // if strategy.position_size == 0 75 | // nPastBars := 0 76 | // nPastBars 77 | // if closeAfterXBars 78 | // ifLongTP := nPastBars >= xBars and close > entry_price ? true : ifLongTP 79 | // ifLongTP 80 | 81 | // Stop Loss 82 | slGroup = 'Stop Loss' 83 | useSL = input.bool(false, title='╔══════   Enable   ══════╗', group=slGroup) 84 | SLPercent = input.float(1.8, title='Percent', group=slGroup) * 0.01 85 | 86 | longStop = strategy.position_avg_price * (1 - SLPercent) 87 | shortStop = strategy.position_avg_price * (1 + SLPercent) 88 | 89 | // strategy.entry('Long', strategy.long, when=entryLong) 90 | // strategy.entry('Short', strategy.short, when=entryLong) 91 | 92 | if showLong 93 | strategy.entry('Long', strategy.long, when=entryLong) 94 | // strategy.close('Long', when=ifLongTP, comment='Close') 95 | strategy.close('Long', when=closeLongBeforeTP, comment='TP') 96 | strategy.exit('SL', 'Long', stop=longStop) 97 | // strategy.exit('SL', 'Long', stop=longStop, qty_percent=100) 98 | if showShort 99 | strategy.entry('Short', strategy.short, when=entryShort) 100 | // strategy.close('Short', when=ifShortTP, comment='Close') 101 | strategy.close('Short', when=closeShortBeforeTP, comment='TP') // Close by Strategy 102 | strategy.exit('SL', 'Short', stop=shortStop) // Sell half position 103 | // strategy.exit('SL', 'Short', stop=shortStop, qty_percent=100) // StopLoss -------------------------------------------------------------------------------- /strategies/2 EMA:SMA + RSI.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © alorse 3 | 4 | //@version=4 5 | strategy("2 EMA/SMA + RSI Strategy [Alorse]", shorttitle="2 SMA + RSI STRTG [Alorse]", overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, default_qty_value=100) 6 | 7 | src = input(title="Source", type=input.source, defval=close) 8 | ma_type1 = input(title="Type", type=input.string, defval="SMA", options=["EMA", "SMA"], group="Moving Average 1 (Fast)") 9 | lenFast = input(10, minval=1, title="Periods", group="Moving Average 1 (Fast)") 10 | ma_type2 = input(title="Type", type=input.string, defval="SMA", options=["EMA", "SMA"], group="Moving Average 2 (Slow)") 11 | lenSlow = input(30, minval=1, title="Periods", group="Moving Average 2 (Slow)") 12 | ma_type3 = input(title="Type", type=input.string, defval="EMA", options=["EMA", "SMA"], group="Moving Average 3 (Tendence)") 13 | lenTend = input(200, minval=1, title="Periods", group="Moving Average 3 (Tendence)") 14 | showCross = input(title="Show MA Cross", defval=true, group="Moving Averages") 15 | 16 | // Calculate moving averages 17 | maFast = ma_type1 == "EMA" ? ema(src, lenFast) : sma(src, lenFast) 18 | maSlow = ma_type2 == "EMA" ? ema(src, lenSlow) : sma(src, lenSlow) 19 | maTend = ma_type3 == "EMA" ? ema(src, lenTend) : sma(src, lenTend) 20 | 21 | // Plot moving averages 22 | plot(maFast, color=color.purple, title="Fast MA") 23 | plot(maSlow, color=color.blue, title="Slow MA") 24 | plot(maTend, color=color.yellow, title="Tendence MA", linewidth=2) 25 | 26 | // Cross detect 27 | cross_up = crossover(maFast , maSlow) 28 | cross_down = crossunder(maFast , maSlow) 29 | plot(showCross and cross_up or showCross and cross_down ? maFast : na, style=plot.style_cross, title="Cross", linewidth=2, color=color.white) 30 | 31 | // RSI 32 | len = input(8, minval=1, title="Length", group="RSI") 33 | up = rma(max(change(src), 0), len) 34 | down = rma(-min(change(src), 0), len) 35 | rsi = rsi(src, len) 36 | 37 | 38 | //Strategy Conditions 39 | showShort = input(false, title="Show Short entries", group="Strategy") 40 | 41 | long = maFast[1] > maSlow[1] and rsi[1] > 25 and rsi[1] < 40 and close[1] > open[1] 42 | short = maFast[1] < maSlow[1] and rsi[1] < 75 and rsi[1] > 60 and close[1] < open[1] 43 | strategy.entry("Long", true, when=long) 44 | strategy.entry("Short", false, when=short) 45 | -------------------------------------------------------------------------------- /strategies/3 EMA:SMA + Cross.pine: -------------------------------------------------------------------------------- 1 | //@version=4 2 | strategy(title="3 EMA/SMA + Cross Strategy [Alorse]", overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, default_qty_value=100) 3 | 4 | // Set stop loss level with input options (optional) 5 | src = input(title="Source", type=input.source, defval=close) 6 | ma_type1 = input(title="Type", type=input.string, defval="EMA", options=["EMA", "SMA"], group="Moving Average 1 (Fast)") 7 | lenFast = input(10, minval=1, title="Periods", group="Moving Average 1 (Fast)") 8 | ma_type2 = input(title="Type", type=input.string, defval="EMA", options=["EMA", "SMA"], group="Moving Average 2 (Slow)") 9 | lenSlow = input(20, minval=1, title="Periods", group="Moving Average 2 (Slow)") 10 | ma_type3 = input(title="Type", type=input.string, defval="EMA", options=["EMA", "SMA"], group="Moving Average 3 (Tendence)") 11 | lenTend = input(100, minval=1, title="Periods", group="Moving Average 3 (Tendence)") 12 | 13 | // Calculate moving averages 14 | maFast = ma_type1 == "EMA" ? ema(src, lenFast) : sma(src, lenFast) 15 | maSlow = ma_type2 == "EMA" ? ema(src, lenSlow) : sma(src, lenSlow) 16 | maTend = ma_type3 == "EMA" ? ema(src, lenTend) : sma(src, lenTend) 17 | avg = round((lenFast+lenSlow)/2.4) 18 | maAvg = ma_type1 == "EMA" ? ema(src, avg) : sma(src, avg) // With Moving Average Type 1 19 | 20 | // Plot moving averages 21 | plot(maFast, color=color.purple, title="Fast MA") 22 | plot(maSlow, color=color.orange, title="Slow MA") 23 | //plot(maTend, color=color.white, title="Tendence MA", linewidth=2) 24 | plot(maAvg, color=color.new(color.silver, 75), title="Average MA") 25 | 26 | // Calculate trading conditions 27 | crossover = crossover(maFast, maSlow) 28 | crossunder = crossunder(maFast, maAvg) 29 | lastCross = cross(maFast, maSlow) 30 | plot(crossover ? maFast : na, style=plot.style_cross, title="Entry cross", linewidth=2, color=color.white) 31 | plot(crossunder ? maAvg : na, style=plot.style_cross, title="Exit cross", linewidth=2, color=color.silver) 32 | 33 | showLong = input(true, title="Show Long entries", group="Strategy") 34 | showShort = input(false, title="Show Short entries", group="Strategy") 35 | crossBack = input(title="Check Cross in the last # candles", type=input.integer, defval=12, minval=4, group="Strategy") 36 | SP = input(title="Short Stop Loss (%)", type=input.float, minval=0.0, step=0.1, defval=3, group="Strategy") * 0.01 37 | 38 | wasCrossLong = false 39 | enterLong = false 40 | wasCrossShort = false 41 | enterShort = false 42 | for i = 1 to crossBack 43 | if crossover(maFast[i], maSlow[i]) 44 | wasCrossLong := true 45 | if crossunder(maFast[i], maSlow[i]) 46 | wasCrossShort := true 47 | for i = 1 to 4 48 | if crossover(maFast[i], maSlow[i]) 49 | wasCrossLong := false 50 | if crossunder(maFast[i], maSlow[i]) 51 | wasCrossShort := false 52 | if barssince(lastCross) <= 4 53 | wasCrossLong := false 54 | wasCrossShort := false 55 | 56 | // LONG 57 | isLong = strategy.position_size > 0 58 | if maFast >= maSlow and close[0] >= maFast and maFast >= low[1] and close[0] >= maTend and close[0] > open[0] 59 | enterLong := true 60 | // Determine stop loss price 61 | longStopPrice = lowest(low, crossBack*2) 62 | //longStopPrice = strategy.position_avg_price * (1 - SP) 63 | // Submit entry orders 64 | strategy.entry("Long", true, when=showLong and wasCrossLong and enterLong, alert_message='{"text": "{{ticker}}: Cruce de EMAs 10/20 en {{interval}} minutos 🟢"}') 65 | strategy.close("Long", when=crossunder, comment = "Close") 66 | // Submit exit orders based on calculated stop loss price 67 | if isLong 68 | strategy.exit(id="Exit SL", stop=longStopPrice) 69 | // Plot stop loss values for confirmation 70 | // plot(showLong and isLong ? longStopPrice[1] : na, color=color.new(color.red, 30), style=plot.style_linebr, title="Long SL") 71 | 72 | // SHORT 73 | isShort = strategy.position_size < 0 74 | if maFast <= maSlow and close[0] <= maFast and maFast <= high[1] and close[0] <= maTend and close[0] < open[0] 75 | enterShort := true 76 | // Determine stop loss price 77 | shortStopPrice = highest(high, crossBack*2) 78 | // shortStopPrice = strategy.position_avg_price * (1 + SP) 79 | // Submit entry orders 80 | strategy.entry("Short", false, when=showShort and wasCrossShort and enterShort, alert_message='{"text": "{{ticker}}: Cruce de EMAs 10/20 en {{interval}} minutos 🔴"}') 81 | strategy.close("Short", when=crossover(maFast, maSlow)) 82 | 83 | // Submit exit orders based on calculated stop loss price 84 | if isShort 85 | strategy.exit(id="Exit", stop=shortStopPrice) 86 | // Plot stop loss values for confirmation 87 | plot(showShort and isShort ? shortStopPrice[1] : na, color=color.new(color.red, 30), style=plot.style_linebr, title="Short SL") 88 | -------------------------------------------------------------------------------- /strategies/BB + Aroon.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © relevantLeader16058 3 | 4 | //@version=5 5 | strategy(title='Bollinger bands + Aroon [Alorse]', shorttitle='BB + Aroon [Alorse]', overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1) 6 | 7 | // BB inputs and calculations 8 | lengthBB = input.int(20, minval=1) 9 | src = input(close, title='Source') 10 | mult = input.float(2.0, minval=0.001, maxval=50, title='StdDev') 11 | basis = ta.sma(src, lengthBB) 12 | dev = mult * ta.stdev(src, lengthBB) 13 | upper = basis + dev 14 | lower = basis - dev 15 | 16 | 17 | lengthAr = input.int(288, minval=1) 18 | AroonUP = 100 * (ta.highestbars(high, lengthAr + 1) + lengthAr) / lengthAr 19 | AroonDown = 100 * (ta.lowestbars(low, lengthAr + 1) + lengthAr) / lengthAr 20 | 21 | 22 | Confirmation = input(90, 'Aroon Confirmation') 23 | Stop = input(70, 'Aroon Stop') 24 | 25 | Bullish = ta.crossunder(close, lower) 26 | Bearish = ta.crossunder(close, upper) 27 | 28 | //Entry 29 | strategy.entry('Long', strategy.long, when=Bullish and AroonUP > Confirmation) 30 | strategy.close('Long', when=Bearish or AroonUP < Stop) 31 | 32 | -------------------------------------------------------------------------------- /strategies/BB Divergence.pine: -------------------------------------------------------------------------------- 1 | // 2 | //@author Alorse 3 | //@version=4 4 | strategy("Bollinger Bands Divergence [Alorse]", shorttitle="BB Divergence [Alorse]", overlay=true, pyramiding=1, currency=currency.USD, default_qty_type=strategy.percent_of_equity, default_qty_value=100) 5 | 6 | // Bollinger Bands 7 | length = input(20, title="Period Bollindger Bands") 8 | mult = input(2.0, minval=0.001, maxval=5) 9 | src = input(title="Source", type=input.source, defval=close) 10 | timeStop = input(20, title="Time-based stop length") 11 | 12 | basis = sma(src, length) 13 | dev = mult * stdev(src, length) 14 | upper = basis + dev 15 | lower = basis - dev 16 | offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500) 17 | 18 | buy = close > upper and upper[0] > upper[1] and lower[0] < lower[1] and close > open 19 | sell = close < lower and lower[0] < lower[1] and upper[0] > upper[1] and close < open 20 | 21 | pb1 = plot(upper, color=buy ? color.green : sell ? color.red : color.blue, title="Upper") 22 | pb2 = plot(lower, color=buy ? color.green : sell ? color.red : color.blue, title="Lower") 23 | plot(buy ? upper : na, color.green, linewith=3) 24 | plot(sell ? lower : na, color.red, linewith=3) 25 | plot(basis, "Basis", color=color.new(color.orange, 75), offset=offset) 26 | fill(pb1, pb2, color=color.new(color.blue, 98), title="Background") 27 | 28 | //Strategy Conditions 29 | candleper = input(title="Candle % below the lower BB", type=input.float, minval=1, maxval=100, defval=30) 30 | tp = input(title="Take profit after (%)", type=input.float, minval=0, maxval=100, defval=5) 31 | //Strategy Condition 32 | candle_size = (high-low) 33 | buyzone = high - (candle_size*((100-candleper)/100)) 34 | sellzone = low - (candle_size*((100-candleper)/100)) 35 | 36 | // LONG 37 | isLong = strategy.position_size > 0 38 | strategy.entry("Long", true, when=buy and buyzone > upper) 39 | if isLong 40 | strategy.close("Long", when=close < basis) 41 | 42 | // SHORT 43 | isShort = strategy.position_size < 0 44 | strategy.entry("Short", false, when=sell and sellzone < lower) 45 | if isShort 46 | strategy.close("Short", when=close > basis) -------------------------------------------------------------------------------- /strategies/BB Winner LITE 1.0.2.pine: -------------------------------------------------------------------------------- 1 | // 2 | //@author Alorse 3 | //@version=4 4 | strategy("Bollinger Bands Winner LITE [Alorse]", shorttitle="BB Winner LITE [Alorse]", overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=1000, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.01) 5 | 6 | verTxt = "1.0.2" 7 | version = input(title="Version", type=input.string, defval=verTxt, options=[verTxt], tooltip="This is informational only, nothing will change.") 8 | 9 | // Bollinger Bands 10 | bbGroup = "Bollindger Bands" 11 | src = input(title="Source", type=input.source, defval=close, group=bbGroup) 12 | length = input(20, title="Length", group=bbGroup) 13 | mult = input(2.0, title="StdDev", minval=0.001, maxval=5, group=bbGroup) 14 | offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500, group=bbGroup) 15 | 16 | basis = sma(src, length) 17 | dev = mult * stdev(src, length) 18 | upper = basis + dev 19 | lower = basis - dev 20 | 21 | pb1 = plot(upper, color=color.new(color.teal, 50), title="Upper") 22 | pb2 = plot(lower, color=color.new(color.teal, 50), title="Lower") 23 | fill(pb1, pb2, color=color.new(color.teal, 98), title="Background") 24 | plot(basis, "Basis", color=color.new(color.orange, 50), offset = offset) 25 | 26 | //Strategy Conditions 27 | showShort = input(false, title="Show Short entries", group="Strategy") 28 | candleper = input(title="Candle % below/above the BB", type=input.float, minval=1, maxval=100, defval=30, group="Strategy")* 0.01 29 | candle_size = high-low 30 | buyzone = (candle_size*candleper) + low 31 | sellzone = high - (candle_size*candleper) 32 | 33 | buy = buyzone < lower //and close < open 34 | 35 | strategy.entry("Long", true, when=buy) 36 | if showShort 37 | strategy.entry("Short", false, when=buyzone > upper) 38 | else 39 | strategy.close("Long", when=buyzone > upper, comment="Close or Stop limit") -------------------------------------------------------------------------------- /strategies/BB Winner LITE.pine: -------------------------------------------------------------------------------- 1 | // 2 | //@author Alorse 3 | //@version=4 4 | strategy("Bollinger Bands Winner LITE [Alorse]", shorttitle="BB Winner LITE [Alorse]", overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=1000, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.01) 5 | 6 | verTxt = "1.0.4" 7 | version = input(title="Version", type=input.string, defval=verTxt, options=[verTxt], tooltip="This is informational only, nothing will change.") 8 | 9 | // Bollinger Bands 10 | bbGroup = "Bollindger Bands" 11 | isBB = input(true, title="╔═════ Show Bollinger Bands ═════╗", group=bbGroup, tooltip="If you don't want to see Bollinger Bands") 12 | src = input(title="Source", type=input.source, defval=close, group=bbGroup) 13 | length = input(20, title="Length", group=bbGroup) 14 | mult = input(2.0, title="StdDev", minval=0.001, maxval=5, group=bbGroup) 15 | offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500, group=bbGroup) 16 | 17 | basis = sma(src, length) 18 | dev = mult * stdev(src, length) 19 | upper = basis + dev 20 | lower = basis - dev 21 | 22 | plot(isBB ? basis : na, "Basis", color=color.new(color.orange, 75), offset = offset) 23 | pb1 = plot(isBB ? upper : na, color=color.new(color.lime, 75), title="Upper") 24 | pb2 = plot(isBB ? lower : na, color=color.new(color.lime, 75), title="Lower") 25 | fill(pb1, pb2, color=color.new(color.lime, 99), title="Background") 26 | 27 | //Strategy Conditions 28 | showShort = input(false, title="Show Short entries", group="Strategy") 29 | candleper = input(title="Candle % below/above the BB", type=input.float, minval=1, maxval=100, defval=30, group="Strategy")* 0.01 30 | candle_size = high-low 31 | buyzone = (candle_size*candleper) + low 32 | sellzone = high - (candle_size*candleper) 33 | 34 | body_size = close > open ? close - open : open - close 35 | bs60 = body_size*0.6 36 | bsBuy = low + bs60 37 | bsSell = high - bs60 38 | 39 | buy = buyzone < lower and not (bsBuy < lower) 40 | 41 | strategy.entry("Long", true, when=buy) 42 | if showShort 43 | strategy.entry("Short", false, when=sellzone > upper) 44 | else 45 | strategy.close("Long", when=sellzone > upper) -------------------------------------------------------------------------------- /strategies/Bollinger Breakout [kodify].pine: -------------------------------------------------------------------------------- 1 | // 2 | //@author KODIFY.NET https://kodify.net/tradingview/strategies/bollinger-breakout/ 3 | //@version=4 4 | // 1. Define strategy settings 5 | strategy(title="Bollinger Breakout [kodify]", overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=1000, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.01) 6 | 7 | bbGroup = "Bollindger Bands" 8 | smaLength = input(title="SMA Length", type=input.integer, defval=350, group=bbGroup) 9 | stdLength = input(title="StdDev Length", type=input.integer, defval=350, group=bbGroup) 10 | ubOffset = input(title="Upper Band Offset", type=input.float, defval=2.5, step=0.5, group=bbGroup) 11 | lbOffset = input(title="Lower Band Offset", type=input.float, defval=2.5, step=0.5, group=bbGroup) 12 | 13 | stratGroup = "Strategy" 14 | showLong = input(true, title="Long entries", group=stratGroup) 15 | showShort = input(false, title="Short entries", group=stratGroup) 16 | 17 | // 2. Calculate strategy values 18 | smaValue = sma(close, smaLength) 19 | stdDev = stdev(close, stdLength) 20 | 21 | upperBand = smaValue + (stdDev * ubOffset) 22 | lowerBand = smaValue - (stdDev * lbOffset) 23 | 24 | // 3. Output strategy data 25 | plot(series=smaValue, title="SMA", color=color.blue) 26 | plot(series=upperBand, title="UB", color=color.new(color.teal, 50)) 27 | plot(series=lowerBand, title="LB", color=color.new(color.teal, 50)) 28 | 29 | // 4. Determine long trading conditions 30 | enterLong = crossover(close, upperBand) 31 | exitLong = crossunder(close, smaValue) 32 | 33 | // 5. Code short trading conditions 34 | enterShort = crossunder(close, lowerBand) 35 | exitShort = crossover(close, smaValue) 36 | 37 | // 6. Submit entry orders 38 | if showLong 39 | strategy.entry(id="EL", long=true, when=enterLong) 40 | strategy.close(id="EL", when=exitLong) 41 | 42 | if showShort 43 | strategy.entry(id="ES", long=false, when=enterShort) 44 | strategy.close(id="ES", when=exitShort) 45 | 46 | // 7. Submit exit orders -------------------------------------------------------------------------------- /strategies/DMI Winner.pine: -------------------------------------------------------------------------------- 1 | //@version=5 2 | strategy('Directional Movement Index Winner [Alorse]', shorttitle='DMI Winner [Alorse]', overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=1000, default_qty_value=20, commission_type=strategy.commission.percent, commission_value=0.01) 3 | 4 | txtVer = '0.0.9' 5 | version = input.string(title='Version', defval=txtVer, options=[txtVer], tooltip='This is informational only, nothing will change.\n\nEntry conditions:\n') 6 | src = input(title='Source', defval=close) 7 | 8 | // DMI 9 | dmiGroup = 'Directional Movement Index' 10 | len = input.int(14, minval=1, title='DI Length', group=dmiGroup) 11 | lensig = input.int(13, title='ADX Smoothing', minval=1, maxval=50, group=dmiGroup) 12 | keyLevel = input.int(23, title='key level', group=dmiGroup) 13 | [diplus, diminus, adx] = ta.dmi(len, lensig) 14 | 15 | // Moving Average 16 | maGroup = 'Moving Average' 17 | hasMa = input.bool(true, title='╔══════   Use MA   ══════╗', group=maGroup) 18 | maType = input.string(title='Type', defval='EMA', options=['EMA', 'SMA'], group=maGroup, inline='ma') 19 | maLen = input.int(55, minval=1, title='Length', group=maGroup, inline='ma') 20 | ma = maType == 'EMA' ? ta.ema(src, maLen) : ta.sma(src, maLen) 21 | plot(hasMa ? ma : na, title='Moving Average', linewidth=1, color=color.new(color.blue, 10)) 22 | buyMaFilter = hasMa ? close > ma : true 23 | sellMaFilter = hasMa ? close < ma : true 24 | 25 | // Strategy 26 | stratGroup = 'Strategy' 27 | showLong = input.bool(true, title='Long entries', group=stratGroup) 28 | showShort = input.bool(false, title='Short entries', group=stratGroup) 29 | 30 | longCond = diplus > diminus and diplus[1] > diminus[1] and diplus[2] > diminus[2] 31 | shortCond = diplus < diminus and diplus[1] < diminus[1] and diplus[2] < diminus[2] 32 | longEntry = longCond and adx > keyLevel and buyMaFilter and close > open 33 | shortEntry = shortCond and adx > keyLevel and sellMaFilter and close < open 34 | 35 | // Backtesting 36 | btGroup = "Backtesting" 37 | startTime = input.time(title="Start time", defval=timestamp("Feb 01 2021 23:59:59"), group=btGroup) 38 | endTime = input.time(title="End time", defval=timestamp("Feb 01 2099 23:59:59"), group=btGroup) 39 | 40 | inDateRange = time >= startTime and time <= endTime 41 | 42 | if showLong and not showShort and inDateRange 43 | strategy.entry('Long', strategy.long, when=longEntry) 44 | strategy.close('Long', when=shortEntry) 45 | if not showLong and showShort and inDateRange 46 | strategy.entry('Short', strategy.short, when=shortEntry) 47 | strategy.close('Short', when=longEntry) 48 | if showLong and showShort and inDateRange 49 | strategy.entry('Long', strategy.long, when=longEntry) 50 | strategy.entry('Short', strategy.short, when=shortEntry) 51 | 52 | // Stop Loss 53 | slGroup = 'Stop Loss' 54 | useSL = input.bool(false, title='╔══════   Enable   ══════╗', group=slGroup) 55 | SLPercent = input.float(10, title='Percent', group=slGroup) * 0.01 56 | 57 | longStop = strategy.position_avg_price * (1 - SLPercent) 58 | shortStop = strategy.position_avg_price * (1 + SLPercent) 59 | 60 | if useSL 61 | strategy.exit('Stop Loss', 'Long', stop=longStop) -------------------------------------------------------------------------------- /strategies/Double RSI.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © alorse 3 | 4 | //@version=5 5 | strategy(title='Double RSI [Alorse]', overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=1000, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.01) 6 | 7 | rsiGroup = 'RSI' 8 | len = input.int(14, minval=1, title='Length', group=rsiGroup) 9 | src = input.source(close, 'Source', group=rsiGroup) 10 | rsi = ta.rsi(src, len) 11 | 12 | multiGroup = 'Multi Timeframe RSI' 13 | resA = input.timeframe(title='Timeframe', defval='15', group=multiGroup) 14 | mRsi = request.security(syminfo.tickerid, resA, ta.rsi(src, len)) 15 | 16 | tpGroup = 'Take Profit' 17 | useTP = input.bool(false, title='╔══════   Enable   ══════╗', group=tpGroup) 18 | TPPercent = input.float(1.2, step=0.1, title='Percent', group=tpGroup) * 0.01 19 | 20 | longTP = strategy.position_avg_price * (1 + TPPercent) 21 | shortTP = strategy.position_avg_price * (1 - TPPercent) 22 | 23 | // Strategy 24 | buy = ta.crossover(rsi, 30) and mRsi < 35 25 | sell = ta.crossunder(rsi, 70) and mRsi > 65 26 | strategy.entry('Long', strategy.long, when=buy) 27 | strategy.exit('Exit', 'Long', stop=na, limit=longTP) 28 | 29 | strategy.entry('Short', strategy.short, when=sell) 30 | strategy.exit('Exit', 'Short', stop=na, limit=shortTP) 31 | 32 | -------------------------------------------------------------------------------- /strategies/Double Supertrend.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © alorse 3 | 4 | //@version=5 5 | strategy(title='Double Supertrend [Alorse]', overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=10000, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.06) 6 | 7 | // Backtesting 8 | btGroup = "Backtesting" 9 | startTime = input.time(title="Start time", defval=timestamp("Dec 01 2021 23:59:59"), group=btGroup) 10 | endTime = input.time(title="End time", defval=timestamp("Feb 01 2022 23:59:59"), group=btGroup) 11 | 12 | inDateRange = time >= startTime and time <= endTime 13 | 14 | st_1 = "Supertrend" 15 | atrPeriod = input(10, "ST1   ATR", group=st_1, inline=st_1) 16 | factor = input.float(3.0, "Factor", step = 0.1, group=st_1, inline=st_1) 17 | 18 | [supertrend, direction] = ta.supertrend(factor, atrPeriod) 19 | 20 | inLong = direction < 0 21 | inShort = direction > 0 22 | 23 | upTrend = plot(inLong? supertrend : na, "Up Trend", color=color.new(color.green, 35), style=plot.style_linebr) 24 | downTrend = plot(inShort ? supertrend : na, "Down Trend", color=color.new(color.red, 35), style=plot.style_linebr) 25 | 26 | bodyMiddle = plot((open + close) / 2, display=display.none) 27 | fill(bodyMiddle, upTrend, color.new(color.green, 92), fillgaps=false) 28 | fill(bodyMiddle, downTrend, color.new(color.red, 92), fillgaps=false) 29 | 30 | st_2 = "Supertrend 2" 31 | atrPeriod2 = input(10, "ST2   ATR", group=st_1, inline=st_2) 32 | factor2 = input.float(5.0, "Factor", step = 0.1, group=st_1, inline=st_2) 33 | 34 | [supertrend2, direction2] = ta.supertrend(factor2, atrPeriod2) 35 | 36 | inLong2 = direction2 < 0 37 | inShort2 = direction2 > 0 38 | 39 | upTrend2 = plot(inLong2? supertrend2 : na, "Up Trend", color=color.new(color.green, 50), style=plot.style_linebr) 40 | downTrend2 = plot(inShort2 ? supertrend2 : na, "Down Trend", color=color.new(color.red, 50), style=plot.style_linebr) 41 | 42 | bodyMiddle2 = plot((open + close) / 2, display=display.none) 43 | fill(bodyMiddle2, upTrend2, color.new(color.green, 95), fillgaps=false) 44 | fill(bodyMiddle2, downTrend2, color.new(color.red, 95), fillgaps=false) 45 | 46 | // Strategy Conditions 47 | stratGroup = 'Strategy' 48 | ifShortLong = input.string(title='Direction', defval='Long', options=['Long', 'Short'], group=stratGroup) 49 | entryLong = inLong 50 | exitLong = ta.change(direction2) > 0 51 | entryShort = inShort 52 | exitShort = ta.change(direction2) < 0 53 | 54 | tpGroup = 'Take Profit' 55 | useTP = input.string(title='Type', defval='Supertrend', options=['Supertrend', '%'], group=tpGroup, inline=tpGroup, tooltip='Supertrend: Cerrará la operacion cuando el ST en 5 cambie de dirección. \nPercent (%): Cerrará la operacion cuando alcance este porcentaje de ganancia.') 56 | TPPercent = input.float(1.5, step=0.1, title='%', group=tpGroup, inline=tpGroup) 57 | 58 | longTP = 99999999999.9 59 | shortTP = 0.0 60 | 61 | if useTP == '%' 62 | longTP := strategy.position_avg_price * (1 + (TPPercent * 0.01)) 63 | shortTP := strategy.position_avg_price * (1 - (TPPercent * 0.01)) 64 | else 65 | longTP := na 66 | shortTP := na 67 | 68 | // Stop Loss 69 | slGroup = 'Stop Loss' 70 | SLPercent = input.float(10, title='Percent', group=slGroup) * 0.01 71 | 72 | longStop = strategy.position_avg_price * (1 - SLPercent) 73 | shortStop = strategy.position_avg_price * (1 + SLPercent) 74 | 75 | if ifShortLong == 'Long' and inDateRange 76 | strategy.entry("Long", strategy.long, when=entryLong) 77 | strategy.close("Long", when=exitLong) 78 | strategy.exit("Exit", "Long", limit=longTP, stop=longStop) 79 | 80 | if ifShortLong == 'Short' and inDateRange 81 | strategy.entry("Short", strategy.short, when=entryShort) 82 | strategy.close("Short", when=exitShort or inLong) 83 | strategy.exit("Exit", "Short", limit=shortTP, stop=shortStop) 84 | -------------------------------------------------------------------------------- /strategies/EMA Moving away Strategy [Alorse].pine: -------------------------------------------------------------------------------- 1 | //@version=5 2 | strategy("EMA Moving away Strategy [Alorse]", overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=1000, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.01) 3 | 4 | // Setup EMA && stop loss 5 | src = input.source(title="Source", defval=close, group="Moving Average") 6 | length = input.int(55, minval=1, title="Periods", group="Moving Average") 7 | moving_away = input.float(2, "Moving away (%)", group="Strategy", tooltip="The required percentage that the price moves away from the EMA to open a position.") 8 | stop_loss_pct = input.float(2, "Stop Loss (%)", group="Stop Loss") 9 | 10 | // Get EMA 11 | ema = ta.ema(src, length) 12 | 13 | lc_pct = math.abs((close - open) / open * 100) 14 | last4CandlesGreen = ta.highest(close > open, 4) == 4 15 | 16 | // Entry and exit conditions for Long position 17 | long_entry_condition = close <= ema * (1 - moving_away/100) and lc_pct < stop_loss_pct 18 | 19 | // Entry and exit conditions for Short position 20 | short_entry_condition = close >= ema * (1 + moving_away/100) and lc_pct < stop_loss_pct and not last4CandlesGreen 21 | 22 | // Entry for Long position 23 | if long_entry_condition 24 | strategy.entry("Long", strategy.long) 25 | 26 | // Exit for Long position 27 | if close >= ema 28 | strategy.close("Long") 29 | 30 | // Entry for Short position 31 | if short_entry_condition 32 | strategy.entry("Short", strategy.short) 33 | 34 | // Exit for Short position 35 | if close <= ema 36 | strategy.close("Short") 37 | 38 | // Set Stop Loss 39 | if strategy.position_size > 0 40 | strategy.exit("Long SL", "Long", stop = strategy.position_avg_price * (1 - stop_loss_pct/100)) 41 | if strategy.position_size < 0 42 | strategy.exit("Short SL", "Short", stop = strategy.position_avg_price * (1 + stop_loss_pct/100)) 43 | 44 | // Visualize EMA 45 | plot(ema, title='EMA Color', color=color.orange) -------------------------------------------------------------------------------- /strategies/Exceeded candle.pine: -------------------------------------------------------------------------------- 1 | // 2 | //@author Alorse 3 | //@version=4 4 | // study("Surpasses candle [Alorse]", overlay=true) 5 | strategy("Exceeded candle [Alorse]", overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=1000, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.01) 6 | 7 | txtVer = "0.0.1" 8 | version = input(title="Version", type=input.string, defval=txtVer, options=[txtVer], tooltip="This is informational only, nothing will change.") 9 | 10 | // Green candle surpasses the red one 11 | greenLastCandle = close[1] < open[1] and close > open and close > open[1] 12 | // Red candle surpasses the green one 13 | redLastCandle = close[1] > open[1] and close < open and close < open[1] 14 | 15 | plotshape(greenLastCandle ? greenLastCandle: na, location=location.belowbar, color=color.green, style=shape.arrowup) 16 | plotshape(redLastCandle ? redLastCandle: na, location=location.abovebar, color=color.fuchsia, style=shape.arrowdown) 17 | 18 | // Bollinger Bands 19 | bbGroup = "Bollindger Bands" 20 | src = input(title="Source", type=input.source, defval=close, group=bbGroup) 21 | length = input(20, title="Length", group=bbGroup) 22 | mult = input(2.0, title="StdDev", minval=0.001, maxval=5, group=bbGroup) 23 | 24 | basis = sma(src, length) 25 | dev = mult * stdev(src, length) 26 | upper = basis + dev 27 | lower = basis - dev 28 | 29 | pb1 = plot(upper, color=color.new(color.teal, 50), title="Upper") 30 | pb2 = plot(lower, color=color.new(color.teal, 50), title="Lower") 31 | fill(pb1, pb2, color=color.new(color.teal, 98), title="Background") 32 | plot(basis, "Basis", color=color.new(color.orange, 50)) 33 | 34 | last3red = close[2] < open[2] and close[3] < open[3] 35 | buyEntry = greenLastCandle and close < basis and not last3red 36 | buyExit = close > upper 37 | 38 | strategy.entry("Long", true, when=buyEntry) 39 | strategy.close("Long", when=buyExit, comment="Exit") 40 | 41 | // strategy.entry("Short", false, when=redLastCandle and close > basis) 42 | // strategy.close("Short", when=close < lower, comment="Exit") -------------------------------------------------------------------------------- /strategies/Flawless Victory.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © Bunghole 3 | 4 | //@version=4 5 | strategy(overlay=true, shorttitle="FVS [Alorse]", default_qty_type = strategy.percent_of_equity, initial_capital = 100000, default_qty_value = 100, pyramiding = 0, title="Flawless Victory Strategy [Alorse]", currency = 'USD') 6 | 7 | ////////// ** Inputs ** ////////// 8 | 9 | // Stoploss and Profits Inputs 10 | 11 | v1 = input(true, title="Version 1 - Doesn't Use SL/TP") 12 | v2 = input(false, title="Version 2 - Uses SL/TP") 13 | v3 = input(false, title="Version 3 - Uses SL/TP") 14 | v2stoploss_input = input(6.604, title='Stop Loss %', type=input.float, minval=0.01)/100 15 | v2takeprofit_input = input(2.328, title='Take Profit %', type=input.float, minval=0.01)/100 16 | v2stoploss_level = strategy.position_avg_price * (1 - v2stoploss_input) 17 | v2takeprofit_level = strategy.position_avg_price * (1 + v2takeprofit_input) 18 | 19 | v3stoploss_input = input(8.882, title='Stop Loss %', type=input.float, minval=0.01)/100 20 | v3takeprofit_input = input(2.317, title='Take Profit %', type=input.float, minval=0.01)/100 21 | v3stoploss_level = strategy.position_avg_price * (1 - v3stoploss_input) 22 | v3takeprofit_level = strategy.position_avg_price * (1 + v3takeprofit_input) 23 | 24 | plot(v2 and v2stoploss_input and v2stoploss_level ? v2stoploss_level: na, color=color.red, style=plot.style_linebr, linewidth=2, title="v2 Stoploss") 25 | plot(v2 and v2takeprofit_input ? v2takeprofit_level: na, color=color.green, style=plot.style_linebr, linewidth=2, title="v2 Profit") 26 | 27 | plot(v3 and v3stoploss_input and v3stoploss_level ? v3stoploss_level: na, color=color.red, style=plot.style_linebr, linewidth=2, title="v3 Stoploss") 28 | plot(v3 and v3takeprofit_input ? v3takeprofit_level: na, color=color.green, style=plot.style_linebr, linewidth=2, title="v3 Profit") 29 | 30 | ////////// ** Indicators ** ////////// 31 | 32 | // RSI 33 | 34 | len = 14 35 | src = close 36 | up = rma(max(change(src), 0), len) 37 | down = rma(-min(change(src), 0), len) 38 | rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - 100 / (1 + up / down) 39 | 40 | // MFI 41 | 42 | MFIlength = 14 43 | MFIsrc = hlc3 44 | MFIupper = sum(volume * (change(MFIsrc) <= 0 ? 0 : MFIsrc), MFIlength) 45 | MFIlower = sum(volume * (change(MFIsrc) >= 0 ? 0 : MFIsrc), MFIlength) 46 | _rsi(MFIupper, MFIlower) => 47 | if MFIlower == 0 48 | 100 49 | if MFIupper == 0 50 | 0 51 | 100.0 - (100.0 / (1.0 + MFIupper / MFIlower)) 52 | mfi = _rsi(MFIupper, MFIlower) 53 | 54 | // v1 Bollinger Bands 55 | 56 | length1 = 20 57 | src1 = close 58 | mult1 = 1.0 59 | basis1 = sma(src1, length1) 60 | dev1 = mult1 * stdev(src1, length1) 61 | upper1 = basis1 + dev1 62 | lower1 = basis1 - dev1 63 | 64 | // v2 Bollinger Bands 65 | 66 | length2 = 17 67 | src2 = close 68 | mult2 = 1.0 69 | basis2 = sma(src2, length2) 70 | dev2 = mult2 * stdev(src2, length2) 71 | upper2 = basis2 + dev2 72 | lower2 = basis2 - dev2 73 | 74 | ////////// ** Triggers and Guards ** ////////// 75 | 76 | // v1 Strategy Parameters 77 | 78 | RSILowerLevel1 = 42 79 | RSIUpperLevel1 = 70 80 | BBBuyTrigger1 = src1 < lower1 81 | BBSellTrigger1 = src1 > upper1 82 | rsiBuyGuard1 = rsi < RSILowerLevel1 83 | rsiSellGuard1 = rsi > RSIUpperLevel1 84 | 85 | // v2 Strategy Parameters 86 | 87 | RSILowerLevel2 = 42 88 | RSIUpperLevel2 = 76 89 | BBBuyTrigger2 = src2 < lower2 90 | BBSellTrigger2 = src2 > upper2 91 | rsiBuyGuard2 = rsi < RSILowerLevel2 92 | rsiSellGuard2 = rsi > RSIUpperLevel2 93 | 94 | // v3 Strategy Parameters 95 | 96 | MFILowerLevel3 = 60 97 | RSIUpperLevel3 = 65 98 | MFIUpperLevel3 = 64 99 | BBBuyTrigger3 = src1 < lower1 100 | BBSellTrigger3 = src1 > upper1 101 | mfiBuyGuard3 = mfi < MFILowerLevel3 102 | rsiSellGuard3 = rsi > RSIUpperLevel3 103 | mfiSellGuard3 = mfi > MFIUpperLevel3 104 | 105 | //////////** Strategy Signals ** ////////// 106 | 107 | // v1 Signals 108 | 109 | Buy_1 = BBBuyTrigger1 and rsiBuyGuard1 110 | Sell_1 = BBSellTrigger1 and rsiSellGuard1 111 | 112 | if v1 == true 113 | strategy.entry("Long", strategy.long, when = Buy_1, alert_message = "v1 - Buy Signal!") 114 | strategy.close("Long", when = Sell_1, alert_message = "v1 - Sell Signal!") 115 | 116 | // v2 Signals 117 | 118 | Buy_2 = BBBuyTrigger2 and rsiBuyGuard2 119 | Sell_2 = BBSellTrigger2 and rsiSellGuard2 120 | 121 | if v2 == true 122 | strategy.entry("Long", strategy.long, when = Buy_2, alert_message = "v2 - Buy Signal!") 123 | strategy.close("Long", when = Sell_2, alert_message = "v2 - Sell Signal!") 124 | strategy.exit("Stoploss/TP", "Long", stop = v2stoploss_level, limit = v2takeprofit_level) 125 | 126 | // v3 Signals 127 | 128 | Buy_3 = BBBuyTrigger3 and mfiBuyGuard3 129 | Sell_3 = BBSellTrigger3 and rsiSellGuard3 and mfiSellGuard3 130 | 131 | if v3 == true 132 | strategy.entry("Long", strategy.long, when = Buy_3, alert_message = "v2 - Buy Signal!") 133 | strategy.close("Long", when = Sell_3, alert_message = "v2 - Sell Signal!") 134 | strategy.exit("Stoploss/TP", "Long", stop = v3stoploss_level, limit = v3takeprofit_level) 135 | 136 | -------------------------------------------------------------------------------- /strategies/Full Candle.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © alorse 3 | 4 | //@version=5 5 | strategy('Full Candle [Alorse]', overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=1000, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.1) 6 | 7 | txtVer = '0.0.1' 8 | version = input.string(title='Version', defval=txtVer, options=[txtVer], tooltip='This is informational only, nothing will change.\n\nEntry conditions:\n') 9 | src = input(title='Source', defval=close) 10 | 11 | 12 | // Moving Averages 13 | lenA = input.int(10, minval=1, title='EMA A Length', group='Moving Averages') 14 | outA = ta.ema(close, lenA) 15 | plot(outA, title='EMA A', color=color.purple) 16 | 17 | // Strategy 18 | stratGroup = 'Strategy' 19 | showLong = input.bool(true, title='Long entries', group=stratGroup) 20 | showShort = input.bool(true, title='Short entries', group=stratGroup) 21 | shadowPercent = input.float(5, step=1, title='Shadow Percent', group=stratGroup) 22 | 23 | tpGroup = 'Take Profit' 24 | useTP = input.bool(false, title='╔══════   Enable   ══════╗', group=tpGroup) 25 | TPPercent = input.float(1.2, step=0.1, title='Percent', group=tpGroup) * 0.01 26 | 27 | longTP = useTP ? strategy.position_avg_price * (1 + TPPercent) : na 28 | shortTP = useTP ? strategy.position_avg_price * (1 - TPPercent) : na 29 | 30 | // Stop Loss 31 | slGroup = 'Stop Loss' 32 | useSL = input.bool(false, title='╔══════   Enable   ══════╗', group=slGroup) 33 | SLPercent = input.float(1.8, title='Percent', group=slGroup) * 0.01 34 | 35 | longStop = useSL ? strategy.position_avg_price * (1 - SLPercent) : na 36 | shortStop = useSL ? strategy.position_avg_price * (1 + SLPercent) : na 37 | 38 | bought = strategy.opentrades[0] == 1 and strategy.position_size[0] > strategy.position_size[1] 39 | entry_price = ta.valuewhen(bought, open, 0) 40 | 41 | candleSize = high - low 42 | shadowSize = close > open ? high - close : close - low 43 | sPer = (shadowSize * 100)/candleSize 44 | 45 | 46 | entryLong = close > open and close > outA and sPer <= shadowPercent 47 | entryShort = close < open and close < outA and sPer <= shadowPercent 48 | exitLong = close > (entry_price + entry_price*0.002) and close > open 49 | exitShort = close < (strategy.position_avg_price - strategy.position_avg_price*0.002) and close < open 50 | 51 | if showLong 52 | strategy.entry('Long', strategy.long, when=entryLong) 53 | strategy.close('Long', when=exitLong) 54 | strategy.exit('TP', 'Long', limit=longTP, stop=longStop) 55 | if showShort 56 | strategy.entry('Short', strategy.short, when=entryShort) 57 | strategy.close('Short', when=exitShort) 58 | strategy.exit('TP', 'Short', limit=shortTP, stop=shortStop) -------------------------------------------------------------------------------- /strategies/GridBotDir [Alorse].pine: -------------------------------------------------------------------------------- 1 | //@version=5 2 | //------------------------------------------------------------------------------------------------<> 3 | // This source code is subject to the terms of the Mozilla Public License 2.0 4 | // https://mozilla.org/MPL/2.0/ 5 | // ©mvs1231 || xxattaxx 6 | // Updated 06/05/2021 to fix Transp deprecation 7 | // indicator('Grid Bot Simulator [Alorse]', shorttitle='GridBotDir [Alorse]', overlay=true) 8 | strategy("Grid Bot Simulator [Alorse]", shorttitle='GridBotDir [Alorse]', overlay=true, pyramiding=10, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=100000, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.06) 9 | //----------------------------------------------------------------------------------------<> 10 | UpperLimit = input.float(48000.0, 'Upper Limit') 11 | LowerLimit = input.float(45000.0, 'Lower Limit') 12 | No_Grids = input.int(10, 'Number of Grids(10)') + 1 13 | Dir = input.string('neutral', 'Market Direction', options=['up', 'neutral', 'down']) 14 | ShowGrids = input(true, 'Show Grids') 15 | HighLight = input(true, 'Highlight Trade Zones') 16 | ShowCurrent = input(false, 'Show Only Current Grids') 17 | Extremes = input(true, 'High/Low for signals') 18 | //-------------------------------------------------------------------------------------<> 19 | LastSignal = 0 20 | LastSignal_Index = 0 21 | LastSignal_Time = time 22 | SignalLine = 0.0 23 | CurrentGrid = 0.0 24 | Buy = false 25 | Sell = false 26 | Direction = Dir == 'up' ? 1 : Dir == 'down' ? -1 : 0 27 | //----------------------------------------------------------------------------------------<> 28 | RedGrid = color.new(color.red, 90) 29 | GreenGrid = color.new(color.green, 90) 30 | Crimson = #DC143C 31 | LimeGreen = #32CD32 32 | //-------------------------------------------------------------------------------<> 33 | GridRange = UpperLimit - LowerLimit 34 | GridInterval = GridRange / (No_Grids - 1) 35 | //------------------------------------------------------------------------------------<> 36 | a_grid = array.new_float(No_Grids) 37 | for x = 0 to No_Grids - 1 by 1 38 | array.set(a_grid, x, LowerLimit + GridInterval * x) 39 | //----------------------------------------------------------------------------<> 40 | Get_Array_Values(ArrayName, index) => 41 | value = array.get(ArrayName, index) 42 | value 43 | //-----------------------------------------------------------------------------<> 44 | Get_BuyLine_Index() => 45 | Index = 0 46 | BuyValue = 0.0 47 | for x = 0 to No_Grids - 1 by 1 48 | BuyValue := LowerLimit + GridInterval * x 49 | if Extremes 50 | Index := high[1] > BuyValue and low <= BuyValue ? x : Index 51 | else 52 | Index := close[1] > BuyValue and close <= BuyValue ? x : Index 53 | Get_SellLine_Index() => 54 | Index = 0 55 | SellValue = 0.0 56 | for x = 0 to No_Grids - 1 by 1 57 | SellValue := LowerLimit + GridInterval * x 58 | if Extremes 59 | Index := low[1] < SellValue and high >= SellValue ? x : Index 60 | else 61 | Index := close[1] < SellValue and close >= SellValue ? x : Index 62 | BuyLine_Index = Get_BuyLine_Index() 63 | SellLine_Index = Get_SellLine_Index() 64 | //---------------------------------------------------------------------------------------<> 65 | Buy := BuyLine_Index > 0 ? true : Buy 66 | Sell := SellLine_Index > 0 ? true : Sell 67 | //No repeat trades at current level 68 | if Extremes 69 | Buy := low >= SignalLine[1] - GridInterval ? false : Buy 70 | Sell := high <= SignalLine[1] + GridInterval ? false : Sell 71 | Sell 72 | else 73 | Buy := close >= SignalLine[1] - GridInterval ? false : Buy 74 | Sell := close <= SignalLine[1] + GridInterval ? false : Sell 75 | Sell 76 | //No trades outside of grid limits 77 | Buy := close >= UpperLimit ? false : Buy 78 | Buy := close < LowerLimit ? false : Buy 79 | Sell := close <= LowerLimit ? false : Sell 80 | Sell := close > UpperLimit ? false : Sell 81 | //Direction Filter (skip one signal if against market direction) 82 | Buy := Direction == -1 and low >= SignalLine[1] - GridInterval * 2 ? false : Buy 83 | Sell := Direction == 1 and high <= SignalLine[1] + GridInterval * 2 ? false : Sell 84 | //--------------------------------------------------------------------------------------<> 85 | LastSignal := Buy ? 1 : Sell ? -1 : LastSignal[1] 86 | LastSignal_Index := Buy ? BuyLine_Index : Sell ? SellLine_Index : LastSignal_Index[1] 87 | LastSignal_Time := Buy or Sell ? time : LastSignal_Time[1] 88 | SignalLine := LowerLimit + GridInterval * LastSignal_Index 89 | //------------------------------------------------------------------------------------<> 90 | for i = 1 to No_Grids - 1 by 1 91 | Array_Value = Get_Array_Values(a_grid, i) 92 | ClosestGrid = Array_Value - close 93 | color linecolor = ClosestGrid > 0 ? RedGrid : ClosestGrid < 0 ? GreenGrid : na 94 | linecolor := i == LastSignal_Index ? na : linecolor 95 | if ShowGrids 96 | if ShowCurrent 97 | LineAbove = line.new(x1=LastSignal_Time, y1=SignalLine + GridInterval, x2=time + 1000000, y2=SignalLine + GridInterval, color=color.new(color.red, 50), width=1, extend=extend.left, xloc=xloc.bar_time) 98 | LineBelow = line.new(x1=LastSignal_Time, y1=SignalLine - GridInterval, x2=time + 1000000, y2=SignalLine - GridInterval, color=color.new(color.green, 50), width=1, extend=extend.left, xloc=xloc.bar_time) 99 | LineBelow 100 | else 101 | color colCurrent = LastSignal == 1 ? color.new(color.green, 95) : color.new(color.red, 95) 102 | GridLines = line.new(x1=time, y1=Array_Value, x2=time[1], y2=Array_Value, color=linecolor, width=1, extend=extend.right, xloc=xloc.bar_time) 103 | //draw line before latest signal 104 | CurrentLine = line.new(x1=LastSignal_Time, y1=SignalLine, x2=LastSignal_Time - 100000, y2=SignalLine, color=colCurrent, width=1, extend=extend.right, xloc=xloc.bar_time) 105 | CurrentLine 106 | UL = ShowGrids and not ShowCurrent 107 | c1Up = close >= UpperLimit ? color.green : color.red 108 | c1Lo = close <= LowerLimit ? color.red : color.green 109 | plot(UL ? UpperLimit : na, color=color.new(c1Up, 50), linewidth=2) 110 | plot(UL ? LowerLimit : na, color=color.new(c1Lo, 50), linewidth=2) 111 | //Lines One Above & One Below 112 | LineAbove = SignalLine == UpperLimit ? SignalLine : SignalLine + GridInterval 113 | LineBelow = SignalLine == LowerLimit ? SignalLine : SignalLine - GridInterval 114 | a = plot(LineAbove, color=color.new(color.red, 100), style=plot.style_circles) 115 | b = plot(LineBelow, color=color.new(color.green, 100), style=plot.style_circles) 116 | boxColor = LastSignal == -1 ? color.new(color.green, 90) : color.new(color.red, 90) 117 | boxColor := HighLight ? boxColor : na 118 | fill(a, b, color=color.new(boxColor, 80)) 119 | 120 | strategy.entry("Long", strategy.long, when=Buy, comment=str.tostring(SignalLine)) 121 | strategy.entry("Short", strategy.short, when=Sell) 122 | //----------------------------------------------------------------------------------<> 123 | plotchar(Buy, 'Buy', color=color.new(LimeGreen, 0), size=size.tiny, location=location.belowbar, char='▲') 124 | plotchar(Sell, 'Sell', color=color.new(Crimson, 0), size=size.tiny, location=location.abovebar, char='▼') 125 | //----------------------------------------------------------------------------------------<> 126 | 127 | -------------------------------------------------------------------------------- /strategies/HA UnivLong&Short Futures.pine: -------------------------------------------------------------------------------- 1 | //@version=5 2 | strategy('HA UnivLong&Short Futures', overlay=false) 3 | 4 | // Calculation HA Values 5 | [haopen, haclose, hahigh, halow] = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, [open, close, high, low]) 6 | // HA colors 7 | hacolor = haclose > haopen ? #26a69a : #ef5350 8 | 9 | len = input(title='Period', defval=3) 10 | smaHigh = ta.sma(hahigh, len) 11 | smaLow = ta.sma(halow, len) 12 | Hlv = int(na) 13 | Hlv := haclose > smaHigh ? 1 : haclose < smaLow ? -1 : Hlv[1] 14 | sslDown = Hlv < 0 ? smaHigh : smaLow 15 | sslUp = Hlv < 0 ? smaLow : smaHigh 16 | 17 | // Strategy 18 | sl_inp = input(1.0, title='Stop Loss %')/100 19 | tp_inp = input(0.3, title='Take Profit %')/100 20 | 21 | stop_level = strategy.position_avg_price * (1 - sl_inp) 22 | take_level = strategy.position_avg_price * (1 + tp_inp) 23 | 24 | stop_level_short = strategy.position_avg_price * (1 + sl_inp) 25 | take_level_short = strategy.position_avg_price * (1 - tp_inp) 26 | 27 | // Backtesting 28 | btGroup = "Backtesting" 29 | startTime = input.time(title="Start time", defval=timestamp("Dec 01 2021 19:45:00"), group=btGroup) 30 | endTime = input.time(title="End time", defval=timestamp("Feb 01 2099 23:59:59"), group=btGroup) 31 | inDateRange = time >= startTime and time <= endTime 32 | 33 | strategy.entry('long', strategy.long, when=ta.crossover(sslUp, sslDown) and inDateRange) 34 | strategy.entry('short', strategy.short, when=ta.crossover(sslDown, sslUp) and inDateRange) 35 | strategy.exit('CLOSE_L", "long', stop=stop_level, limit=take_level) 36 | strategy.exit('CLOSE_S", "short', stop=stop_level_short, limit=take_level_short) 37 | 38 | plotcandle(haopen, hahigh, halow, haclose, title='HA', color=hacolor, wickcolor=hacolor, bordercolor=hacolor) 39 | plot(sslDown, linewidth=1, color=color.new(color.red, 0)) 40 | plot(sslUp, linewidth=1, color=color.new(color.lime, 0)) -------------------------------------------------------------------------------- /strategies/Heikin Ashi Strategy V2 [FAKE].pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // Heikin Ashi Strategy V2 [Alorse] based on breizh29 script 3 | // © alorse 4 | 5 | //@version=4 6 | strategy("Heikin Ashi Strategy V2 [Alorse]",shorttitle="HAS V2 [Alorse]", overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, default_qty_value=100) 7 | 8 | res = input(title="Timeframe", type=input.resolution, defval="60", group="Heikin Ashi Candle") 9 | hshift = input(1,title="Timeframe Shift", group="Heikin Ashi Candle") 10 | res1 = input(title="EMA Timeframe", type=input.resolution, defval="180", group="Heikin Ashi EMA") 11 | mhshift = input(0,title="EMA Timeframe Shift", group="Heikin Ashi EMA") 12 | fama = input(1,"EMA Period", group="Heikin Ashi EMA") 13 | test = input(1,"EMA Shift", group="Heikin Ashi EMA") 14 | sloma = input(30,"EMA Period", group="Slow EMA") 15 | slomas = input(1,"EMA Shift", group="Slow EMA") 16 | 17 | showShort = input(false, title="Show only Long entries", group="Strategy") 18 | 19 | macdf = input(false,title="With MACD filter", group="MACD") 20 | res2 = input(title="MACD Time Frame", type=input.resolution, defval="15", group="MACD") 21 | macds = input(1,title="MACD Shift", group="MACD") 22 | ha_t = heikinashi(syminfo.tickerid) 23 | ha_close = security(ha_t, res, close[hshift], barmerge.gaps_off, barmerge.lookahead_on) 24 | mha_close = security(ha_t, res1, close[mhshift], barmerge.gaps_off, barmerge.lookahead_on) 25 | 26 | //macd 27 | [macdLine, signalLine, histLine] = macd(close, 12, 26, 9) 28 | macdl = security(ha_t,res2,macdLine[macds], barmerge.gaps_off, barmerge.lookahead_on) 29 | macdsl= security(ha_t,res2,signalLine[macds], barmerge.gaps_off, barmerge.lookahead_on) 30 | 31 | //Moving Average 32 | fma = ema(mha_close[test], fama) 33 | sma = ema(ha_close[slomas], sloma) 34 | 35 | plot(fma,title="MA", color=color.blue, linewidth=1, style=plot.style_line) 36 | plot(sma,title="SMA", color=color.purple, linewidth=1, style=plot.style_line) 37 | 38 | 39 | //BACKTESTING 40 | startDate = input(title="Day", type=input.integer, defval=1, minval=1, maxval=31, group="Backtesting starts") 41 | startMonth = input(title="Month", type=input.integer, defval=7, minval=1, maxval=12, group="Backtesting starts") 42 | startYear = input(title="Year", type=input.integer, defval=2021, minval=1800, maxval=2100, group="Backtesting starts") 43 | 44 | endDate = input(title="Day", type=input.integer, defval=21, minval=1, maxval=31, group="Backtesting ends") 45 | endMonth = input(title="Month", type=input.integer, defval=12, minval=1, maxval=12, group="Backtesting ends") 46 | endYear = input(title="Year", type=input.integer, defval=2022, minval=1800, maxval=2100, group="Backtesting ends") 47 | 48 | inDateRange = (time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0)) and (time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0)) 49 | 50 | //Strategy 51 | golong = crossover(fma,sma) and (macdl > macdsl or macdf == false) 52 | goshort = crossunder(fma,sma) and (macdl < macdsl or macdf == false) 53 | 54 | strategy.entry("Buy", strategy.long, when=golong) 55 | if showShort == false 56 | strategy.entry("Sell", strategy.short, when=goshort) 57 | else 58 | strategy.close("Buy", when=goshort) 59 | -------------------------------------------------------------------------------- /strategies/Improvisando [Alorse].pine: -------------------------------------------------------------------------------- 1 | //@version=5 2 | strategy('Improvisando [Alorse]', overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=1000, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.1) 3 | 4 | txtVer = '0.0.1' 5 | version = input.string(title='Version', defval=txtVer, options=[txtVer], tooltip='This is informational only, nothing will change.\n\nEntry conditions:\n') 6 | src = input(title='Source', defval=close) 7 | 8 | 9 | // Strategy 10 | stratGroup = 'Strategy' 11 | showLong = input.bool(true, title='Long entries', group=stratGroup) 12 | showShort = input.bool(false, title='Short entries', group=stratGroup) 13 | 14 | // Moving Averages 15 | len_a = input.int(10, minval=1, title='EMA A Length', group='Moving Averages') 16 | out_a = ta.ema(close, len_a) 17 | plot(out_a, title='EMA A', color=color.purple) 18 | 19 | // RSI 20 | len = input.int(14, minval=1, title='Length', group='RSI') 21 | rsi = ta.rsi(close, len) 22 | 23 | // MACD 24 | fast_length = 12 25 | slow_length = 26 26 | fast_ma = ta.ema(src, fast_length) 27 | slow_ma = ta.ema(src, slow_length) 28 | macd = fast_ma - slow_ma 29 | 30 | buy = close[1] < open[1] and close > open[1] 31 | sell = close[1] > open[1] and close < open[1] 32 | 33 | entryLong = buy and close > out_a and close[1] > out_a and rsi < 65 and macd[0] > macd[1] 34 | entryShort = sell and close < out_a and close[1] < out_a and rsi > 35 and macd[0] < macd[1] 35 | 36 | tpGroup = 'Take Profit' 37 | // useTP = input.bool(false, title='╔══════   Enable   ══════╗', group=tpGroup) 38 | TPPercent = input.float(1.2, step=0.1, title='Percent', group=tpGroup) * 0.01 39 | 40 | longTP = strategy.position_avg_price * (1 + TPPercent) 41 | shortTP = strategy.position_avg_price * (1 - TPPercent) 42 | 43 | // Stop Loss 44 | slGroup = 'Stop Loss' 45 | // useSL = input.bool(false, title='╔══════   Enable   ══════╗', group=slGroup) 46 | SLPercent = input.float(1.8, title='Percent', group=slGroup) * 0.01 47 | 48 | longStop = strategy.position_avg_price * (1 - SLPercent) 49 | shortStop = strategy.position_avg_price * (1 + SLPercent) 50 | 51 | bought = strategy.opentrades[0] == 1 and strategy.position_size[0] > strategy.position_size[1] 52 | entry_price = ta.valuewhen(bought, open, 0) 53 | 54 | AvgLongTP = (longTP + entry_price) / 2 55 | AvgShortTP = (shortTP - entry_price) / 2 56 | 57 | TlongStop = 0.0 58 | TshortStop = 0.0 59 | TlongStop := close > AvgLongTP ? strategy.position_avg_price * (1.002) : math.max(TlongStop[1], longStop) 60 | TshortStop := close < AvgShortTP ? strategy.position_avg_price * (1 - 0.002) : math.max(TshortStop[1], shortStop) 61 | 62 | exitLong2 = close > close[1] and close[1] > close[2] and close[2] > close[3] and close > strategy.position_avg_price * (1.004) 63 | exitShort2 = close < close[1] and close[1] < close[2] and close[2] < close[3] and close < strategy.position_avg_price * (1 - 0.004) 64 | 65 | if showLong 66 | strategy.entry('Long', strategy.long, when=entryLong) 67 | strategy.close('Long', when=close < TlongStop or exitLong2) 68 | strategy.exit('TP', 'Long', limit=longTP, stop=longStop) 69 | if showShort 70 | strategy.entry('Short', strategy.short, when=entryShort) 71 | strategy.close('Short', when=close > TshortStop or exitShort2) 72 | strategy.exit('TP', 'Short', limit=shortTP, stop=shortStop) -------------------------------------------------------------------------------- /strategies/Javo v1 [Repinta].pine: -------------------------------------------------------------------------------- 1 | //@version=5 2 | strategy('Japo v1 [Alorse]', shorttitle='Japo [Alorse]', overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=10000, default_qty_value=50, commission_type=strategy.commission.percent, commission_value=0.1) 3 | 4 | res = input.timeframe(title="Heikin Ashi Candle Timeframe", defval="60") 5 | hshift = input(1, title="Heikin Ashi Candle Timeframe Shift") 6 | res1 = input.timeframe(title="Heikin Ashi Candle Timeframe", defval="180") 7 | mshift = input(0, title="Heikin Ashi EMA timeframe Shift") 8 | fama = input(1, title="Heikin Ashi EMA Periods") 9 | test = input(1, title="Heikin Ashi EMA Shift") 10 | sloma = input(30, title="Slow EMA Periods") 11 | slomas = input(1, title="Slow EMA Shift") 12 | 13 | // Heikin Ashi Open/Close price 14 | ha_t = ticker.heikinashi(syminfo.tickerid) 15 | 16 | ha_close = request.security(ha_t, res, close[hshift], lookahead=barmerge.lookahead_on) 17 | mha_close = request.security(ha_t, res1, close[mshift], lookahead=barmerge.lookahead_on) 18 | 19 | // EMAs 20 | fma = ta.ema(mha_close[test], fama) 21 | sma = ta.ema(mha_close[slomas], sloma) 22 | plot(fma, title="MA", color=color.lime, linewidth=2, style=plot.style_line) 23 | plot(sma, title="SMA", color=color.red, linewidth=2, style=plot.style_line) 24 | 25 | // Strategy 26 | golong = ta.crossover(fma,sma) 27 | goshort = ta.crossunder(fma,sma) 28 | 29 | // Backtesting 30 | btGroup = "Backtesting" 31 | startTime = input.time(title="Start time", defval=timestamp("Nov 01 2021 23:59:59"), group=btGroup) 32 | endTime = input.time(title="End time", defval=timestamp("Feb 01 2099 23:59:59"), group=btGroup) 33 | 34 | inDateRange = time >= startTime and time <= endTime 35 | 36 | if inDateRange 37 | strategy.entry("Long", strategy.long, when=golong) 38 | strategy.entry("Short", strategy.short, when=goshort) -------------------------------------------------------------------------------- /strategies/MA Cross + DMI.pine: -------------------------------------------------------------------------------- 1 | //@version=4 2 | strategy("MA Cross + DMI [Alorse]", shorttitle="MA Cross + DMI [Alorse]", overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=1000, default_qty_value=20, commission_type=strategy.commission.percent, commission_value=0.01) 3 | 4 | txtVer = "0.0.1" 5 | version = input(title="Version", type=input.string, defval=txtVer, options=[txtVer], tooltip="This is informational only, nothing will change.\n\nEntry conditions:\n") 6 | src = input(title="Source", type=input.source, defval=close) 7 | 8 | // DMI 9 | dmiGroup = "Directional Movement Index" 10 | len = input(14, minval=1, title="DI Length", group=dmiGroup) 11 | lensig = input(13, title="ADX Smoothing", minval=1, maxval=50, group=dmiGroup) 12 | keyLevel = input(23, title="key level", group=dmiGroup) 13 | [diplus,diminus,adx] = dmi(len, lensig) 14 | 15 | // Moving Average 16 | maGroup = "Moving Average" 17 | ma1Type = input(title="Type", type=input.string, defval="EMA", options=["EMA", "SMA"], group=maGroup, inline="ma1") 18 | ma1Len = input(10, minval=1, title="Length", group=maGroup, inline="ma1") 19 | ma1 = ma1Type == "EMA" ? ema(src, ma1Len) : sma(src, ma1Len) 20 | plot(ma1, title="Moving Average 1", linewidth=1, color=color.new(color.blue, 10)) 21 | 22 | ma2Type = input(title="Type", type=input.string, defval="EMA", options=["EMA", "SMA"], group=maGroup, inline="ma2") 23 | ma2Len = input(20, minval=1, title="Length", group=maGroup, inline="ma2") 24 | ma2 = ma2Type == "EMA" ? ema(src, ma2Len) : sma(src, ma2Len) 25 | plot(ma2, title="Moving Average 2", linewidth=1, color=color.new(color.orange, 10)) 26 | 27 | 28 | // Strategy 29 | stratGroup = "Strategy" 30 | showLong = input(true, title="Long entries", group=stratGroup) 31 | showShort = input(false, title="Short entries", group=stratGroup) 32 | 33 | longCond = diplus < diminus and diplus[1] < diminus[1] //and diplus[2] < diminus[2] 34 | shortCond = diplus > diminus and diplus[1] > diminus[1] //and diplus[2] > diminus[2] 35 | longEntry = crossover(ma1, ma2) 36 | shortEntry = crossunder(ma1, ma2) 37 | 38 | if showLong and not showShort 39 | strategy.entry("Long", true, when=longEntry) 40 | strategy.close("Long", when=shortEntry) 41 | if not showLong and showShort 42 | strategy.entry("Short", false, when=shortEntry) 43 | strategy.close("Short", when=longEntry) 44 | if showLong and showShort 45 | strategy.entry("Long", true, when=longEntry) 46 | strategy.entry("Short", false, when=shortEntry) 47 | 48 | // Stop Loss 49 | slGroup = "Stop Loss" 50 | useSL = input(false, title="╔══════   Enable   ══════╗", group=slGroup) 51 | SLPercent = input(10, title="Percent", type=input.float, group=slGroup) * 0.01 52 | 53 | longStop = strategy.position_avg_price * (1 - SLPercent) 54 | shortStop = strategy.position_avg_price * (1 + SLPercent) 55 | 56 | if useSL 57 | strategy.exit("Stop Loss", "Long", stop=longStop) -------------------------------------------------------------------------------- /strategies/MACD + BB + RSI.pine: -------------------------------------------------------------------------------- 1 | // 2 | //@author Alorse 3 | //@version=5 4 | strategy('MACD + BB + RSI [Alorse]', shorttitle='MACD + BB + RSI [Alorse]', overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=1000, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.1) 5 | 6 | txtVer = '1.0.8' 7 | version = input.string(title='Version', defval=txtVer, options=[txtVer], tooltip='This is informational only, nothing will change.\n\nEntry conditions:\nThe MACD line crosses over the signal line.\nRSI less than 50.\nPrice below the BB baseline.\n\nExit conditions:\nRSI greater than 70.\nClosing price higher than upper BB.') 8 | src = input(title='Source', defval=close) 9 | 10 | // MACD 11 | macdGroup = 'MACD' 12 | fast_length = input.int(title='Length   Fast', defval=12, group=macdGroup, inline='macdLength') 13 | slow_length = input.int(title='Slow', defval=26, group=macdGroup, inline='macdLength') 14 | signal_length = input.int(title='Signal Smoothing', minval=1, maxval=50, defval=9, group=macdGroup) 15 | sma_source = input.string(title='Oscillator', defval='EMA', options=['SMA', 'EMA'], group=macdGroup, inline='macdMa', tooltip='Moving Average Type') 16 | sma_signal = input.string(title='Signal Line', defval='EMA', options=['SMA', 'EMA'], group=macdGroup, inline='macdMa', tooltip='Moving Average Type') 17 | fast_ma = sma_source == 'SMA' ? ta.sma(src, fast_length) : ta.ema(src, fast_length) 18 | slow_ma = sma_source == 'SMA' ? ta.sma(src, slow_length) : ta.ema(src, slow_length) 19 | macd = fast_ma - slow_ma 20 | signal = sma_signal == 'SMA' ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length) 21 | 22 | // Bollinger Bands 23 | bbGroup = 'Bollindger Bands' 24 | isBB = input.bool(true, title='╔═════ Show Bollinger Bands ═════╗', group=bbGroup, tooltip='If you don\'t want to see Bollinger Bands') 25 | length = input.int(20, title='Length', group=bbGroup) 26 | mult = input.float(2.0, title='StdDev', minval=0.001, maxval=5, group=bbGroup) 27 | offset = input.int(0, 'Offset', minval=-500, maxval=500, group=bbGroup) 28 | 29 | basis = ta.sma(src, length) 30 | dev = mult * ta.stdev(src, length) 31 | upper = basis + dev 32 | lower = basis - dev 33 | 34 | plot(isBB ? basis : na, 'Basis', color=color.new(color.orange, 75), offset=offset) 35 | pb1 = plot(isBB ? upper : na, color=color.new(color.lime, 75), title='Upper') 36 | pb2 = plot(isBB ? lower : na, color=color.new(color.lime, 75), title='Lower') 37 | fill(pb1, pb2, color=color.new(color.lime, 99), title='Background') 38 | 39 | // RSI 40 | rsiGroup = 'RSI' 41 | lenRSI = input.int(14, title='Length', minval=1, group=rsiGroup) 42 | RSI = ta.rsi(src, lenRSI) 43 | 44 | // DMI 45 | dmiGroup = 'Directional Movement Index' 46 | isDMI = input.bool(false, title='╔═════ DMI Filter ═════╗', group=dmiGroup, tooltip='Most Percent Profitable, less trades') 47 | len = input.int(14, minval=1, title='DI Length', group=dmiGroup) 48 | lensig = input.int(13, title='ADX Smoothing', minval=1, maxval=50, group=dmiGroup) 49 | keyLevel = input.int(23, title='key level', group=dmiGroup) 50 | [diplus, diminus, adx] = ta.dmi(len, lensig) 51 | dmiLongFilter = isDMI ? diplus > diminus or adx < keyLevel : true 52 | dmiShortFilter = isDMI ? diplus < diminus or adx < keyLevel : true 53 | 54 | // Strategy Conditions 55 | stratGroup = 'Strategy' 56 | showLong = input.bool(true, title='Long entries', group=stratGroup) 57 | showShort = input.bool(false, title='Short entries', group=stratGroup) 58 | entryLong = ta.crossover(macd, signal) and RSI < 50 and close < basis and dmiLongFilter //and close > open 59 | exitLong = RSI > 70 and close > upper 60 | entryShort = ta.crossunder(macd, signal) and RSI > 50 and close > basis and dmiShortFilter 61 | exitShort = RSI < 31 and close < lower 62 | // doNotClose = input.int(25, title='Do not close trade yet', group=stratGroup, tooltip='Do not close the trade if ADX is lower than "X" and is rising.') 63 | // exitLong := diplus > diminus and adx < doNotClose and adx[0] > adx[1] and adx[1] > adx[2] ? false : exitLong 64 | closeAfterXBars = input.bool(false, title='Close after X # bars', group=stratGroup, tooltip='If trade is in profit') 65 | xBars = input.int(20, title='# bars', group=stratGroup) 66 | 67 | //If (#bars since close < lower BB)/2 is greater than green bars, so false. 68 | longBars = ta.barssince(close < lower) 69 | greenBars = 0 70 | if entryLong 71 | for i = 1 to longBars by 1 72 | greenBars := close[i] > close[i + 1] ? greenBars + 1 : greenBars 73 | greenBars 74 | entryLong := greenBars >= longBars / 2 - 1 ? true : false 75 | entryLong 76 | // Stop Loss 77 | slGroup = 'Stop Loss' 78 | useSL = input.bool(false, title='╔══════   Enable   ══════╗', group=slGroup, tooltip='If you are using this strategy for Scalping or Futures market, we do not recommend using Stop Loss.') 79 | SLPercent = input.float(10, title='Percent', group=slGroup) * 0.01 80 | 81 | longStop = strategy.position_avg_price * (1 - SLPercent) 82 | shortStop = strategy.position_avg_price * (1 + SLPercent) 83 | 84 | tpGroup = 'Take Profit' 85 | useTP = input.bool(false, title='╔══════   Enable   ══════╗', group=tpGroup) 86 | TPPercent = input.float(1.2, step=0.1, title='Percent', group=tpGroup) * 0.01 87 | 88 | longTP = strategy.position_avg_price * (1 + TPPercent) 89 | shortTP = strategy.position_avg_price * (1 - TPPercent) 90 | 91 | longIsOpen = strategy.position_size > 0 92 | shortIsOpen = strategy.position_size < 0 93 | 94 | bought = strategy.opentrades[0] == 1 and strategy.position_size[0] > strategy.position_size[1] 95 | entry_price = ta.valuewhen(bought, open, 0) 96 | 97 | var int nPastBars = 0 98 | if strategy.position_size > 0 99 | nPastBars := nPastBars + 1 100 | nPastBars 101 | if strategy.position_size == 0 102 | nPastBars := 0 103 | nPastBars 104 | if closeAfterXBars 105 | exitLong := nPastBars >= xBars and close > upper and close > entry_price ? true : exitLong 106 | exitLong 107 | 108 | if showLong 109 | strategy.entry('Long', strategy.long, when=entryLong and not shortIsOpen) 110 | strategy.close('Long', when=exitLong) 111 | strategy.exit('Exit', 'Long', stop=useSL ? longStop : na, limit=useTP ? longTP : na) 112 | if showShort 113 | strategy.entry('Short', strategy.short, when=entryShort and not longIsOpen) 114 | strategy.close('Short', when=exitShort, comment='Exit') 115 | strategy.exit('Exit', 'Short', stop=useSL ? shortStop : na, limit=useTP ? shortTP : na) 116 | 117 | if entryLong 118 | label.new(bar_index, low, 'Buy', color=color.green, style=label.style_label_up, textcolor=color.white, size=size.small) 119 | if exitLong 120 | label.new(bar_index, high, 'Sell', color=color.red, style=label.style_label_down, textcolor=color.white, size=size.small) 121 | 122 | -------------------------------------------------------------------------------- /strategies/MACD + DMI.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | //@version=4 3 | strategy(shorttitle='MACD + DMI [Alorse]',title='MACD + DMI [Alorse]', overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=1000, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.01) 4 | 5 | // Works better on 3h, 1h, 2h, 4h 6 | // DMI and MACD inputs and calculations 7 | 8 | [pos_dm, neg_dm, avg_dm] = dmi(14, 14) 9 | [macd, macd_signal, macd_histogram] = macd(close, 12, 26, 9) 10 | 11 | 12 | length = input(20, "Length", minval = 2) 13 | src = input(close, "Source") 14 | factor = input(2.0, "vStop Multiplier", minval = 0.25, step = 0.25) 15 | volStop(src, atrlen, atrfactor) => 16 | var max = src 17 | var min = src 18 | var uptrend = true 19 | var stop = 0.0 20 | atrM = nz(atr(atrlen) * atrfactor, tr) 21 | max := max(max, src) 22 | min := min(min, src) 23 | stop := nz(uptrend ? max(stop, max - atrM) : min(stop, min + atrM), src) 24 | uptrend := src - stop >= 0.0 25 | if uptrend != nz(uptrend[1], true) 26 | max := src 27 | min := src 28 | stop := uptrend ? max - atrM : min + atrM 29 | [stop, uptrend] 30 | 31 | [vStop, uptrend] = volStop(src, length, factor) 32 | 33 | tales = crossunder(macd, macd_signal) and pos_dm > neg_dm ? false : crossunder(macd, macd_signal) and pos_dm < neg_dm ? true : false 34 | closeLong = tales or crossunder(close, vStop) 35 | 36 | //Entry 37 | strategy.entry("long",true, when=crossover(macd, macd_signal) and pos_dm > neg_dm) 38 | //Exit 39 | strategy.close("long", when=closeLong) 40 | -------------------------------------------------------------------------------- /strategies/MACD Long Strategy [Bunghole].pine: -------------------------------------------------------------------------------- 1 | //@version=5 2 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 3 | // © Bunghole 2021 4 | strategy(title='MACD Long Strategy [Alorse]', overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=1000, default_qty_value=20, commission_type=strategy.commission.percent, commission_value=0.1) 5 | 6 | 7 | //// Stoploss and Take Profit Parameters 8 | // Enable Long Strategy 9 | enable_long_strategy = input.bool(true, title='Enable Long Strategy', group='SL/TP For Long Strategy', inline='1') 10 | long_stoploss_value = input.float(defval=50, title='Stoploss %', minval=0.1, group='SL/TP For Long Strategy', inline='2') 11 | long_stoploss_percentage = close * (long_stoploss_value / 100) / syminfo.mintick 12 | long_takeprofit_value = input.float(defval=50, title='Take Profit %', minval=0.1, group='SL/TP For Long Strategy', inline='2') 13 | long_takeprofit_percentage = close * (long_takeprofit_value / 100) / syminfo.mintick 14 | 15 | // Enable Short Strategy 16 | enable_short_strategy = input.bool(true, title='Enable Short Strategy', group='SL/TP For Short Strategy', inline='3') 17 | short_stoploss_value = input.float(defval=50, title='Stoploss %', minval=0.1, group='SL/TP For Short Strategy', inline='4') 18 | short_stoploss_percentage = close * (short_stoploss_value / 100) / syminfo.mintick 19 | short_takeprofit_value = input.float(defval=50, title='Take Profit %', minval=0.1, group='SL/TP For Short Strategy', inline='4') 20 | short_takeprofit_percentage = close * (short_takeprofit_value / 100) / syminfo.mintick 21 | 22 | 23 | //// Indicator Inputs 24 | // RSI 25 | rsi_over_sold = input.int(defval=30, minval=1, title='Over Sold Level', group='RSI') 26 | rsi_over_bought = input.int(defval=70, minval=1, title='Over Bought Level', group='RSI') 27 | rsi_length = input.int(defval=14, minval=1, title='RSI Length', group='RSI') 28 | rsi = ta.rsi(close, rsi_length) 29 | 30 | // MACD 31 | fast_ma = input.int(defval=12, minval=1, title='FastMA Length', group='MACD') 32 | slow_ma = input.int(defval=26, minval=1, title='SlowMA Length', group='MACD') 33 | signal_length = input.int(defval=9, minval=1, title='Signal Length', group='MACD') 34 | [macd_line, signal_line, hist_line] = ta.macd(close, fast_ma, slow_ma, signal_length) 35 | 36 | 37 | //// Strategy 38 | // Creating Long and Short Strategy 39 | was_over_sold = ta.barssince(rsi <= rsi_over_sold) <= 10 40 | was_over_bought = ta.barssince(rsi >= rsi_over_bought) <= 10 41 | crossover_bull = ta.crossover(macd_line, signal_line) 42 | crossover_bear = ta.crossunder(macd_line, signal_line) 43 | buy_signal = was_over_sold and crossover_bull 44 | sell_signal = was_over_bought and crossover_bear 45 | 46 | // Long Strategy 47 | if buy_signal and enable_long_strategy 48 | strategy.entry('Long', strategy.long, when=buy_signal, alert_message='Open Long Position') 49 | strategy.exit('Long SL/TP', from_entry='Long', loss=long_stoploss_percentage, profit=long_takeprofit_percentage, alert_message='Your Long SL/TP Limit As Been Triggered.') 50 | strategy.close('Long', when=sell_signal, alert_message='Close Long Position') 51 | 52 | // Short Strategy 53 | if sell_signal and enable_short_strategy 54 | strategy.entry('Short', strategy.short, when=sell_signal, alert_message='Open Short Position') 55 | strategy.exit('Short SL/TP', from_entry='Short', loss=short_stoploss_percentage, profit=short_takeprofit_percentage, alert_message='Your Short SL/TP Limit As Been Triggered.') 56 | strategy.close('Short', when=buy_signal, alert_message='Close Short Position') 57 | -------------------------------------------------------------------------------- /strategies/MACD+RSI.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © fredoorse 3 | 4 | //@version=4 5 | strategy(title="MACD + RSI Strategy [Alorse]", overlay=true, shorttitle="MACD+RSI STRTG", pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, default_qty_value=100) 6 | 7 | src = input(title="Source", type=input.source, defval=close) 8 | // MACD 9 | // Getting inputs 10 | fast_length = input(title="Fast Length", type=input.integer, defval=12, group="MACD") 11 | slow_length = input(title="Slow Length", type=input.integer, defval=26, group="MACD") 12 | signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9, group="MACD") 13 | sma_source = input(title="Oscillator MA Type", type=input.string, defval="EMA", options=["SMA", "EMA"], group="MACD") 14 | sma_signal = input(title="Signal Line MA Type", type=input.string, defval="EMA", options=["SMA", "EMA"], group="MACD") 15 | // Calculating 16 | fast_ma = sma_source == "SMA" ? sma(src, fast_length) : ema(src, fast_length) 17 | slow_ma = sma_source == "SMA" ? sma(src, slow_length) : ema(src, slow_length) 18 | macd = fast_ma - slow_ma 19 | signal = sma_signal == "SMA" ? sma(macd, signal_length) : ema(macd, signal_length) 20 | 21 | // RSI 22 | len = input(14, minval=1, title="Length", group="RSI") 23 | rsi = rsi(src, len) 24 | 25 | // Strategy 26 | SL = input(title="Stop Loss %", type=input.integer, defval=99, group="Strategy") * 0.01 27 | TP = input(title="Take Profit %", type=input.integer, defval=10, group="Strategy") 28 | rsiBack = input(title="Check RSI last # candles", type=input.integer, defval=5, group="Strategy") 29 | rsiDown = input(title="RSI over sold level", type=input.integer, defval=30, group="Strategy") 30 | rsiUp = input(title="RSI over bought level", type=input.integer, defval=70, group="Strategy") 31 | 32 | wasRsiDown = false 33 | for i = 1 to rsiBack 34 | if rsi[i] <= rsiDown 35 | wasRsiDown := true 36 | break 37 | 38 | wasRsiUp = false 39 | for i = 1 to rsiBack 40 | if rsi[i] >= rsiUp 41 | wasRsiUp := true 42 | break 43 | 44 | bull_cross = crossover(macd, signal) and wasRsiDown 45 | bear_cross = crossunder(macd, signal) and wasRsiUp 46 | strategy.entry("Long", strategy.long, when=bull_cross) 47 | // strategy.entry("Sell", strategy.short, when=bear_cross) 48 | strategy.close("Long", when=bear_cross) 49 | 50 | StopPrice = strategy.position_avg_price * (1 - SL) 51 | 52 | if (strategy.position_size > 0) 53 | strategy.exit(id="Exit", stop=StopPrice) 54 | -------------------------------------------------------------------------------- /strategies/MEMA + BB + RSI [Alorse].pine: -------------------------------------------------------------------------------- 1 | // 2 | //@author Alorse 3 | //@version=5 4 | strategy('MEMA + BB + RSI [Alorse]', overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=1000, default_qty_value=20, commission_type=strategy.commission.percent, commission_value=0.01) 5 | 6 | txtVer = '1.0.0' 7 | version = input.string(title='Version', defval=txtVer, options=[txtVer], tooltip='This is informational only, nothing will change.\n\nEntry conditions:\nTales') 8 | src = input(title='Source', defval=close) 9 | 10 | // EMA 11 | ma1 = input.int(10, minval=1, title='Periods', group='Moving Average') 12 | res1 = input.timeframe(title='Timeframe', defval='1D', group='Moving Average') 13 | ma2 = input.int(55, minval=1, title='Periods', group='Moving Average') 14 | res2 = input.timeframe(title='Timeframe', defval='1D', group='Moving Average') 15 | // Calculate moving averages 16 | maPlot1 = request.security(syminfo.tickerid, res1, ta.ema(src, ma1)) 17 | maPlot2 = request.security(syminfo.tickerid, res2, ta.ema(src, ma2)) 18 | 19 | // Plot moving averages 20 | plot(maPlot1, color=color.new(color.purple, 0), title='Moving Average', linewidth=1) 21 | plot(maPlot2, color=color.new(color.blue, 0), title='Moving Average', linewidth=2) 22 | 23 | // Bollinger Bands 24 | bbGroup = 'Bollindger Bands' 25 | isBB = input.bool(true, title='╔═════ Show Bollinger Bands ═════╗', group=bbGroup, tooltip='If you don\'t want to see Bollinger Bands') 26 | length = input.int(20, title='Length', group=bbGroup) 27 | mult = input.float(2.0, title='StdDev', minval=0.001, maxval=5, group=bbGroup) 28 | offset = input.int(0, 'Offset', minval=-500, maxval=500, group=bbGroup) 29 | 30 | basis = ta.sma(src, length) 31 | dev = mult * ta.stdev(src, length) 32 | upper = basis + dev 33 | lower = basis - dev 34 | 35 | plot(isBB ? basis : na, 'Basis', color=color.new(color.orange, 75), offset=offset) 36 | pb1 = plot(isBB ? upper : na, color=color.new(color.lime, 75), title='Upper') 37 | pb2 = plot(isBB ? lower : na, color=color.new(color.lime, 75), title='Lower') 38 | fill(pb1, pb2, color=color.new(color.lime, 99), title='Background') 39 | 40 | // RSI 41 | rsiGroup = 'RSI' 42 | lenRSI = input.int(14, title='Length', minval=1, group=rsiGroup) 43 | oversold = input.int(71, title='Oversold', minval=1, group=rsiGroup) 44 | RSI = ta.rsi(src, lenRSI) 45 | 46 | // Strategy Conditions 47 | stratGroup = 'Strategy' 48 | showLong = input.bool(true, title='Long entries', group=stratGroup) 49 | showShort = input.bool(false, title='Short entries', group=stratGroup) 50 | entryLong = close > maPlot1 and low < lower //and high < basis 51 | exitLong = RSI > oversold //or (high[1] > upper and close < basis) 52 | entryShort = close < maPlot1 and high > upper and RSI > 50 53 | exitShort = close < lower 54 | closeAfterXBars = input.bool(false, title='Close after X # bars', group=stratGroup, tooltip='If trade is in profit') 55 | xBars = input.int(12, title='# bars', group=stratGroup) 56 | 57 | slGroup = 'Stop Loss' 58 | useSL = input.bool(false, title='╔══════   Enable   ══════╗', group=slGroup, tooltip='If you are using this strategy for Scalping or Futures market, we do not recommend using Stop Loss.') 59 | SLPercent = input.float(10, title='Percent', group=slGroup) * 0.01 60 | 61 | 62 | tpGroup = 'Take Profit' 63 | useTP = input.bool(false, title='╔══════   Enable   ══════╗', group=tpGroup) 64 | TPPercent = input.float(10, title='Percent', group=tpGroup) * 0.01 65 | 66 | longStop = strategy.position_avg_price * (1 - SLPercent) 67 | shortStop = strategy.position_avg_price * (1 + SLPercent) 68 | 69 | longTP = strategy.position_avg_price * (1 + TPPercent) 70 | shortTP = strategy.position_avg_price * (1 - TPPercent) 71 | 72 | ifLongTP = useTP ? close > longTP and close > basis : false 73 | ifShortTP = useTP ? close < shortTP and close < basis : false 74 | 75 | exitLong := exitLong or close < maPlot2 or ifLongTP // Tendece changes 76 | exitShort := exitShort or close > maPlot2 or ifShortTP // Tendece changes 77 | 78 | longIsOpen = strategy.position_size > 0 79 | shortIsOpen = strategy.position_size < 0 80 | 81 | bought = strategy.opentrades[0] == 1 and strategy.position_size[0] > strategy.position_size[1] 82 | entry_price = ta.valuewhen(bought, open, 0) 83 | 84 | var int nPastBars = 0 85 | if strategy.position_size > 0 86 | nPastBars := nPastBars + 1 87 | nPastBars 88 | if strategy.position_size == 0 89 | nPastBars := 0 90 | nPastBars 91 | if closeAfterXBars 92 | exitLong := nPastBars >= xBars and close > upper and close > entry_price ? true : exitLong 93 | exitLong 94 | 95 | if showLong 96 | strategy.entry('Long', strategy.long, when=entryLong and not shortIsOpen) 97 | strategy.close('Long', when=exitLong) 98 | if useSL 99 | strategy.exit('Stop Loss', 'Long', stop=longStop) 100 | if showShort 101 | strategy.entry('Short', strategy.short, when=entryShort and not longIsOpen) 102 | strategy.close('Short', when=exitShort, comment='Exit') 103 | if useSL 104 | strategy.exit('Stop Loss', 'Short', stop=shortStop) 105 | 106 | // if entryLong 107 | // label.new(bar_index, low, 'Buy', color=color.green, style=label.style_label_up, textcolor=color.white, size=size.small) 108 | // if exitLong 109 | // label.new(bar_index, high, 'Sell', color=color.red, style=label.style_label_down, textcolor=color.white, size=size.small) 110 | 111 | -------------------------------------------------------------------------------- /strategies/MTF BB.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | //@author Alorse 3 | //@version=4 4 | strategy("MTF Bollindger Bands Strategy [Alorse]", shorttitle="MTF BB Strategy [Alorse]", overlay=true, pyramiding=0, initial_capital=1000, currency=currency.USD, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.01) 5 | 6 | txtVer = "1.0.3" 7 | version = input(title="Version", type=input.string, defval=txtVer, options=[txtVer], tooltip="This is informational only, nothing will change.") 8 | res = input(title="Multi Timeframe", type=input.resolution, defval="60", tooltip="Timeframe recommended is 5 minutes, if you want to use the strategy in higher timeframes, please also increase Multi Timeframe.\nEg: If you want to use the strategy in 1 hour, put the Multi Timeframe in 4 hours.") 9 | 10 | // MTF Bollinger Bands 11 | bbGroup = "MTF Bollindger Bands" 12 | src = input(title="Source", type=input.source, defval=close, group=bbGroup) 13 | length = input(20, title="Length", group=bbGroup) 14 | mult = input(2.0, title="StdDev", minval=0.001, maxval=5, group=bbGroup) 15 | 16 | basis = sma(src, length) 17 | dev = mult * stdev(src, length) 18 | upper = basis + dev 19 | lower = basis - dev 20 | 21 | mtfBasis = security(syminfo.tickerid, res, basis) 22 | mtfUpper = security(syminfo.tickerid, res, upper) 23 | mtfLower = security(syminfo.tickerid, res, lower) 24 | 25 | pb1 = plot(mtfUpper, color=color.new(color.teal, 50), title="Upper") 26 | pb2 = plot(mtfLower, color=color.new(color.teal, 50), title="Lower") 27 | fill(pb1, pb2, color=color.new(color.teal, 98), title="Background") 28 | plot(mtfBasis, "Basis", color=color.new(color.orange, 60)) 29 | 30 | // MTF EMA 31 | maGroup = "MTF Moving Average Filter" 32 | hasMa = input(false, title="╔══════   Use MA   ══════╗", group=maGroup, tooltip="If Moving Average Filter is enabled, strategy only shows Long entries when the price is above the MA and Short entries when the price is below the MA.") 33 | mtfType = input(title="MultiTimeframe MA Type", type=input.string, defval="EMA", options=["EMA", "SMA"], group=maGroup) 34 | emaLen = input(title='MA Periods', minval=1, defval=200, group=maGroup) 35 | ema = security(syminfo.tickerid, res, mtfType == "EMA" ? ema(close, emaLen) : sma(close, emaLen)) 36 | 37 | plot(hasMa ? ema : na, title="Moving Average", linewidth=1, color=color.new(color.blue, 10)) 38 | buyMaFilter = hasMa ? close > ema : true 39 | sellMaFilter = hasMa ? close < ema : true 40 | 41 | //Strategy 42 | stratGroup = "Strategy" 43 | showLong = input(true, title="Long entries", group=stratGroup) 44 | showShort = input(false, title="Short entries", group=stratGroup) 45 | 46 | buy = close < mtfLower and buyMaFilter 47 | sell = close > mtfUpper and sellMaFilter 48 | 49 | // Stop Loss 50 | slGroup = "Stop Loss" 51 | useSL = input(true, title="╔══════   Enable   ══════╗", group=slGroup, tooltip="If you are using this strategy for Scalping or Futures market, we do not recommend using Stop Loss.") 52 | SLbased = input(title="Based on", type=input.string, defval="Percent", options=["ATR", "Percent"], group=slGroup, tooltip="ATR: Average True Range\nPercent: eg. 5%.") 53 | multiATR = input(6.0, title="ATR   Mult", type=input.float, group=slGroup, inline="atr") 54 | lengthATR = input(14, title="Length", type=input.integer, group=slGroup, inline="atr") 55 | SLPercent = input(6, title="Percent", type=input.float, group=slGroup) * 0.01 56 | 57 | longStop = 0.0 58 | shortStop = 0.0 59 | 60 | if SLbased == "ATR" 61 | longStop := valuewhen(buy, low, 0) - (valuewhen(buy, rma(tr(true), lengthATR), 0) * multiATR) 62 | longStopPrev = nz(longStop[1], longStop) 63 | longStop := close[1] > longStopPrev ? max(longStop, longStopPrev) : longStop 64 | 65 | shortStop := (valuewhen(sell, rma(tr(true), lengthATR), 0) * multiATR) + valuewhen(sell, high, 0) 66 | shortStopPrev = nz(shortStop[1], shortStop) 67 | shortStop := close[1] > shortStopPrev ? max(shortStop, shortStopPrev) : shortStop 68 | if SLbased == "Percent" 69 | longStop := strategy.position_avg_price * (1 - SLPercent) 70 | shortStop := strategy.position_avg_price * (1 + SLPercent) 71 | 72 | if showLong 73 | strategy.entry("Long", true, when=buy) 74 | strategy.close("Long", when=close > mtfUpper) 75 | if useSL 76 | strategy.exit("SL", "Long", stop=longStop) 77 | if showShort 78 | strategy.entry("Short", false, when=sell) 79 | strategy.close("Short", when=close < mtfLower) 80 | if useSL 81 | strategy.exit("SL", "Short", stop=shortStop) -------------------------------------------------------------------------------- /strategies/MTF RSI.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © alorse 3 | 4 | //@version=5 5 | strategy("MTF RSI", overlay=true, overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=1000, default_qty_value=20, commission_type=strategy.commission.percent, commission_value=0.01) 6 | 7 | // RSI 8 | rsiGroup = 'RSI' 9 | lenRSI = input.int(14, title='Length', minval=1, group=rsiGroup) 10 | rsi_overbought = input(70, title='RSI Overbought Level', group=rsiGroup) 11 | rsi_oversold = input(30, title='RSI Overbought Level', group=rsiGroup) 12 | RSI = ta.rsi(close, lenRSI) 13 | 14 | maGroup = "Moving Average" 15 | ma_type = input.string(title='Type', defval='EMA', options=['SMA', 'EMA'], group=maGroup, inline='ma') 16 | ma_length = input.int(title='Length', defval=900, group=maGroup, inline='ma') 17 | ma = ma_type == 'SMA' ? ta.sma(close, ma_length) : ta.ema(close, ma_length) 18 | 19 | longEntry = close > ma and RSI < rsi_oversold 20 | longExit = RSI > rsi_overbought or close < ma 21 | 22 | strategy.entry('Long', strategy.long, when=longEntry) 23 | strategy.close('Long', when=longExit) 24 | -------------------------------------------------------------------------------- /strategies/MacdNew.pine: -------------------------------------------------------------------------------- 1 | //@version=4 2 | strategy(title="MACD + Divergences [Alorse]", shorttitle = "MACD + Divergences", pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=1000, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.01) 3 | // Getting inputs 4 | src = input(title="Source", type=input.source, defval=close) 5 | fast_length = input(title="Fast Length", type=input.integer, defval=12) 6 | slow_length = input(title="Slow Length", type=input.integer, defval=26) 7 | signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9) 8 | sma_source = input(title="Oscillator MA Type", type=input.string, defval="EMA", options=["SMA", "EMA"]) 9 | sma_signal = input(title="Signal Line MA Type", type=input.string, defval="EMA", options=["SMA", "EMA"]) 10 | 11 | col_macd = input(#2962FF, "MACD Line  ", input.color, group="Color Settings", inline="MACD") 12 | col_signal = input(#FF6D00, "Signal Line  ", input.color, group="Color Settings", inline="Signal") 13 | showCross = input(title="Show Signals&MACD Cross", defval=true, group="Color Settings") // Show cross bt MACD & Signal 14 | col_grow_above = input(#00796b, "Above   Grow", input.color, group="Histogram", inline="Above") 15 | col_fall_above = input(#26a69a, "Fall", input.color, group="Histogram", inline="Above") 16 | col_grow_below = input(#ef5350, "Below Grow", input.color, group="Histogram", inline="Below") 17 | col_fall_below = input(#b71c1c, "Fall", input.color, group="Histogram", inline="Below") 18 | 19 | fast_ma = sma_source == "SMA" ? sma(src, fast_length) : ema(src, fast_length) 20 | slow_ma = sma_source == "SMA" ? sma(src, slow_length) : ema(src, slow_length) 21 | macd = fast_ma - slow_ma 22 | signal = sma_signal == "SMA" ? sma(macd, signal_length) : ema(macd, signal_length) 23 | hist = macd - signal 24 | osc = macd 25 | 26 | plot(hist, title="Histogram", style=plot.style_columns, color=color.new((hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below) ),0)) 27 | plot(macd, title="MACD", color=color.new(col_macd, 10)) 28 | plot(signal, title="Signal", color=color.new(col_signal, 10)) 29 | 30 | donttouchzero = input(title="Don't touch the zero line?", defval=true) 31 | 32 | //Divergences 33 | lbR = input(title="Pivot Lookback Right", defval=5, group="Divergences") 34 | lbL = input(title="Pivot Lookback Left", defval=5, group="Divergences") 35 | rangeUpper = input(title="Max of Lookback Range", defval=60, group="Divergences") 36 | rangeLower = input(title="Min of Lookback Range", defval=5, group="Divergences") 37 | plotBull = input(title="Plot Bullish", defval=true, group="Divergences") 38 | plotBear = input(title="Plot Bearish", defval=true, group="Divergences") 39 | plotHiddenBull = input(title="Plot Hidden Bullish", defval=false, group="Divergences") 40 | plotHiddenBear = input(title="Plot Hidden Bearish", defval=false, group="Divergences") 41 | 42 | bearColor = color.red 43 | bullColor = color.green 44 | hiddenBullColor = color.new(color.yellow,50) 45 | hiddenBearColor = color.new(color.yellow,50) 46 | textColor = color.white 47 | noneColor = color.new(color.white, 100) 48 | 49 | plFound = na(pivotlow(osc, lbL, lbR)) ? false : true 50 | phFound = na(pivothigh(osc, lbL, lbR)) ? false : true 51 | 52 | _inRange(cond) => 53 | bars = barssince(cond == true) 54 | rangeLower <= bars and bars <= rangeUpper 55 | 56 | //Get MA Values 57 | maA = input(150, minval=1, title="EMA 1", group="Moving Averages") 58 | maB = input(600, minval=1, title="EMA 2", group="Moving Averages") 59 | //Get MTF data 60 | dataA = ema(src, maA) 61 | dataB = ema(src, maB) 62 | 63 | trendBull = dataA > dataB //and signal < 0 64 | trendBear = dataA < dataB //and signal > 0 65 | 66 | //------------------------------------------------------------------------------ 67 | // Regular Bullish 68 | 69 | // Osc: Higher Low 70 | oscHL = osc[lbR] > valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1]) 71 | 72 | // Price: Lower Low 73 | priceLL = low[lbR] < valuewhen(plFound, low[lbR], 1) 74 | 75 | bullCond = plotBull and priceLL and oscHL and plFound 76 | 77 | plot(plFound ? osc[lbR] : na,offset=-lbR,title="Regular Bullish",linewidth=2,color=(bullCond ? bullColor : noneColor),transp=0) 78 | plotshape(bullCond ? osc[lbR] : na,offset=-lbR,title="Regular Bullish Label",text="⬆",style=shape.labelup,location=location.absolute,color=bullColor,textcolor=textColor,transp=0) 79 | 80 | //------------------------------------------------------------------------------ 81 | // Hidden Bullish 82 | 83 | // Osc: Lower Low 84 | oscLL = osc[lbR] < valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1]) 85 | 86 | // Price: Higher Low 87 | priceHL = low[lbR] > valuewhen(plFound, low[lbR], 1) 88 | 89 | hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound 90 | 91 | plot(plFound ? osc[lbR] : na,offset=-lbR,title="Hidden Bullish",linewidth=2,color=(hiddenBullCond ? hiddenBullColor : noneColor),transp=0) 92 | plotshape(hiddenBullCond ? osc[lbR] : na,offset=-lbR,title="Hidden Bullish Label",text="⬆H",style=shape.labelup,location=location.absolute,color=bullColor,textcolor=textColor,transp=0) 93 | 94 | //------------------------------------------------------------------------------ 95 | // Regular Bearish 96 | 97 | // Osc: Lower High 98 | oscLH = osc[lbR] < valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1]) 99 | 100 | // Price: Higher High 101 | priceHH = high[lbR] > valuewhen(phFound, high[lbR], 1) 102 | 103 | bearCond = plotBear and priceHH and oscLH and phFound 104 | 105 | plot(phFound ? osc[lbR] : na, offset=-lbR, title="Regular Bearish", linewidth=2, color=(bearCond ? color.new(bearColor, trendBear ? 0 : 50) : noneColor)) 106 | plotshape(bearCond ? osc[lbR] : na, offset=-lbR, title="Regular Bearish Label", text="⬇", style=shape.labeldown, location=location.absolute, color=color.new(bearColor,100), textcolor=color.new(bearColor, trendBear ? 0 : 50)) 107 | 108 | //------------------------------------------------------------------------------ 109 | // Hidden Bearish 110 | 111 | // Osc: Higher High 112 | oscHH = osc[lbR] > valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1]) 113 | 114 | // Price: Lower High 115 | priceLH = high[lbR] < valuewhen(phFound, high[lbR], 1) 116 | 117 | hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound 118 | 119 | plot(phFound ? osc[lbR] : na,offset=-lbR,title="Hidden Bearish",linewidth=2,color=(hiddenBearCond ? hiddenBearColor : noneColor),transp=0) 120 | plotshape(hiddenBearCond ? osc[lbR] : na,offset=-lbR,title="Hidden Bearish Label",text="⬇H",style=shape.labeldown,location=location.absolute,color=bearColor,textcolor=textColor,transp=0) 121 | 122 | plot(showCross and cross(osc, signal) and trendBear ? osc : na, style=plot.style_cross, color=color.silver, linewidth = 2) 123 | 124 | // Strategy 125 | stratGroup = "Strategy" 126 | barsBack = input(title="Bars back", type=input.integer, minval=0, maxval=100, defval=10, group=stratGroup, tooltip="") 127 | tpFactor = input(title="Take profit factor", type=input.float, minval=0, maxval=100, defval=1.5, group=stratGroup, tooltip="") 128 | 129 | buySignal = bullCond and trendBull 130 | sellSignal = bearCond and trendBear 131 | float slBuy = 0.0 132 | slBuy := strategy.position_size == 0 ? lowest(barsBack) : na(slBuy[1]) ? na : slBuy[1] 133 | float slSell = 0.0 134 | slSell := strategy.position_size == 0 ? highest(barsBack) : na(slSell[1]) ? na : slSell[1] 135 | 136 | entry_price = 0.0 137 | entry_price := buySignal ? close : sellSignal ? close : na(entry_price[1]) ? na : entry_price[1] 138 | 139 | tpBuy = entry_price + ((entry_price - slBuy) * tpFactor) 140 | tpSell = entry_price - ((slSell - entry_price) * tpFactor) 141 | 142 | 143 | strategy.entry("Long", true, when=buySignal) 144 | strategy.exit("Exit", "Long", stop=slBuy, limit=tpBuy) 145 | strategy.entry("Short", false, when=sellSignal) 146 | strategy.exit("Exit", "Short", stop=slSell, limit=tpSell) -------------------------------------------------------------------------------- /strategies/Multi BB.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © alorse 3 | 4 | //@version=4 5 | strategy(title="Multi Bollinger Bands [Alorse]", shorttitle="Multi BB [Alorse]", overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=1000, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.01) 6 | 7 | txtVer = "0.0.2" 8 | version = input(title="Version", type=input.string, defval=txtVer, options=[txtVer], tooltip="This is informational only, nothing will change.") 9 | 10 | // Bollinger Bands 11 | bbGroup = "Bollindger Bands" 12 | src = input(title="Source", type=input.source, defval=close, group=bbGroup) 13 | length = input(20, title="Length", group=bbGroup) 14 | mult = input(2.0, title="StdDev", minval=0.001, maxval=5, group=bbGroup) 15 | 16 | basis = sma(src, length) 17 | dev = mult * stdev(src, length) 18 | upper = basis + dev 19 | lower = basis - dev 20 | 21 | pb1 = plot(upper, color=color.new(color.teal, 100), title="Upper") 22 | pb2 = plot(lower, color=color.new(color.teal, 100), title="Lower") 23 | 24 | // MTF Bollinger Bands 25 | res = input(title="Multi Timeframe", type=input.resolution, defval="15", tooltip="5 minutes => 15 minutes\n15 minutes => 45 minutes") 26 | mtfUpper = security(syminfo.tickerid, res, upper) 27 | mtfLower = security(syminfo.tickerid, res, lower) 28 | 29 | mpb1 = plot(mtfUpper, color=color.new(color.teal, 100), title="Upper") 30 | mpb2 = plot(mtfLower, color=color.new(color.teal, 100), title="Lower") 31 | 32 | avgUpper = avg(upper, mtfUpper) 33 | avgLower = avg(lower, mtfLower) 34 | 35 | plot(avgUpper, "Upper Basis", color=color.new(color.orange, 60)) 36 | plot(avgLower, "Lower Basis", color=color.new(color.orange, 60)) 37 | 38 | fill(pb1, mpb1, color=color.new(color.red, 95), title="Background") 39 | fill(pb2, mpb2, color=color.new(color.teal, 95), title="Background") 40 | 41 | strategy.entry("Long", true, when=close < avgLower) 42 | strategy.close("Long", when=close > upper) 43 | 44 | //strategy.entry("Short", false, when=close > avgUpper) -------------------------------------------------------------------------------- /strategies/Omar MMR [Alorse].pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © alorse 3 | 4 | //@version=5 5 | strategy("Omar MMR [Alorse]", overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=100000, default_qty_value=100, commission_type=strategy.commission.percent) 6 | 7 | // RSI 8 | rsiGroup = 'RSI' 9 | src = input(title='Source', defval=close, group=rsiGroup, inline=rsiGroup) 10 | lenRSI = input.int(14, title='Length', minval=1, group=rsiGroup, inline=rsiGroup) 11 | RSI = ta.rsi(src, lenRSI) 12 | 13 | // Moving Averages 14 | groupEma = 'Moving Averages' 15 | len_a = input.int(20, minval=1, title='Length   A', group=groupEma, inline=groupEma) 16 | ema_a = ta.ema(close, len_a) 17 | plot(ema_a, title='EMA A', color=color.new(color.orange, 10)) 18 | len_b = input.int(50, minval=1, title='B', group=groupEma, inline=groupEma) 19 | ema_b = ta.ema(close, len_b) 20 | plot(ema_b, title='EMA B', color=color.new(color.purple, 10)) 21 | len_c = input.int(200, minval=1, title='C', group=groupEma, inline=groupEma) 22 | ema_c = ta.ema(close, len_c) 23 | plot(ema_c, title='EMA C', color=color.new(color.green, 10), linewidth=2) 24 | 25 | // MACD 26 | macdGroup = 'MACD' 27 | fast_ma = input.int(defval=12, minval=1, title='Length   Fast', group=macdGroup, inline=macdGroup) 28 | slow_ma = input.int(defval=26, minval=1, title='Slow', group=macdGroup, inline=macdGroup) 29 | signal_length = input.int(defval=9, minval=1, title='Signal', group=macdGroup, inline=macdGroup) 30 | [macd_line, signal_line, hist_line] = ta.macd(close, fast_ma, slow_ma, signal_length) 31 | 32 | longEntry = close > ema_c and ema_a > ema_b and ta.crossover(macd_line, signal_line) and RSI > 29 and RSI < 70 33 | isLong = strategy.position_size > 0 34 | 35 | plot_ln = plot(isLong ? strategy.position_avg_price : na, color=#787b86, style=plot.style_linebr, linewidth=1, title="Entry Price") 36 | // Take profit 37 | longProfitPerc = input.float(title="Take Profit (%)", step=0.1, defval=1.5, group="Strategy") * 0.01 38 | longExitPrice = strategy.position_avg_price * (1 + longProfitPerc) 39 | plot_tp = plot(isLong ? longExitPrice : na, color=color.new(#009688, 100), title="Take Profit") 40 | 41 | // Stop loss 42 | longLossPerc = input.float(title="Stop Loss (%)", step=0.1, defval=2.0, group="Strategy") * 0.01 43 | longStopPrice = strategy.position_avg_price * (1 - longLossPerc) 44 | plot_sl = plot(isLong ? longStopPrice : na, color=color.new(#f44336, 100), title="Stop Loss") 45 | 46 | fill(plot_ln, plot_tp, title='UpTrend Highligter', color=color.new(#009688, 80)) 47 | fill(plot_ln, plot_sl, title='DownTrend Highligter', color=color.new(#f44336, 80)) 48 | 49 | am_entry = "🔶Scalping Deal🔶\n \n 🟢**BUY NOW!**🟢\n#" + str.tostring(syminfo.ticker) + "\n\n💰Price " + str.tostring(close) + "\n⬆️Target: " + str.tostring(close * (1 + longProfitPerc)) + "\n❌Stop loss: " + str.tostring(close * (1 - longLossPerc)) 50 | ame_win="**Take Profit**\n#" + str.tostring(syminfo.ticker) + "\n\n✅Price " + str.tostring(longExitPrice)+ "\nYou won : 1.5%" 51 | ame_loss="**Stop Loss**\n#" + str.tostring(syminfo.ticker) + "\n\n❌Price " + str.tostring(longStopPrice) +"\nYou lost : 2%" 52 | 53 | exit_msg = close[1] > strategy.position_avg_price ? ame_win : ame_loss 54 | 55 | strategy.entry('Long', strategy.long, when=longEntry, alert_message=am_entry) 56 | strategy.exit('Exit', 'Long', limit=longExitPrice, stop=longStopPrice, alert_message=exit_msg) 57 | 58 | -------------------------------------------------------------------------------- /strategies/Password protected.pine: -------------------------------------------------------------------------------- 1 | //@author Alorse 2 | //@version=4 3 | strategy(title="Password for my scripts [Alorse]", shorttitle="Password protected [Alorse]", overlay=true) 4 | 5 | // Password 6 | passCode = "TV123" 7 | password = input(title="Password", type=input.string, defval=passCode, tooltip="Try with: TV123") 8 | 9 | // Bollinger Bands 10 | upper = sma(close, 20) + 2 * stdev(close, 20) 11 | lower = sma(close, 20) - 2 * stdev(close, 20) 12 | 13 | //Strategy 14 | len = input(200, minval=1, title="Length") 15 | buy = close < lower and close > ema(close, len) 16 | sell = close > upper and close < ema(close, len) 17 | 18 | // Check if the password is correct 19 | validPass = password == passCode 20 | 21 | longStop = strategy.position_avg_price * (1 - 0.03) 22 | shortStop = strategy.position_avg_price * (1 + 0.03) 23 | 24 | strategy.entry("Long", true, when=buy and validPass) 25 | strategy.close("Long", when=close > upper, comment="SL") 26 | strategy.exit("SL", "Long", stop=longStop) 27 | strategy.entry("Short", false, when=sell and validPass) 28 | strategy.close("Short", when=close < lower, comment="SS") 29 | strategy.exit("SL", "Short", stop=shortStop) 30 | 31 | var lastTradeId = "somerandomid" 32 | var lastTradeWasLoss = false 33 | barsWait = 5 // our N 34 | 35 | if (strategy.losstrades[0] > strategy.losstrades[1]) 36 | // last trade was a loss 37 | lastTradeWasLoss := true 38 | 39 | if (strategy.wintrades[0] > strategy.wintrades[1]) 40 | // successful trade, reset 41 | lastTradeWasLoss := false 42 | 43 | // Check if strategy has no open position 44 | isFlat = strategy.position_size == 0 45 | 46 | // Check if strategy had no open position for more than N bars 47 | if (isFlat and lastTradeWasLoss and barssince(isFlat) > barsWait) 48 | // it's been more than N bars since last position was flat 49 | 50 | // store last trade id for later use 51 | lastTradeId := "somethingotherrandom" 52 | 53 | // execute trade 54 | // strategy.entry(id=lastTradeId, ...) -------------------------------------------------------------------------------- /strategies/Pin Bar Magic v1.pine: -------------------------------------------------------------------------------- 1 | //@version=4 2 | //Time Frame: H1 3 | strategy("Pin Bar Magic v1", overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=1000, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.1) 4 | 5 | // User Input 6 | usr_risk = input(title="Equity Risk (%)",type=input.integer,minval=1,maxval=100,step=1,defval=3,confirm=false) 7 | atr_mult = input(title="Stop Loss (x*ATR, Float)",type=input.float,minval=0.1,maxval=100,step=0.1,defval=0.5,confirm=false) 8 | slPoints = input(title="Stop Loss Trail Points (Pips)",type=input.integer,minval=1,maxval=1000,step=1,defval=1,confirm=false) 9 | slOffset = input(title="Stop Loss Trail Offset (Pips)",type=input.integer,minval=1,maxval=1000,step=1,defval=1,confirm=false) 10 | sma_slow = input(title="Slow SMA (Period)",type=input.integer,minval=1,maxval=500,step=1,defval=50,confirm=false) 11 | ema_medm = input(title="Medm EMA (Period)",type=input.integer,minval=1,maxval=500,step=1,defval=18,confirm=false) 12 | ema_fast = input(title="Fast EMA (Period)",type=input.integer,minval=1,maxval=500,step=1,defval=6,confirm=false) 13 | atr_valu = input(title="ATR (Period)",type=input.integer,minval=1,maxval=500,step=1,defval=14,confirm=false) 14 | ent_canc = input(title="Cancel Entry After X Bars (Period)",type=input.integer,minval=1,maxval=500,step=1,defval=3,confirm=false) 15 | 16 | // Create Indicators 17 | slowSMA = sma(close, sma_slow) 18 | medmEMA = ema(close, ema_medm) 19 | fastEMA = ema(close, ema_fast) 20 | bullishPinBar = ((close > open) and ((open - low) > 0.66 * (high - low))) or ((close < open) and ((close - low) > 0.66 * (high - low))) 21 | bearishPinBar = ((close > open) and ((high - close) > 0.66 * (high - low))) or ((close < open) and ((high - open) > 0.66 * (high - low))) 22 | atr = atr(atr_valu) 23 | 24 | // Specify Trend Conditions 25 | fanUpTrend = (fastEMA > medmEMA) and (medmEMA > slowSMA) 26 | fanDnTrend = (fastEMA < medmEMA) and (medmEMA < slowSMA) 27 | 28 | // Specify Piercing Conditions 29 | bullPierce = ((low < fastEMA) and (open > fastEMA) and (close > fastEMA)) or ((low < medmEMA) and (open > medmEMA) and (close > medmEMA)) or ((low < slowSMA) and (open > slowSMA) and (close > slowSMA)) 30 | bearPierce = ((high > fastEMA) and (open < fastEMA) and (close < fastEMA)) or ((high > medmEMA) and (open < medmEMA) and (close < medmEMA)) or ((high > slowSMA) and (open < slowSMA) and (close < slowSMA)) 31 | 32 | // Specify Entry Conditions 33 | longEntry = fanUpTrend and bullishPinBar and bullPierce 34 | shortEntry = fanDnTrend and bearishPinBar and bearPierce 35 | 36 | // Long Entry Function 37 | enterlong() => 38 | risk = usr_risk * 0.01 * strategy.equity 39 | stopLoss = low[1] - atr[1] * atr_mult 40 | entryPrice = high[1] 41 | units = risk / (entryPrice - stopLoss) 42 | strategy.entry("long", strategy.long, units, stop=entryPrice) 43 | strategy.exit("exit long", from_entry="long", trail_points=slPoints, trail_offset=slOffset) 44 | 45 | // Short Entry Function 46 | entershort() => 47 | risk = usr_risk * 0.01 * strategy.equity 48 | stopLoss = high[1] + atr[1] * atr_mult 49 | entryPrice = low[1] 50 | units = risk / (stopLoss - entryPrice) 51 | strategy.entry("short", strategy.short, units, stop=entryPrice) 52 | strategy.exit("exit short", from_entry="short", trail_points=slPoints, trail_offset=slOffset) 53 | 54 | // Execute Long Entry 55 | if (longEntry) 56 | enterlong() 57 | 58 | // Execute Short Entry 59 | if (shortEntry) 60 | entershort() 61 | 62 | // Cancel the Entry if Bar Time is Exceeded 63 | strategy.cancel("long", barssince(longEntry) > ent_canc) 64 | strategy.cancel("short", barssince(shortEntry) > ent_canc) 65 | 66 | // Force Close During Certain Conditions 67 | strategy.close_all(when = hour==16 and dayofweek==dayofweek.friday, comment = "exit all, market-closed") 68 | strategy.close_all(when = crossunder(fastEMA, medmEMA), comment = "exit long, re-cross") 69 | strategy.close_all(when = crossover(fastEMA, medmEMA), comment = "exit short, re-cross") -------------------------------------------------------------------------------- /strategies/QQE signals.pine: -------------------------------------------------------------------------------- 1 | //@version=4 2 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 3 | // © colinmck 4 | 5 | strategy("QQE signals [Alorse]", shorttitle="QQE signals [Alorse]", overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=1000, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.01) 6 | 7 | RSI_Period = input(14, title='RSI Length') 8 | SF = input(5, title='RSI Smoothing') 9 | QQE = input(4.238, title='Fast QQE Factor') 10 | ThreshHold = input(10, title="Thresh-hold") 11 | 12 | src = close 13 | Wilders_Period = RSI_Period * 2 - 1 14 | 15 | Rsi = rsi(src, RSI_Period) 16 | RsiMa = ema(Rsi, SF) 17 | AtrRsi = abs(RsiMa[1] - RsiMa) 18 | MaAtrRsi = ema(AtrRsi, Wilders_Period) 19 | dar = ema(MaAtrRsi, Wilders_Period) * QQE 20 | 21 | longband = 0.0 22 | shortband = 0.0 23 | trend = 0 24 | 25 | DeltaFastAtrRsi = dar 26 | RSIndex = RsiMa 27 | newshortband = RSIndex + DeltaFastAtrRsi 28 | newlongband = RSIndex - DeltaFastAtrRsi 29 | longband := RSIndex[1] > longband[1] and RSIndex > longband[1] ? max(longband[1], newlongband) : newlongband 30 | shortband := RSIndex[1] < shortband[1] and RSIndex < shortband[1] ? min(shortband[1], newshortband) : newshortband 31 | cross_1 = cross(longband[1], RSIndex) 32 | trend := cross(RSIndex, shortband[1]) ? 1 : cross_1 ? -1 : nz(trend[1], 1) 33 | FastAtrRsiTL = trend == 1 ? longband : shortband 34 | 35 | // Find all the QQE Crosses 36 | 37 | QQExlong = 0 38 | QQExlong := nz(QQExlong[1]) 39 | QQExshort = 0 40 | QQExshort := nz(QQExshort[1]) 41 | QQExlong := FastAtrRsiTL < RSIndex ? QQExlong + 1 : 0 42 | QQExshort := FastAtrRsiTL > RSIndex ? QQExshort + 1 : 0 43 | 44 | //Conditions 45 | 46 | qqeLong = QQExlong == 1 ? FastAtrRsiTL[1] - 50 : na 47 | qqeShort = QQExshort == 1 ? FastAtrRsiTL[1] - 50 : na 48 | 49 | // Plotting 50 | 51 | // plotshape(qqeLong, title="QQE long", text="Long", textcolor=color.white, style=shape.labelup, location=location.belowbar, color=color.green, transp=0, size=size.tiny) 52 | // plotshape(qqeShort, title="QQE short", text="Short", textcolor=color.white, style=shape.labeldown, location=location.abovebar, color=color.red, transp=0, size=size.tiny) 53 | 54 | // Alerts 55 | strategy.entry("Long", true, when=qqeLong) 56 | // strategy.entry("Short", false, when=qqeShort) 57 | strategy.close("Long", when=qqeShort) 58 | -------------------------------------------------------------------------------- /strategies/RSI + 1200.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © alorse 3 | 4 | //@version=5 5 | strategy("RSI + 1200 Strategy [Alose]", overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=100000, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.01) 6 | 7 | // RSI 8 | rsiGroup = 'RSI' 9 | src = input(title='Source', defval=close, group=rsiGroup) 10 | lenRSI = input.int(14, title='Length', minval=1, group=rsiGroup) 11 | RSI = ta.rsi(src, lenRSI) 12 | RSIoverbought = input.int(72, title='Overbought', minval=1, group=rsiGroup, tooltip='The trade will close when the RSI crosses up this point.') 13 | RSIoversold = input.int(28, title='Oversold', minval=1, group=rsiGroup, tooltip='The trade will close when the RSI crosses below this point.') 14 | 15 | // MTF EMA 16 | maGroup = "MTF Moving Average" 17 | emaLen = input(title='MA Periods', defval=150, group=maGroup) 18 | res = input.timeframe(title="Multi Timeframe", defval="120") 19 | ema = request.security(syminfo.tickerid, res, ta.ema(close, emaLen)) 20 | plot(ema, title="Moving Average", linewidth=1, color=color.yellow) 21 | 22 | // Strategy Conditions 23 | stratGroup = 'Strategy' 24 | showLong = input.bool(true, title='Long entries', group=stratGroup) 25 | showShort = input.bool(true, title='Short entries', group=stratGroup) 26 | SL = input.int(title="Stop Loss %", defval=10, group=stratGroup) * 0.01 27 | 28 | secureLong = strategy.position_avg_price * (1 + 0.002) 29 | secureShort = strategy.position_avg_price * (1 - 0.002) 30 | 31 | // Determine trail stop loss prices 32 | longStopPrice = strategy.position_avg_price * (1 - SL) 33 | shortStopPrice = strategy.position_avg_price * (1 + SL) 34 | 35 | slackLongPercent = close > ema * 1.01 // +1% 36 | slackShortPercent = close < ema * 0.99 // -1% 37 | 38 | fiveLong = close > ema and close < ema * 1.02 and close < open and close[1] < open[1] and close[2] < open[2] //and close[3] < open[3] and close[4] < open[4] 39 | fiveShort = close < ema and close > ema * 0.99 and close > open and close[1] > open[1] and close[2] > open[2] //and close[3] > open[3] and close[4] > open[4] 40 | 41 | entryLong = close > ema and ta.crossover(RSI, RSIoversold) and slackLongPercent 42 | exitLong = RSI > RSIoverbought or fiveLong 43 | 44 | entryShort = close < ema and ta.crossunder(RSI, RSIoverbought) and slackShortPercent 45 | exitShort = RSI < RSIoversold or fiveShort 46 | 47 | if showLong 48 | strategy.entry("Long", strategy.long, when=entryLong) 49 | strategy.exit("Exit", "Long", stop=longStopPrice) 50 | strategy.close("Long", when=exitLong) 51 | 52 | if showShort 53 | strategy.entry("Short", strategy.short, when=entryShort) 54 | strategy.exit("Exit", "Short", stop=shortStopPrice) 55 | strategy.close("Short", when=exitShort) 56 | -------------------------------------------------------------------------------- /strategies/RSI + EMA.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // alorse 3 | 4 | //@version=5 5 | strategy(title='RSI + EMA [Alorse]', shorttitle='RSI + EMA [Alorse]', overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=1000, default_qty_value=20, commission_type=strategy.commission.percent, commission_value=0.01) 6 | 7 | src = input(close, 'Source') 8 | rsi_length = input(14, title='RSI Length') 9 | rsi_overbought = input(70, title='RSI Overbought Level') 10 | rsi_oversold = input(30, title='RSI Overbought Level') 11 | up = ta.rma(math.max(ta.change(src), 0), rsi_length) 12 | down = ta.rma(-math.min(ta.change(src), 0), rsi_length) 13 | rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - 100 / (1 + up / down) 14 | 15 | maGroup = "Moving Average 1" 16 | ma_type = input.string(title='Type', defval='EMA', options=['SMA', 'EMA'], group=maGroup, inline='ma') 17 | ma_length = input.int(title='Length', defval=150, group=maGroup, inline='ma') 18 | ma = ma_type == 'SMA' ? ta.sma(src, ma_length) : ta.ema(src, ma_length) 19 | plot(ma, title=maGroup, color=color.purple) 20 | 21 | ma2Group = "Moving Average 2" 22 | ma2_type = input.string(title='Type', defval='EMA', options=['SMA', 'EMA'], group=ma2Group, inline='ma') 23 | ma2_length = input.int(title='Length', defval=600, group=ma2Group, inline='ma') 24 | ma2 = ma2_type == 'SMA' ? ta.sma(src, ma2_length) : ta.ema(src, ma2_length) 25 | plot(ma2, title=ma2Group, color=color.orange) 26 | 27 | 28 | longEntry = rsi < rsi_oversold and ma > ma2 29 | shortEntry = rsi > rsi_overbought and ma > ma2 30 | 31 | 32 | strategy.entry('Long', strategy.long, when=longEntry) 33 | strategy.close('Long', when=rsi > rsi_overbought) 34 | 35 | 36 | strategy.entry('Short', strategy.short, when=shortEntry) 37 | strategy.close('Short', when=rsi < rsi_oversold) 38 | -------------------------------------------------------------------------------- /strategies/Stoch RSI Crossover Strat + EMA - YT-Trade Pro.pine: -------------------------------------------------------------------------------- 1 | //@version=4 2 | // Strategy posted by Trade Pro on YT: https://www.youtube.com/watch?v=7NM7bR2mL7U&t=299s 3 | // This strat uses a 3:1 risk reward ratio, but can be changed by setting the ATR multiplier 4 | // The script has a time range picker added to back test from a specific date. 5 | // Best results achieved on EURGBP on 15min 3:1 and USDCAD 30m with a 1:3 RRR 6 | 7 | strategy(title="Stoch RSI Crossover Strat + EMA - YT:Trade Pro", shorttitle="Stoch RSI Cross + EMA Strat", overlay = true, pyramiding = 0, calc_on_order_fills = false, commission_type = strategy.commission.percent, commission_value = 0, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, initial_capital=10000, currency=currency.USD) 8 | 9 | // STEP 1: 10 | // Configure backtest start date with inputs 11 | startDate = input(title="Start Date", type=input.integer, 12 | defval=1, minval=1, maxval=31) 13 | startMonth = input(title="Start Month", type=input.integer, 14 | defval=1, minval=1, maxval=12) 15 | startYear = input(title="Start Year", type=input.integer, 16 | defval=2000, minval=1800, maxval=2100) 17 | 18 | // STEP 2: 19 | // See if this bar's time happened on/after start date 20 | afterStartDate = (time >= timestamp(syminfo.timezone, 21 | startYear, startMonth, startDate, 0, 0)) 22 | 23 | 24 | smoothK = input(3, minval=1) 25 | smoothD = input(3, minval=1) 26 | lengthRSI = input(14, minval=1) 27 | lengthStoch = input(14, minval=1) 28 | src = input(close, title="RSI Source") 29 | 30 | rsi1 = rsi(src, lengthRSI) 31 | k = sma(stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK) 32 | d = sma(k, smoothD) 33 | 34 | //Multi EMA 35 | emasrc = close, 36 | len1 = input(8, minval=1, title="EMA 1") 37 | len2 = input(14, minval=1, title="EMA 2") 38 | len3 = input(50, minval=1, title="EMA 3") 39 | 40 | ema1 = ema(emasrc, len1) 41 | ema2 = ema(emasrc, len2) 42 | ema3 = ema(emasrc, len3) 43 | 44 | col1 = color.lime 45 | col2 = color.blue 46 | col3 = color.orange 47 | 48 | 49 | //EMA Plots 50 | plot(ema1, title="EMA 1", linewidth=1, color=col1) 51 | plot(ema2, title="EMA 2", linewidth=1, color=col2) 52 | plot(ema3, title="EMA 3", linewidth=1, color=col3) 53 | 54 | crossup = k[1] >= d[1] and k[2] <= d[2] and k <= 60 and k >= 10 55 | barbuy = crossup and ema1 > ema2 and ema2 > ema3 and close > ema1 56 | crossdown = k[1] <= d[1] and k[2] >= d[2] and k >= 40 and k <= 95 57 | barsell = crossdown and ema3 > ema2 and ema2 > ema1 and close < ema1 58 | 59 | //plotshape(crossup, style=shape.triangleup, location=location.belowbar, color=color.white) 60 | plotshape(barbuy, style=shape.triangleup, location=location.belowbar, color=color.green) 61 | //plotshape(crossdown, style=shape.triangledown, location=location.abovebar, color=color.white) 62 | plotshape(barsell, style=shape.triangledown, location=location.abovebar, color=color.red) 63 | 64 | 65 | if (afterStartDate) 66 | strategy.entry("Long", strategy.long, when = barbuy) 67 | strategy.entry("Short", strategy.short, when = barsell) 68 | 69 | lengthATR = input(title="ATR Length", defval=14, minval=1) 70 | atr_loss = input(title="ATR loss multiplier", defval=3, minval=1) 71 | atr_profit = input(title="ATR profit multiplier", defval=1, minval=1) 72 | atr = atr(lengthATR) 73 | longloss = sma(open, 1) 74 | longprofit = sma(open, 1) 75 | shortloss = sma(open, 1) 76 | shortprofit = sma(open, 1) 77 | longloss := barbuy ? open - (atr * atr_loss) : longloss[1] 78 | longprofit := barbuy ? open + (atr * atr_profit) : longprofit[1] 79 | shortloss := barsell ? open + (atr * atr_loss) : shortloss[1] 80 | shortprofit := barsell ? open - (atr * atr_profit) : shortprofit[1] 81 | 82 | strategy.exit("exit long", from_entry="Long", stop=longloss, limit=longprofit) 83 | strategy.exit("exit short", from_entry="Short", stop=shortloss,limit=shortprofit) 84 | //strategy.close(id="Long", when=crossdown) 85 | //strategy.close(id="Short", when=crossup) 86 | -------------------------------------------------------------------------------- /strategies/StochRSI + Supertrend Strategy.pine: -------------------------------------------------------------------------------- 1 | // 2 | //@author Alorse 3 | //@version=4 4 | strategy("StochRSI + Supertrend Strategy [Alorse]", shorttitle="StochRSI+ST STRTG [Alorse]", overlay=true, pyramiding=0, initial_capital=1000, currency=currency.USD, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.01) 5 | smoothK = input(3, "K", minval=1) 6 | smoothD = input(3, "D", minval=1) 7 | lengthRSI = input(14, "RSI Length", minval=1) 8 | lengthStoch = input(14, "Stochastic Length", minval=1) 9 | src = input(close, title="RSI Source") 10 | rsi1 = rsi(src, lengthRSI) 11 | k = sma(stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK) 12 | d = sma(k, smoothD) 13 | 14 | // MA 15 | ma_type = input(title="Type", type=input.string, defval="EMA", options=["EMA", "SMA"], group="Tendence Moving Average") 16 | lenTend = input(200, minval=1, title="Periods", group="Tendence Moving Average") 17 | maTend = ma_type == "EMA" ? ema(src, lenTend) : sma(src, lenTend) 18 | plot(maTend, color=color.white, title="Tendence MA", linewidth=2) 19 | 20 | // SUPERTREND 21 | atrPeriod2 = input(11, "ATR Length", group="SUPERTREND 2") 22 | factor2 = input(2, "Factor", group="SUPERTREND 2") 23 | [supertrend2, direction2] = supertrend(factor2, atrPeriod2) 24 | plot(direction2 < 0 ? supertrend2 : na, "Up Trend 2", color = color.green, style=plot.style_linebr) 25 | plot(direction2 < 0 ? na : supertrend2, "Down Trend 2", color = color.red, style=plot.style_linebr) 26 | 27 | // STRATEGY 28 | showShort = input(false, title="Show Short entries", group="Strategy") 29 | 30 | buy = close > maTend and k < 20 and crossover(k, d) and direction2 < 0 31 | sell = close < maTend and k > 80 and crossunder(k, d) and direction2 > 0 32 | closeBuy = k > 80 and crossunder(k, d) 33 | closeSell = k < 20 and crossover(k, d) 34 | 35 | // LONG 36 | strategy.entry("Long", true, when=buy) 37 | strategy.close("Long", when=closeBuy) 38 | 39 | // SHORT 40 | if showShort 41 | strategy.entry("Short", false, when=sell) 42 | strategy.close("Short", when=closeSell) -------------------------------------------------------------------------------- /strategies/StratBase.pine: -------------------------------------------------------------------------------- 1 | //@version=5 2 | strategy('Strat base [Alorse]', overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=1000, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.1) 3 | 4 | txtVer = '0.0.1' 5 | version = input.string(title='Version', defval=txtVer, options=[txtVer], tooltip='This is informational only, nothing will change.\n\nEntry conditions:\n') 6 | src = input(title='Source', defval=close) 7 | 8 | 9 | // Strategy 10 | stratGroup = 'Strategy' 11 | showLong = input.bool(true, title='Long entries', group=stratGroup) 12 | showShort = input.bool(false, title='Short entries', group=stratGroup) 13 | 14 | // Moving Averages 15 | len_a = input.int(10, minval=1, title='EMA A Length', group='Moving Averages') 16 | out_a = ta.ema(close, len_a) 17 | plot(out_a, title='EMA A', color=color.purple) 18 | 19 | 20 | entryLong = 21 | entryShort = 22 | exitLong = 23 | exitShort = 24 | 25 | tpGroup = 'Take Profit' 26 | useTP = input.bool(false, title='╔══════   Enable   ══════╗', group=tpGroup) 27 | TPPercent = input.float(1.2, step=0.1, title='Percent', group=tpGroup) * 0.01 28 | 29 | longTP = useTP ? strategy.position_avg_price * (1 + TPPercent) : na 30 | shortTP = useTP ? strategy.position_avg_price * (1 - TPPercent) : na 31 | 32 | // Stop Loss 33 | slGroup = 'Stop Loss' 34 | useSL = input.bool(false, title='╔══════   Enable   ══════╗', group=slGroup) 35 | SLPercent = input.float(1.8, title='Percent', group=slGroup) * 0.01 36 | 37 | longStop = useSL ? strategy.position_avg_price * (1 - SLPercent) : na 38 | shortStop = useSL ? strategy.position_avg_price * (1 + SLPercent) : na 39 | 40 | bought = strategy.opentrades[0] == 1 and strategy.position_size[0] > strategy.position_size[1] 41 | entry_price = ta.valuewhen(bought, open, 0) 42 | 43 | if showLong 44 | strategy.entry('Long', strategy.long, when=entryLong) 45 | strategy.close('Long', when=exitLong) 46 | strategy.exit('TP', 'Long', limit=longTP, stop=longStop) 47 | if showShort 48 | strategy.entry('Short', strategy.short, when=entryShort) 49 | strategy.close('Short', when=exitShort) 50 | strategy.exit('TP', 'Short', limit=shortTP, stop=shortStop) -------------------------------------------------------------------------------- /strategies/Strategy Tester [Lupown].pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © Lupown 3 | // i got inpiration from @The art of trading 4 | 5 | //@version=5 6 | strategy('Strategy Tester', shorttitle='StrategyTest', overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=1000, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.01) 7 | 8 | lengthM = input.int(20, title='Length', minval=1, step=1, group='Momentum Indicator') 9 | srcM = input(close, title='Source', group='Momentum Indicator') 10 | 11 | adxlen = input.int(14, title = "ADX Smoothing", group='Directional Movement Index') 12 | dilen = input.int(14, title = "DI Length", group='Directional Movement Index') 13 | keyLevel = input.int(23, title = "Key level for ADX", group='Directional Movement Index') 14 | 15 | source_ATR = input(close, title='Source', group='Average True Range') 16 | length_ATR = input.int(14, minval=1, title='Period', group='Average True Range') 17 | multiplier = input.float(1.6, minval=0.1, step=0.1, title='Multiplier', group='Average True Range') 18 | shortStopLoss = source_ATR + ta.atr(length_ATR) * multiplier 19 | longStopLoss = source_ATR - ta.atr(length_ATR) * multiplier 20 | structureLookback = input(1, title='Lookback', group='Average True Range') 21 | 22 | momentum = input(false, title='Salir por momentum', tooltip='Cuando el Momentum Indicator se gire a la baja.') 23 | estrategia = input(true, title='Salir por estrategia', tooltip='') 24 | drawTester = input(true, title='Mostrar estadísticas', tooltip='Muestra un cuadro en la parte inferior derecha del gráfico con las estadisticas de la estrategia en la temporalidad actual.') 25 | 26 | //Momentum 27 | sz = ta.linreg(srcM - math.avg(math.avg(ta.highest(high, lengthM), ta.lowest(low, lengthM)), ta.sma(close, lengthM)), lengthM, 0) 28 | lbR = 1 29 | lbL = 1 30 | 31 | //FUNCTIONS 32 | plFound(osc) => 33 | na(ta.pivotlow(osc, lbL, lbR)) ? false : true 34 | phFound(osc) => 35 | na(ta.pivothigh(osc, lbL, lbR)) ? false : true 36 | 37 | [adxValue, diplus, diminus] = ta.dmi(dilen, adxlen) 38 | 39 | buy_cond1 = phFound(sz) and adxValue < adxValue[1] ? true : false 40 | buy_cond2 = phFound(adxValue) and sz >= sz[1] and sz < 0 ? true : false 41 | 42 | buy_c = buy_cond1 or buy_cond2 43 | 44 | 45 | sell_cond1 = phFound(sz) and adxValue < adxValue[1] ? true : false 46 | sell_cond2 = phFound(adxValue) and sz < sz[1] and sz > 0 and adxValue > keyLevel ? true : false 47 | 48 | sell_c = sell_cond1 or sell_cond2 49 | 50 | goLongCondition1 = buy_c 51 | goLongCondition2 = true 52 | inTradeL = strategy.position_size > 0 53 | notInTrade = strategy.position_size == 0 54 | inTradeS = strategy.position_size < 0 55 | goShortCondition1 = false //sell_c// 56 | goShortCondition2 = false 57 | exitL = phFound(sz) 58 | var longStop = 0.0 59 | var shortStopl = 0.0 60 | var limitL = 0.0 61 | var limitS = 0.0 62 | var longslp = 0.0 63 | 64 | 65 | //timePeriod = time >= timestamp(syminfo.timezone, 2020, 11, 1, 0, 0) 66 | if goLongCondition1 and notInTrade 67 | strategy.entry('long', strategy.long, when=inTradeL != true) 68 | limitL := shortStopLoss + shortStopLoss - close 69 | strategy.exit('exit', 'long', stop=longStopLoss) //,limit = limitL //limit is if you wanna have 1:1 70 | longStop := longStopLoss 71 | longStop 72 | 73 | if goShortCondition1 and notInTrade //in this code go ShortCondition is false by default 74 | strategy.entry('short', strategy.short, when=inTradeS != true) 75 | limitS := longStopLoss - (close - longStopLoss) 76 | strategy.exit('exitShort', 'short', stop=shortStopLoss) //, limit = limitS //limit is if you wanna have 1:1 77 | shortStopl := shortStopLoss 78 | shortStopl 79 | 80 | 81 | var trailPrice = 0.0 82 | var trailPrices = 0.0 83 | atr = ta.atr(length_ATR) 84 | t_trailPrice = ta.lowest(low, structureLookback) - atr * multiplier 85 | t_trailPrices = ta.lowest(low, structureLookback) + atr * multiplier 86 | 87 | 88 | if inTradeL and sell_c and estrategia 89 | strategy.close_all() 90 | if inTradeL and exitL and momentum 91 | strategy.close_all() 92 | 93 | truncate(_number, _decimalPlaces) => 94 | _factor = math.pow(10, _decimalPlaces) 95 | int(_number * _factor) / _factor 96 | 97 | // Prepare stats table 98 | var table testTable = table.new(position.bottom_right, 5, 2, border_width=1) 99 | f_fillCell(_table, _column, _row, _title, _value, _bgcolor, _txtcolor) => 100 | _cellText = _title + '\n' + _value 101 | table.cell(_table, _column, _row, _cellText, bgcolor=_bgcolor, text_color=_txtcolor) 102 | 103 | // Draw stats table 104 | var bgcolor = color.new(color.black, 0) 105 | if drawTester 106 | if barstate.islastconfirmedhistory 107 | percent = strategy.netprofit * 100 / strategy.initial_capital 108 | f_fillCell(testTable, 0, 0, 'Total Trades:', str.tostring(strategy.closedtrades), bgcolor, color.white) 109 | f_fillCell(testTable, 0, 1, 'Win Rate:', str.tostring(truncate(strategy.wintrades / strategy.closedtrades * 100, 2)) + '%', bgcolor, color.white) 110 | f_fillCell(testTable, 1, 0, 'Starting:', '$' + str.tostring(strategy.initial_capital), bgcolor, color.white) 111 | f_fillCell(testTable, 1, 1, 'Ending:', '$' + str.tostring(truncate(strategy.initial_capital + strategy.netprofit, 2)), bgcolor, color.white) 112 | f_fillCell(testTable, 2, 0, 'Return:', '$' + str.tostring(truncate(strategy.netprofit, 2)), strategy.netprofit > 0 ? color.green : color.red, color.white) 113 | f_fillCell(testTable, 2, 1, '% return:', (percent > 0 ? '+' : '') + str.tostring(truncate(percent, 2)), percent > 0 ? color.green : color.red, color.white) 114 | -------------------------------------------------------------------------------- /strategies/Supertrend + EMA rebound [Alorse].pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © alorse 3 | 4 | //@version=5 5 | strategy(title='Supertrend + EMA rebound [Alorse]', overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=10000, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.1) 6 | 7 | // Backtesting 8 | btGroup = "Backtesting" 9 | startTime = input.time(title="Start time", defval=timestamp("Nov 01 2021 23:59:59"), group=btGroup) 10 | endTime = input.time(title="End time", defval=timestamp("Feb 01 2099 23:59:59"), group=btGroup) 11 | 12 | inDateRange = time >= startTime and time <= endTime 13 | 14 | atrPeriod = input(10, "ATR Length") 15 | factor = input.float(3.0, "Factor", step = 0.1) 16 | 17 | [supertrend, direction] = ta.supertrend(factor, atrPeriod) 18 | 19 | inLong = direction < 0 20 | inShort = direction > 0 21 | 22 | upTrend = plot(inLong? supertrend : na, "Up Trend", color = color.green, style=plot.style_linebr) 23 | downTrend = plot(inShort ? supertrend : na, "Down Trend", color = color.red, style=plot.style_linebr) 24 | 25 | bodyMiddle = plot((open + close) / 2, display=display.none) 26 | fill(bodyMiddle, upTrend, color.new(color.green, 90), fillgaps=false) 27 | fill(bodyMiddle, downTrend, color.new(color.red, 90), fillgaps=false) 28 | 29 | // Moving Averages 30 | len_a = input.int(20, minval=1, title='EMA A Length', group='Moving Average') 31 | out_a = ta.ema(close, len_a) 32 | plot(out_a, title='EMA A', color=color.yellow) 33 | 34 | lastEntry = strategy.opentrades.entry_price(0) 35 | // Strategy Conditions 36 | stratGroup = 'Strategy' 37 | showLong = input.bool(true, title='Long entries', group=stratGroup) 38 | showShort = input.bool(true, title='Short entries', group=stratGroup) 39 | entryLong = ta.change(direction) < 0 40 | entryLong := entryLong or (inLong and close[1] < out_a and close > out_a and close < lastEntry) 41 | exitLong = ta.change(direction) > 0 42 | 43 | entryShort = ta.change(direction) > 0 44 | entryShort := entryShort or (inShort and close[1] > out_a and close < out_a and close > lastEntry) 45 | exitShort = ta.change(direction) < 0 46 | 47 | tpGroup = 'Take Profit' 48 | useTP = input.string(title='Type', defval='Supertrend', options=['Supertrend', '%'], group=tpGroup, tooltip='Supertrend: \nPercent (%): \nRatio:') 49 | TPPercent = input.float(1.5, step=0.1, title='Percent/Ratio', group=tpGroup) 50 | 51 | longTP = 99999999999.9 52 | shortTP = 0.0 53 | 54 | bought = strategy.opentrades[0] == 1 and strategy.position_size[0] > strategy.position_size[1] 55 | entry_price = ta.valuewhen(bought, open, 0) 56 | 57 | if useTP == '%' 58 | longTP := strategy.position_avg_price * (1 + (TPPercent * 0.01)) 59 | shortTP := strategy.position_avg_price * (1 - (TPPercent * 0.01)) 60 | else 61 | longTP := na 62 | shortTP := na 63 | 64 | if showLong and inDateRange 65 | strategy.entry("Long", strategy.long, when=entryLong) 66 | strategy.close("Long", when=exitLong) 67 | strategy.exit("Exit", "Long", limit=longTP) 68 | 69 | if showShort and inDateRange 70 | strategy.entry("Short", strategy.short, when=entryShort) 71 | strategy.close("Short", when=exitShort) 72 | strategy.exit("Exit", "Short", limit=shortTP) 73 | -------------------------------------------------------------------------------- /strategies/Supertrend + RSI.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // © alorse 3 | 4 | //@version=5 5 | strategy("Supertrend + RSI Strategy [Alose]", overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=1000, default_qty_value=20, commission_type=strategy.commission.percent, commission_value=0.01) 6 | 7 | stGroup = 'Supertrend' 8 | atrPeriod = input(10, "ATR Length", group=stGroup) 9 | factor = input.float(3.0, "Factor", step = 0.01, group=stGroup) 10 | 11 | [_, direction] = ta.supertrend(factor, atrPeriod) 12 | 13 | inLong = direction < 0 14 | inShort = direction > 0 15 | 16 | // RSI 17 | rsiGroup = 'RSI' 18 | src = input(title='Source', defval=close, group=rsiGroup) 19 | lenRSI = input.int(14, title='Length', minval=1, group=rsiGroup) 20 | RSI = ta.rsi(src, lenRSI) 21 | 22 | // Strategy Conditions 23 | stratGroup = 'Strategy' 24 | showLong = input.bool(true, title='Long entries', group=stratGroup) 25 | showShort = input.bool(false, title='Short entries', group=stratGroup) 26 | TPPercent = input.float(1.2, step=0.1, title='TP', group=stratGroup) 27 | RSIoverbought = input.int(72, title='Exit Long', minval=1, group=stratGroup, tooltip='The trade will close when the RSI crosses up this point.') 28 | RSIoversold = input.int(28, title='Exit Short', minval=1, group=stratGroup, tooltip='The trade will close when the RSI crosses below this point.') 29 | 30 | entryLong = inLong and RSI[1] < 50 and RSI > 50 31 | exitLong = RSI > RSIoverbought or ta.change(direction) > 0 32 | 33 | entryShort = inShort and RSI[1] > 50 and RSI < 50 34 | exitShort = RSI < RSIoversold or ta.change(direction) < 0 35 | 36 | longTP = strategy.position_avg_price * (1 + (TPPercent * 0.01)) 37 | shortTP = strategy.position_avg_price * (1 - (TPPercent * 0.01)) 38 | 39 | if showLong 40 | strategy.entry("Long", strategy.long, when=entryLong) 41 | // strategy.exit("Exit", "Long", limit=longTP) 42 | strategy.close("Long", when=exitLong) 43 | 44 | if showShort 45 | strategy.entry("Short", strategy.short, when=entryShort) 46 | // strategy.exit("Exit", "Short", limit=shortTP) 47 | strategy.close("Short", when=exitShort) 48 | -------------------------------------------------------------------------------- /strategies/Supertrend.pine: -------------------------------------------------------------------------------- 1 | //@version=4 2 | strategy("Supertrend [Alorse]", overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=1000, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.01) 3 | 4 | stGroup = "Supertrend" 5 | src = input(hl2, title="Source", group=stGroup) 6 | Periods = input(title="ATR Period", type=input.integer, defval=10, group=stGroup) 7 | Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.7, group=stGroup) 8 | atr= atr(Periods) 9 | up=src-(Multiplier*atr) 10 | up1 = nz(up[1],up) 11 | up := close[1] > up1 ? max(up,up1) : up 12 | dn=src+(Multiplier*atr) 13 | dn1 = nz(dn[1], dn) 14 | dn := close[1] < dn1 ? min(dn, dn1) : dn 15 | trend = 1 16 | trend := nz(trend[1], trend) 17 | trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend 18 | upPlot = plot(trend == 1 ? up : na, title="Up Signal", style=plot.style_linebr, linewidth=2, color=color.green) 19 | dnPlot = plot(trend == 1 ? na : dn, title="Down Signal", style=plot.style_linebr, linewidth=2, color=color.red) 20 | 21 | 22 | // Strategy 23 | stratGroup = "Strategy" 24 | barsBack = input(title="Bars back", type=input.integer, minval=0, maxval=100, defval=2, group=stratGroup, tooltip="") 25 | tpFactor = input(title="Take profit factor", type=input.float, minval=0, maxval=100, defval=1.5, group=stratGroup, tooltip="") 26 | 27 | buySignal = trend == 1 and trend[1] == -1 28 | sellSignal = trend == -1 and trend[1] == 1 29 | float slBuy = 0.0 30 | slBuy := strategy.position_size == 0 ? lowest(barsBack) : na(slBuy[1]) ? na : slBuy[1] 31 | float slSell = 0.0 32 | slSell := strategy.position_size == 0 ? highest(barsBack) : na(slSell[1]) ? na : slSell[1] 33 | 34 | entry_price = 0.0 35 | entry_price := buySignal ? close : sellSignal ? close : na(entry_price[1]) ? na : entry_price[1] 36 | 37 | tpBuy = entry_price + ((entry_price - slBuy) * tpFactor) 38 | tpSell = entry_price - ((slSell - entry_price) * tpFactor) 39 | 40 | 41 | strategy.entry("Long", true, when=buySignal) 42 | strategy.exit("Exit", "Long", stop=slBuy, limit=tpBuy) 43 | 44 | // strategy.entry("Short", false, when=sellSignal) 45 | // strategy.exit("Exit", "Short", stop=slSell, limit=tpSell) 46 | 47 | -------------------------------------------------------------------------------- /strategies/TTM Squeeze.pine: -------------------------------------------------------------------------------- 1 | //@version=5 2 | strategy(title='TTM Squeeze [Alorse]', overlay=false, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=1000, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.01) 3 | length = input.int(title='Length', defval=20, minval=0) 4 | bband(length, mult) => 5 | ta.sma(close, length) + mult * ta.stdev(close, length) 6 | keltner(length, mult) => 7 | ta.ema(close, length) + mult * ta.ema(ta.tr, length) 8 | 9 | e1 = (ta.highest(high, length) + ta.lowest(low, length)) / 2 + ta.sma(close, length) 10 | osc = ta.linreg(close - e1 / 2, length, 0) 11 | diff = bband(length, 2) - keltner(length, 1) 12 | 13 | osc_color = osc[1] < osc[0] ? osc[0] >= 0 ? color.lime : color.maroon : osc[0] >= 0 ? color.green : color.red 14 | mid_color = diff >= 0 ? color.white : color.black 15 | 16 | len = input.int(14, minval=1, title='Length', group='RSI') 17 | src = input.source(close, 'Source', group='RSI') 18 | rsi = ta.rsi(src, len) 19 | 20 | tpGroup = 'Take Profit' 21 | useTP = input.bool(false, title='╔══════   Enable   ══════╗', group=tpGroup) 22 | TPPercent = input.float(1.2, step=0.1, title='Percent', group=tpGroup) * 0.01 23 | 24 | longTP = strategy.position_avg_price * (1 + TPPercent) 25 | shortTP = strategy.position_avg_price * (1 - TPPercent) 26 | 27 | // Strategy 28 | buy = osc < 0 and osc[1] < osc[0] and osc[2] < osc[0] and ta.crossover(rsi, 30) 29 | sell = osc > 0 and osc[1] > osc[0] and osc[2] > osc[0] and ta.crossunder(rsi, 70) 30 | strategy.entry('Long', strategy.long, when=buy) 31 | strategy.exit('Exit', 'Long', stop=na, limit=longTP) 32 | 33 | strategy.entry('Short', strategy.short, when=sell) 34 | strategy.exit('Exit', 'Short', stop=na, limit=shortTP) 35 | 36 | plot(osc, color=osc_color, style=plot.style_area, linewidth=1) 37 | plot(0, color=mid_color, style=plot.style_circles, linewidth=1) 38 | -------------------------------------------------------------------------------- /strategies/Tendency EMA + RSI.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | //@author Alorse 3 | 4 | //@version=5 5 | strategy(title='Tendency EMA + RSI [Alorse]', shorttitle='Tendece EMA + RSI [Alorse]', overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=1000, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.1) 6 | 7 | // Bollinger Bands 8 | len = input.int(14, minval=1, title='Length', group='RSI') 9 | src = input.source(close, 'Source', group='RSI') 10 | rsi = ta.rsi(src, len) 11 | 12 | // Moving Averages 13 | len_a = input.int(10, minval=1, title='EMA A Length', group='Moving Averages') 14 | out_a = ta.ema(close, len_a) 15 | plot(out_a, title='EMA A', color=color.purple) 16 | 17 | len_b = input.int(20, minval=1, title='EMA B Length', group='Moving Averages') 18 | out_b = ta.ema(close, len_b) 19 | plot(out_b, title='EMA B', color=color.orange) 20 | 21 | len_c = input.int(100, minval=1, title='EMA C Length', group='Moving Averages') 22 | out_c = ta.ema(close, len_c) 23 | plot(out_c, title='EMA C', color=color.green) 24 | 25 | // Strategy Conditions 26 | stratGroup = 'Strategy' 27 | showLong = input.bool(true, title='Long entries', group=stratGroup) 28 | showShort = input.bool(false, title='Short entries', group=stratGroup) 29 | closeAfterXBars = input.bool(true, title='Close after X # bars', tooltip='If trade is in profit', group=stratGroup) 30 | xBars = input.int(24, title='# bars') 31 | 32 | entryLong = ta.crossover(out_a, out_b) and out_a > out_c and close > open 33 | exitLong = rsi > 70 34 | 35 | entryShort = ta.crossunder(out_a, out_b) and out_a < out_c and close < open 36 | exitShort = rsi < 30 37 | 38 | 39 | bought = strategy.opentrades[0] == 1 and strategy.position_size[0] > strategy.position_size[1] 40 | entry_price = ta.valuewhen(bought, open, 0) 41 | var int nPastBars = 0 42 | if strategy.position_size > 0 or strategy.position_size < 0 43 | nPastBars := nPastBars + 1 44 | if strategy.position_size == 0 45 | nPastBars := 0 46 | if closeAfterXBars 47 | exitLong := nPastBars >= xBars and close > entry_price ? true : exitLong 48 | exitShort := nPastBars >= xBars and close < entry_price ? true : exitShort 49 | 50 | // Long Entry 51 | strategy.entry('Long', strategy.long, when=entryLong and showLong) 52 | strategy.close('Long', when=exitLong) 53 | 54 | // Short Entry 55 | strategy.entry('Short', strategy.short, when=entryShort and showShort) 56 | strategy.close('Short', when=exitShort) 57 | -------------------------------------------------------------------------------- /strategies/Williams Vix Fix.pine: -------------------------------------------------------------------------------- 1 | //@version=4 2 | strategy("Williams Vix Fix Strategy [Alorse]", shorttitle="WVF STRTG [Alorse]", overlay=false, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=1000, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.01) 3 | 4 | // Bollinger Bands 5 | bbGroup = "Bollindger Bands" 6 | src = input(title="Source", type=input.source, defval=close, group=bbGroup) 7 | bbl = input(20, title="Length", group=bbGroup) 8 | mult = input(2.0, minval=1, maxval=5, title="Standard Deviation", group=bbGroup) 9 | 10 | basis = sma(src, bbl) 11 | dev = mult * stdev(src, bbl) 12 | upper = basis + dev 13 | lower = basis - dev 14 | 15 | // Williams Vix Fix 16 | wvfGroup = "Williams Vix Fix" 17 | pd = input(20, title="LookBack Period StdDev", tooltip="LookBack Period Standard Deviation", group=wvfGroup) 18 | lb = input(50, title="LookBack Period Percentile", group=wvfGroup) 19 | ph = input(85, title="Highest Percentile", group=wvfGroup) * 0.01 20 | pl = input(99, title="Lowest Percentile", group=wvfGroup)*0.01 21 | 22 | wvf = ((highest(close, pd)-low)/(highest(close, pd)))*100 23 | sDev = mult * stdev(wvf, bbl) 24 | midLine = sma(wvf, bbl) 25 | upperBand = midLine + sDev 26 | rangeHigh = highest(wvf, lb) * ph 27 | colNormal = wvf >= upperBand or wvf >= rangeHigh ? color.lime : color.new(color.silver, 20) 28 | 29 | 30 | wvfInv = ((high-lowest(close, pd))/lowest(close, pd))*100 31 | sDevInv = mult * stdev(wvfInv, bbl) 32 | midLineInv = sma(wvfInv, bbl) 33 | upperBandInv = midLineInv + sDevInv 34 | rangeHighInv = lowest(wvfInv, lb) * pl 35 | colInv = wvfInv <= upperBandInv or wvfInv <= rangeHighInv ? color.new(color.silver, 20) : color.orange 36 | 37 | sellCond = (wvfInv <= upperBandInv or wvfInv <= rangeHighInv) and (wvfInv[1] <= upperBandInv[1] or wvfInv[1] <= rangeHighInv[1]) and close < upper ? false : true 38 | 39 | buy = (wvf >= upperBand or wvf >= rangeHigh) and (wvf[1] >= upperBand[1] or wvf[1] >= rangeHigh[1]) and close < lower 40 | sell = sellCond and close > upper 41 | 42 | strategy.entry("Long", true, when=buy) 43 | strategy.close("Long", when=sell) 44 | 45 | plot(wvf, title="Williams Vix Fix", style=plot.style_columns, color=colNormal) 46 | plot(upperBand, title="Normal StdDev line", style=plot.style_line, linewidth=1,color=color.blue) 47 | 48 | plot(0, title="Cero line", color=color.white, style=plot.style_line) 49 | 50 | plot(wvfInv*-1, title="Williams Vix Fix Inverted", style=plot.style_columns, color=colInv) 51 | plot(upperBandInv*-1, title="Inverted StdDev line", style=plot.style_line, linewidth=1,color=color.blue) -------------------------------------------------------------------------------- /strategies/estrategia10:20ema copy.pine: -------------------------------------------------------------------------------- 1 | //@version=4 2 | strategy(title="3 EMA/SMA + Cross Strategy [Alorse]", overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, default_qty_value=100) 3 | 4 | // STEP 1: 5 | // Set stop loss level with input options (optional) 6 | src = input(title="Source", type=input.source, defval=close) 7 | SP = input(title="Short Stop Loss (%)", type=input.float, minval=0.0, step=0.1, defval=99) * 0.01 8 | lenFast = input(10, minval=1, title="Fast EMA") 9 | lenSlow = input(20, minval=1, title="Slow EMA") 10 | lenTend = input(100, minval=1, title="Tendence EMA") 11 | 12 | // Calculate moving averages 13 | fastEMA = ema(src, lenFast) 14 | slowEMA = ema(src, lenSlow) 15 | tendEMA = ema(src, lenTend) 16 | 17 | // Plot moving averages 18 | plot(fastEMA, color=#c643dc) 19 | plot(slowEMA, color=color.orange) 20 | plot(tendEMA, color=color.white) 21 | 22 | // Calculate trading conditions 23 | crossover = crossover(fastEMA, slowEMA) 24 | crossunder = crossunder(fastEMA, slowEMA) 25 | plot(crossover or crossunder ? fastEMA : na, style=plot.style_cross, title="Cross", linewidth=2, color=color.white) 26 | 27 | crossBack = input(title="Check Cross in the last # candles", type=input.integer, defval=10, group="Strategy") 28 | 29 | // LONG 30 | wasCrossLong = false 31 | enterLong = false 32 | for i = 1 to crossBack 33 | if crossover(fastEMA[i], slowEMA[i]) 34 | wasCrossLong := true 35 | break 36 | 37 | // numBars = 0 38 | // if fastEMA > slowEMA 39 | // numBars := numBars[1] + 1 40 | // else 41 | // numBars := 0 42 | 43 | // inCross = barssince(crossover(fastEMA, slowEMA)) 44 | // inCross := inCross > crossBack ? crossBack : inCross 45 | // count = 0 46 | // for i = 1 to inCross 47 | // if low[i] <= fastEMA[i] 48 | // count := count + 1 49 | 50 | if close[0] >= fastEMA and low[1] <= fastEMA and tendEMA <= close[0] 51 | enterLong := true 52 | 53 | // SHORT 54 | // wasCrossShort = false 55 | // enterShort = false 56 | // for i = 1 to crossBack 57 | // if crossunder(fastEMA[i], slowEMA[i]) 58 | // wasCrossShort := true 59 | // break 60 | 61 | // count := 0 62 | // for i = 1 to 5 63 | // if high[i] >= fastEMA[i] 64 | // count += 1 65 | 66 | // if close[0] <= fastEMA and high[1] >= fastEMA and tendEMA >= close[0] //and count < (inCross/2) 67 | // enterShort := true 68 | 69 | // STEP 2: 70 | // Determine stop loss price 71 | longStopPrice = strategy.position_avg_price * (1 - SP) 72 | shortStopPrice = strategy.position_avg_price * (1 + SP) 73 | 74 | // Plot stop loss values for confirmation 75 | // plot((strategy.position_size > 0) ? longStopPrice : na, 76 | // color=color.new(color.red, 30), style=plot.style_linebr, 77 | // linewidth=1, title="Long Stop Loss") 78 | // plot((strategy.position_size < 0) ? shortStopPrice : na, 79 | // color=color.new(color.red, 30), style=plot.style_linebr, 80 | // linewidth=1, title="Short Stop Loss") 81 | 82 | // Submit entry orders 83 | strategy.entry("Long", true, when=wasCrossLong and enterLong) 84 | strategy.close("Long", when=crossunder(fastEMA, slowEMA)) 85 | // strategy.entry("Short", false, when=wasCrossShort and enterShort) 86 | // strategy.close("Short", when=crossover(fastEMA, slowEMA)) 87 | 88 | // STEP 3: 89 | // Submit exit orders based on calculated stop loss price 90 | if (strategy.position_size > 0) 91 | strategy.exit(id="Exit", stop=longStopPrice) 92 | 93 | if (strategy.position_size < 0) 94 | strategy.exit(id="Exit", stop=shortStopPrice) -------------------------------------------------------------------------------- /strategies/velaSuperada.pine: -------------------------------------------------------------------------------- 1 | //@version=5 2 | strategy('Improvisando [Alorse]', overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=1000, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.1) 3 | 4 | txtVer = '0.0.1' 5 | version = input.string(title='Version', defval=txtVer, options=[txtVer], tooltip='This is informational only, nothing will change.\n\nEntry conditions:\n') 6 | src = input(title='Source', defval=close) 7 | 8 | 9 | // Strategy 10 | stratGroup = 'Strategy' 11 | showLong = input.bool(true, title='Long entries', group=stratGroup) 12 | showShort = input.bool(false, title='Short entries', group=stratGroup) 13 | 14 | // Moving Averages 15 | len_a = input.int(10, minval=1, title='EMA A Length', group='Moving Averages') 16 | out_a = ta.ema(close, len_a) 17 | plot(out_a, title='EMA A', color=color.purple) 18 | 19 | // RSI 20 | len = input.int(14, minval=1, title='Length', group='RSI') 21 | rsi = ta.rsi(close, len) 22 | 23 | // MACD 24 | fast_length = 12 25 | slow_length = 26 26 | fast_ma = ta.ema(src, fast_length) 27 | slow_ma = ta.ema(src, slow_length) 28 | macd = fast_ma - slow_ma 29 | 30 | buy = close[1] < open[1] and close > open[1] 31 | sell = close[1] > open[1] and close < open[1] 32 | 33 | entryLong = buy and close > out_a and close[1] > out_a and rsi < 65 and macd[0] > macd[1] 34 | entryShort = sell and close < out_a and close[1] < out_a and rsi > 35 and macd[0] < macd[1] 35 | 36 | tpGroup = 'Take Profit' 37 | // useTP = input.bool(false, title='╔══════   Enable   ══════╗', group=tpGroup) 38 | TPPercent = input.float(1.2, step=0.1, title='Percent', group=tpGroup) * 0.01 39 | 40 | longTP = strategy.position_avg_price * (1 + TPPercent) 41 | shortTP = strategy.position_avg_price * (1 - TPPercent) 42 | 43 | // Stop Loss 44 | slGroup = 'Stop Loss' 45 | // useSL = input.bool(false, title='╔══════   Enable   ══════╗', group=slGroup) 46 | SLPercent = input.float(1.8, title='Percent', group=slGroup) * 0.01 47 | 48 | longStop = strategy.position_avg_price * (1 - SLPercent) 49 | shortStop = strategy.position_avg_price * (1 + SLPercent) 50 | 51 | bought = strategy.opentrades[0] == 1 and strategy.position_size[0] > strategy.position_size[1] 52 | entry_price = ta.valuewhen(bought, open, 0) 53 | 54 | AvgLongTP = (longTP + entry_price) / 2 55 | AvgShortTP = (shortTP - entry_price) / 2 56 | 57 | TlongStop = 0.0 58 | TshortStop = 0.0 59 | TlongStop := close > AvgLongTP ? strategy.position_avg_price * (1.002) : math.max(TlongStop[1], longStop) 60 | TshortStop := close < AvgShortTP ? strategy.position_avg_price * (1 - 0.002) : math.max(TshortStop[1], shortStop) 61 | 62 | exitLong2 = close > close[1] and close[1] > close[2] and close[2] > close[3] and close > strategy.position_avg_price * (1.004) 63 | exitShort2 = close < close[1] and close[1] < close[2] and close[2] < close[3] and close < strategy.position_avg_price * (1 - 0.004) 64 | 65 | if showLong 66 | strategy.entry('Long', strategy.long, when=entryLong) 67 | strategy.close('Long', when=close < TlongStop or exitLong2) 68 | strategy.exit('TP', 'Long', limit=longTP, stop=longStop) 69 | if showShort 70 | strategy.entry('Short', strategy.short, when=entryShort) 71 | strategy.close('Short', when=close > TshortStop or exitShort2) 72 | strategy.exit('TP', 'Short', limit=shortTP, stop=shortStop) --------------------------------------------------------------------------------