Advertisement
Guest User

Untitled

a guest
Jul 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 32.86 KB | None | 0 0
  1. //@version=3
  2.  
  3. //
  4. //▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ VOLATTITLITY PRICE ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  5.  
  6.  
  7. sTitle = "VWAP"
  8. sShort = "WeightedPRICE"
  9. sRelease = "2018-06-22"
  10. sOverlay = true
  11. sScale = scale.right
  12. sPrecision = 0
  13. sInitial_capital = 10000
  14. sCommission_value = 0.05
  15. sPyramiding = 1
  16. sDefault_qty_type = strategy.percent_of_equity
  17. sDefault_qty_value = 100
  18. sCalc_on_order_fills = true
  19. sCalc_on_every_tick = true
  20. 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)
  21.  
  22.  
  23.  
  24. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  25. // ♣DEFAULT SETTINGS♣
  26. //
  27. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  28.  
  29. defLongLen = 390
  30. defLongTF = 0
  31. defShortLen = 70
  32. defShortTF = 0
  33. //INPUTS
  34.  
  35.  
  36.  
  37. defLongDev = "price"
  38. defLongDev1 = 1.28
  39. defLongDev2 = 2.01
  40. defLongDev3 = 2.51
  41. defLongDev4 = 3.09
  42. defLongDev5 = 4.01
  43.  
  44.  
  45. defShortDev = "price"
  46. defShortDev1 = 0
  47. defShortDev2 = 0
  48. defShortDev3 = 0
  49. defShortDev4 = 0
  50. defShortDev5 = 0
  51.  
  52.  
  53. defShowLongBands = "[4] Standard to Bronze"
  54. defShowShortBands = "[4] Standard to Bronze"
  55.  
  56. defThemeLongShade = "Dark"
  57. defThemeColorAboveLong = "10 Cyan"
  58. defThemeColorBelowLong = "08 Green"
  59. defThemeLongCenter = "Light Grey"
  60.  
  61. defThemeShortShade = "Dark"
  62. defThemeColorAboveShort = "10 Cyan"
  63. defThemeColorBelowShort = "08 Green"
  64. defThemeShortCenter = "Light Grey"
  65.  
  66. //
  67. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  68. // ♣FUNCTION INPUTS♣
  69. //
  70. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  71.  
  72. // Source for price and volume
  73. source = close
  74.  
  75. //________________________________
  76. // LONG TIMEFRAME SETTINGS
  77.  
  78. useTrueRange = input(defval="Auto", options=["Always", "Auto", "Never"], title="Use True Range instead of Volume")
  79. vol = useTrueRange == "Always" or (useTrueRange == "Auto" and na(timenow))? volume : timenow
  80. //
  81.  
  82. enableLong = input(true, title="-------- LONG VOLATILITY BANDS -------- [uncheck to disable]")
  83.  
  84. // VWAP Length (average over N bars back)
  85. longLength = input( title="Length (bars back)", type=integer, defval=defLongLen, minval=1 )
  86.  
  87. // Long resolution
  88. longCustomRes = input(title="Timeframe (minutes) [0 to use current chart's]", type=integer, defval=defLongTF, minval=0, step=100)
  89. longRes = longCustomRes==0 ? period : tostring(longCustomRes)
  90.  
  91.  
  92. func_intbyMints() =>
  93. intMints = 0.0
  94. intMints := isintraday ? interval :
  95. isdaily ? interval * 24 * 60 :
  96. isweekly ? interval * 7 * 24 * 60 :
  97. ismonthly ? interval * 4 * 7 * 24 * 60 : interval
  98. intMints // output
  99.  
  100. Mnts= func_intbyMints()
  101.  
  102. VWMnts = Mnts<=3 ? 5 : Mnts
  103.  
  104. //
  105. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  106. // ♣LONG DEVIATION INPUT SETTINGS♣
  107. //
  108. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  109.  
  110. showLongBands = input(title="How many deviation bands to display" , type=string, defval=defShowLongBands,
  111. options=["VWAP only", "[1] Standard Deviation", "[2] Standard & Golden", "[3] Stardard to Silver", "[4] Standard to Bronze", "[5] All"])
  112.  
  113. // Long Standard Deviations Parameters (default: Metallic Means)
  114. longDev1 = input(title='[1] "Standard" Deviation (default: 1 SD)', defval=defLongDev1) // Zero ratio (Fib ratio n=0)
  115. longDev2 = input(title='[2] "Golden" Deviation (1.618 SD)' , defval=defLongDev2) // Golden ratio (Fib ratio n=1)
  116. longDev3 = input(title='[3] "Silver" Deviation (2.414 SD)' , defval=defLongDev3) // Silver ratio (Fib ratio n=2)
  117. longDev4 = input(title='[4] "Bronze" Deviation (3.303 SD)' , defval=defLongDev4) // Bronze ratio (Fib ratio n=3)
  118. longDev5 = input(title='[5] "Copper" Deviation (4.236 SD)' , defval=defLongDev5) // Copper ratio (Fib ratio n=4)
  119.  
  120.  
  121.  
  122. //
  123. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  124. // ♣LONG TIMEFRAME INPUTS♣
  125. //
  126. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  127. themeLongShade = input(title="Color shade", type=string, defval=defThemeLongShade,
  128. options=["Dark", "Light"])
  129.  
  130. // Long: Color selection for each side
  131. themeColorAboveLong = input(title="Color above VWAP", type=string, defval=defThemeColorAboveLong,
  132. options=["01 Red","08 Green", "10 Cyan","03 Black","02 Deep Orange","12 Blue", "16 Blue Grey", "00 Grey"])
  133. themeColorBelowLong = input(title="Color below VWAP", type=string, defval=defThemeColorBelowLong,
  134. options=["01 Red", "08 Green","02 Deep Orange","03 Black","10 Cyan", "12 Blue", "16 Blue Grey", "00 Grey"])
  135.  
  136. // Long alternating fill selector (bullish/bearish)
  137. longFillAlt = input(false, title="Bullish/Bearish alternating fill")
  138.  
  139. // Center and "opposite" bands (other side of the mean)
  140. themeLongCenter = input(title="Center & opposite bands", type=string, defval=defThemeLongCenter,
  141. options=["Light Grey", "Dark Grey", "Red", "Blue"])
  142.  
  143.  
  144. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  145. // ♣SHORT TIMEFRAME INPUT♣
  146. //
  147. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  148. enableShort = input(false, title="-------- SHORT VOLATILITY BANDS -------- [uncheck to disable]")
  149.  
  150. // VWAP Length
  151. shortLength = input( title="Length (bars back)", type=integer, defval=defShortLen, minval=1 )
  152.  
  153. // Short resolution
  154. shortCustomRes = input(title="Timeframe (minutes) [0 to use current chart's]", type=float, defval=defShortTF, minval=0, step=1)
  155. shortRes = shortCustomRes==0 ? period : tostring(shortCustomRes)
  156. //
  157. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  158. // ♣DEVIATION INPUTS♣
  159. //
  160. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  161. showShortBands = input(title="How many deviation bands to display", type=string, defval=defShowShortBands,
  162. options=["VWAP only", "[1] Standard Deviation", "[2] Standard & Golden", "[3] Stardard to Silver", "[4] Standard to Bronze", "[5] All"])
  163.  
  164. // Standard Deviations Parameters (default: Metallic Means)type = float, step = 0.1)
  165. shortDev1 = input(title='[1] "Standard" Deviation [0 = same as long]', minval=0, step=0.1, defval=defShortDev1) // Zero ratio (Fib ratio n=0)
  166. shortDev2 = input(title='[2] "Golden" Deviation [0 = same as long]' , minval=0, step=0.1, defval=defShortDev2) // Golden ratio (Fib ratio n=1)
  167. shortDev3 = input(title='[3] "Silver" Deviation [0 = same as long]' , minval=0, step=0.1, defval=defShortDev3) // Silver ratio (Fib ratio n=2)
  168. shortDev4 = input(title='[4] "Bronze" Deviation [0 = same as long]' , minval=0, step=0.1, defval=defShortDev4) // Bronze ratio (Fib ratio n=3)
  169. shortDev5 = input(title='[5] "Copper" Deviation [0 = same as long]' , minval=0, step=0.1, defval=defShortDev5) // Copper ratio (Fib ratio n=4)
  170.  
  171.  
  172.  
  173. //
  174. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  175. // ♣THEMES♣
  176. //
  177. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  178. // Short shades (Dark to Light)
  179. themeShortShade = input(title="Color shade", type=string, defval=defThemeShortShade,
  180. options=["Dark", "Light"])
  181.  
  182. // Short: Color selection for each side
  183. themeColorAboveShort = input(title="Color above VWAP", type=string, defval=defThemeColorAboveShort,
  184. options=["01 Red", "08 Green","02 Deep Orange","03 Black", "10 Cyan", "12 Blue", "16 Blue Grey", "00 Grey"])
  185. themeColorBelowShort = input(title="Color below VWAP", type=string, defval=defThemeColorBelowShort,
  186. options=["01 Red","03 Black","08 Green","02 Deep Orange", "10 Cyan", "12 Blue", "16 Blue Grey", "00 Grey"])
  187.  
  188. // Short alternating fill selector (bullish/bearish)
  189. shortFillAlt = input(false, title="Bullish/Bearish alternating fill")
  190.  
  191. // Center and "opposite" bands (other side of the mean)
  192. themeShortCenter = input(title="Center & opposite bands", type=string, defval=defThemeShortCenter,
  193. options=["Light Grey", "Dark Grey", "Red", "Blue"])
  194.  
  195. //
  196. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  197. // ♣STRATEGY INPUTS♣
  198. //
  199. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  200.  
  201.  
  202. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  203. // ♣FUNCTIONS♣
  204. //
  205. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  206. fnVWAP(Price, Weight, Length) => sum(Price * Weight, Length ) / sum(Weight, Length)
  207.  
  208. // fnWeightedStDev: Weighted Standard Deviation (WSD)
  209. // Calculate deviation based on the sliding Length (N minutes)
  210. fnWeightedStDev(Price, Weight, Length) => sqrt(sum(Weight * pow((Price-sma(Price,Length)),2),Length)/sum(Weight, Length))
  211.  
  212.  
  213.  
  214. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  215. // ♣ CALCULATE♣
  216.  
  217. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  218.  
  219. // Evaluate if long and short deviation multipliers are the same (otherwise use short value).
  220. shortDev1 := shortDev1 == 0 ? longDev1 : shortDev1
  221. shortDev2 := shortDev2 == 0 ? longDev2 : shortDev2
  222. shortDev3 := shortDev3 == 0 ? longDev3 : shortDev3
  223. shortDev4 := shortDev4 == 0 ? longDev4 : shortDev4
  224. shortDev5 := shortDev5 == 0 ? longDev5 : shortDev5
  225.  
  226.  
  227. longPrice = security(tickerid, longRes, close)
  228. longVolume = security(tickerid, longRes, volume)
  229. shortPrice = security(tickerid, shortRes, close)
  230. shortVolume = security(tickerid, shortRes, volume)
  231. shortTime = security(tickerid, shortRes, VWMnts)
  232. longTime = security(tickerid, longRes, VWMnts)
  233. // VWAP
  234. longMean = enableLong ==true ? fnVWAP( longPrice, longVolume, longLength) : na
  235. shortMean = enableShort==true ? fnVWAP(shortPrice, shortVolume, shortLength) : na
  236.  
  237. // WEIGHTED STANDARD DEVIATION
  238. longDeviation = fnWeightedStDev( longPrice, longTime, longLength)
  239. shortDeviation = fnWeightedStDev(shortPrice, shortTime,shortLength)
  240.  
  241.  
  242. //
  243. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  244. // ♣Deviations♣
  245. //
  246. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  247.  
  248. // Which long lines to calculate and draw
  249. showLongDev5 = showLongBands=="[5] All"
  250. showLongDev4 = showLongBands=="[4] Standard to Bronze" or showLongDev5
  251. showLongDev3 = showLongBands=="[3] Stardard to Silver" or showLongDev4
  252. showLongDev2 = showLongBands=="[2] Standard & Golden" or showLongDev3
  253. showLongDev1 = showLongBands=="[1] Standard Deviation" or showLongDev2
  254. showLongMean = showLongBands=="VWAP only" or showLongDev1
  255.  
  256. // Which short lines to calculate and draw
  257. showShortDev5 = showShortBands=="[5] All"
  258. showShortDev4 = showShortBands=="[4] Standard to Bronze" or showShortDev5
  259. showShortDev3 = showShortBands=="[3] Stardard to Silver" or showShortDev4
  260. showShortDev2 = showShortBands=="[2] Standard & Golden" or showShortDev3
  261. showShortDev1 = showShortBands=="[1] Standard Deviation" or showShortDev2
  262. showShortMean = showShortBands=="VWAP only" or showShortDev1
  263.  
  264. // Long Timeframe above
  265.  
  266. longDevLineAbove1 = showLongDev1 ? longMean + ( longDev1 * longDeviation ) : na
  267. longDevLineAbove2 = showLongDev2 ? longMean + ( longDev2 * longDeviation ) : na
  268. longDevLineAbove3 = showLongDev3 ? longMean + ( longDev3 * longDeviation ) : na
  269. longDevLineAbove4 = showLongDev4 ? longMean + ( longDev4 * longDeviation ) : na
  270. longDevLineAbove5 = showLongDev5 ? longMean + ( longDev5 * longDeviation ) : na
  271. // Long Timeframe below
  272. longDevLineBelow1 = showLongDev1 ? longMean - ( longDev1 * longDeviation ) : na
  273. longDevLineBelow2 = showLongDev2 ? longMean - ( longDev2 * longDeviation ) : na
  274. longDevLineBelow3 = showLongDev3 ? longMean - ( longDev3 * longDeviation ) : na
  275. longDevLineBelow4 = showLongDev4 ? longMean - ( longDev4 * longDeviation ) : na
  276. longDevLineBelow5 = showLongDev5 ? longMean - ( longDev5 * longDeviation ) : na
  277.  
  278. // Short Timeframe above
  279. shortDevLineAbove1 = showShortDev1 ? shortMean + ( shortDev1 * shortDeviation ) : na
  280. shortDevLineAbove2 = showShortDev2 ? shortMean + ( shortDev2 * shortDeviation ) : na
  281. shortDevLineAbove3 = showShortDev3 ? shortMean + ( shortDev3 * shortDeviation ) : na
  282. shortDevLineAbove4 = showShortDev4 ? shortMean + ( shortDev4 * shortDeviation ) : na
  283. shortDevLineAbove5 = showShortDev5 ? shortMean + ( shortDev5 * shortDeviation ) : na
  284. // Long Timeframe below
  285. shortDevLineBelow1 = showShortDev1 ? shortMean - ( shortDev1 * shortDeviation ) : na
  286. shortDevLineBelow2 = showShortDev2 ? shortMean - ( shortDev2 * shortDeviation ) : na
  287. shortDevLineBelow3 = showShortDev3 ? shortMean - ( shortDev3 * shortDeviation ) : na
  288. shortDevLineBelow4 = showShortDev4 ? shortMean - ( shortDev4 * shortDeviation ) : na
  289. shortDevLineBelow5 = showShortDev5 ? shortMean - ( shortDev5 * shortDeviation ) : na
  290.  
  291. //
  292. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  293. // ♣STRATEGY♣
  294. //
  295. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  296.  
  297. //priceOverNegStDev1 = crossover(low, longDevLineBelow1)
  298. //priceOverPosStDev1 = crossunder(high, longDevLineAbove1)
  299. //long Signal
  300. isCrossO(val,toCrs) => crossover(val, toCrs)
  301. isCrossU(val,toCrs) => crossunder(val, toCrs)
  302.  
  303.  
  304.  
  305. //bullLong0Cond = isCrossO(low,longMean)
  306. bullLong1Cond = isCrossO(open,longDevLineBelow1)
  307. bullLong2Cond = isCrossO(open,longDevLineBelow2)
  308. bullLong3Cond = isCrossO(open,longDevLineBelow3)
  309. bullLong4Cond = isCrossO(open,longDevLineBelow4)
  310. bullLong5Cond = isCrossO(open,longDevLineBelow5)
  311.  
  312.  
  313.  
  314. //bearLong0Cond = isCrossU(low,longMean)
  315. bearLong1Cond = isCrossU(close,longDevLineAbove1)
  316. bearLong2Cond = isCrossU(close,longDevLineAbove2)
  317. bearLong3Cond = isCrossU(close,longDevLineAbove3)
  318. bearLong4Cond = isCrossU(close,longDevLineAbove4)
  319. bearLong5Cond = isCrossU(close,longDevLineAbove5)
  320.  
  321.  
  322. longBullSignal = bullLong1Cond or bullLong2Cond or bullLong3Cond or bullLong4Cond or bullLong5Cond ? true : false
  323. longBearSignal = bearLong1Cond or bearLong2Cond or bearLong3Cond or bearLong4Cond or bearLong5Cond ? true : false
  324.  
  325.  
  326.  
  327.  
  328. //Short Signal
  329. //sbLL0Cond = isCrossO(low,shortMean)
  330. sbLL1Cond = isCrossO(open,shortDevLineBelow1)
  331. sbLL2Cond = isCrossO(open,shortDevLineBelow2)
  332. sbLL3Cond = isCrossO(open,shortDevLineBelow3)
  333. sbLL4Cond = isCrossO(open,shortDevLineBelow4)
  334. sbLL5Cond = isCrossO(open,shortDevLineBelow5)
  335.  
  336.  
  337.  
  338. //sbL0Cond = isCrossU(low,shortMean)
  339. sbL1Cond = isCrossU(close,shortDevLineAbove1)
  340. sbL2Cond = isCrossU(close,shortDevLineAbove2)
  341. sbL3Cond = isCrossU(close,shortDevLineAbove3)
  342. sbL4Cond = isCrossU(close,shortDevLineAbove4)
  343. sbL5Cond = isCrossU(close,shortDevLineAbove5)
  344.  
  345. shortBullSignal = sbLL1Cond or sbLL2Cond or sbLL3Cond or sbLL4Cond or sbLL5Cond ? true : false
  346. shortBearSignal = sbL1Cond or sbL2Cond or sbL3Cond or sbL4Cond or sbL5Cond ? true : false
  347.  
  348.  
  349. // LONG STRATEGY
  350. // BULL TRADE
  351. strategy.entry( "LONG", strategy.long, when=( longBullSignal and time ) )
  352. strategy.exit( "LONG", when=( longBearSignal and time ) )
  353.  
  354.  
  355.  
  356. // BEAR TRADE
  357. strategy.entry( "SHORT", strategy.short, when=( longBearSignal and time ) )
  358. strategy.exit( "SHORT", when=( longBullSignal and time ) )
  359.  
  360. //SHORT STRATEGY
  361. // BULL TRADE
  362. strategy.entry( "LONG", strategy.long, when=( shortBullSignal and time) )
  363. strategy.exit( "LONG", when=( shortBearSignal and time ) )
  364.  
  365. // BEAR TRADE
  366. strategy.entry( "SHORT", strategy.short, when=( shortBearSignal and time ) )
  367. strategy.exit( "SHORT", when=( shortBullSignal and time) )
  368. // End of STRATEGY
  369. // *****************************************************************************
  370. // -----------------------------------------------------------------------------
  371.  
  372.  
  373. //
  374. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  375. // ♣DESIGN♣
  376. //
  377. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  378.  
  379. // Red, Pink, Purple, Deep Purple
  380. red20 = #EF9A9A , pink20 = #F48FB1 , purple20 = #CE93D8 , deepPurple20 = #B39DDB
  381. red30 = #E57373 , pink30 = #F06292 , purple30 = #BA68C8 , deepPurple30 = #9575CD
  382. red50 = #F44336 , pink50 = #E91E63 , purple50 = #9C27B0 , deepPurple50 = #673AB7
  383. red70 = #D32F2F , pink70 = #C2185B , purple70 = #7B1FA2 , deepPurple70 = #512DA8
  384. red90 = #B71C1C , pink90 = #880E4F , purple90 = #D500F9 , deepPurple90 = #311B92
  385. // Indigo, Blue, Light Blue, Cyan
  386. indigo20 = #9FA8DA , blue20 = #90CAF9 , lightBlue20 = #81D4FA , cyan20 = #80DEEA
  387. indigo30 = #7986CB , blue30 = #64B5F6 , lightBlue30 = #4FC3F7 , cyan30 = #4DD0E1
  388. indigo50 = #3F51B5 , blue50 = #2196F3 , lightBlue50 = #03A9F4 , cyan50 = #E57373
  389. indigo70 = #303F9F , blue70 = #1976D2 , lightBlue70 = #0288D1 , cyan70 = #E57373
  390. indigo90 = #1A237E , blue90 = #0D47A1 , lightBlue90 = #01579B , cyan90 = #E57373
  391. // Teal, Green, Light Green, Lime
  392. teal20 = #80CBC4 , green20 = #A5D6A7 , lightGreen20 = #C5E1A5 , lime20 = #E6EE9C
  393. teal30 = #4DB6AC , green30 = #81C784 , lightGreen30 = #AED581 , lime30 = #DCE775
  394. teal50 = #009688 , green50 = #4CAF50 , lightGreen50 = #8BC34A , lime50 = #CDDC39
  395. teal70 = #00796B , green70 = #A5D6A7 , lightGreen70 = #689F38 , lime70 = #AFB42B
  396. teal90 = #004D40 , green90 = #4CAF50 , lightGreen90 = #33691E , lime90 = #827717
  397. // Yellow, Amber, Orange, Deep Orange
  398. yellow20 = #FFF59D , amber20 = #FFE082 , orange20 = #FFCC80 , deepOrange20 = #FFAB91
  399. yellow30 = #FFF176 , amber30 = #FFD54F , orange30 = #FFB74D , deepOrange30 = #FF8A65
  400. yellow50 = #FFEB3B , amber50 = #FFC107 , orange50 = #FF9800 , deepOrange50 = #FF5722
  401. yellow70 = #FBC02D , amber70 = #FFA000 , orange70 = #F57C00 , deepOrange70 = #E64A19
  402. yellow90 = #F57F17 , amber90 = #FF6F00 , orange90 = #E65100 , deepOrange90 = #BF360C
  403. // Grey,blue gray
  404. grey20 = #EEEEEE, bluegrey20 = #B0BEC5
  405. grey30 = #E0E0E0, bluegrey40 = #78909C
  406. grey40 = #BDBDBD, bluegrey60 = #546E7A
  407. grey50 = #9E9E9E, bluegrey70 = #455A64
  408. grey70 = #616161, bluegrey80 = #37474F
  409. grey80 = #424242, bluegrey90 = #26C6DA
  410. grey90 = #212121
  411. black00 = #000000
  412.  
  413. //
  414. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  415. // ♣COLOR THEMES♣
  416. //
  417. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  418.  
  419. // work out the shade here first, then plug that variable into colorAbove and colorBelow
  420. colorLongRed = themeLongShade=="Dark" ? red90 : red70
  421. colorLongDeepOr = themeLongShade=="Dark" ? deepOrange70 : deepOrange50
  422. colorLongBlack = themeLongShade=="Dark" ? black00 : black00
  423. colorLongBlueGrey = themeLongShade=="Dark" ? bluegrey60 : bluegrey20
  424. colorLongGreen = themeLongShade=="Dark" ? green90 : green70
  425. colorLongCyan = themeLongShade=="Dark" ? cyan70 : cyan50
  426. colorLongBlue = themeLongShade=="Dark" ? blue90 : blue70
  427.  
  428. colorLongPink = themeLongShade=="Dark" ? pink70 : pink50
  429. colorLongGrey = themeLongShade=="Dark" ? grey80 : grey50
  430. colorShortBlack = themeLongShade=="Dark" ? black00 : black00
  431. colorShortRed = themeShortShade=="Dark" ? red90 : red70
  432. colorShortDeepOr = themeShortShade=="Dark" ? deepOrange70 : deepOrange50
  433.  
  434. colorShortGreen = themeShortShade=="Dark" ? green90 : green70
  435. colorShortCyan = themeShortShade=="Dark" ? cyan70 : cyan50
  436. colorShortBlue = themeShortShade=="Dark" ? blue90 : blue70
  437. colorShortBlueGrey = themeShortShade=="Dark" ? bluegrey80 : bluegrey60
  438.  
  439. colorShortPink = themeShortShade=="Dark" ? pink70 : pink50
  440. colorShortGrey = themeShortShade=="Dark" ? grey80 : grey50
  441.  
  442. colorAboveLong =
  443. themeColorAboveLong=="01 Red" ? colorLongRed :
  444. themeColorAboveLong=="02 Deep Orange" ? colorLongDeepOr :
  445.  
  446. themeColorAboveLong=="08 Green" ? colorLongGreen :
  447. themeColorAboveLong=="10 Cyan" ? colorLongCyan :
  448. themeColorAboveLong=="12 Blue" ? colorLongBlue :
  449. themeColorAboveLong=="03 Black" ? colorLongBlack :
  450. themeColorAboveLong=="16 Blue Grey" ? colorLongBlueGrey :
  451. colorLongGrey
  452.  
  453. colorBelowLong =
  454. themeColorBelowLong=="01 Red" ? colorLongRed :
  455. themeColorBelowLong=="02 Deep Orange" ? colorLongDeepOr :
  456. themeColorBelowLong=="03 Black" ? colorLongBlack :
  457. themeColorBelowLong=="08 Green" ? colorLongGreen :
  458.  
  459. themeColorBelowLong=="10 Cyan" ? colorLongCyan :
  460. themeColorBelowLong=="12 Blue" ? colorLongBlue :
  461.  
  462. themeColorBelowLong=="16 Blue Grey" ? colorLongBlueGrey :
  463. colorLongGrey
  464.  
  465. colorAboveShort =
  466. themeColorAboveShort=="01 Red" ? colorShortRed :
  467. themeColorAboveShort=="02 Deep Orange" ? colorShortDeepOr :
  468. themeColorAboveShort=="03 Black" ? colorShortBlack :
  469. themeColorAboveShort=="08 Green" ? colorShortGreen :
  470. themeColorAboveShort=="10 Cyan" ? colorShortCyan :
  471.  
  472. themeColorAboveShort=="12 Blue" ? colorShortBlue :
  473.  
  474. themeColorAboveShort=="16 Blue Grey" ? colorShortBlueGrey :
  475. colorShortGrey
  476.  
  477. colorBelowShort =
  478. themeColorBelowShort=="01 Red" ? colorShortRed :
  479. themeColorBelowShort=="02 Deep Orange" ? colorShortDeepOr :
  480. themeColorBelowShort=="03 Black" ? colorShortBlack :
  481. themeColorBelowShort=="08 Green" ? colorShortGreen :
  482. // themeColorBelowShort=="09 Teal" ? colorShortTeal :
  483. themeColorBelowShort=="10 Cyan" ? colorShortCyan :
  484. // themeColorBelowShort=="11 Light Blue" ? colorShortLiteBl :
  485. themeColorBelowShort=="12 Blue" ? colorShortBlue :
  486.  
  487. themeColorBelowShort=="16 Blue Grey" ? colorShortBlueGrey :
  488. colorShortGrey
  489.  
  490.  
  491. //
  492. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  493. // ♣FILL POINTS FOR BULLISH/BEARISH♣
  494. //
  495. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  496. longFillCenter = themeLongCenter=="Light Grey" ? grey40 : themeLongCenter=="Dark Grey" ? grey90 : themeLongCenter=="Red" ? red : blue
  497. shortFillCenter = themeShortCenter=="Light Grey" ? grey40 : themeLongCenter=="Dark Grey" ? grey90 : themeLongCenter=="Red" ? red : blue
  498.  
  499. // Long bands fill color
  500. isLongBullish = close > longMean
  501. fillLongAbove = not(isLongBullish) and longFillAlt ? longFillCenter : colorAboveLong
  502. fillLongBelow = isLongBullish and longFillAlt ? longFillCenter : colorBelowLong
  503.  
  504. // Short bands fill color
  505. isShortBullish = close > shortMean
  506. fillShortAbove = not(isShortBullish) and shortFillAlt ? shortFillCenter : colorAboveShort
  507. fillShortBelow = isShortBullish and shortFillAlt ? shortFillCenter : colorBelowShort
  508.  
  509.  
  510.  
  511. //
  512. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  513. // ♣PLOT♣
  514. //
  515. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  516.  
  517.  
  518. // Means
  519. mainLongMean = plot(longMean , title="------ MEAN (LONG) -------", linewidth=1, style=circles, join=false, transp=0, color=grey80)
  520. mainShortMean =plot(shortMean, title="------ MEAN (SHORT) ------", linewidth=1, style=circles , join=false, transp=0, color=grey80)
  521.  
  522. // Long Deviation Lines
  523. longAbove1 = plot( longDevLineAbove1, title="[1🔼] Standard Deviation (SELL?)", style=circles, join=false, transp=0 , color=grey50 )
  524. longAbove2 = plot( longDevLineAbove2, title="[2🔼] Golden Dev. Above ", style=circles, join=false, transp=0 ,color=colorAboveLong )
  525. longAbove3 = plot( longDevLineAbove3, title="[3🔼] Silver Dev. Above ", style=circles, join=false, transp=0 , color=colorAboveLong )
  526. longAbove4 = plot( longDevLineAbove4, title="[4🔼] Bronze Dev. Above ", style=circles, join=false, transp=0 , color=colorAboveLong )
  527. longAbove5 = plot( longDevLineAbove5, title="[5🔼] Copper Dev. Above ", style=circles, join=false, transp=100, color=colorAboveLong )
  528. longBelow1 = plot( longDevLineBelow1, title="[1🔽] Standard Deviation (BUY?)", style=circles, join=false, transp=0 , color=grey50)
  529. longBelow2 = plot( longDevLineBelow2, title="[2🔽] Golden Dev. Below ", style=circles, join=false, transp=0 , color=colorBelowLong )
  530. longBelow3 = plot( longDevLineBelow3, title="[3🔽] Silver Dev. Below ", style=circles, join=false, transp=0 , color=colorBelowLong )
  531. longBelow4 = plot( longDevLineBelow4, title="[4🔽] Bronze Dev. Below ", style=circles, join=false, transp=0 , color=colorBelowLong )
  532. longBelow5 = plot( longDevLineBelow5, title="[5🔽] Copper Dev. Below ", style=circles, join=false, transp=100, color=colorBelowLong )
  533.  
  534. // Short Deviation Lines
  535. shortAbove1 = plot( shortDevLineAbove1, title="[1🔼] Standard Deviation (SELL?)", style=circles, join=false, transp=0, color=grey50 )
  536. shortAbove2 = plot( shortDevLineAbove2, title="[2🔼] Golden Dev. Above ", style=circles, join=false, transp=0, color=colorAboveShort )
  537. shortAbove3 = plot( shortDevLineAbove3, title="[3🔼] Silver Dev. Above ", style=circles, join=false, transp=0, color=colorAboveShort )
  538. shortAbove4 = plot( shortDevLineAbove4, title="[4🔼] Bronze Dev. Above ", style=circles, join=false, transp=0, color=colorAboveShort )
  539. shortAbove5 = plot( shortDevLineAbove5, title="[5🔼] Copper Dev. Above ", style=circles, join=false, transp=0, color=colorAboveShort )
  540. shortBelow1 = plot( shortDevLineBelow1, title="[1🔽] Standard Deviation (BUY?)", style=circles, join=false, transp=0, color=grey50 )
  541. shortBelow2 = plot( shortDevLineBelow2, title="[2🔽] Golden Dev. Below ", style=circles, join=false, transp=0, color=colorBelowShort )
  542. shortBelow3 = plot( shortDevLineBelow3, title="[3🔽] Silver Dev. Below ", style=circles, join=false, transp=0, color=colorBelowShort )
  543. shortBelow4 = plot( shortDevLineBelow4, title="[4🔽] Bronze Dev. Below ", style=circles, join=false, transp=0, color=colorBelowShort )
  544. shortBelow5 = plot( shortDevLineBelow5, title="[5🔽] Copper Dev. Below ", style=circles, join=false, transp=0, color=colorBelowShort )
  545.  
  546.  
  547. //
  548. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  549. // FILL PLOT
  550. //
  551. //▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  552.  
  553. // Long Bands Fill
  554. fill ( longBelow1, longAbove1, transp=90, color=longFillCenter , title="------ Fill: 1 SD Band around Long Mean ------")
  555. fill ( longAbove1, longAbove2, transp=80, color=fillLongAbove, title="[2🔼] Long Overbought (Golden Band)" )
  556. fill ( longAbove2, longAbove3, transp=80, color=fillLongAbove, title="[3🔼] Long Overbought (Silver Band)" )
  557. fill ( longAbove3, longAbove4, transp=80, color=fillLongAbove, title="[4🔼] Long Overbought (Bronze Band)" )
  558. fill ( longAbove4, longAbove5, transp=80, color=fillLongAbove, title="[5🔼] Long Overbought (Copper Band)" )
  559. fill ( longBelow1, longBelow2, transp=80, color=fillLongBelow, title="[2🔽] Long Oversold (Golden Band)" )
  560. fill ( longBelow2, longBelow3, transp=80, color=fillLongBelow, title="[3🔽] Long Oversold (Silver Band)" )
  561. fill ( longBelow3, longBelow4, transp=80, color=fillLongBelow, title="[4🔽] Long Oversold (Bronze Band)" )
  562. fill ( longBelow4, longBelow5, transp=80, color=fillLongBelow, title="[5🔽] Long Oversold (Copper Band)" )
  563.  
  564. // Short Bands fill
  565. fill ( shortBelow1, shortAbove1, transp=90, color=shortFillCenter , title="------ Fill 1 SD Band around Short Mean ------")
  566. fill ( shortAbove1, shortAbove2, transp=80, color=fillShortAbove, title="[2🔼] Short Overbought (Golden Band)" )
  567. fill ( shortAbove2, shortAbove3, transp=80, color=fillShortAbove, title="[3🔼] Short Overbought (Silver Band)" )
  568. fill ( shortAbove3, shortAbove4, transp=80, color=fillShortAbove, title="[4🔼] Short Overbought (Bronze Band)" )
  569. fill ( shortAbove4, shortAbove5, transp=80, color=fillShortAbove, title="[5🔼] Short Overbought (Copper Band)" )
  570. fill ( shortBelow1, shortBelow2, transp=80, color=fillShortBelow, title="[2🔽] Short Oversold (Golden Band)" )
  571. fill ( shortBelow2, shortBelow3, transp=80, color=fillShortBelow, title="[3🔽] Short Oversold (Silver Band)" )
  572. fill ( shortBelow3, shortBelow4, transp=80, color=fillShortBelow, title="[4🔽] Short Oversold (Bronze Band)" )
  573. fill ( shortBelow4, shortBelow5, transp=80, color=fillShortBelow, title="[5🔽] Short Oversold (Copper Band)" )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement