Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=3
- //
- //▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ VOLATTITLITY PRICE ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
- sTitle = "VWAP"
- sShort = "WeightedPRICE"
- sRelease = "2018-06-22"
- sOverlay = true
- sScale = scale.right
- sPrecision = 0
- sInitial_capital = 10000
- sCommission_value = 0.05
- sPyramiding = 1
- sDefault_qty_type = strategy.percent_of_equity
- sDefault_qty_value = 100
- sCalc_on_order_fills = true
- sCalc_on_every_tick = true
- strategy(title=sTitle+" [v"+sRelease+"]", shorttitle=sShort, overlay=sOverlay, scale=sScale, precision=sPrecision,initial_capital=sInitial_capital, commission_value=sCommission_value, pyramiding=sPyramiding,calc_on_every_tick=sCalc_on_every_tick, default_qty_value=sDefault_qty_value, calc_on_order_fills=sCalc_on_order_fills)
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- // ♣DEFAULT SETTINGS♣
- //
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- defLongLen = 390
- defLongTF = 0
- defShortLen = 70
- defShortTF = 0
- //INPUTS
- defLongDev = "price"
- defLongDev1 = 1.28
- defLongDev2 = 2.01
- defLongDev3 = 2.51
- defLongDev4 = 3.09
- defLongDev5 = 4.01
- defShortDev = "price"
- defShortDev1 = 0
- defShortDev2 = 0
- defShortDev3 = 0
- defShortDev4 = 0
- defShortDev5 = 0
- defShowLongBands = "[4] Standard to Bronze"
- defShowShortBands = "[4] Standard to Bronze"
- defThemeLongShade = "Dark"
- defThemeColorAboveLong = "10 Cyan"
- defThemeColorBelowLong = "08 Green"
- defThemeLongCenter = "Light Grey"
- defThemeShortShade = "Dark"
- defThemeColorAboveShort = "10 Cyan"
- defThemeColorBelowShort = "08 Green"
- defThemeShortCenter = "Light Grey"
- //
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- // ♣FUNCTION INPUTS♣
- //
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- // Source for price and volume
- source = close
- //________________________________
- // LONG TIMEFRAME SETTINGS
- useTrueRange = input(defval="Auto", options=["Always", "Auto", "Never"], title="Use True Range instead of Volume")
- vol = useTrueRange == "Always" or (useTrueRange == "Auto" and na(timenow))? volume : timenow
- //
- enableLong = input(true, title="-------- LONG VOLATILITY BANDS -------- [uncheck to disable]")
- // VWAP Length (average over N bars back)
- longLength = input( title="Length (bars back)", type=integer, defval=defLongLen, minval=1 )
- // Long resolution
- longCustomRes = input(title="Timeframe (minutes) [0 to use current chart's]", type=integer, defval=defLongTF, minval=0, step=100)
- longRes = longCustomRes==0 ? period : tostring(longCustomRes)
- func_intbyMints() =>
- intMints = 0.0
- intMints := isintraday ? interval :
- isdaily ? interval * 24 * 60 :
- isweekly ? interval * 7 * 24 * 60 :
- ismonthly ? interval * 4 * 7 * 24 * 60 : interval
- intMints // output
- Mnts= func_intbyMints()
- VWMnts = Mnts<=3 ? 5 : Mnts
- //
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- // ♣LONG DEVIATION INPUT SETTINGS♣
- //
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- showLongBands = input(title="How many deviation bands to display" , type=string, defval=defShowLongBands,
- options=["VWAP only", "[1] Standard Deviation", "[2] Standard & Golden", "[3] Stardard to Silver", "[4] Standard to Bronze", "[5] All"])
- // Long Standard Deviations Parameters (default: Metallic Means)
- longDev1 = input(title='[1] "Standard" Deviation (default: 1 SD)', defval=defLongDev1) // Zero ratio (Fib ratio n=0)
- longDev2 = input(title='[2] "Golden" Deviation (1.618 SD)' , defval=defLongDev2) // Golden ratio (Fib ratio n=1)
- longDev3 = input(title='[3] "Silver" Deviation (2.414 SD)' , defval=defLongDev3) // Silver ratio (Fib ratio n=2)
- longDev4 = input(title='[4] "Bronze" Deviation (3.303 SD)' , defval=defLongDev4) // Bronze ratio (Fib ratio n=3)
- longDev5 = input(title='[5] "Copper" Deviation (4.236 SD)' , defval=defLongDev5) // Copper ratio (Fib ratio n=4)
- //
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- // ♣LONG TIMEFRAME INPUTS♣
- //
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- themeLongShade = input(title="Color shade", type=string, defval=defThemeLongShade,
- options=["Dark", "Light"])
- // Long: Color selection for each side
- themeColorAboveLong = input(title="Color above VWAP", type=string, defval=defThemeColorAboveLong,
- options=["01 Red","08 Green", "10 Cyan","03 Black","02 Deep Orange","12 Blue", "16 Blue Grey", "00 Grey"])
- themeColorBelowLong = input(title="Color below VWAP", type=string, defval=defThemeColorBelowLong,
- options=["01 Red", "08 Green","02 Deep Orange","03 Black","10 Cyan", "12 Blue", "16 Blue Grey", "00 Grey"])
- // Long alternating fill selector (bullish/bearish)
- longFillAlt = input(false, title="Bullish/Bearish alternating fill")
- // Center and "opposite" bands (other side of the mean)
- themeLongCenter = input(title="Center & opposite bands", type=string, defval=defThemeLongCenter,
- options=["Light Grey", "Dark Grey", "Red", "Blue"])
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- // ♣SHORT TIMEFRAME INPUT♣
- //
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- enableShort = input(false, title="-------- SHORT VOLATILITY BANDS -------- [uncheck to disable]")
- // VWAP Length
- shortLength = input( title="Length (bars back)", type=integer, defval=defShortLen, minval=1 )
- // Short resolution
- shortCustomRes = input(title="Timeframe (minutes) [0 to use current chart's]", type=float, defval=defShortTF, minval=0, step=1)
- shortRes = shortCustomRes==0 ? period : tostring(shortCustomRes)
- //
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- // ♣DEVIATION INPUTS♣
- //
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- showShortBands = input(title="How many deviation bands to display", type=string, defval=defShowShortBands,
- options=["VWAP only", "[1] Standard Deviation", "[2] Standard & Golden", "[3] Stardard to Silver", "[4] Standard to Bronze", "[5] All"])
- // Standard Deviations Parameters (default: Metallic Means)type = float, step = 0.1)
- shortDev1 = input(title='[1] "Standard" Deviation [0 = same as long]', minval=0, step=0.1, defval=defShortDev1) // Zero ratio (Fib ratio n=0)
- shortDev2 = input(title='[2] "Golden" Deviation [0 = same as long]' , minval=0, step=0.1, defval=defShortDev2) // Golden ratio (Fib ratio n=1)
- shortDev3 = input(title='[3] "Silver" Deviation [0 = same as long]' , minval=0, step=0.1, defval=defShortDev3) // Silver ratio (Fib ratio n=2)
- shortDev4 = input(title='[4] "Bronze" Deviation [0 = same as long]' , minval=0, step=0.1, defval=defShortDev4) // Bronze ratio (Fib ratio n=3)
- shortDev5 = input(title='[5] "Copper" Deviation [0 = same as long]' , minval=0, step=0.1, defval=defShortDev5) // Copper ratio (Fib ratio n=4)
- //
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- // ♣THEMES♣
- //
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- // Short shades (Dark to Light)
- themeShortShade = input(title="Color shade", type=string, defval=defThemeShortShade,
- options=["Dark", "Light"])
- // Short: Color selection for each side
- themeColorAboveShort = input(title="Color above VWAP", type=string, defval=defThemeColorAboveShort,
- options=["01 Red", "08 Green","02 Deep Orange","03 Black", "10 Cyan", "12 Blue", "16 Blue Grey", "00 Grey"])
- themeColorBelowShort = input(title="Color below VWAP", type=string, defval=defThemeColorBelowShort,
- options=["01 Red","03 Black","08 Green","02 Deep Orange", "10 Cyan", "12 Blue", "16 Blue Grey", "00 Grey"])
- // Short alternating fill selector (bullish/bearish)
- shortFillAlt = input(false, title="Bullish/Bearish alternating fill")
- // Center and "opposite" bands (other side of the mean)
- themeShortCenter = input(title="Center & opposite bands", type=string, defval=defThemeShortCenter,
- options=["Light Grey", "Dark Grey", "Red", "Blue"])
- //
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- // ♣STRATEGY INPUTS♣
- //
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- // ♣FUNCTIONS♣
- //
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- fnVWAP(Price, Weight, Length) => sum(Price * Weight, Length ) / sum(Weight, Length)
- // fnWeightedStDev: Weighted Standard Deviation (WSD)
- // Calculate deviation based on the sliding Length (N minutes)
- fnWeightedStDev(Price, Weight, Length) => sqrt(sum(Weight * pow((Price-sma(Price,Length)),2),Length)/sum(Weight, Length))
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- // ♣ CALCULATE♣
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- // Evaluate if long and short deviation multipliers are the same (otherwise use short value).
- shortDev1 := shortDev1 == 0 ? longDev1 : shortDev1
- shortDev2 := shortDev2 == 0 ? longDev2 : shortDev2
- shortDev3 := shortDev3 == 0 ? longDev3 : shortDev3
- shortDev4 := shortDev4 == 0 ? longDev4 : shortDev4
- shortDev5 := shortDev5 == 0 ? longDev5 : shortDev5
- longPrice = security(tickerid, longRes, close)
- longVolume = security(tickerid, longRes, volume)
- shortPrice = security(tickerid, shortRes, close)
- shortVolume = security(tickerid, shortRes, volume)
- shortTime = security(tickerid, shortRes, VWMnts)
- longTime = security(tickerid, longRes, VWMnts)
- // VWAP
- longMean = enableLong ==true ? fnVWAP( longPrice, longVolume, longLength) : na
- shortMean = enableShort==true ? fnVWAP(shortPrice, shortVolume, shortLength) : na
- // WEIGHTED STANDARD DEVIATION
- longDeviation = fnWeightedStDev( longPrice, longTime, longLength)
- shortDeviation = fnWeightedStDev(shortPrice, shortTime,shortLength)
- //
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- // ♣Deviations♣
- //
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- // Which long lines to calculate and draw
- showLongDev5 = showLongBands=="[5] All"
- showLongDev4 = showLongBands=="[4] Standard to Bronze" or showLongDev5
- showLongDev3 = showLongBands=="[3] Stardard to Silver" or showLongDev4
- showLongDev2 = showLongBands=="[2] Standard & Golden" or showLongDev3
- showLongDev1 = showLongBands=="[1] Standard Deviation" or showLongDev2
- showLongMean = showLongBands=="VWAP only" or showLongDev1
- // Which short lines to calculate and draw
- showShortDev5 = showShortBands=="[5] All"
- showShortDev4 = showShortBands=="[4] Standard to Bronze" or showShortDev5
- showShortDev3 = showShortBands=="[3] Stardard to Silver" or showShortDev4
- showShortDev2 = showShortBands=="[2] Standard & Golden" or showShortDev3
- showShortDev1 = showShortBands=="[1] Standard Deviation" or showShortDev2
- showShortMean = showShortBands=="VWAP only" or showShortDev1
- // Long Timeframe above
- longDevLineAbove1 = showLongDev1 ? longMean + ( longDev1 * longDeviation ) : na
- longDevLineAbove2 = showLongDev2 ? longMean + ( longDev2 * longDeviation ) : na
- longDevLineAbove3 = showLongDev3 ? longMean + ( longDev3 * longDeviation ) : na
- longDevLineAbove4 = showLongDev4 ? longMean + ( longDev4 * longDeviation ) : na
- longDevLineAbove5 = showLongDev5 ? longMean + ( longDev5 * longDeviation ) : na
- // Long Timeframe below
- longDevLineBelow1 = showLongDev1 ? longMean - ( longDev1 * longDeviation ) : na
- longDevLineBelow2 = showLongDev2 ? longMean - ( longDev2 * longDeviation ) : na
- longDevLineBelow3 = showLongDev3 ? longMean - ( longDev3 * longDeviation ) : na
- longDevLineBelow4 = showLongDev4 ? longMean - ( longDev4 * longDeviation ) : na
- longDevLineBelow5 = showLongDev5 ? longMean - ( longDev5 * longDeviation ) : na
- // Short Timeframe above
- shortDevLineAbove1 = showShortDev1 ? shortMean + ( shortDev1 * shortDeviation ) : na
- shortDevLineAbove2 = showShortDev2 ? shortMean + ( shortDev2 * shortDeviation ) : na
- shortDevLineAbove3 = showShortDev3 ? shortMean + ( shortDev3 * shortDeviation ) : na
- shortDevLineAbove4 = showShortDev4 ? shortMean + ( shortDev4 * shortDeviation ) : na
- shortDevLineAbove5 = showShortDev5 ? shortMean + ( shortDev5 * shortDeviation ) : na
- // Long Timeframe below
- shortDevLineBelow1 = showShortDev1 ? shortMean - ( shortDev1 * shortDeviation ) : na
- shortDevLineBelow2 = showShortDev2 ? shortMean - ( shortDev2 * shortDeviation ) : na
- shortDevLineBelow3 = showShortDev3 ? shortMean - ( shortDev3 * shortDeviation ) : na
- shortDevLineBelow4 = showShortDev4 ? shortMean - ( shortDev4 * shortDeviation ) : na
- shortDevLineBelow5 = showShortDev5 ? shortMean - ( shortDev5 * shortDeviation ) : na
- //
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- // ♣STRATEGY♣
- //
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- //priceOverNegStDev1 = crossover(low, longDevLineBelow1)
- //priceOverPosStDev1 = crossunder(high, longDevLineAbove1)
- //long Signal
- isCrossO(val,toCrs) => crossover(val, toCrs)
- isCrossU(val,toCrs) => crossunder(val, toCrs)
- //bullLong0Cond = isCrossO(low,longMean)
- bullLong1Cond = isCrossO(open,longDevLineBelow1)
- bullLong2Cond = isCrossO(open,longDevLineBelow2)
- bullLong3Cond = isCrossO(open,longDevLineBelow3)
- bullLong4Cond = isCrossO(open,longDevLineBelow4)
- bullLong5Cond = isCrossO(open,longDevLineBelow5)
- //bearLong0Cond = isCrossU(low,longMean)
- bearLong1Cond = isCrossU(close,longDevLineAbove1)
- bearLong2Cond = isCrossU(close,longDevLineAbove2)
- bearLong3Cond = isCrossU(close,longDevLineAbove3)
- bearLong4Cond = isCrossU(close,longDevLineAbove4)
- bearLong5Cond = isCrossU(close,longDevLineAbove5)
- longBullSignal = bullLong1Cond or bullLong2Cond or bullLong3Cond or bullLong4Cond or bullLong5Cond ? true : false
- longBearSignal = bearLong1Cond or bearLong2Cond or bearLong3Cond or bearLong4Cond or bearLong5Cond ? true : false
- //Short Signal
- //sbLL0Cond = isCrossO(low,shortMean)
- sbLL1Cond = isCrossO(open,shortDevLineBelow1)
- sbLL2Cond = isCrossO(open,shortDevLineBelow2)
- sbLL3Cond = isCrossO(open,shortDevLineBelow3)
- sbLL4Cond = isCrossO(open,shortDevLineBelow4)
- sbLL5Cond = isCrossO(open,shortDevLineBelow5)
- //sbL0Cond = isCrossU(low,shortMean)
- sbL1Cond = isCrossU(close,shortDevLineAbove1)
- sbL2Cond = isCrossU(close,shortDevLineAbove2)
- sbL3Cond = isCrossU(close,shortDevLineAbove3)
- sbL4Cond = isCrossU(close,shortDevLineAbove4)
- sbL5Cond = isCrossU(close,shortDevLineAbove5)
- shortBullSignal = sbLL1Cond or sbLL2Cond or sbLL3Cond or sbLL4Cond or sbLL5Cond ? true : false
- shortBearSignal = sbL1Cond or sbL2Cond or sbL3Cond or sbL4Cond or sbL5Cond ? true : false
- // LONG STRATEGY
- // BULL TRADE
- strategy.entry( "LONG", strategy.long, when=( longBullSignal and time ) )
- strategy.exit( "LONG", when=( longBearSignal and time ) )
- // BEAR TRADE
- strategy.entry( "SHORT", strategy.short, when=( longBearSignal and time ) )
- strategy.exit( "SHORT", when=( longBullSignal and time ) )
- //SHORT STRATEGY
- // BULL TRADE
- strategy.entry( "LONG", strategy.long, when=( shortBullSignal and time) )
- strategy.exit( "LONG", when=( shortBearSignal and time ) )
- // BEAR TRADE
- strategy.entry( "SHORT", strategy.short, when=( shortBearSignal and time ) )
- strategy.exit( "SHORT", when=( shortBullSignal and time) )
- // End of STRATEGY
- // *****************************************************************************
- // -----------------------------------------------------------------------------
- //
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- // ♣DESIGN♣
- //
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- // Red, Pink, Purple, Deep Purple
- red20 = #EF9A9A , pink20 = #F48FB1 , purple20 = #CE93D8 , deepPurple20 = #B39DDB
- red30 = #E57373 , pink30 = #F06292 , purple30 = #BA68C8 , deepPurple30 = #9575CD
- red50 = #F44336 , pink50 = #E91E63 , purple50 = #9C27B0 , deepPurple50 = #673AB7
- red70 = #D32F2F , pink70 = #C2185B , purple70 = #7B1FA2 , deepPurple70 = #512DA8
- red90 = #B71C1C , pink90 = #880E4F , purple90 = #D500F9 , deepPurple90 = #311B92
- // Indigo, Blue, Light Blue, Cyan
- indigo20 = #9FA8DA , blue20 = #90CAF9 , lightBlue20 = #81D4FA , cyan20 = #80DEEA
- indigo30 = #7986CB , blue30 = #64B5F6 , lightBlue30 = #4FC3F7 , cyan30 = #4DD0E1
- indigo50 = #3F51B5 , blue50 = #2196F3 , lightBlue50 = #03A9F4 , cyan50 = #E57373
- indigo70 = #303F9F , blue70 = #1976D2 , lightBlue70 = #0288D1 , cyan70 = #E57373
- indigo90 = #1A237E , blue90 = #0D47A1 , lightBlue90 = #01579B , cyan90 = #E57373
- // Teal, Green, Light Green, Lime
- teal20 = #80CBC4 , green20 = #A5D6A7 , lightGreen20 = #C5E1A5 , lime20 = #E6EE9C
- teal30 = #4DB6AC , green30 = #81C784 , lightGreen30 = #AED581 , lime30 = #DCE775
- teal50 = #009688 , green50 = #4CAF50 , lightGreen50 = #8BC34A , lime50 = #CDDC39
- teal70 = #00796B , green70 = #A5D6A7 , lightGreen70 = #689F38 , lime70 = #AFB42B
- teal90 = #004D40 , green90 = #4CAF50 , lightGreen90 = #33691E , lime90 = #827717
- // Yellow, Amber, Orange, Deep Orange
- yellow20 = #FFF59D , amber20 = #FFE082 , orange20 = #FFCC80 , deepOrange20 = #FFAB91
- yellow30 = #FFF176 , amber30 = #FFD54F , orange30 = #FFB74D , deepOrange30 = #FF8A65
- yellow50 = #FFEB3B , amber50 = #FFC107 , orange50 = #FF9800 , deepOrange50 = #FF5722
- yellow70 = #FBC02D , amber70 = #FFA000 , orange70 = #F57C00 , deepOrange70 = #E64A19
- yellow90 = #F57F17 , amber90 = #FF6F00 , orange90 = #E65100 , deepOrange90 = #BF360C
- // Grey,blue gray
- grey20 = #EEEEEE, bluegrey20 = #B0BEC5
- grey30 = #E0E0E0, bluegrey40 = #78909C
- grey40 = #BDBDBD, bluegrey60 = #546E7A
- grey50 = #9E9E9E, bluegrey70 = #455A64
- grey70 = #616161, bluegrey80 = #37474F
- grey80 = #424242, bluegrey90 = #26C6DA
- grey90 = #212121
- black00 = #000000
- //
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- // ♣COLOR THEMES♣
- //
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- // work out the shade here first, then plug that variable into colorAbove and colorBelow
- colorLongRed = themeLongShade=="Dark" ? red90 : red70
- colorLongDeepOr = themeLongShade=="Dark" ? deepOrange70 : deepOrange50
- colorLongBlack = themeLongShade=="Dark" ? black00 : black00
- colorLongBlueGrey = themeLongShade=="Dark" ? bluegrey60 : bluegrey20
- colorLongGreen = themeLongShade=="Dark" ? green90 : green70
- colorLongCyan = themeLongShade=="Dark" ? cyan70 : cyan50
- colorLongBlue = themeLongShade=="Dark" ? blue90 : blue70
- colorLongPink = themeLongShade=="Dark" ? pink70 : pink50
- colorLongGrey = themeLongShade=="Dark" ? grey80 : grey50
- colorShortBlack = themeLongShade=="Dark" ? black00 : black00
- colorShortRed = themeShortShade=="Dark" ? red90 : red70
- colorShortDeepOr = themeShortShade=="Dark" ? deepOrange70 : deepOrange50
- colorShortGreen = themeShortShade=="Dark" ? green90 : green70
- colorShortCyan = themeShortShade=="Dark" ? cyan70 : cyan50
- colorShortBlue = themeShortShade=="Dark" ? blue90 : blue70
- colorShortBlueGrey = themeShortShade=="Dark" ? bluegrey80 : bluegrey60
- colorShortPink = themeShortShade=="Dark" ? pink70 : pink50
- colorShortGrey = themeShortShade=="Dark" ? grey80 : grey50
- colorAboveLong =
- themeColorAboveLong=="01 Red" ? colorLongRed :
- themeColorAboveLong=="02 Deep Orange" ? colorLongDeepOr :
- themeColorAboveLong=="08 Green" ? colorLongGreen :
- themeColorAboveLong=="10 Cyan" ? colorLongCyan :
- themeColorAboveLong=="12 Blue" ? colorLongBlue :
- themeColorAboveLong=="03 Black" ? colorLongBlack :
- themeColorAboveLong=="16 Blue Grey" ? colorLongBlueGrey :
- colorLongGrey
- colorBelowLong =
- themeColorBelowLong=="01 Red" ? colorLongRed :
- themeColorBelowLong=="02 Deep Orange" ? colorLongDeepOr :
- themeColorBelowLong=="03 Black" ? colorLongBlack :
- themeColorBelowLong=="08 Green" ? colorLongGreen :
- themeColorBelowLong=="10 Cyan" ? colorLongCyan :
- themeColorBelowLong=="12 Blue" ? colorLongBlue :
- themeColorBelowLong=="16 Blue Grey" ? colorLongBlueGrey :
- colorLongGrey
- colorAboveShort =
- themeColorAboveShort=="01 Red" ? colorShortRed :
- themeColorAboveShort=="02 Deep Orange" ? colorShortDeepOr :
- themeColorAboveShort=="03 Black" ? colorShortBlack :
- themeColorAboveShort=="08 Green" ? colorShortGreen :
- themeColorAboveShort=="10 Cyan" ? colorShortCyan :
- themeColorAboveShort=="12 Blue" ? colorShortBlue :
- themeColorAboveShort=="16 Blue Grey" ? colorShortBlueGrey :
- colorShortGrey
- colorBelowShort =
- themeColorBelowShort=="01 Red" ? colorShortRed :
- themeColorBelowShort=="02 Deep Orange" ? colorShortDeepOr :
- themeColorBelowShort=="03 Black" ? colorShortBlack :
- themeColorBelowShort=="08 Green" ? colorShortGreen :
- // themeColorBelowShort=="09 Teal" ? colorShortTeal :
- themeColorBelowShort=="10 Cyan" ? colorShortCyan :
- // themeColorBelowShort=="11 Light Blue" ? colorShortLiteBl :
- themeColorBelowShort=="12 Blue" ? colorShortBlue :
- themeColorBelowShort=="16 Blue Grey" ? colorShortBlueGrey :
- colorShortGrey
- //
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- // ♣FILL POINTS FOR BULLISH/BEARISH♣
- //
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- longFillCenter = themeLongCenter=="Light Grey" ? grey40 : themeLongCenter=="Dark Grey" ? grey90 : themeLongCenter=="Red" ? red : blue
- shortFillCenter = themeShortCenter=="Light Grey" ? grey40 : themeLongCenter=="Dark Grey" ? grey90 : themeLongCenter=="Red" ? red : blue
- // Long bands fill color
- isLongBullish = close > longMean
- fillLongAbove = not(isLongBullish) and longFillAlt ? longFillCenter : colorAboveLong
- fillLongBelow = isLongBullish and longFillAlt ? longFillCenter : colorBelowLong
- // Short bands fill color
- isShortBullish = close > shortMean
- fillShortAbove = not(isShortBullish) and shortFillAlt ? shortFillCenter : colorAboveShort
- fillShortBelow = isShortBullish and shortFillAlt ? shortFillCenter : colorBelowShort
- //
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- // ♣PLOT♣
- //
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- // Means
- mainLongMean = plot(longMean , title="------ MEAN (LONG) -------", linewidth=1, style=circles, join=false, transp=0, color=grey80)
- mainShortMean =plot(shortMean, title="------ MEAN (SHORT) ------", linewidth=1, style=circles , join=false, transp=0, color=grey80)
- // Long Deviation Lines
- longAbove1 = plot( longDevLineAbove1, title="[1🔼] Standard Deviation (SELL?)", style=circles, join=false, transp=0 , color=grey50 )
- longAbove2 = plot( longDevLineAbove2, title="[2🔼] Golden Dev. Above ", style=circles, join=false, transp=0 ,color=colorAboveLong )
- longAbove3 = plot( longDevLineAbove3, title="[3🔼] Silver Dev. Above ", style=circles, join=false, transp=0 , color=colorAboveLong )
- longAbove4 = plot( longDevLineAbove4, title="[4🔼] Bronze Dev. Above ", style=circles, join=false, transp=0 , color=colorAboveLong )
- longAbove5 = plot( longDevLineAbove5, title="[5🔼] Copper Dev. Above ", style=circles, join=false, transp=100, color=colorAboveLong )
- longBelow1 = plot( longDevLineBelow1, title="[1🔽] Standard Deviation (BUY?)", style=circles, join=false, transp=0 , color=grey50)
- longBelow2 = plot( longDevLineBelow2, title="[2🔽] Golden Dev. Below ", style=circles, join=false, transp=0 , color=colorBelowLong )
- longBelow3 = plot( longDevLineBelow3, title="[3🔽] Silver Dev. Below ", style=circles, join=false, transp=0 , color=colorBelowLong )
- longBelow4 = plot( longDevLineBelow4, title="[4🔽] Bronze Dev. Below ", style=circles, join=false, transp=0 , color=colorBelowLong )
- longBelow5 = plot( longDevLineBelow5, title="[5🔽] Copper Dev. Below ", style=circles, join=false, transp=100, color=colorBelowLong )
- // Short Deviation Lines
- shortAbove1 = plot( shortDevLineAbove1, title="[1🔼] Standard Deviation (SELL?)", style=circles, join=false, transp=0, color=grey50 )
- shortAbove2 = plot( shortDevLineAbove2, title="[2🔼] Golden Dev. Above ", style=circles, join=false, transp=0, color=colorAboveShort )
- shortAbove3 = plot( shortDevLineAbove3, title="[3🔼] Silver Dev. Above ", style=circles, join=false, transp=0, color=colorAboveShort )
- shortAbove4 = plot( shortDevLineAbove4, title="[4🔼] Bronze Dev. Above ", style=circles, join=false, transp=0, color=colorAboveShort )
- shortAbove5 = plot( shortDevLineAbove5, title="[5🔼] Copper Dev. Above ", style=circles, join=false, transp=0, color=colorAboveShort )
- shortBelow1 = plot( shortDevLineBelow1, title="[1🔽] Standard Deviation (BUY?)", style=circles, join=false, transp=0, color=grey50 )
- shortBelow2 = plot( shortDevLineBelow2, title="[2🔽] Golden Dev. Below ", style=circles, join=false, transp=0, color=colorBelowShort )
- shortBelow3 = plot( shortDevLineBelow3, title="[3🔽] Silver Dev. Below ", style=circles, join=false, transp=0, color=colorBelowShort )
- shortBelow4 = plot( shortDevLineBelow4, title="[4🔽] Bronze Dev. Below ", style=circles, join=false, transp=0, color=colorBelowShort )
- shortBelow5 = plot( shortDevLineBelow5, title="[5🔽] Copper Dev. Below ", style=circles, join=false, transp=0, color=colorBelowShort )
- //
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- // FILL PLOT
- //
- //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
- // Long Bands Fill
- fill ( longBelow1, longAbove1, transp=90, color=longFillCenter , title="------ Fill: 1 SD Band around Long Mean ------")
- fill ( longAbove1, longAbove2, transp=80, color=fillLongAbove, title="[2🔼] Long Overbought (Golden Band)" )
- fill ( longAbove2, longAbove3, transp=80, color=fillLongAbove, title="[3🔼] Long Overbought (Silver Band)" )
- fill ( longAbove3, longAbove4, transp=80, color=fillLongAbove, title="[4🔼] Long Overbought (Bronze Band)" )
- fill ( longAbove4, longAbove5, transp=80, color=fillLongAbove, title="[5🔼] Long Overbought (Copper Band)" )
- fill ( longBelow1, longBelow2, transp=80, color=fillLongBelow, title="[2🔽] Long Oversold (Golden Band)" )
- fill ( longBelow2, longBelow3, transp=80, color=fillLongBelow, title="[3🔽] Long Oversold (Silver Band)" )
- fill ( longBelow3, longBelow4, transp=80, color=fillLongBelow, title="[4🔽] Long Oversold (Bronze Band)" )
- fill ( longBelow4, longBelow5, transp=80, color=fillLongBelow, title="[5🔽] Long Oversold (Copper Band)" )
- // Short Bands fill
- fill ( shortBelow1, shortAbove1, transp=90, color=shortFillCenter , title="------ Fill 1 SD Band around Short Mean ------")
- fill ( shortAbove1, shortAbove2, transp=80, color=fillShortAbove, title="[2🔼] Short Overbought (Golden Band)" )
- fill ( shortAbove2, shortAbove3, transp=80, color=fillShortAbove, title="[3🔼] Short Overbought (Silver Band)" )
- fill ( shortAbove3, shortAbove4, transp=80, color=fillShortAbove, title="[4🔼] Short Overbought (Bronze Band)" )
- fill ( shortAbove4, shortAbove5, transp=80, color=fillShortAbove, title="[5🔼] Short Overbought (Copper Band)" )
- fill ( shortBelow1, shortBelow2, transp=80, color=fillShortBelow, title="[2🔽] Short Oversold (Golden Band)" )
- fill ( shortBelow2, shortBelow3, transp=80, color=fillShortBelow, title="[3🔽] Short Oversold (Silver Band)" )
- fill ( shortBelow3, shortBelow4, transp=80, color=fillShortBelow, title="[4🔽] Short Oversold (Bronze Band)" )
- fill ( shortBelow4, shortBelow5, transp=80, color=fillShortBelow, title="[5🔽] Short Oversold (Copper Band)" )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement