Strategy · Pine Script v5 · On the chart

Big Snapper Chaiking Volatility + TP RSI

by hasnocool

This strategy builds upon the Big Snapper system by combining trend-following moving averages, Chaikin Volatility, and volume filtering to generate trade signals directly on the main chart.

View on GitHub

GitHub stars106on the repository
Pine versionv5runs as is
Lines of code875
Settings40inputs
LicenceGPL-3.0
Last update2 years ago18 Sep 2024

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

875 lines of Pine Script v5 from Big Snapper Alerts R3.0 + Chaiking Volatility condition + TP RSI.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

Big Snapper Alerts R3.0 + Chaiking Volatility condition + TP RSI.pine
//@version=5
//
// Bannos
// #NotTradingAdvice #DYOR
// Disclaimer.
// I AM NOT A FINANCIAL ADVISOR.
// THESE IDEAS ARE NOT ADVICE AND ARE FOR EDUCATION PURPOSES ONLY.
// ALWAYS DO YOUR OWN RESEARCH
//
// Author:  Adaptation from JustUncleL Big Snapper by Bannos
// Date:    May-2022
// Last:    Nov-2022 
// Version: R4.0
//Description of this addon - Script using several new conditions to give Long/short and SL levels which was not proposed in the Big Snapper strategy "Big Snapper Alerts R3.0"
//"
//This strategy is based on the use of the Big Snapper outputs from the JustUncleL script and the addition of several conditions to define filtered conditions selecting signal synchrones with a trend and a rise of the volatility.
//Also the strategy proposes to define proportional stop losses and dynamic Take profit using an RSI strategy.
// After delivering the temporary ong/short signal and ploting a green or purple signal, several conditions are defined to consider a Signal is Long or short.
//Let s take the long signal as example(this is the same process with the opposite values for a short).
//step 1 - Long Definition:
    // Snapper long signal stored in the buffer variable Longbuffer to say that in a close future, we could have all conditions for a long
    // Now we need some conditions to combine with it: 
    //the second one is to be over the Ma_medium(55) 
    //and because this is not selective enough, the third one is a Volatility indicator "Chaikin Volatility" indicator giving an indication about the volatility of the price compared to the 10 last values
    // -> Using the volatility indicator gives the possibility to increase the potential rise if the volatility is higher compared to the last periods.
    //With these 3 signals, we get a robust indication about a potential long signal which is then stored in the variable "Longe"
    
    //Now we have a long signal and can give a long signal with its Stop Loss
    // The Long Signal is automatically given as the 3 conditions above are satisfied.
    // The Stop loss is a function of the last Candle sizes giving a stop below the 70% of the overall candle which can be assimilated to a Fibonacci level. Below this level it makes sense to stop the trade as the chance to recover the complete Candle is more than 60% 
    
    //Now we are in an open Long and can use all the mentioned Stop loss condition but still need a Take Profit condition
    //The take profit condition is based on a RSI strategy consisting in taking profit as soon as the RSI come back from the overbought area (which is here defined as a rsi over 70) and reaching the 63.5 level to trigger the Take Profit
    //This TP condition is only active when Long is active and when an entry value as been defined.
    
    //Entry and SL level appreas as soon as a Long or short arrow signal does appears. The Take profit will be conidtioned to the RSI.
    
    //The final step in the cycle is a reinitialization of all the values giving the possibility to detect and treat any long new signal coming from the Big Snapper signal.
