Advertisement
NKactive

Untitled

Nov 23rd, 2023
263
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.60 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. // © danielcantea
  3.  
  4.  
  5. //@version=5
  6. strategy("THE MATRIX KILLER", overlay=true, pyramiding = 0, slippage = 1, initial_capital = 100, default_qty_type = strategy.percent_of_equity, default_qty_value = 100)
  7.  
  8. // Plot Cobra Metrics Table
  9. import EliCobra/CobraMetrics/4 as cobra
  10.  
  11.  
  12. disp_ind = input.string ("Equity" , title = "Display Curve" , tooltip = "Choose which data you would like to display", options=["Strategy", "Equity", "Open Profit", "Gross Profit", "Net Profit", "None"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
  13. pos_table = input.string("Bottom Right", "Table Position", options = ["Top Left", "Middle Left", "Bottom Left", "Top Right", "Middle Right", "Bottom Right", "Top Center", "Bottom Center"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
  14. type_table = input.string("Full", "Table Type", options = ["Full", "Simple", "None"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
  15.  
  16. plot(cobra.curve(disp_ind))
  17. cobra.cobraTable(type_table, pos_table)
  18.  
  19. // Time Range
  20. startTime = input.time(defval = timestamp("01 January 2018"), title = "Start Date")
  21. isInTimeRange = time >= startTime
  22.  
  23.  
  24. //////////////////////////////////////////////////////////////////////////Main indicators////////////////////////////////////////////////////////////////////////
  25.  
  26.  
  27.  
  28. fastLength = input(title='MACD Fast Length', defval=9)
  29. slowLength = input(title='MACD Slow Length', defval=34)
  30. cycleLength = input(title='Cycle Length', defval=11)
  31. d1Length = input(title='1st %D Length', defval=1)
  32. d2Length = input(title='2nd %D Length', defval=4)
  33. src = close
  34. upper = 75
  35. lower = 25
  36.  
  37. macd = ta.ema(src, fastLength) - ta.ema(src, slowLength)
  38. k = nz(fixnan(ta.stoch(macd, macd, macd, cycleLength)))
  39. d = ta.ema(k, d1Length)
  40. kd = nz(fixnan(ta.stoch(d, d, d, cycleLength)))
  41. stc = ta.ema(kd, d2Length)
  42. stc := math.max(math.min(stc, 100), 0)
  43.  
  44.  
  45. buySignal = ta.crossover(stc, lower)
  46. sellSignal = ta.crossunder(stc, upper)
  47.  
  48.  
  49. lensig = input.int(36, title="ADX Smoothing", minval=1, maxval=50)
  50. lenDmi = input.int(6, minval=1, title="DI Length")
  51. upD = ta.change(high)
  52. downD = -ta.change(low)
  53. plusDM = na(upD) ? na : (upD > downD and upD > 0 ? upD : 0)
  54. minusDM = na(downD) ? na : (downD > upD and downD > 0 ? downD : 0)
  55. trur = ta.rma(ta.tr, lenDmi)
  56. plus = fixnan(550 * ta.rma(plusDM, lenDmi) / trur)
  57. minus = fixnan(500 * ta.rma(minusDM, lenDmi) / trur)
  58. sum = plus + minus
  59. adx = 520 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), lensig)
  60.  
  61. long_condition = ta.cross(adx, plus)
  62. short_condition = ta.cross(adx, minus)
  63.  
  64.  
  65.  
  66.  
  67. // RTI
  68. trend_data_count = input.int(113, step=1, minval=10, title="Trend Length", inline = "RT", group="RTI")
  69. trend_sensitivity_percentage = input.int(95, step=1,minval=50, maxval=98,title='Sensitivity', inline = "RT1", group="RTI")
  70.  
  71. upper_trend = close + ta.stdev(close, 2)
  72. lower_trend = close - ta.stdev(close, 2)
  73.  
  74. upper_array = array.new<float>(0)
  75. lower_array = array.new<float>(0)
  76. for i = 0 to trend_data_count - 1
  77. upper_array.push(upper_trend[i])
  78. lower_array.push(lower_trend[i])
  79. upper_array.sort()
  80. lower_array.sort()
  81.  
  82. upper_index = math.round(trend_sensitivity_percentage / 100 * trend_data_count) - 1
  83. lower_index = math.round((100 - trend_sensitivity_percentage) / 100 * trend_data_count) - 1
  84. UpperTrend = upper_array.get(upper_index)
  85. LowerTrend = lower_array.get(lower_index)
  86. RelativeTrendIndex = ((close - LowerTrend) / (UpperTrend - LowerTrend))*100
  87. //
  88. RTIlong = RelativeTrendIndex > 21
  89. RTIshort = RelativeTrendIndex < 30
  90.  
  91. // RTIlong = ta.crossover(RelativeTrendIndex, 50)
  92. // RTIshort = ta.crossunder(RelativeTrendIndex, 50)
  93.  
  94. // rsi
  95. rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="RSI Settings")
  96. rsiSourceInput = input.source(close, group="RSI Settings")
  97. uprsi = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
  98. downrsi = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
  99. rsi = downrsi == 0 ? 100 : uprsi == 0 ? 0 : 100 - (100 / (1 + uprsi / downrsi))
  100.  
  101. rsi2 = ta.rsi(close, 5)
  102.  
  103. RSI_long = rsi2 > 50
  104. RSI_short = rsi2 < 50
  105. // RSI_long = ta.crossover(rsi2, 50)
  106. // RSI_short = ta.crossunder(rsi2, 50)
  107.  
  108. // Loxx supertrend
  109.  
  110. RMA(x, t) =>
  111. EMA1 = x
  112. EMA1 := na(EMA1[1]) ? x : (x - nz(EMA1[1])) * (1/t) + nz(EMA1[1])
  113. EMA1
  114.  
  115. fdip(float srcloxx, int per, int speedin)=>
  116. float fmax = ta.highest(srcloxx, per)
  117. float fmin = ta.lowest(srcloxx, per)
  118. float lengthloxx = 0
  119. float diff = 0
  120. for i = 1 to per - 1
  121. diff := (nz(srcloxx[i]) - fmin) / (fmax - fmin)
  122. if i > 0
  123. lengthloxx += math.sqrt( math.pow(nz(diff[i]) - nz(diff[i + 1]), 2) + (1 / math.pow(per, 2)))
  124. float fdi = 1 + (math.log(lengthloxx) + math.log(2)) / math.log(2 * per)
  125. float traildim = 1 / (2 - fdi)
  126. float alpha = traildim / 2
  127. int speed = math.round(speedin * alpha)
  128. speed
  129.  
  130. pine_supertrend(float srcloxx, float factor, int atrPeriod) =>
  131. float atr = RMA(ta.tr(true), atrPeriod)
  132. float upperBand = srcloxx + factor * atr
  133. float lowerBand = srcloxx - factor * atr
  134. float prevLowerBand = nz(lowerBand[1])
  135. float prevUpperBand = nz(upperBand[1])
  136.  
  137. lowerBand := lowerBand > prevLowerBand or close[1] < prevLowerBand ? lowerBand : prevLowerBand
  138. upperBand := upperBand < prevUpperBand or close[1] > prevUpperBand ? upperBand : prevUpperBand
  139. int directionloxx = na
  140. float superTrend = na
  141. float prevSuperTrend = superTrend[1]
  142. if na(atr[1])
  143. directionloxx := 1
  144. else if prevSuperTrend == prevUpperBand
  145. directionloxx := close > upperBand ? -1 : 1
  146. else
  147. directionloxx := close < lowerBand ? 1 : -1
  148. superTrend := directionloxx == -1 ? lowerBand : upperBand
  149. [superTrend, directionloxx]
  150.  
  151. srcloxx = input.source(hl2, group = "Loxx")
  152. per = input.int(30, "Fractal Period Ingest", group = "Loxx")
  153. speed = input.int(20, "Speed", group = "Loxx")
  154.  
  155. //Loxx input
  156. multloxx5 = input.float(7 , "1st Multiplier", group = "Loxx", step=1) //~using the same step as supertrend and *2 to test the robustness = 0.05*2 = 0.1
  157.  
  158. multloxx2 = input.float(3 , "2rd Multiplier", group = "Loxx", step=1) //~
  159.  
  160. adaptloxx = input.bool(true)
  161.  
  162. masterdom = fdip(srcloxx, per, speed)
  163. int lenloxx = math.floor(masterdom) < 1 ? 1 : math.floor(masterdom)
  164. lenloxx := nz(lenloxx, 1)
  165.  
  166. [supertrendloxx5, directionloxx] = pine_supertrend(srcloxx, multloxx5, adaptloxx ? lenloxx : per)
  167.  
  168. [supertrendloxx2, directionloxx2] = pine_supertrend(srcloxx, multloxx2, adaptloxx ? lenloxx : per)
  169.  
  170. loxx_long = close > supertrendloxx5
  171. loxx_short = close < supertrendloxx5
  172.  
  173. loxx_long_2 = directionloxx2 == -1 and directionloxx2[1] == 1
  174. loxx_short_2 = close < supertrendloxx2
  175.  
  176.  
  177. // rough avg
  178. len = input.int(70, "Length", group = "Rough AVG")
  179. colbar = input.string("None", "Bar Coloring", ["None", "Trend", "Extremities", "Reversions"])
  180. revshow = input.bool(true)
  181.  
  182. f_checkp() =>
  183. p = close
  184. count = 0
  185.  
  186. while p > 1
  187. p /= 10
  188. count += 1
  189.  
  190. math.pow(10, count)
  191.  
  192. f_profile(len) =>
  193. l = len
  194. integral = 0.0
  195.  
  196. f_x = math.abs(ta.rsi(close, len))
  197.  
  198. for x = low / f_checkp() to high / f_checkp()
  199. integral := integral + f_x
  200.  
  201. l * integral
  202.  
  203. spacing_profile = f_profile(len)
  204.  
  205. ra = ta.rsi(ta.ema(spacing_profile, len), len)
  206.  
  207. roughlong = ra > 50
  208. roughshort = ra < 50
  209. // roughlong = ta.crossover(ra, 50)
  210. // roughshort = ta.crossunder(ra, 50)
  211.  
  212. // {Gunzo} Trend Sniper
  213.  
  214. float ma_source = input(title='MA Source', defval=close,group = "Trend Sniper Settings")
  215. int ma_length = input.int(title='MA Length', defval=28, minval=1,group = "Trend Sniper Settings")
  216. int smoothing_length = input.int(title='MA Smooth ', defval=10, minval=1, maxval=13,group = "Trend Sniper Settings")
  217. coefficient = ma_length / 3.0
  218.  
  219. fn_calculate_wma_with_coefficient(source, length, coefficient) =>
  220.  
  221. candle_weighted_sum = 0.0
  222. total_weight = 0.0
  223.  
  224.  
  225. for i = 0 to length by 1
  226. candle_weight = length - i
  227. candle_weighted_sum += (candle_weight - coefficient) * source[i]
  228. total_weight += candle_weight - coefficient
  229. total_weight
  230.  
  231.  
  232. weighted_line = candle_weighted_sum / total_weight
  233.  
  234. [weighted_line]
  235.  
  236. [weighted_line] = fn_calculate_wma_with_coefficient(ma_source, ma_length, coefficient)
  237. weighted_line_smooth = ta.ema(weighted_line, smoothing_length)
  238.  
  239.  
  240.  
  241. trend_up = ta.crossover(weighted_line_smooth, weighted_line_smooth[1])
  242. // trend_down = ta.crossunder(weighted_line_smooth, weighted_line_smooth[1])
  243.  
  244. // {Gunzo} Trend Sniper_2
  245.  
  246. float ma_source2 = input(title='MA sni Source2', defval=close,group = "Trend Sniper Settings")
  247. int ma_length2 = input.int(title='MA sni Length2', defval=34, minval=1,group = "Trend Sniper Settings")
  248. int smoothing_length2 = input.int(title='MA sni Smooth2 ', defval=9, minval=1, maxval=13,group = "Trend Sniper Settings")
  249.  
  250. coefficient2 = ma_length2 / 3.0
  251.  
  252. fn_calculate_wma_with_coefficient2(source1, length2, coefficient2) =>
  253.  
  254. candle_weighted_sum2 = 0.0
  255. total_weight2 = 0.0
  256.  
  257.  
  258. for i2 = 0 to length2 by 1
  259. candle_weight2 = length2 - i2
  260. candle_weighted_sum2 += (candle_weight2 - coefficient2) * source1[i2]
  261. total_weight2 += candle_weight2 - coefficient2
  262. total_weight2
  263.  
  264.  
  265. weighted_line2 = candle_weighted_sum2 / total_weight2
  266.  
  267. [weighted_line2]
  268.  
  269. [weighted_line2] = fn_calculate_wma_with_coefficient2(ma_source2, ma_length2, coefficient2)
  270. weighted_line_smooth2 = ta.ema(weighted_line2, smoothing_length2)
  271.  
  272. trend_up2 = ta.crossover(weighted_line_smooth2, weighted_line_smooth2[1])
  273.  
  274.  
  275. //Hull
  276. // Inputs
  277. timeframe1=input.timeframe(defval ='1D', group = "Hull", tooltip = "Select a different timeframe for this series") // Use Alternative timeframe
  278. modeSwitch = input.string("Thma", title="Hull Variation", options=["Thma"])
  279. length = input(192, title="Length(180-200 for floating S/R , 55 for swing entry)")
  280. lengthMult = input.float(1.0, title="Length multiplier (Used to view higher timeframes with straight band)")
  281. useHtf = input(false, title="Show Hull MA from X timeframe? (good for scalping)")
  282. htf = input("240", title="Higher timeframe")
  283.  
  284. //FUNCTIONS
  285. src1 = request.security(syminfo.tickerid,timeframe1 ,close)
  286.  
  287. //THMA
  288. //THMA(_src, _length) => ta.wma(ta.wma(_src,_length / 3) * 3 - ta.wma(_src, _length / 2) - ta.wma(_src, _length), _length)
  289. THMA(_src, _length) => request.security(syminfo.tickerid,timeframe1 ,ta.wma(ta.wma(_src,_length / 3) * 3 - ta.wma(_src, _length / 2) - ta.wma(_src, _length), _length))
  290.  
  291. //SWITCH
  292. Mode(modeSwitch, src1, len) =>
  293. modeSwitch == "Thma" ? request.security(syminfo.tickerid,timeframe1,THMA(src1, len/2)) : na
  294.  
  295. //OUT
  296. _hull = Mode(modeSwitch, src1, int(length * lengthMult))
  297. HULL = useHtf ? request.security(syminfo.tickerid, htf, _hull) : _hull
  298. MHULL = HULL[0]
  299. SHULL = HULL[2]
  300.  
  301. HullLong = request.security(syminfo.tickerid,timeframe1 ,ta.crossover(MHULL, SHULL))
  302. HullShort = request.security(syminfo.tickerid,timeframe1 ,ta.crossover(SHULL, MHULL))
  303.  
  304.  
  305. //EFI
  306.  
  307. // Inputs
  308. timeframeefi=input.timeframe(defval ='3D', group = "EFI", tooltip = "Select a different timeframe for this series") // Use Alternative timeframe
  309. efilength = input.int(111, minval=1, group = "EFI")
  310.  
  311. // Get high and low from selected timeframe instead of the one on the chart
  312. TFclose=request.security(syminfo.tickerid,timeframeefi , close)
  313. TFvolume=request.security(syminfo.tickerid,timeframeefi , volume)
  314.  
  315. var cumVol = 0.
  316. cumVol += request.security(syminfo.tickerid,timeframeefi ,nz(volume))
  317. if barstate.islast and cumVol == 0
  318. runtime.error('Nope')
  319. efi = ta.ema(ta.change(TFclose) * TFvolume, efilength)
  320. efiLong = efi > 0
  321. efiShort = efi < 0
  322.  
  323.  
  324.  
  325. // ***************************************************************************************************************************************************************
  326.  
  327. // VR
  328. volatilityLower = input.float(title = "Lower Range", defval= -39, group = "VRG")
  329. volatilityHigher = input.float(title = "Higher Range", defval= 9)
  330. volatilityLength = 58
  331. volatilityRange = ta.sma(close - open, volatilityLength)
  332.  
  333. //VR PARAMETERS
  334. VRL = volatilityRange > volatilityLower
  335. VRS = volatilityRange < volatilityHigher
  336.  
  337.  
  338. //VZO
  339. // inputs
  340. src0 = input.source(high, 'Source', group="VZO")
  341. len1 = input.float(17.25, 'VZO Length', minval=1, step=0.5, group="VZO")
  342. flen = input.float(3.5, 'Fisher Length', minval=1, step=0.5, group="VZO")
  343. ud = input.int(12, 'Updown val', group="VZO")
  344. var VZO_Intraday = input.bool(true, 'Smoothing', group="VZO")
  345. var repaint = input.bool(false, 'Allow Repainting', group="VZO")
  346. timeframe2=input.timeframe(defval ='4D', group="VZO", tooltip = "Select a different timeframe for this series") // Use Alternative timeframe
  347.  
  348. // Sauce
  349. get_close = request.security(syminfo.tickerid,timeframe2 , close[repaint ? 0 : 1])
  350. get_vol = request.security(syminfo.tickerid,timeframe2 , volume[repaint ? 0 : 1])
  351. sym = syminfo.tickerid
  352. VZO(length, get_close, vol) =>
  353. Volume_Direction = get_close > get_close[3] ? vol : -vol
  354. VZO_volume = request.security(syminfo.tickerid,timeframe2 , ta.linreg(Volume_Direction, int(length), 0))
  355. Total_volume = request.security(syminfo.tickerid,timeframe2 , ta.linreg(vol, int(length), 0))
  356. 100 * VZO_volume / Total_volume
  357.  
  358. VZO_ = VZO(len, get_close, get_vol)
  359. if VZO_Intraday
  360. VZO_ := ta.ema(VZO_, 9)
  361.  
  362. // Fish
  363. fsrc = VZO_
  364. MaxH = request.security(syminfo.tickerid,timeframe2 , ta.highest(fsrc, int(flen)))
  365. MinL = request.security(syminfo.tickerid,timeframe2 , ta.lowest(fsrc, int(flen)))
  366. var nValue1 = 0.0
  367. var nFish = 0.0
  368. nValue1 := 0.33 * 2 * ((fsrc - MinL) / (MaxH - MinL) - 0.5) + 0.67 * nz(nValue1[1])
  369. nValue2 = (nValue1 > 0.99 ? 0.999 : (nValue1 < -0.99 ? -0.999 : nValue1))
  370. nFish := 0.5 * math.log((1 + nValue2) / (1 - nValue2)) + 0.5 * nz(nFish[1])
  371. f1 = nFish
  372. f2 = nz(nFish[1])
  373. stat = 0
  374. fzvzo_up = f1 > f2
  375. fzvzo_down = f1 < f2
  376. // Can use stat or fzvzoshort and fzvzoshort for firing buy/sell signals
  377. fzvzoshort = request.security(syminfo.tickerid,timeframe2 , ta.crossunder(f1, f2))
  378. fzvzolong = request.security(syminfo.tickerid,timeframe2 , ta.crossover(f1, f2))
  379. if fzvzolong
  380. stat := 1
  381. if fzvzoshort
  382. stat := -1
  383.  
  384. //MACD
  385.  
  386. // Inputs
  387. FastLength = input(title="MACD Fast Length", group="MACD", defval=44)
  388. Slowlength = input(title="MACD Slow Length", group="MACD", defval=95)
  389. MACDLength = input(title="MACD Signal Length", group="MACD", defval=31)
  390. timeframe3=input.timeframe(defval ='1D', group = "MACD", tooltip = "Select a different timeframe for this series") // Use Alternative timeframe
  391.  
  392. MACD = request.security(syminfo.tickerid,timeframe3 , ta.ema(close, FastLength)) - request.security(syminfo.tickerid,timeframe3 , ta.ema(close, Slowlength))
  393. aMACD = request.security(syminfo.tickerid,timeframe3 , ta.ema(MACD, MACDLength))
  394. delta = MACD - aMACD
  395.  
  396.  
  397.  
  398. // Calculate Buy/Sell orders
  399. LongMACD = ta.crossover(delta, 0)
  400. ShortMACD = ta.crossunder(delta, 0)
  401. //
  402.  
  403.  
  404. length4 = input.int(46, minval=1, title="CCI LENGTH", group = "CCI")
  405. src_CCI = high
  406.  
  407. //CALCULATIONS//
  408. ma = ta.sma(src_CCI, length4)
  409. cci = (src_CCI - ma) / (0.015 * ta.dev(src_CCI, length4))
  410.  
  411. //TRADE CONDITIONS//
  412. CCI_LONG = cci >-90
  413. CCI_SHORT = cci < 90
  414.  
  415. // Coral Trend
  416. sm =input(5, title="Smoothing Period", group = "CoralTrend")
  417. cd = input(2.6, title="Constant D", group = "CoralTrend")
  418. ribm=input(false, title="Ribbon Mode", group = "CoralTrend")
  419. timeframe4=input.timeframe(defval ='4D', group = "CoralTrend")
  420.  
  421. //initialise vars
  422. var float i1 = na
  423. var float i2 = na
  424. var float i3 = na
  425. var float i4 = na
  426. var float i5 = na
  427. var float i6 = na
  428.  
  429. src12=request.security(syminfo.tickerid,timeframe4, close)
  430.  
  431. di = (sm - 1.0) / 2.0 + 1.0
  432. c1 = 2 / (di + 1.0)
  433. c2 = 1 - c1
  434. c3 = 3.0 * (cd * cd + cd * cd * cd)
  435. c4 = -3.0 * (2.0 * cd * cd + cd + cd * cd * cd)
  436. c5 = 3.0 * cd + 1.0 + cd * cd * cd + 3.0 * cd * cd
  437.  
  438. i1 := c1*src1 + c2*nz(i1[1])
  439. i2 := c1*i1 + c2*nz(i2[1])
  440. i3 := c1*i2 + c2*nz(i3[1])
  441. i4 := c1*i3 + c2*nz(i4[1])
  442. i5 := c1*i4 + c2*nz(i5[1])
  443. i6 := c1*i5 + c2*nz(i6[1])
  444.  
  445. bfr = -cd*cd*cd*i6 + c3*(i5) + c4*(i4) + c5*(i3)
  446.  
  447. CoralLong = bfr > nz(bfr[1])?true:false
  448. CoralShort = bfr < nz(bfr[1])?true:false
  449.  
  450.  
  451. //INPUTS//
  452. length_AROON = input.int(13, minval=1, group = "AROON")
  453.  
  454. //CALCULATIONS//
  455. upper1 = 100 * (ta.highestbars(high, length_AROON + 1) + length_AROON)/length_AROON
  456. lower1 = 100 * (ta.lowestbars(low, length_AROON + 1) + length_AROON)/length_AROON
  457.  
  458. //TRADE CONDITIONS//
  459. AROON_LONG = upper1 > 94 and lower1 < 6
  460. AROON_SHORT = lower1 > 94 and upper1< 6
  461.  
  462. // STOCHASTIC
  463.  
  464. lengthK = input.int(10, "%K Length", minval = 1, maxval = 15000)
  465. lengthD = input.int(4, "%D Length", minval = -1, maxval = 4999)
  466. lengthEMA = input.int(13, "EMA Length", minval = 1, maxval = 4999)
  467.  
  468. emaEma(source, length) => ta.ema(ta.ema(source, length), length)
  469.  
  470. highestHigh = ta.highest(lengthK)
  471. lowestLow = ta.lowest(lengthK)
  472. highestLowestRange = highestHigh - lowestLow
  473. relativeRange = close - (highestHigh + lowestLow) / 2
  474. smi = 200 * (emaEma(relativeRange, lengthD) / emaEma(highestLowestRange, lengthD))
  475. EMAsmi = ta.ema(smi, lengthEMA)
  476.  
  477. // LONG/SHORT STOCHASTIC
  478.  
  479. StochasticLong = smi > EMAsmi
  480. StochasticShort = smi < EMAsmi
  481.  
  482.  
  483. length1 = input.int(6, minval=1)
  484. upper12 = 100 * (ta.highestbars(high, length+1) + length1)/length1
  485. lower12 = 100 * (ta.lowestbars(low, length+1) + length1)/length1
  486.  
  487. long_Condition = ta.crossover(upper12,lower12)
  488. short_Condition = ta.crossunder(upper12,lower12)
  489.  
  490. top = input.float(0.6, step=0.1)
  491. bottom = input.float(4, step=0.01)
  492. miningRevenue = request.security('QUANDL:BCHAIN/MIREV', 'D', close[1], barmerge.gaps_off, barmerge.lookahead_on)
  493. ma365 = request.security('QUANDL:BCHAIN/MIREV', 'D', ta.sma(close, 365)[1], barmerge.gaps_off, barmerge.lookahead_on)
  494. puellMultiple = miningRevenue / ma365
  495.  
  496. smonadnu = puellMultiple < top
  497. smonavrhu = puellMultiple > bottom
  498.  
  499. // User Inputsplot
  500. EEEEEE = input(37, 'LengthSTC', group="STC")
  501. BBBB = input(54, 'FastLengthSTC', group="STC")
  502. BBBBB = input(730, 'SlowLengthSTC', group="STC")
  503. AAA = input.float(0.19, title="STC Factor", group="STC", step = 0.01)
  504.  
  505. // STC Calculations
  506. AAAA(BBB, BBBB, BBBBB) =>
  507. fastMA = ta.ema(BBB, BBBB)
  508. slowMA = ta.ema(BBB, BBBBB)
  509. AAAA = fastMA - slowMA
  510. AAAA
  511.  
  512. AAAAA(EEEEEE, BBBB, BBBBB) =>
  513. var CCCCC = 0.0
  514. var DDD = 0.0
  515. var DDDDDD = 0.0
  516. var EEEEE = 0.0
  517. BBBBBB = AAAA(close, BBBB, BBBBB)
  518. CCC = ta.lowest(BBBBBB, EEEEEE)
  519. CCCC = ta.highest(BBBBBB, EEEEEE) - CCC
  520. CCCCC := CCCC > 0 ? (BBBBBB - CCC) / CCCC * 100 : nz(CCCCC[1])
  521. DDD := na(DDD[1]) ? CCCCC : DDD[1] + AAA * (CCCCC - DDD[1])
  522. DDDD = ta.lowest(DDD, EEEEEE)
  523. DDDDD = ta.highest(DDD, EEEEEE) - DDDD
  524. DDDDDD := DDDDD > 0 ? (DDD - DDDD) / DDDDD * 100 : nz(DDDDDD[1])
  525. EEEEE := na(EEEEE[1]) ? DDDDDD : EEEEE[1] + AAA * (DDDDDD - EEEEE[1])
  526. EEEEE
  527.  
  528. mAAAAA = AAAAA(EEEEEE, BBBB, BBBBB)
  529. mColor = mAAAAA > mAAAAA[1] ? color.new(color.green, 20) : color.new(color.red, 20)
  530.  
  531. stc_low = mAAAAA < 50
  532. stc_high = mAAAAA > 50
  533. stc_long = mAAAAA > mAAAAA[1]
  534. stc_short = mAAAAA < mAAAAA[1]
  535.  
  536. // ----- PSAR -----
  537. start = input.float(0.004, step=0.001, group = "PSAR")
  538. increment = input.float(0.009, step=0.001, group = "PSAR")
  539. maximum = input.float(0.5, step=0.01, group = "PSAR")
  540. out1 = ta.sar(start, increment, maximum)
  541. // plot(out, "ParabolicSAR", style=plot.style_cross, color=#2962FF)
  542. psarLong = out1 < close
  543. psarShort = out1 > close
  544.  
  545.  
  546. //Moving Average
  547. ma1 = ta.vwma(src,input.int(4, group = 'Moving Average'))
  548. malong = close > ma1
  549. mashort = close < ma1
  550. marise = ta.rising(ma1, 1)
  551. mafall = ta.falling(ma1, 1)
  552.  
  553.  
  554.  
  555.  
  556. // ----- QSTICK -----
  557. length2=input(4, group = "QSTICK")
  558. hline(0)
  559. s2=ta.sma((close-open),length2)
  560. qLong = s2 >= 0
  561. qShort = s2 < 0
  562.  
  563. // RSI Strat
  564. rsiLen = input( 5 )
  565. rsiBot = input( 5 )
  566. rsiTop = input( 99 )
  567. price = close
  568. vrsi = ta.rsi(price, rsiLen)
  569. co = ta.crossover(vrsi, rsiTop)
  570. cu = ta.crossunder(vrsi, rsiBot)
  571.  
  572.  
  573.  
  574.  
  575. //RAVI
  576.  
  577. LengthMAFast = input(19, title="Length MA Fast", group = "RAVI")
  578. LengthMASlow = input(65, title="Length MA Slow", group = "RAVI")
  579. TradeLine = input.float(0.14, title="Trade Line", step=0.01, group = "RAVI")
  580.  
  581. xMAF = ta.sma(close, LengthMAFast)
  582. xMAS = ta.sma(close, LengthMASlow)
  583. xRAVI = ((xMAF - xMAS) / xMAS) * 100
  584.  
  585. var float pos = na
  586. if xRAVI > TradeLine
  587. pos := 1
  588. else if xRAVI < TradeLine
  589. pos := -1
  590. else
  591. pos := nz(pos[1], 0)
  592.  
  593. RAVILONG = (ta.crossover(xRAVI, TradeLine) and pos == 1)
  594. rAVISHORT = (ta.crossunder(xRAVI, TradeLine) and pos == -1)
  595.  
  596. //TRIX Component
  597. TRIXLENGTH = input.int(67, minval=1, title = "TRIX Length", group = "TRIX")
  598.  
  599. // Calculate TRIX
  600. trixValue = 10000 * ta.change(ta.ema(ta.ema(ta.ema(math.log(close), TRIXLENGTH), TRIXLENGTH), TRIXLENGTH))
  601.  
  602.  
  603. // Define long and short conditions
  604. TRIXLONG = ta.crossover(trixValue, 0)
  605. TRIXSHORT = ta.crossunder(trixValue, 0)
  606. //END TRIX
  607.  
  608.  
  609. //ICHIMOKU CLOUD component
  610. conversionPeriods = input.int(9, minval=1, title="Conversion Line Length", group = "ICHO")
  611. basePeriods = input.int(26, minval=1, title="Base Line Length", group = "ICHO")
  612. laggingSpan2Periods = input.int(52, minval=1, title="Leading Span B Length", group = "ICHO")
  613. displacement = input.int(26, minval=1, title="Lagging Span", group = "ICHO")
  614. donchian(len) => math.avg(ta.lowest(len), ta.highest(len))
  615. conversionLine = donchian(conversionPeriods)
  616. baseLine = donchian(basePeriods)
  617. leadLine1 = math.avg(conversionLine, baseLine)
  618. leadLine2 = donchian(laggingSpan2Periods)
  619.  
  620. // Define buy and sell conditions
  621. ICHLONG = ta.crossover(conversionLine, baseLine) and close > leadLine1 and close > leadLine2
  622. ICHSHORT = ta.crossunder(conversionLine, baseLine) and close < leadLine1 and close < leadLine2
  623. //END ICHIMOKU CLOUD
  624. /// (buySignal and RSI_long ) //and (CoralLong and malong)
  625. //(sellSignal and RSI_short) //and (CoralShort or qShort) and (mafall or mashort ) or AROON_SHORT
  626. /////////
  627. longCondition = (buySignal and RSI_long ) and CoralLong and malong
  628. shortCondition = (sellSignal and RSI_short or rAVISHORT or TRIXSHORT and short_condition) and (CoralShort or qShort) and (mafall or mashort) or AROON_SHORT and RTIshort or HullShort
  629.  
  630. //shortCondition = (sellSignal and RSI_short or rAVISHORT and short_condition) and (CoralShort or qShort) and (mafall or mashort) or AROON_SHORT and RTIshort or HullShort
  631. if barstate.isconfirmed and isInTimeRange and longCondition
  632. strategy.entry("Long", strategy.long)
  633.  
  634.  
  635. if barstate.isconfirmed and isInTimeRange and shortCondition
  636. strategy.entry("Short", strategy.short)
  637.  
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