Advertisement
danucante

Untitled

Nov 26th, 2023
294
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.26 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © indheaddHe
  3.  
  4. //@version=5
  5. strategy("BTCUSD - J.A BTC", initial_capital = 1000, default_qty_type = strategy.percent_of_equity,
  6. default_qty_value = 100, pyramiding = 0, slippage = 0, overlay = true)
  7.  
  8. ////DATE SETTINGS
  9.  
  10. begin = input.time(defval=timestamp("01 January 2018"), title="start time")
  11. end = input.time(defval=timestamp("01 January 2030"), title="end time")
  12.  
  13. timezone = time >= begin and time <= end
  14.  
  15. //// END OF DATE SETTINGS
  16.  
  17. //////// INDICATORS SET UP ////////
  18.  
  19. ////DMI SETTINGS
  20.  
  21. lensig = input.int(14, title="ADX Smoothing", minval=1, maxval=50, group = "DMI SETTINGS")
  22. lenDMI = input.int(10, minval=1, title="DI Length", group = "DMI SETTINGS")
  23.  
  24. up = ta.change(high)
  25. down = -ta.change(low)
  26. plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
  27. minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
  28. trur = ta.rma(ta.tr, lenDMI)
  29. plus = 100 * ta.rma(plusDM, lenDMI) / trur
  30. minus = 100 * ta.rma(minusDM, lenDMI) / trur
  31.  
  32. // DMI Signal Conditions
  33. DMILong = ta.crossover(plus, minus)
  34. DMIShort = ta.crossunder(plus, minus)
  35.  
  36. //// STC SETTINGS
  37.  
  38. EEEEEE = input(29, 'Length', group = "STC Settings")
  39. BBBB = input(45, 'FastLength', group = "STC Settings")
  40. BBBBB = input(75, 'SlowLength', group = "STC Settings")
  41.  
  42. AAAA(BBB, BBBB, BBBBB) =>
  43. fastMA = ta.ema(BBB, BBBB)
  44. slowMA = ta.ema(BBB, BBBBB)
  45. AAAA = fastMA - slowMA
  46. AAAA
  47.  
  48. AAAAA(EEEEEE, BBBB, BBBBB) =>
  49. AAA = input.float(0.75, step = 0.01, group = "STC Settings")
  50. var CCCCC = 0.0
  51. var DDD = 0.0
  52. var DDDDDD = 0.0
  53. var EEEEE = 0.0
  54. BBBBBB = AAAA(close, BBBB, BBBBB)
  55. CCC = ta.lowest(BBBBBB, EEEEEE)
  56. CCCC = ta.highest(BBBBBB, EEEEEE) - CCC
  57. CCCCC := CCCC > 0 ? (BBBBBB - CCC) / CCCC * 100 : nz(CCCCC[1])
  58. DDD := na(DDD[1]) ? CCCCC : DDD[1] + AAA * (CCCCC - DDD[1])
  59. DDDD = ta.lowest(DDD, EEEEEE)
  60. DDDDD = ta.highest(DDD, EEEEEE) - DDDD
  61. DDDDDD := DDDDD > 0 ? (DDD - DDDD) / DDDDD * 100 : nz(DDDDDD[1])
  62. EEEEE := na(EEEEE[1]) ? DDDDDD : EEEEE[1] + AAA * (DDDDDD - EEEEE[1])
  63. EEEEE
  64.  
  65. mAAAAA = AAAAA(EEEEEE, BBBB, BBBBB)
  66.  
  67. //STC Signal Conditions
  68.  
  69. StcLong = mAAAAA > mAAAAA[1]
  70. StcShort = mAAAAA <= mAAAAA[1]
  71.  
  72. //// END OF STC SETTINGS
  73.  
  74. //// MACD SETTINGS
  75.  
  76. maType = input.string(title="MA Type", defval="SMA", options=["SMA", "EMA"], group="MACD SETTINGS")
  77. fastLen = input.int(title="Fast Length", defval=22, group="MACD SETTINGS")
  78. slowLen = input.int(title="Slow Length", defval=139, group="MACD SETTINGS")
  79. macdLen = input.int(title="MACD Length", defval=18, group="MACD SETTINGS")
  80. fast_ma = maType == "SMA" ? ta.sma(close, fastLen) : ta.ema(close, fastLen)
  81. slow_ma = maType == "SMA" ? ta.sma(close, slowLen) : ta.ema(close, slowLen)
  82. macd = fast_ma - slow_ma
  83. aMacd = ta.ema(macd, macdLen)
  84.  
  85. // MACD Signal Conditions
  86.  
  87. macdLong = macd > aMacd
  88. macdShort = macd < aMacd
  89.  
  90. //// Bollinger Bands SETTINGS
  91.  
  92. bbLen = input.int(title="Length", defval=12, step = 1, group = "BB SETTINGS")
  93. bbMultiplier = input.float(title="Multiplier", defval=0.1, step = 0.1, group = "BB SETTINGS")
  94. bbBase = ta.sma(close, bbLen)
  95. bbStd = bbMultiplier * ta.stdev(close, bbLen)
  96. bbUpper = bbBase + bbStd
  97. bbLower = bbBase - bbStd
  98.  
  99. // BB Signal Conditions
  100.  
  101. bbLong = close > bbUpper
  102. bbShort = close < bbLower
  103.  
  104. //// END OF BOLLINGER BANDS SETTINGS
  105.  
  106. // SUPERTREND SETTINGS
  107.  
  108. atrPeriod = input(4, "ATR Length", group = "Supertrend Settings")
  109. factor = input.float(0.78, "Factor", step = 0.01, group = "Supertrend Settings")
  110.  
  111. [_, direction] = ta.supertrend(factor, atrPeriod)
  112.  
  113. //SuperTrend SignaL Conditions
  114.  
  115. supertrendLong = ta.change(direction) < 0
  116. supertrendShort = ta.change(direction) > 0
  117.  
  118. //// END OF SUPERTREND SETTINGS
  119.  
  120. //// Regularized MA SETTINGS
  121.  
  122. f_kama(src, len, kamaf, kamas) =>
  123. white = math.abs(src - src[1])
  124. ama = 0.0
  125. nsignal = math.abs(src - src[len])
  126. nnoise = math.sum(white, len)
  127. nefratio = nnoise != 0 ? nsignal / nnoise : 0
  128. nsmooth = math.pow(nefratio * (kamaf - kamas) + kamas, 2)
  129. ama := nz(ama[1]) + nsmooth * (src - nz(ama[1]))
  130. ama
  131.  
  132. f_t3(src, len) =>
  133. x1 = ta.ema(src, len)
  134. x2 = ta.ema(x1, len)
  135. x3 = ta.ema(x2, len)
  136. x4 = ta.ema(x3, len)
  137. x5 = ta.ema(x4, len)
  138. x6 = ta.ema(x5, len)
  139. b = 0.7
  140. c1 = - math.pow(b, 3)
  141. c2 = 3 * math.pow(b, 2) + 3 * math.pow(b, 3)
  142. c3 = -6 * math.pow(b, 2) - 3 * b - 3 * math.pow(b, 3)
  143. c4 = 1 + 3 * b + math.pow(b, 3) + 3 * math.pow(b, 2)
  144. c1 * x6 + c2 * x5 + c3 * x4 + c4 * x3
  145.  
  146. f_ma(src, len, type, kamaf, kamas, offset, sigma) =>
  147. x = switch type
  148. "SMA" => ta.sma(src, len)
  149. "EMA" => ta.ema(src, len)
  150. "HMA" => ta.hma(src, len)
  151. "RMA" => ta.rma(src, len)
  152. "WMA" => ta.wma(src, len)
  153. "VWMA" => ta.vwma(src, len)
  154. "ALMA" => ta.alma(src, len, offset, sigma)
  155. "DEMA" => 2 * ta.ema(src, len) - ta.ema(ta.ema(src, len), len)
  156. "TEMA" => 3 * ta.ema(src, len) - 3 * ta.ema(ta.ema(src, len), len) + ta.ema(ta.ema(ta.ema(src, len), len), len)
  157. "EHMA" => ta.ema(2 * ta.ema(src, len / 2) - ta.ema(src, len), math.round(math.sqrt(len)))
  158. "THMA" => ta.wma(ta.wma(src, len / 3) * 3 - ta.wma(src, len / 2) - ta.wma(src, len), len)
  159. "T3" => f_t3(src, len)
  160. "KAMA" => f_kama(src, len, kamaf, kamas)
  161. "LSMA" => ta.linreg(src, len, 0)
  162. x
  163.  
  164. matype = input.string("LSMA", "Type", ["SMA", "EMA", "DEMA", "TEMA", "HMA", "EHMA", "THMA", "RMA", "WMA", "VWMA", "T3", "KAMA", "ALMA", "LSMA"], group = "R.MA Settings")
  165. src = input.source(close, "Source", inline = "1", group = "R.MA Settings")
  166. len = input.int(23, "Length", inline = "1", group = "R.MA Settings")
  167. kamaf = input.float(0.666, "Kaufman Fast", group = "R.MA Settings")
  168. kamas = input.float(0.0645, "Kaufman Slow", group = "R.MA Settings")
  169. offset = input.float(0.85, "ALMA Offset", group = "R.MA Settings")
  170. sigma = input.int(6, "ALMA Sigma", group = "R.MA Settings")
  171. norm = input.int(7, "Regularize Length", group = "R.MA Settings")
  172.  
  173. ma = f_ma(src, len, matype, kamaf, kamas, offset, sigma)
  174. mean = ta.sma(ma, norm)
  175. dev = ta.stdev(ma, norm)
  176. zmean = (ma - mean) / dev
  177.  
  178. RmaLong = ta.crossover(zmean, 0)
  179. RmaShort = ta.crossunder(zmean, 0)
  180.  
  181. //// END OF RMA SETTINGS
  182.  
  183. //// RAVI-FISHER SETTINGS
  184.  
  185. srcRavi = input.source(close, "Source", group = "RAVI SETTINGS")
  186. maf = input.int(23, "Fast MA Length", minval = 1, group = "RAVI SETTINGS")
  187. mas = input.int(28, "Slow MA Length", minval = 1, group = "RAVI SETTINGS")
  188. trigger = input.float(0.07, "Trigger", minval = 0, step = 0.01, group = "RAVI SETTINGS")
  189. maval = (ta.wma(srcRavi, maf) - ta.wma(srcRavi, mas)) * ta.atr(maf) / ta.wma(srcRavi, mas) / ta.atr(mas)
  190. maval := 100 * maval
  191. fish = (math.exp(2 * maval) - 1) / (math.exp(2 * maval) + 1)
  192. raviLong = fish >= 0
  193. raviShort = fish <= 0
  194.  
  195. //// END OF RAVI-FISHER SETTINGS
  196.  
  197. // CCI SETTINGS
  198. CCILength = input.int(defval = 42, step = 1, title = "CCI Length", group = "CCI")
  199.  
  200. cci = ta.cci(hlc3,CCILength)
  201.  
  202. CCIlong = ta.crossover(cci,100)
  203. CCIshort = ta.crossunder(cci,-100)
  204.  
  205. /// END OF CCI SETTINGS
  206.  
  207. //// ALPHATREND SETTINGS
  208.  
  209. coeff = input.float(0.2, 'Multiplier', step=0.1, group = "ALPHATREND SETTINGS")
  210. AP = input(3, 'Common Period', group = "ALPHATREND SETTINGS")
  211. ATR = ta.sma(ta.tr, AP)
  212. srcALPHA = input(close, group = "ALPHATREND SETTINGS")
  213. showsignalsk = input(title='Show Signals?', defval=true, group = "ALPHATREND SETTINGS")
  214. novolumedata = input(title='Change calculation (no volume data)?', defval=false, group = "ALPHATREND SETTINGS")
  215. upT = low - ATR * coeff
  216. downT = high + ATR * coeff
  217. AlphaTrend = 0.0
  218. AlphaTrend := (novolumedata ? ta.rsi(srcALPHA, AP) >= 50 : ta.mfi(hlc3, AP) >= 50) ? upT < nz(AlphaTrend[1]) ? nz(AlphaTrend[1]) : upT : downT > nz(AlphaTrend[1]) ? nz(AlphaTrend[1]) : downT
  219.  
  220. buySignalk = ta.crossover(AlphaTrend, AlphaTrend[2])
  221. sellSignalk = ta.crossunder(AlphaTrend, AlphaTrend[2])
  222.  
  223. K1 = ta.barssince(buySignalk)
  224. K2 = ta.barssince(sellSignalk)
  225. O1 = ta.barssince(buySignalk[1])
  226. O2 = ta.barssince(sellSignalk[1])
  227.  
  228. alphaLong = buySignalk and (O1 > K2)
  229. alphaShort = sellSignalk and (O2 > K1)
  230.  
  231. //// END OF ALPHATREND SETTINGS
  232.  
  233. ///// NORMALIZED KAMA SETTINGS
  234.  
  235. // Define input parameters
  236. fast_period = input.int(title='Fast Period', defval=8, minval=1, group = "KAMA SETTINGS")
  237. slow_period = input.int(title='Slow Period', defval=4, minval=1, group = "KAMA SETTINGS")
  238. er_period = input.int(title='Efficiency Ratio Period', defval=32, minval=1, group = "KAMA SETTINGS")
  239. norm_period = input.int(title='Normalization lookback', defval=21, minval=1, group = "KAMA SETTINGS")
  240.  
  241. // Calculate the efficiency ratio
  242. change = math.abs(close - close[er_period])
  243. volatility = math.sum(math.abs(close - close[1]), er_period)
  244. er = change / volatility
  245.  
  246. // Calculate the smoothing constant
  247. sc = er * (2 / (fast_period + 1) - 2 / (slow_period + 1)) + 2 / (slow_period + 1)
  248.  
  249. // Calculate the KAMA
  250. kama = ta.ema(close, fast_period) + sc * (close - ta.ema(close, fast_period))
  251.  
  252. // Normalize the oscillator
  253. lowest = ta.lowest(kama, norm_period)
  254. highest = ta.highest(kama, norm_period)
  255. normalized = (kama - lowest) / (highest - lowest) - 0.5
  256.  
  257. // Kama L/S Conditions
  258. kamalong = ta.crossover(normalized, 0)
  259. kamashort = ta.crossunder(normalized, 0)
  260.  
  261. //// END OF KAMA SETTINGS
  262.  
  263. ////Execution (ALL SIGNALS) = StcLong bbLong macdLong supertrendLong DMILong RmaLong CCIlong raviLong kamalong alphaLong
  264. // DMI/ADX
  265. dmiGroup = "DMI/ADX"
  266. adxSmoothing = input.int(6, title="ADX Smoothing", group=dmiGroup)
  267. diLength = input.int(19, title="DI Length", group=dmiGroup)
  268.  
  269. [diPlus, diMinus, adx] = ta.dmi(diLength, adxSmoothing)
  270.  
  271. adxLong = diPlus > diMinus and adx > adx[1]
  272. adxShort = diMinus > diPlus
  273.  
  274. LongCondition = bbLong and adxLong
  275. ShortCondition = bbShort and adxShort
  276.  
  277. if strategy.equity > 0 and timezone and LongCondition and barstate.isconfirmed
  278. strategy.entry("B", strategy.long)
  279. if strategy.equity > 0 and timezone and ShortCondition and barstate.isconfirmed
  280. strategy.entry("S", strategy.short)
  281.  
  282. //ELI CobraMetrics TABLE INPUTS
  283. import EliCobra/CobraMetrics/4 as cobra
  284. import TradingView/ta/5
  285. disp_ind = input.string ("None" , title = "Display Curve" , tooltip = "Choose which data you would like to display", options=["Strategy", "Equity", "Open Profit", "Gross Profit", "Net Profit", "None"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
  286. pos_table = input.string("Middle Left", "Table Position", options = ["Top Left", "Middle Left", "Bottom Left", "Top Right", "Middle Right", "Bottom Right", "Top Center", "Bottom Center"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
  287. type_table = input.string("Full", "Table Type", options = ["Full", "Simple", "None"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
  288. plot(cobra.curve(disp_ind))
  289. cobra.cobraTable(type_table, pos_table)
  290.  
  291.  
  292.  
Advertisement
Comments
  • # text 0.12 KB | 0 0
    1. download all types of premium tradingview indicators codes available on telegram - https://t.me/tradingview_premium_indicator
Add Comment
Please, Sign In to add comment
Advertisement