//-------------------------------------------------------------------------------------------------------
strategy(title='Big Snapper Chaiking Volatility + TP RSI + Trend determination using RVWAP + spkie filtering using Vol. oscilator', shorttitle='SNAPPER Bannos', overlay=true)
//Super Oscillator----------------------------------------------------------------------------------------------------------------------
length = input.int(10, minval=1)
mult = input.float(2., minval=1)
smooth = input.int(72, minval=1)
//Misc
fixed = input.bool(false, 'Fixed Transparency', group='Misc')
show_ln = input.bool(true, 'Show Lines', group='Misc')
show_lb = input.bool(true, 'Show Labels', group='Misc')
show_per = input.bool(false, 'Show % False Signals', group='Misc')
//----
src = close
lowerr = 0.
upperr = 0.
trend = 0
var up_col = array.new_color(0)
var dn_col = array.new_color(0)
if barstate.isfirst
    array.push(up_col, color.new(#0cb51a, 100))
    array.push(up_col, color.new(#0cb51a, 99))
    array.push(up_col, color.new(#0cb51a, 98))
    array.push(up_col, color.new(#0cb51a, 97))
    array.push(up_col, color.new(#0cb51a, 96))
    array.push(up_col, color.new(#0cb51a, 95))
    array.push(up_col, color.new(#0cb51a, 94))
    array.push(up_col, color.new(#0cb51a, 93))
    array.push(up_col, color.new(#0cb51a, 92))
    array.push(up_col, color.new(#0cb51a, 91))
    array.push(up_col, color.new(#0cb51a, 90))
    array.push(up_col, color.new(#0cb51a, 89))
    array.push(up_col, color.new(#0cb51a, 88))
    array.push(up_col, color.new(#0cb51a, 87))
    array.push(up_col, color.new(#0cb51a, 86))
    array.push(up_col, color.new(#0cb51a, 85))
    array.push(up_col, color.new(#0cb51a, 84))
    array.push(up_col, color.new(#0cb51a, 83))
    array.push(up_col, color.new(#0cb51a, 82))
    array.push(up_col, color.new(#0cb51a, 81))
    array.push(up_col, color.new(#0cb51a, 80))
    array.push(up_col, color.new(#0cb51a, 79))
    array.push(up_col, color.new(#0cb51a, 78))
    array.push(up_col, color.new(#0cb51a, 77))
    array.push(up_col, color.new(#0cb51a, 76))
    array.push(up_col, color.new(#0cb51a, 75))
    array.push(up_col, color.new(#0cb51a, 74))
    array.push(up_col, color.new(#0cb51a, 73))
    array.push(up_col, color.new(#0cb51a, 72))
    array.push(up_col, color.new(#0cb51a, 71))
    array.push(up_col, color.new(#0cb51a, 70))
    array.push(up_col, color.new(#0cb51a, 69))
    array.push(up_col, color.new(#0cb51a, 68))
    array.push(up_col, color.new(#0cb51a, 67))
    array.push(up_col, color.new(#0cb51a, 66))
    array.push(up_col, color.new(#0cb51a, 65))
    array.push(up_col, color.new(#0cb51a, 64))
    array.push(up_col, color.new(#0cb51a, 63))
    array.push(up_col, color.new(#0cb51a, 62))
    array.push(up_col, color.new(#0cb51a, 61))
    array.push(up_col, color.new(#0cb51a, 60))
    array.push(up_col, color.new(#0cb51a, 59))
    array.push(up_col, color.new(#0cb51a, 58))
    array.push(up_col, color.new(#0cb51a, 57))
    array.push(up_col, color.new(#0cb51a, 56))
    array.push(up_col, color.new(#0cb51a, 55))
    array.push(up_col, color.new(#0cb51a, 54))
    array.push(up_col, color.new(#0cb51a, 53))
    array.push(up_col, color.new(#0cb51a, 52))
    array.push(up_col, color.new(#0cb51a, 51))
    array.push(up_col, color.new(#0cb51a, 50))
    array.push(up_col, color.new(#0cb51a, 49))
    array.push(up_col, color.new(#0cb51a, 48))
    array.push(up_col, color.new(#0cb51a, 47))
    array.push(up_col, color.new(#0cb51a, 46))
    array.push(up_col, color.new(#0cb51a, 45))
    array.push(up_col, color.new(#0cb51a, 44))
    array.push(up_col, color.new(#0cb51a, 43))
    array.push(up_col, color.new(#0cb51a, 42))
    array.push(up_col, color.new(#0cb51a, 41))
    array.push(up_col, color.new(#0cb51a, 40))
    array.push(up_col, color.new(#0cb51a, 39))
    array.push(up_col, color.new(#0cb51a, 38))
    array.push(up_col, color.new(#0cb51a, 37))
    array.push(up_col, color.new(#0cb51a, 36))
    array.push(up_col, color.new(#0cb51a, 35))
    array.push(up_col, color.new(#0cb51a, 34))
    array.push(up_col, color.new(#0cb51a, 33))
    array.push(up_col, color.new(#0cb51a, 32))
    array.push(up_col, color.new(#0cb51a, 31))
    array.push(up_col, color.new(#0cb51a, 30))
    array.push(up_col, color.new(#0cb51a, 29))
    array.push(up_col, color.new(#0cb51a, 28))
    array.push(up_col, color.new(#0cb51a, 27))
    array.push(up_col, color.new(#0cb51a, 26))
    array.push(up_col, color.new(#0cb51a, 25))
    array.push(up_col, color.new(#0cb51a, 24))
    array.push(up_col, color.new(#0cb51a, 23))
    array.push(up_col, color.new(#0cb51a, 22))
    array.push(up_col, color.new(#0cb51a, 21))
    array.push(up_col, color.new(#0cb51a, 20))
    array.push(up_col, color.new(#0cb51a, 19))
    array.push(up_col, color.new(#0cb51a, 18))
    array.push(up_col, color.new(#0cb51a, 17))
    array.push(up_col, color.new(#0cb51a, 16))
    array.push(up_col, color.new(#0cb51a, 15))
    array.push(up_col, color.new(#0cb51a, 14))
    array.push(up_col, color.new(#0cb51a, 13))
    array.push(up_col, color.new(#0cb51a, 12))
    array.push(up_col, color.new(#0cb51a, 11))
    array.push(up_col, color.new(#0cb51a, 10))
    array.push(up_col, color.new(#0cb51a, 9))
    array.push(up_col, color.new(#0cb51a, 8))
    array.push(up_col, color.new(#0cb51a, 7))
    array.push(up_col, color.new(#0cb51a, 6))
    array.push(up_col, color.new(#0cb51a, 5))
    array.push(up_col, color.new(#0cb51a, 4))
    array.push(up_col, color.new(#0cb51a, 3))
    array.push(up_col, color.new(#0cb51a, 2))
    array.push(up_col, color.new(#0cb51a, 1))
    array.push(dn_col, color.new(#ff1100, 100))
    array.push(dn_col, color.new(#ff1100, 99))
    array.push(dn_col, color.new(#ff1100, 98))
    array.push(dn_col, color.new(#ff1100, 97))
    array.push(dn_col, color.new(#ff1100, 96))
    array.push(dn_col, color.new(#ff1100, 95))
    array.push(dn_col, color.new(#ff1100, 94))
    array.push(dn_col, color.new(#ff1100, 93))
    array.push(dn_col, color.new(#ff1100, 92))
    array.push(dn_col, color.new(#ff1100, 91))
    array.push(dn_col, color.new(#ff1100, 90))
    array.push(dn_col, color.new(#ff1100, 89))
    array.push(dn_col, color.new(#ff1100, 88))
    array.push(dn_col, color.new(#ff1100, 87))
    array.push(dn_col, color.new(#ff1100, 86))
    array.push(dn_col, color.new(#ff1100, 85))
    array.push(dn_col, color.new(#ff1100, 84))
    array.push(dn_col, color.new(#ff1100, 83))
    array.push(dn_col, color.new(#ff1100, 82))
    array.push(dn_col, color.new(#ff1100, 81))
    array.push(dn_col, color.new(#ff1100, 80))
    array.push(dn_col, color.new(#ff1100, 79))
    array.push(dn_col, color.new(#ff1100, 78))
    array.push(dn_col, color.new(#ff1100, 77))
    array.push(dn_col, color.new(#ff1100, 76))
    array.push(dn_col, color.new(#ff1100, 75))
    array.push(dn_col, color.new(#ff1100, 74))
    array.push(dn_col, color.new(#ff1100, 73))
    array.push(dn_col, color.new(#ff1100, 72))
    array.push(dn_col, color.new(#ff1100, 71))
    array.push(dn_col, color.new(#ff1100, 70))
    array.push(dn_col, color.new(#ff1100, 69))
    array.push(dn_col, color.new(#ff1100, 68))
    array.push(dn_col, color.new(#ff1100, 67))
    array.push(dn_col, color.new(#ff1100, 66))
    array.push(dn_col, color.new(#ff1100, 65))
    array.push(dn_col, color.new(#ff1100, 64))
    array.push(dn_col, color.new(#ff1100, 63))
    array.push(dn_col, color.new(#ff1100, 62))
    array.push(dn_col, color.new(#ff1100, 61))
    array.push(dn_col, color.new(#ff1100, 60))
    array.push(dn_col, color.new(#ff1100, 59))
    array.push(dn_col, color.new(#ff1100, 58))
    array.push(dn_col, color.new(#ff1100, 57))
    array.push(dn_col, color.new(#ff1100, 56))
    array.push(dn_col, color.new(#ff1100, 55))
    array.push(dn_col, color.new(#ff1100, 54))
    array.push(dn_col, color.new(#ff1100, 53))
    array.push(dn_col, color.new(#ff1100, 52))
    array.push(dn_col, color.new(#ff1100, 51))
    array.push(dn_col, color.new(#ff1100, 50))
    array.push(dn_col, color.new(#ff1100, 49))
    array.push(dn_col, color.new(#ff1100, 48))
    array.push(dn_col, color.new(#ff1100, 47))
    array.push(dn_col, color.new(#ff1100, 46))
    array.push(dn_col, color.new(#ff1100, 45))
    array.push(dn_col, color.new(#ff1100, 44))
    array.push(dn_col, color.new(#ff1100, 43))
    array.push(dn_col, color.new(#ff1100, 42))
    array.push(dn_col, color.new(#ff1100, 41))
    array.push(dn_col, color.new(#ff1100, 40))
    array.push(dn_col, color.new(#ff1100, 39))
    array.push(dn_col, color.new(#ff1100, 38))
    array.push(dn_col, color.new(#ff1100, 37))
    array.push(dn_col, color.new(#ff1100, 36))
    array.push(dn_col, color.new(#ff1100, 35))
    array.push(dn_col, color.new(#ff1100, 34))
    array.push(dn_col, color.new(#ff1100, 33))
    array.push(dn_col, color.new(#ff1100, 32))
    array.push(dn_col, color.new(#ff1100, 31))
    array.push(dn_col, color.new(#ff1100, 30))
    array.push(dn_col, color.new(#ff1100, 29))
    array.push(dn_col, color.new(#ff1100, 28))
    array.push(dn_col, color.new(#ff1100, 27))
    array.push(dn_col, color.new(#ff1100, 26))
    array.push(dn_col, color.new(#ff1100, 25))
    array.push(dn_col, color.new(#ff1100, 24))
    array.push(dn_col, color.new(#ff1100, 23))
    array.push(dn_col, color.new(#ff1100, 22))
    array.push(dn_col, color.new(#ff1100, 21))
    array.push(dn_col, color.new(#ff1100, 20))
    array.push(dn_col, color.new(#ff1100, 19))
    array.push(dn_col, color.new(#ff1100, 18))
    array.push(dn_col, color.new(#ff1100, 17))
    array.push(dn_col, color.new(#ff1100, 16))
    array.push(dn_col, color.new(#ff1100, 15))
    array.push(dn_col, color.new(#ff1100, 14))
    array.push(dn_col, color.new(#ff1100, 13))
    array.push(dn_col, color.new(#ff1100, 12))
    array.push(dn_col, color.new(#ff1100, 11))
    array.push(dn_col, color.new(#ff1100, 10))
    array.push(dn_col, color.new(#ff1100, 9))
    array.push(dn_col, color.new(#ff1100, 8))
    array.push(dn_col, color.new(#ff1100, 7))
    array.push(dn_col, color.new(#ff1100, 6))
    array.push(dn_col, color.new(#ff1100, 5))
    array.push(dn_col, color.new(#ff1100, 4))
    array.push(dn_col, color.new(#ff1100, 3))
    array.push(dn_col, color.new(#ff1100, 2))
    array.push(dn_col, color.new(#ff1100, 1))
//----
atr = ta.atr(length) * mult
uppp = hl2 + atr
dn = hl2 - atr
upperr := src[1] < upperr[1] ? math.min(uppp, upperr[1]) : uppp
lowerr := src[1] > lowerr[1] ? math.max(dn, lowerr[1]) : dn
trend := src > upperr[1] ? 1 : src < lowerr[1] ? 0 : trend[1]
Spt = trend * lowerr + (1 - trend) * upperr
//----
ama = 0.
osc = math.max(math.min((src - Spt) / (upperr - lowerr), 1), -1)
alpha = math.pow(osc, 2) / length
ama := nz(ama[1] + alpha * (osc - ama[1]), osc)
hist = ta.ema(osc - ama, smooth)
//----
fix_css = osc > 0 ? #0cb51a : #ff1100
var_css = osc > 0 ? array.get(up_col, math.round(osc * 99)) : array.get(dn_col, math.round(osc * -1 * 99))
sig_css = ama > 0 ? #2157f3 : #673ab7
// plot(fixed ? osc * 100 : na, 'Main Fixed', fix_css, 1, plot.style_area)
// plot(fixed ? na : osc * 100, 'Main Transp', var_css, 1, plot.style_columns, editable=false)
// plot(hist * 100, 'Histogram', color.new(#808080, 40), 1, plot.style_area)
// plot(ama * 100, 'Signal', sig_css)
//----
a = hline(80)
b = hline(-80)
fill(a, b, color.new(#2157f3, 90))
//----
css = osc > 0 ? #ff1100 : #0cb51a
sig = ta.change(math.sign(osc)) ? osc * -100 : na
plot(show_ln ? sig : na, color=css)
//----
n = bar_index
cross = ta.cross(src, Spt)
x2 = ta.valuewhen(cross, n, 0)
//----
false_buy = ta.valuewhen(ta.crossunder(src, Spt), src, 0) < ta.valuewhen(ta.crossover(src, Spt), src, 0)
false_sell = ta.valuewhen(ta.crossover(src, Spt), src, 0) > ta.valuewhen(ta.crossunder(src, Spt), src, 0)
num = ta.cum(cross and (false_buy or false_sell) ? 1 : 0)
den = ta.cum(cross ? 1 : 0)
per = num / den * 100
//----
if barstate.islast and show_ln
    line.delete(line.new(x2, math.sign(osc) * -100, n, osc * 100, color=osc < 0 ? #ff1100 : #0cb51a)[1])
if show_lb
    if ta.crossover(src, Spt)
        txt = false_sell ? '❌' : '✔️'
        label.new(x2, -80, txt, color=#00000000, style=label.style_label_up, textcolor=color.gray, textalign=text.align_center)
    if ta.crossunder(src, Spt)
        txt = false_buy ? '❌' : '✔️'
        label.new(x2, 80, txt, color=#00000000, style=label.style_label_down, textcolor=color.gray, textalign=text.align_center)
    if barstate.islast and show_per
        txt = '❌' + str.tostring(per, '#.##') + '%'
        label.delete(label.new(n, osc, txt, color=#00000000, style=label.style_label_left, textcolor=color.gray, textalign=text.align_left)[1])
// plot(osc,"osc")
// === INPUTS ===
// Coloured MA - type, length, source
typeColoured = input.string(defval='HullMA', title='Coloured MA Type: ', options=['SMA', 'EMA', 'WMA', 'VWMA', 'SMMA', 'DEMA', 'TEMA', 'HullMA', 'ZEMA', 'TMA', 'SSMA'])
lenColoured = input.int(defval=18, title='Coloured MA - Length', minval=1)
srcColoured = input(close, title='Coloured MA - Source')
// Fast MA - type, length
typeFast = input.string(defval='EMA', title='Fast MA Type: ', options=['SMA', 'EMA', 'WMA', 'VWMA', 'SMMA', 'DEMA', 'TEMA', 'HullMA', 'ZEMA', 'TMA', 'SSMA'])
lenFast = input.int(defval=21, title='Fast MA - Length', minval=1)
// Medium MA - type, length
typeMedium = input.string(defval='EMA', title='Medium MA Type: ', options=['SMA', 'EMA', 'WMA', 'VWMA', 'SMMA', 'DEMA', 'TEMA', 'HullMA', 'ZEMA', 'TMA', 'SSMA'])
lenMedium = input.int(defval=55, title='Medium MA - Length', minval=1)
// Slow MA - type, length
typeSlow = input.string(defval='EMA', title='Slow MA Type: ', options=['SMA', 'EMA', 'WMA', 'VWMA', 'SMMA', 'DEMA', 'TEMA', 'HullMA', 'ZEMA', 'TMA', 'SSMA'])
lenSlow = input.int(defval=89, title='Slow MA Length', minval=1)
// 3xMA source
ma_src = input(close, title='3xMA and Bollinger Source')
//
filterOption = input.string('SuperTrend', title='Signal Filter Option : ', options=['3xMATrend', 'SuperTrend', 'SuperTrend+3xMA', 'ColouredMA', 'No Alerts', 'MACross', 'MACross+ST', 'MACross+3xMA', 'OutsideIn:MACross', 'OutsideIn:MACross+ST', 'OutsideIn:MACross+3xMA'])
//
hideMALines = input(false)
hideSuperTrend = input(true)
hideBollingerBands = input(true)
hideTrendDirection = input(true)
//
disableFastMAFilter = input(false)
disableMediumMAFilter = input(false)
disableSlowMAFilter = input(false)
//
uKC = false  // input(false,title="Use Keltner Channel (KC) instead of Bollinger")
bbLength = input.int(20, minval=2, step=1, title='Bollinge Bands Length')
bbStddev = input.float(2.0, minval=0.5, step=0.1, title='Bollinger Bands StdDevs')
oiLength = input(8, title='Bollinger Outside In LookBack')
//
SFactor = input.float(3.618, minval=1.0, title='SuperTrend Factor')
SPd = input.int(5, minval=1, title='SuperTrend Length')
//
buyColour_ = input.string('Green', title='BUY Marker Colour: ', options=['Green', 'Lime', 'Aqua', 'DodgerBlue', 'Gray', 'Yellow'])
sellColour_ = input.string('Maroon', title='SELL Marker Colour: ', options=['Maroon', 'Red', 'Fuchsia', 'Blue', 'Black', 'Orange'])
// --- Allocate Correct Filtering Choice
// Can only be one choice
uSuperTrendFilter = filterOption == 'SuperTrend' ? true : false
u3xMATrendFilter = filterOption == '3xMATrend' ? true : false
uBothTrendFilters = filterOption == 'SuperTrend+3xMA' ? true : false
//uOIFilter           = filterOption == "OutsideIn:ClrMA" ? true : false
uOIMACrossFilter = filterOption == 'OutsideIn:MACross' ? true : false
uOI3xMAFilter = filterOption == 'OutsideIn:MACross+3xMA' ? true : false
uOISTFilter = filterOption == 'OutsideIn:MACross+ST' ? true : false
uMACrossFilter = filterOption == 'MACross' ? true : false
uMACrossSTFilter = filterOption == 'MACross+ST' ? true : false
uMACross3xMAFilter = filterOption == 'MACross+3xMA' ? true : false
// unless all 3 MAs disabled.
disable3xMAFilter = disableFastMAFilter and disableMediumMAFilter and disableSlowMAFilter
u3xMATrendFilter := disable3xMAFilter ? false : u3xMATrendFilter
// if no filters selected then must be "No Filters" option
disableAllFilters = u3xMATrendFilter or uSuperTrendFilter or uBothTrendFilters or uOI3xMAFilter or uOISTFilter or uOIMACrossFilter or uMACrossFilter or uMACrossSTFilter or uMACross3xMAFilter ? false : true
// if "No Alerts" option selected, then disable all selections
disableAllFilters := filterOption == 'No Alerts' ? false : disableAllFilters
uSuperTrendFilter := filterOption == 'No Alerts' ? false : uSuperTrendFilter
u3xMATrendFilter := filterOption == 'No Alerts' ? false : u3xMATrendFilter
uBothTrendFilters := filterOption == 'No Alerts' ? false : uBothTrendFilters
//uOIFilter           := filterOption == "No Alerts"? false : uOIFilter
uOIMACrossFilter := filterOption == 'No Alerts' ? false : uOIMACrossFilter
uOI3xMAFilter := filterOption == 'No Alerts' ? false : uOI3xMAFilter
uOISTFilter := filterOption == 'No Alerts' ? false : uOISTFilter
uMACrossFilter := filterOption == 'No Alerts' ? false : uMACrossFilter
uMACrossSTFilter := filterOption == 'No Alerts' ? false : uMACrossSTFilter
uMACross3xMAFilter := filterOption == 'No Alerts' ? false : uMACross3xMAFilter
// --- CONSTANTS ---
dodgerblue = #1E90FF
lightcoral = #F08080
buyColour = color.green  // for big Arrows, must be a constant.
sellColour = color.maroon  // for big Arrows
// Colour Selectable for Big Fat Bars.
buyclr = buyColour_ == 'Lime' ? color.lime : buyColour_ == 'Aqua' ? color.aqua : buyColour_ == 'DodgerBlue' ? dodgerblue : buyColour_ == 'Gray' ? color.gray : buyColour_ == 'Yellow' ? color.yellow : color.green
sellclr = sellColour_ == 'Red' ? color.red : sellColour_ == 'Fuchsia' ? color.fuchsia : sellColour_ == 'Blue' ? color.blue : sellColour_ == 'Black' ? color.black : sellColour_ == 'Orange' ? color.orange : color.maroon
// === /INPUTS ===
// === FUNCTIONS ===
// Returns MA input selection variant, default to SMA if blank or typo.
variant(type, src, len) =>
    v1 = ta.sma(src, len)  // Simple
    v2 = ta.ema(src, len)  // Exponential
    v3 = ta.wma(src, len)  // Weighted
    v4 = ta.vwma(src, len)  // Volume Weighted
    v5 = 0.0
    sma_1 = ta.sma(src, len)  // Smoothed
    v5 := na(v5[1]) ? sma_1 : (v5[1] * (len - 1) + src) / len
    v6 = 2 * v2 - ta.ema(v2, len)  // Double Exponential
    v7 = 3 * (v2 - ta.ema(v2, len)) + ta.ema(ta.ema(v2, len), len)  // Triple Exponential
    v8 = ta.wma(2 * ta.wma(src, len / 2) - ta.wma(src, len), math.round(math.sqrt(len)))  // Hull WMA = (2*WMA (n/2) − WMA (n)), sqrt (n))
    v11 = ta.sma(ta.sma(src, len), len)  // Triangular
    // SuperSmoother filter
    // © 2013  John F. Ehlers
    a1 = math.exp(-1.414 * 3.14159 / len)
    b1 = 2 * a1 * math.cos(1.414 * 3.14159 / len)
    c2 = b1
    c3 = -a1 * a1
    c1 = 1 - c2 - c3
    v9 = 0.0
    v9 := c1 * (src + nz(src[1])) / 2 + c2 * nz(v9[1]) + c3 * nz(v9[2])
    // Zero Lag Exponential
    e = ta.ema(v1, len)
    v10 = v1 + v1 - e
    // return variant, defaults to SMA if input invalid.
    type == 'EMA' ? v2 : type == 'WMA' ? v3 : type == 'VWMA' ? v4 : type == 'SMMA' ? v5 : type == 'DEMA' ? v6 : type == 'TEMA' ? v7 : type == 'HullMA' ? v8 : type == 'SSMA' ? v9 : type == 'ZEMA' ? v10 : type == 'TMA' ? v11 : v1
// === /FUNCTIONS ===
// === SERIES VARIABLES ===
// MA's
ma_fast = variant(typeFast, ma_src, lenFast)
ma_medium = variant(typeMedium, ma_src, lenMedium)
ma_slow = variant(typeSlow, ma_src, lenSlow)
ma_coloured = variant(typeColoured, srcColoured, lenColoured)
// Get Direction of Coloured Moving Average
clrdirection = 1
falling_1 = ta.falling(ma_coloured, 2)
clrdirection := ta.rising(ma_coloured, 2) ? 1 : falling_1 ? -1 : nz(clrdirection[1], 1)
// get 3xMA trend direction based on selections.
madirection = ma_fast > ma_medium and ma_medium > ma_slow ? 1 : ma_fast < ma_medium and ma_medium < ma_slow ? -1 : 0
madirection := disableSlowMAFilter ? ma_fast > ma_medium ? 1 : ma_fast < ma_medium ? -1 : 0 : madirection
madirection := disableMediumMAFilter ? ma_fast > ma_slow ? 1 : ma_fast < ma_slow ? -1 : 0 : madirection
madirection := disableFastMAFilter ? ma_medium > ma_slow ? 1 : ma_medium < ma_slow ? -1 : 0 : madirection
madirection := disableFastMAFilter and disableMediumMAFilter ? ma_coloured > ma_slow ? 1 : -1 : madirection
madirection := disableFastMAFilter and disableSlowMAFilter ? ma_coloured > ma_medium ? 1 : -1 : madirection
madirection := disableSlowMAFilter and disableMediumMAFilter ? ma_coloured > ma_fast ? 1 : -1 : madirection
//
// Supertrend Calculations
SUp = hl2 - SFactor * ta.atr(SPd)
SDn = hl2 + SFactor * ta.atr(SPd)
STrendUp = 0.0
STrendDown = 0.0
STrendUp := close[1] > STrendUp[1] ? math.max(SUp, STrendUp[1]) : SUp
STrendDown := close[1] < STrendDown[1] ? math.min(SDn, STrendDown[1]) : SDn
STrend = 0
STrend := close > STrendDown[1] ? 1 : close < STrendUp[1] ? -1 : nz(STrend[1], 1)
Tsl = STrend == 1 ? STrendUp : STrendDown
// Standard Bollinger or KC Bands
basis = ta.sma(ma_src, bbLength)
rangema = ta.sma(ta.tr, bbLength)
stdev_1 = ta.stdev(ma_src, bbLength)
dev = uKC ? bbStddev * rangema : bbStddev * stdev_1
// Calculate Bollinger or KC Channel
upper = basis + dev
lower = basis - dev
// Lookback for previous highest bar index
noiupper = math.abs(ta.highestbars(oiLength))
noilower = math.abs(ta.lowestbars(oiLength))
// ColouredMA OutsideIn
//oiupper = clrdirection<0 and noiupper>0 and highest(oiLength)>upper[noiupper]? 1 : 0
//oilower = clrdirection>0 and noilower>0 and lowest(oiLength)<lower[noilower]? 1 : 0
// MACross OutsideIN
oiMACrossupper = ta.crossunder(ma_fast, ma_coloured) and noiupper > 0 and ta.highest(oiLength) > upper[noiupper] ? 1 : 0
oiMACrosslower = ta.crossover(ma_fast, ma_coloured) and noilower > 0 and ta.lowest(oiLength) < lower[noilower] ? 1 : 0
// === /SERIES VARIABLES ===
// === PLOTTING ===
// All the MA's
//plot(ma_coloured, title='Coloured MA', color=clrdirection < 0 ? lightcoral : color.blue, linewidth=3, transp=20)
//plot(hideMALines ? na : ma_fast, title='Fast MA', color=color.new(color.lime, 20), linewidth=2)
// plot(hideMALines ? na : ma_medium, title='Medium MA', color=color.new(color.red, 10), linewidth=2)
// plot(hideMALines ? na : ma_slow, title='Slow MA', color=color.new(color.gray, 10), linewidth=2)
// show 3xMA Trend Direction State.
dcolour = madirection == 1 ? color.green : madirection == -1 ? color.red : color.yellow
// plotshape(hideTrendDirection ? na : madirection, title='3xMA Trend Direction', location=location.bottom, style=shape.square, color=dcolour, transp=10)
// // SuperTrend
// plot(hideSuperTrend ? na : Tsl, color=STrend == 1 ? color.green : color.maroon, style=plot.style_line, linewidth=2, title='SuperTrend')
// Bollinger Bands
p1 = plot(hideBollingerBands ? na : upper, title='BB upper', color=color.new(dodgerblue, 20), linewidth=1)
p2 = plot(hideBollingerBands ? na : lower, title='BB lower', color=color.new(dodgerblue, 20), linewidth=1)
fill(p1, p2, color=color.new(dodgerblue, 96), title='BB fill')
// === /PLOTTING ===
// === ALERTING ===
// 3xMA Filtering
_3xmabuy = 0
_3xmasell = 0
_3xmabuy := clrdirection == 1 and close > ma_fast and madirection == 1 ? nz(_3xmabuy[1]) + 1 : clrdirection == 1 and madirection == 1 ? nz(_3xmabuy[1]) > 0 ? nz(_3xmabuy[1]) + 1 : 0 : 0
_3xmasell := clrdirection == -1 and close < ma_fast and madirection == -1 ? nz(_3xmasell[1]) + 1 : clrdirection == -1 and madirection == -1 ? nz(_3xmasell[1]) > 0 ? nz(_3xmasell[1]) + 1 : 0 : 0
//
// SuperTrend Filtering
stbuy = 0
stsell = 0
stbuy := clrdirection == 1 and STrend == 1 ? nz(stbuy[1]) + 1 : 0
stsell := clrdirection == -1 and STrend == -1 ? nz(stsell[1]) + 1 : 0
//
// 3xMA & SuperTrend Filtering
//
st3xmabuy = 0
st3xmasell = 0
st3xmabuy := (disable3xMAFilter or _3xmabuy > 0) and stbuy > 0 ? nz(st3xmabuy[1]) + 1 : 0
st3xmasell := (disable3xMAFilter or _3xmasell > 0) and stsell > 0 ? nz(st3xmasell[1]) + 1 : 0
// Bollinger Outside In using ColuredMA direction Filter.
//oibuy = 0
//oisell = 0
//oibuy  := clrdirection == 1 and oilower==1? nz(oibuy[1])+1  : 0
//oisell := clrdirection ==-1 and oiupper==1? nz(oisell[1])+1 : 0
// Bollinger Outside In using MACross signal Filter
oiMACrossbuy = 0
oiMACrosssell = 0
oiMACrossbuy := oiMACrosslower == 1 ? nz(oiMACrossbuy[1]) + 1 : 0
oiMACrosssell := oiMACrossupper == 1 ? nz(oiMACrosssell[1]) + 1 : 0
// Bollinger Outside In + 3xMA Filter
oi3xmabuy = 0
oi3xmasell = 0
oi3xmabuy := oiMACrossbuy > 0 and (disable3xMAFilter or madirection == 1) ? nz(oi3xmabuy[1]) + 1 : 0
oi3xmasell := oiMACrosssell > 0 and (disable3xMAFilter or madirection == -1) ? nz(oi3xmasell[1]) + 1 : 0
// Bollinger Outside In + SuperTrend Filter
oistbuy = 0
oistsell = 0
oistbuy := oiMACrossbuy > 0 and STrend == 1 ? nz(oistbuy[1]) + 1 : 0
oistsell := oiMACrosssell > 0 and STrend == -1 ? nz(oistsell[1]) + 1 : 0
// FastMA crossover HullMA and SuperTrend
macrossSTbuy = 0
macrossSTsell = 0
macrossSTbuy := ta.crossover(ma_fast, ma_coloured) and STrend == 1 ? nz(macrossSTbuy[1]) + 1 : 0
macrossSTsell := ta.crossunder(ma_fast, ma_coloured) and STrend == -1 ? nz(macrossSTsell[1]) + 1 : 0
// FastMA crossover HullMA and 3xMA
macross3xMAbuy = 0
macross3xMAsell = 0
macross3xMAbuy := ta.crossover(ma_fast, ma_coloured) and (disable3xMAFilter or madirection == 1) ? nz(macross3xMAbuy[1]) + 1 : 0
macross3xMAsell := ta.crossunder(ma_fast, ma_coloured) and (disable3xMAFilter or madirection == -1) ? nz(macross3xMAsell[1]) + 1 : 0
//
// Check any Alerts set
long = u3xMATrendFilter and _3xmabuy == 1 or uSuperTrendFilter and stbuy == 1 or uBothTrendFilters and st3xmabuy == 1 or uOI3xMAFilter and oi3xmabuy == 1 or uOISTFilter and oistbuy == 1 or uOIMACrossFilter and oiMACrossbuy == 1 or uMACrossSTFilter and macrossSTbuy == 1 or uMACross3xMAFilter and macross3xMAbuy == 1
short = u3xMATrendFilter and _3xmasell == 1 or uSuperTrendFilter and stsell == 1 or uBothTrendFilters and st3xmasell == 1 or uOI3xMAFilter and oi3xmasell == 1 or uOISTFilter and oistsell == 1 or uOIMACrossFilter and oiMACrosssell == 1 or uMACrossSTFilter and macrossSTsell == 1 or uMACross3xMAFilter and macross3xMAsell == 1
//
// If Alert Detected, then Draw Big fat liner
plotshape(long ? long : na, title='Long Line Marker', location=location.belowbar, style=shape.arrowup, color=buyclr, size=size.auto, text='█', textcolor=buyclr, transp=20) //size=size.auto, text='████████████████'
plotshape(short ? short : na, title='Short Line Marker', location=location.abovebar, style=shape.arrowdown, color=sellclr, size=size.auto, text='█', textcolor=sellclr, transp=20) //text='████████████████',
// --- Arrow style signals
// No Filters only Hull Signals
hbuy = 0
hsell = 0
hbuy := clrdirection == 1 ? nz(hbuy[1]) + 1 : 0
hsell := clrdirection == -1 ? nz(hsell[1]) + 1 : 0
// FastMA crossover HullMA
macrossbuy = 0
macrosssell = 0
macrossbuy := ta.crossover(ma_fast, ma_coloured) ? nz(macrossbuy[1]) + 1 : 0
macrosssell := ta.crossunder(ma_fast, ma_coloured) ? nz(macrosssell[1]) + 1 : 0
//
along = disableAllFilters and hbuy == 1 or uMACrossFilter and macrossbuy == 1
ashort = disableAllFilters and hsell == 1 or uMACrossFilter and macrosssell == 1
// 
// If ColouredMA or MACross then draw big arrows
plotarrow(along ? 1 : ashort ? -1 : na, title='ColouredMA or MACross Arrow', colorup=color.new(buyColour, 20), colordown=color.new(sellColour, 20), maxheight=100, minheight=50)
//--------------------------------RVWAP
import PineCoders/ConditionalAverages/1 as pc
// ———————————————————— Constants and Inputs {
// ————— Constants
int MS_IN_MIN   = 60 * 1000
int MS_IN_HOUR  = MS_IN_MIN  * 60
int MS_IN_DAY   = MS_IN_HOUR * 24
string TT_SRC     = "The source used to calculate the VWAP. The default is the average of the high, low and close prices."
string TT_WINDOW  = "By default, the time period used to calculate the RVWAP automatically adjusts with the chart's timeframe.
  Check this to use a fixed-size time period instead, which you define with the following three values."
string TT_MINBARS = "The minimum number of last values to keep in the moving window, even if these values are outside the time period.
  This avoids situations where a large time gap between two bars would cause the time window to be empty."
string TT_STDEV   = "The multiplier for the standard deviation bands offset above and below the RVWAP. Example: 1.0 is 100% of the offset value. 
  \n\nNOTE: A value of 0.0 will hide the bands."
string TT_TABLE   = "Displays the time period of the rolling window."
// ————— Inputs
float   srcInput                = input.source(hlc3, "Source", tooltip = TT_SRC)
string  GRP2                    = '═══════════   Time Period   ═══════════'
bool    fixedTfInput            = input.bool(false,         "Use a fixed time period", group = GRP2, tooltip = TT_WINDOW)
int     daysInput               = input.int(1,              "Days",                    group = GRP2, minval = 0, maxval = 90) * MS_IN_DAY
int     hoursInput              = input.int(0,              "Hours",                   group = GRP2, minval = 0, maxval = 23) * MS_IN_HOUR
int     minsInput               = input.int(0,              "Minutes",                 group = GRP2, minval = 0, maxval = 59) * MS_IN_MIN
bool    showInfoBoxInput        = input.bool(true,          "Show time period",        group = GRP2)
string  infoBoxSizeInput        = input.string("small",     "Size ",    inline = "21", group = GRP2, options = ["tiny", "small", "normal", "large", "huge", "auto"])
string  infoBoxYPosInput        = input.string("bottom",    "↕",        inline = "21", group = GRP2, options = ["top", "middle", "bottom"])
string  infoBoxXPosInput        = input.string("left",      "↔",        inline = "21", group = GRP2, options = ["left", "center", "right"])
color   infoBoxColorInput       = input.color(color.gray,   "",         inline = "21", group = GRP2)
color   infoBoxTxtColorInput    = input.color(color.white,  "T",        inline = "21", group = GRP2)
string  GRP3                    = '═════════  Deviation Bands  ═════════'
float   stdevMult1              = input.float(0.0, "Bands Multiplier 1", group = GRP3, inline = "31", minval = 0.0, step = 0.5, tooltip = TT_STDEV)
float   stdevMult2              = input.float(0.0, "Bands Multiplier 2", group = GRP3, inline = "32", minval = 0.0, step = 0.5, tooltip = TT_STDEV)
float   stdevMult3              = input.float(0.0, "Bands Multiplier 3", group = GRP3, inline = "33", minval = 0.0, step = 0.5, tooltip = TT_STDEV)
color   stdevColor1             = input.color(color.green,  "",          group = GRP3, inline = "31")
color   stdevColor2             = input.color(color.yellow, "",          group = GRP3, inline = "32")
color   stdevColor3             = input.color(color.red,    "",          group = GRP3, inline = "33")
string  GRP4                    = '════════  Minimum Window Size  ════════'
int     minBarsInput            = input.int(10, "Bars", group = GRP4, tooltip = TT_MINBARS) 
// }
// ———————————————————— Functions {
// @function    Determines a time period from the chart's timeframe.
// @returns     (int) A value of time in milliseconds that is appropriate for the current chart timeframe. To be used in the RVWAP calculation.
timeStep() =>
    int tfInMs = timeframe.in_seconds() * 1000
    float step =
      switch
        tfInMs <= MS_IN_MIN        => MS_IN_HOUR
        tfInMs <= MS_IN_MIN  * 5   => MS_IN_HOUR * 4
        tfInMs <= MS_IN_HOUR       => MS_IN_DAY  * 1
        tfInMs <= MS_IN_HOUR * 4   => MS_IN_DAY  * 3
        tfInMs <= MS_IN_HOUR * 12  => MS_IN_DAY  * 7
        tfInMs <= MS_IN_DAY        => MS_IN_DAY  * 30.4375
        tfInMs <= MS_IN_DAY  * 7   => MS_IN_DAY  * 90
        => MS_IN_DAY * 365
    int result = int(step)
// @function    Produces a string corresponding to the input time in days, hours, and minutes.
// @param       (series int) A time value in milliseconds to be converted to a string variable. 
// @returns     (string) A string variable reflecting the amount of time from the input time.
tfString(int timeInMs) =>
    int s  = timeInMs / 1000
    int m  = s / 60
    int h  = m / 60
    int tm = math.floor(m % 60)
    int th = math.floor(h % 24)
    int d  = math.floor(h / 24)
    string result = 
      switch
        d == 30 and th == 10 and tm == 30 => "1M"
        d == 7  and th == 0  and tm == 0  => "1W"
        =>
            string dStr = d  ? str.tostring(d)  + "D "  : ""
            string hStr = th ? str.tostring(th) + "H "  : ""
            string mStr = tm ? str.tostring(tm) + "min" : ""
            dStr + hStr + mStr
// }
// ———————————————————— Calculations and Plots {
// Stop the indicator on charts with no volume.
if barstate.islast and ta.cum(nz(volume)) == 0
    runtime.error("No volume is provided by the data vendor.")
// RVWAP + stdev bands
int   timeInMs     = fixedTfInput ? minsInput + hoursInput + daysInput : timeStep()
float sumSrcVol    = pc.totalForTimeWhen(srcInput * volume, timeInMs, true, minBarsInput)
float sumVol       = pc.totalForTimeWhen(volume, timeInMs, true, minBarsInput)
float sumSrcSrcVol = pc.totalForTimeWhen(volume * math.pow(srcInput, 2), timeInMs, true, minBarsInput)
float rollingVWAP  = sumSrcVol / sumVol
float variance     = sumSrcSrcVol / sumVol - math.pow(rollingVWAP, 2)
variance          := math.max(0, variance)
float stDev        = math.sqrt(variance)
float upperBand1   = rollingVWAP + stDev * stdevMult1
float lowerBand1   = rollingVWAP - stDev * stdevMult1
float upperBand2   = rollingVWAP + stDev * stdevMult2
float lowerBand2   = rollingVWAP - stDev * stdevMult2
float upperBand3   = rollingVWAP + stDev * stdevMult3
float lowerBand3   = rollingVWAP - stDev * stdevMult3
plot(rollingVWAP, "Rolling VWAP", color.orange)
p11 = plot(stdevMult1 != 0 ? upperBand1 : na, "Upper Band 1", stdevColor1)
p22 = plot(stdevMult1 != 0 ? lowerBand1 : na, "Lower Band 1", stdevColor1)
p3 = plot(stdevMult2 != 0 ? upperBand2 : na, "Upper Band 2", stdevColor2)
p4 = plot(stdevMult2 != 0 ? lowerBand2 : na, "Lower Band 2", stdevColor2)
p5 = plot(stdevMult3 != 0 ? upperBand3 : na, "Upper Band 3", stdevColor3)
p6 = plot(stdevMult3 != 0 ? lowerBand3 : na, "Lower Band 3", stdevColor3)
fill(p11, p22, color.new(color.green, 95), "Bands Fill")
fill(p3, p4, color.new(color.green, 95), "Bands Fill")
fill(p5, p6, color.new(color.green, 95), "Bands Fill")
// Display of time period.
var table tfDisplay = table.new(infoBoxYPosInput + "_" + infoBoxXPosInput, 1, 1)
if showInfoBoxInput and barstate.islastconfirmedhistory
    table.cell(tfDisplay, 0, 0, tfString(timeInMs), bgcolor = infoBoxColorInput, text_color = infoBoxTxtColorInput, text_size = infoBoxSizeInput)
// }
//----------Input Bannos----------------------------------------------------------------------------------------------------------//
var triggerlong = 0
var triggershort = 0
var up = 0
var down = 0
var bool longe = 0
var bool shorte = 0
var SL = 0
var entryvalueup = 0.00
var entryvaluedown = 0.00
var SLup = 0.00
var SLdown = 0.00
var longbuffer = 0
var shortbuffer = 0
var lastredlow=0.0
var lastgreenhigh=0.0
spikefactor = input.float(1.9, minval=0, title='Spikefactor')
slfactor = input.float(1.5, minval=0, title='Slfactor')
oscfactor = input.float(1.9, minval=0, title='oscfactor')
amafactor = input.float(0.66, minval=0, title='amafactor')
varVWAP = rollingVWAP
lasthigh=ta.highest(close,100)
lastlow=ta.lowest(close,100)
smma6 = ta.sma(close, 10)
//RSI parameters
overbought = input(77, title="overbought value")
oversold = input(26, title="oversold value")
sellRsi = ta.rsi(close, 14) > overbought
buyRsi = ta.rsi(close, 14) < oversold
var tampon_overbought = 0
var tampon_oversold = 0
//condition to use RSI
if sellRsi
    tampon_overbought := 1
if buyRsi
    tampon_oversold := 1
    
//close condition SL
if entryvalueup > 0  and low < SLup
    SL := 1
    
if entryvaluedown > 0  and high > SLdown
    SL := 1
//Chaikin Volatility Strategy indicator if Volatility > 0 then Long or short, otherweise no
Length = input.int(10, '', minval=1)
ROCLength = input.int(12, '',minval=1)
Trigger = input.int(0, '',minval=0)
hline(0)
hline(Trigger)
xPrice1 = high
xPrice2 = low
xPrice = xPrice1 - xPrice2
xROC_EMA = ta.roc(ta.ema(xPrice, Length), ROCLength)
var pos = 0
if xROC_EMA < Trigger
    pos := 1
    nz(pos[1], 0)
if xROC_EMA > Trigger
    pos := -1
    nz(pos[1], 0)
//---------------------Volatility Oscillator
lengthh = input(100)
spike = close - open
x = ta.stdev(spike, lengthh)
y = ta.stdev(spike, lengthh) * -1
// plot(spike, color=color.new(color.white, 0), linewidth=2, title='Spike Linel')
// p111 = plot(x, 'Upper Line')
// p222 = plot(y, 'Lower Line')
// plot(0, color=color.new(color.gray, 0), title='Zero Line')
// plot(spike, color=color.new(color.blue, 80), style=plot.style_area, title='Spike Fill')
osc2 = spike
lbR = 5
lbL = 5
rangeUpper = 60
rangeLower = 5
plotBull = input(title='Plot Bullish', defval=true)
plotHiddenBull = input(title='Plot Hidden Bullish', defval=false)
plotBear = input(title='Plot Bearish', defval=true)
plotHiddenBear = input(title='Plot Hidden Bearish', defval=false)
delay_plot_til_closed = input(title='Delay diversion plot until candle is closed (don\'t repaint)', defval=false)
bearColor = color.red
bullColor = color.green
hiddenBullColor = color.new(color.green, 80)
hiddenBearColor = color.new(color.red, 80)
textColor = color.white
noneColor = color.new(color.white, 100)
repaint = not delay_plot_til_closed or barstate.ishistory or barstate.isconfirmed
plFound = na(ta.pivotlow(osc2, lbL, lbR)) ? false : true
phFound = na(ta.pivothigh(osc2, lbL, lbR)) ? false : true
_inRange(cond) =>
    bars = ta.barssince(cond == true)
    rangeLower <= bars and bars <= rangeUpper
//------------------------------------------------------------------------------
// Regular Bullish
// Osc: Higher Low
oscHL = osc2[lbR] > ta.valuewhen(plFound, osc2[lbR], 1) and _inRange(plFound[1])
// Price: Lower Low
priceLL = low[lbR] < ta.valuewhen(plFound, low[lbR], 1)
bullCond = plotBull and priceLL and oscHL and plFound and repaint
//plotshape(bullCond ? osc2[lbR] : na, offset=-lbR, title='Regular Bullish Label', text='R', style=shape.labelup, location=location.absolute, color=color.new(bullColor, 0), textcolor=color.new(textColor, 0))
//------------------------------------------------------------------------------
// Hidden Bullish
// Osc: Lower Low
oscLL = osc2[lbR] < ta.valuewhen(plFound, osc2[lbR], 1) and _inRange(plFound[1])
// Price: Higher Low
priceHL = low[lbR] > ta.valuewhen(plFound, low[lbR], 1)
hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound and repaint
//plotshape(hiddenBullCond ? osc2[lbR] : na, offset=-lbR, title='Hidden Bullish Label', text='H', style=shape.labelup, location=location.absolute, color=color.new(bullColor, 0), textcolor=color.new(textColor, 0))
//------------------------------------------------------------------------------
// Regular Bearish
// Osc: Lower High
oscLH = osc2[lbR] < ta.valuewhen(phFound, osc2[lbR], 1) and _inRange(phFound[1])
// Price: Higher High
priceHH = high[lbR] > ta.valuewhen(phFound, high[lbR], 1)
bearCond = plotBear and priceHH and oscLH and phFound and repaint
//plotshape(bearCond ? osc2[lbR] : na, offset=-lbR, title='Regular Bearish Label', text='R', style=shape.labeldown, location=location.absolute, color=color.new(bearColor, 0), textcolor=color.new(textColor, 0))
//------------------------------------------------------------------------------
// Hidden Bearish
// Osc: Higher High
oscHH = osc2[lbR] > ta.valuewhen(phFound, osc2[lbR], 1) and _inRange(phFound[1])
// Price: Lower High
priceLH = high[lbR] < ta.valuewhen(phFound, high[lbR], 1)
hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound and repaint
//plotshape(hiddenBearCond ? osc2[lbR] : na, offset=-lbR, title='Hidden Bearish Label', text='H', style=shape.labeldown, location=location.absolute, color=color.new(bearColor, 0), textcolor=color.new(textColor, 0))
//barcolor(color = spike > 0 ? color.green : color.red )
//-----------------------------------------------------------------------------
// plot(xROC_EMA, title="Chaikin Volatility Strategy")
// plot(longe ? 1 : 0, 'longe')
// plot(shorte ? 1 : 0, 'shorte')
// plot(entryvalueup, 'entrryvalueup')
// plot(entryvaluedown, 'entrryvaluedown')
// plot(up, 'up')
//plot(down, 'down')
// plot(ta.rsi(close, 11), 'RSI')
// plot(tampon_overbought, 'tampon Overbought')
// plot(tampon_oversold, 'tampon Oversold')
// plot( triggerlong, ' triggerlong')
// plot( triggershort, ' triggershort')
// plot(sellRsi ? 1 : 0, 'sellRsi')
//close condition TP
closelong = (tampon_overbought == 1 and ta.rsi(close, 14) < 59) or SL == 1 or (osc*oscfactor<ama and ama>0 and ama>amafactor)
closeshort = (tampon_oversold == 1 and ta.rsi(close, 14) > 41) or SL == 1 or (osc*oscfactor>ama and ama<0 and ama<amafactor)
//reinit after long Close
if closelong
    up := 0
    longe := 0
    tampon_overbought := 0
    triggerlong := 0
    SL := 0
    entryvalueup := 0
    SLup := 0
    
    //reinit after short Close
if closeshort
    down := 0
    shorte := 0
    tampon_oversold := 0
    triggershort := 0
    SL := 0
    entryvaluedown := 0
    SLdown := 0
    
    
//condition sous sur MA SLOW to start
if varVWAP < ma_medium
    triggerlong := 0
    triggershort := 1
    
if varVWAP > ma_medium
    triggershort := 0
    triggerlong := 1
// Update alarm conditions
if long or along
    longbuffer := 1
    shortbuffer := 0
if short or ashort
    shortbuffer := 1
    longbuffer := 0
longe := triggerlong and longbuffer and xROC_EMA > -9 and spike > x*spikefactor and (osc ==1 or osc[1]==1) and osc[4]<0
shorte := triggershort and shortbuffer and xROC_EMA > -9 and spike < y*spikefactor and (osc ==-1 or osc[1]==-1) and osc[4]>0
// // var longe = long ? 1 : 0
// // var shorte = short ? 1 : 0
if longe == 1 and close > open
    up := 1
    down  := 0
    entryvalueup :=close
    SLup := close - slfactor*(high - low) // close - 1.4/100*close  // 0.7*(high - low)
    SLdown := 0
    longbuffer := 0
if shorte == 1 and close < open
    down := 1
    up := 0
    entryvaluedown := close
    SLdown := close + slfactor*(high - low) //close + 1.4/100*close // 0.7*(high - low)
    SLup := 0
    shortbuffer := 0
strategy.entry('longe', strategy.long, 1000.0, when = up)
strategy.entry('shorte', strategy.short, 1000.0, when = down)
strategy.close('longe', when= closelong)
strategy.close('shorte', when= closeshort)
plot(entryvalueup, 'entree Long', color.green)
plot(SLup, 'SL Long', color.red)
plot(entryvaluedown, 'entree Short', color.green)
plot(SLdown, 'SL Short', color.red)
// === /ALERTING ===
// === ALARMS ===
//
alertcondition(up, title='Long Alert', message='LONG')
alertcondition(down, title='Short Alert', message='SHORT')
alertcondition(closelong, title='close Long Alert', message='Close LONG')
alertcondition(closeshort, title='close Short Alert', message='Close SHORT')
// === /ALARMS ===
//EOF
Expand (1004 lines)

Overview

Long and short entries trigger when Snapper signals align with medium moving average direction and elevated volatility. Exits are managed dynamically through an RSI overbought/oversold reversal rule and candle-based stop levels. User inputs allow full customization of moving average types, lengths, SuperTrend filters, and Bollinger Band constraints.

Details

Published by

hasnocool on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Trend, Volatility & bands, Oscillators & momentum, Moving averages

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Topics

analysisbtcusdtcryptocurrencydatapandaspythonsimulationtradingtradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
lengthint10length
multfloat2.mult
smoothint72smooth
Fixed Transparencyboolfalsefixed
Show Linesbooltrueshow_ln
Show Labelsbooltrueshow_lb
Show % False Signalsboolfalseshow_per
Coloured MA Type: stringHullMAtypeColoured
Coloured MA - Lengthint18lenColoured
Coloured MA - SourcesourceclosesrcColoured
Fast MA Type: stringEMAtypeFast
Fast MA - Lengthint21lenFast
Show all 40 settings
SettingTypeDefaultVariable
Medium MA Type: stringEMAtypeMedium
Medium MA - Lengthint55lenMedium
Slow MA Type: stringEMAtypeSlow
Slow MA Lengthint89lenSlow
3xMA and Bollinger Sourcesourceclosema_src
Signal Filter Option : stringSuperTrendfilterOption
hideMALinesboolfalsehideMALines
hideSuperTrendbooltruehideSuperTrend
hideBollingerBandsbooltruehideBollingerBands
hideTrendDirectionbooltruehideTrendDirection
disableFastMAFilterboolfalsedisableFastMAFilter
disableMediumMAFilterboolfalsedisableMediumMAFilter
disableSlowMAFilterboolfalsedisableSlowMAFilter
Bollinge Bands Lengthint20bbLength
Bollinger Bands StdDevsfloat2.0bbStddev
Bollinger Outside In LookBackint8oiLength
SuperTrend Factorfloat3.618SFactor
SuperTrend Lengthint5SPd
BUY Marker Colour: stringGreenbuyColour_
SELL Marker Colour: stringMaroonsellColour_
Sourcesourcehlc3srcInput
Use a fixed time periodboolfalsefixedTfInput
Daysint1daysInput
Hoursint0hoursInput
Minutesint0minsInput
Show time periodbooltrueshowInfoBoxInput
Size stringsmallinfoBoxSizeInput
↕stringbottominfoBoxYPosInput
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

Momentum Rider DAILY FINAL

by greenpeas007
58 stars

This strategy combines exponential moving averages (EMA 9, 21, 50), RSI, MACD, and Supertrend indicators to enter long positions. It triggers trades using six dynamic setups based on momentum breakouts, EMA crossovers, and pullbacks. Position sizing is compute

Strategy v6 TrendOscillators & momentum Repaints
Updated 4 months ago · Custom licence GitHub repository of Momentum Rider DAILY FINAL

CombinedBinHAndClucV6

by viktors1982
36 stars

CombinedBinHAndClucV6 is a trading strategy based on the popular BinHV45 and ClucMay72018 algorithms. It calculates dual Bollinger Bands, Exponential Moving Averages, Relative Strength Index, Average True Range, and volume metrics across primary and one-hour h

Strategy v4 Volatility & bandsOscillators & momentum Repaints
Updated 2 years ago · None stated GitHub repository of CombinedBinHAndClucV6

BB Swing

by benso87
24 stars

This strategy calculates Bollinger Bands, a configurable moving average slope, Stochastic RSI, ATR, and ADX directly on the price chart. It evaluates trend bias and momentum conditions to generate long and short swing entries using percent-of-equity sizing. Th

Strategy v5 Volatility & bandsOscillators & momentum
Updated 4 years ago · MPL-2.0 GitHub repository of BB Swing

This strategy trades long and short on the price chart using a multi-timeframe TradingLatino setup. It requires EMA 10 to cross or sit above or below EMA 55 on the one-hour, four-hour, and daily charts, together with a positive ADX slope, a directional monitor

Strategy v5 TrendMoving averages
Updated 1 year ago · None stated GitHub repository of Ruckard ABCBitcoin TradingLatino A010

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers