Advertisement
danucante

Untitled

Nov 23rd, 2023
186
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.40 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(9, 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. // Inputs
  275. timeframe1=input.timeframe(defval ='1D', group = "Hull", tooltip = "Select a different timeframe for this series") // Use Alternative timeframe
  276. modeSwitch = input.string("Thma", title="Hull Variation", options=["Thma"])
  277. length = input(192, title="Length(180-200 for floating S/R , 55 for swing entry)")
  278. lengthMult = input.float(1.0, title="Length multiplier (Used to view higher timeframes with straight band)")
  279. useHtf = input(false, title="Show Hull MA from X timeframe? (good for scalping)")
  280. htf = input("240", title="Higher timeframe")
  281.  
  282. //FUNCTIONS
  283. src1 = request.security(syminfo.tickerid,timeframe1 ,close)
  284.  
  285. //THMA
  286. //THMA(_src, _length) => ta.wma(ta.wma(_src,_length / 3) * 3 - ta.wma(_src, _length / 2) - ta.wma(_src, _length), _length)
  287. 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))
  288.  
  289. //SWITCH
  290. Mode(modeSwitch, src1, len) =>
  291. modeSwitch == "Thma" ? request.security(syminfo.tickerid,timeframe1,THMA(src1, len/2)) : na
  292.  
  293. //OUT
  294. _hull = Mode(modeSwitch, src1, int(length * lengthMult))
  295. HULL = useHtf ? request.security(syminfo.ticker, htf, _hull) : _hull
  296. MHULL = HULL[0]
  297. SHULL = HULL[2]
  298.  
  299. HullLong = request.security(syminfo.tickerid,timeframe1 ,ta.crossover(MHULL, SHULL))
  300. HullShort = request.security(syminfo.tickerid,timeframe1 ,ta.crossover(SHULL, MHULL))
  301.  
  302.  
  303. //EFI
  304.  
  305. // Inputs
  306. timeframeefi=input.timeframe(defval ='3D', group = "EFI", tooltip = "Select a different timeframe for this series") // Use Alternative timeframe
  307. efilength = input.int(111, minval=1, group = "EFI")
  308.  
  309. // Get high and low from selected timeframe instead of the one on the chart
  310. TFclose=request.security(syminfo.tickerid,timeframeefi , close)
  311. TFvolume=request.security(syminfo.tickerid,timeframeefi , volume)
  312.  
  313. var cumVol = 0.
  314. cumVol += request.security(syminfo.tickerid,timeframeefi ,nz(volume))
  315. if barstate.islast and cumVol == 0
  316. runtime.error('Nope')
  317. efi = ta.ema(ta.change(TFclose) * TFvolume, efilength)
  318. efiLong = efi > 0
  319. efiShort = efi < 0
  320.  
  321.  
  322.  
  323. // ***************************************************************************************************************************************************************
  324.  
  325. // VR
  326. volatilityLower = input.float(title = "Lower Range", defval= -39, group = "VRG")
  327. volatilityHigher = input.float(title = "Higher Range", defval= 9)
  328. volatilityLength = 58
  329. volatilityRange = ta.sma(close - open, volatilityLength)
  330.  
  331. //VR PARAMETERS
  332. VRL = volatilityRange > volatilityLower
  333. VRS = volatilityRange < volatilityHigher
  334.  
  335.  
  336. //VZO
  337. // inputs
  338. src0 = input.source(high, 'Source', group="VZO")
  339. len1 = input.float(17.25, 'VZO Length', minval=1, step=0.5, group="VZO")
  340. flen = input.float(3.5, 'Fisher Length', minval=1, step=0.5, group="VZO")
  341. ud = input.int(12, 'Updown val', group="VZO")
  342. var VZO_Intraday = input.bool(true, 'Smoothing', group="VZO")
  343. var repaint = input.bool(false, 'Allow Repainting', group="VZO")
  344. timeframe2=input.timeframe(defval ='4D', group="VZO", tooltip = "Select a different timeframe for this series") // Use Alternative timeframe
  345.  
  346. // Sauce
  347. get_close = request.security(syminfo.tickerid,timeframe2 , close[repaint ? 0 : 1])
  348. get_vol = request.security(syminfo.tickerid,timeframe2 , volume[repaint ? 0 : 1])
  349. sym = syminfo.tickerid
  350. VZO(length, get_close, vol) =>
  351. Volume_Direction = get_close > get_close[3] ? vol : -vol
  352. VZO_volume = request.security(syminfo.tickerid,timeframe2 , ta.linreg(Volume_Direction, int(length), 0))
  353. Total_volume = request.security(syminfo.tickerid,timeframe2 , ta.linreg(vol, int(length), 0))
  354. 100 * VZO_volume / Total_volume
  355.  
  356. VZO_ = VZO(len, get_close, get_vol)
  357. if VZO_Intraday
  358. VZO_ := ta.ema(VZO_, 9)
  359.  
  360. // Fish
  361. fsrc = VZO_
  362. MaxH = request.security(syminfo.tickerid,timeframe2 , ta.highest(fsrc, int(flen)))
  363. MinL = request.security(syminfo.tickerid,timeframe2 , ta.lowest(fsrc, int(flen)))
  364. var nValue1 = 0.0
  365. var nFish = 0.0
  366. nValue1 := 0.33 * 2 * ((fsrc - MinL) / (MaxH - MinL) - 0.5) + 0.67 * nz(nValue1[1])
  367. nValue2 = (nValue1 > 0.99 ? 0.999 : (nValue1 < -0.99 ? -0.999 : nValue1))
  368. nFish := 0.5 * math.log((1 + nValue2) / (1 - nValue2)) + 0.5 * nz(nFish[1])
  369. f1 = nFish
  370. f2 = nz(nFish[1])
  371. stat = 0
  372. fzvzo_up = f1 > f2
  373. fzvzo_down = f1 < f2
  374. // Can use stat or fzvzoshort and fzvzoshort for firing buy/sell signals
  375. fzvzoshort = request.security(syminfo.tickerid,timeframe2 , ta.crossunder(f1, f2))
  376. fzvzolong = request.security(syminfo.tickerid,timeframe2 , ta.crossover(f1, f2))
  377. if fzvzolong
  378. stat := 1
  379. if fzvzoshort
  380. stat := -1
  381.  
  382. //MACD
  383.  
  384. // Inputs
  385. FastLength = input(title="MACD Fast Length", group="MACD", defval=44)
  386. Slowlength = input(title="MACD Slow Length", group="MACD", defval=95)
  387. MACDLength = input(title="MACD Signal Length", group="MACD", defval=31)
  388. timeframe3=input.timeframe(defval ='1D', group = "MACD", tooltip = "Select a different timeframe for this series") // Use Alternative timeframe
  389.  
  390. MACD = request.security(syminfo.tickerid,timeframe3 , ta.ema(close, FastLength)) - request.security(syminfo.tickerid,timeframe3 , ta.ema(close, Slowlength))
  391. aMACD = request.security(syminfo.tickerid,timeframe3 , ta.ema(MACD, MACDLength))
  392. delta = MACD - aMACD
  393.  
  394.  
  395.  
  396. // Calculate Buy/Sell orders
  397. LongMACD = ta.crossover(delta, 0)
  398. ShortMACD = ta.crossunder(delta, 0)
  399. //
  400.  
  401.  
  402. length4 = input.int(46, minval=1, title="CCI LENGTH", group = "CCI")
  403. src_CCI = high
  404.  
  405. //CALCULATIONS//
  406. ma = ta.sma(src_CCI, length4)
  407. cci = (src_CCI - ma) / (0.015 * ta.dev(src_CCI, length4))
  408.  
  409. //TRADE CONDITIONS//
  410. CCI_LONG = cci >-90
  411. CCI_SHORT = cci < 90
  412.  
  413. // Coral Trend
  414. sm =input(5, title="Smoothing Period", group = "CoralTrend")
  415. cd = input(2.6, title="Constant D", group = "CoralTrend")
  416. ribm=input(false, title="Ribbon Mode", group = "CoralTrend")
  417. timeframe4=input.timeframe(defval ='4D', group = "CoralTrend")
  418.  
  419. //initialise vars
  420. var float i1 = na
  421. var float i2 = na
  422. var float i3 = na
  423. var float i4 = na
  424. var float i5 = na
  425. var float i6 = na
  426.  
  427. src12=request.security(syminfo.tickerid,timeframe4, close)
  428.  
  429. di = (sm - 1.0) / 2.0 + 1.0
  430. c1 = 2 / (di + 1.0)
  431. c2 = 1 - c1
  432. c3 = 3.0 * (cd * cd + cd * cd * cd)
  433. c4 = -3.0 * (2.0 * cd * cd + cd + cd * cd * cd)
  434. c5 = 3.0 * cd + 1.0 + cd * cd * cd + 3.0 * cd * cd
  435.  
  436. i1 := c1*src1 + c2*nz(i1[1])
  437. i2 := c1*i1 + c2*nz(i2[1])
  438. i3 := c1*i2 + c2*nz(i3[1])
  439. i4 := c1*i3 + c2*nz(i4[1])
  440. i5 := c1*i4 + c2*nz(i5[1])
  441. i6 := c1*i5 + c2*nz(i6[1])
  442.  
  443. bfr = -cd*cd*cd*i6 + c3*(i5) + c4*(i4) + c5*(i3)
  444.  
  445. CoralLong = bfr > nz(bfr[1])?true:false
  446. CoralShort = bfr < nz(bfr[1])?true:false
  447.  
  448.  
  449. //INPUTS//
  450. length_AROON = input.int(13, minval=1, group = "AROON")
  451.  
  452. //CALCULATIONS//
  453. upper1 = 100 * (ta.highestbars(high, length_AROON + 1) + length_AROON)/length_AROON
  454. lower1 = 100 * (ta.lowestbars(low, length_AROON + 1) + length_AROON)/length_AROON
  455.  
  456. //TRADE CONDITIONS//
  457. AROON_LONG = upper1 > 94 and lower1 < 6
  458. AROON_SHORT = lower1 > 94 and upper1< 6
  459.  
  460. // STOCHASTIC
  461.  
  462. lengthK = input.int(10, "%K Length", minval = 1, maxval = 15000)
  463. lengthD = input.int(4, "%D Length", minval = -1, maxval = 4999)
  464. lengthEMA = input.int(13, "EMA Length", minval = 1, maxval = 4999)
  465.  
  466. emaEma(source, length) => ta.ema(ta.ema(source, length), length)
  467.  
  468. highestHigh = ta.highest(lengthK)
  469. lowestLow = ta.lowest(lengthK)
  470. highestLowestRange = highestHigh - lowestLow
  471. relativeRange = close - (highestHigh + lowestLow) / 2
  472. smi = 200 * (emaEma(relativeRange, lengthD) / emaEma(highestLowestRange, lengthD))
  473. EMAsmi = ta.ema(smi, lengthEMA)
  474.  
  475. // LONG/SHORT STOCHASTIC
  476.  
  477. StochasticLong = smi > EMAsmi
  478. StochasticShort = smi < EMAsmi
  479.  
  480.  
  481. length1 = input.int(6, minval=1)
  482. upper12 = 100 * (ta.highestbars(high, length+1) + length1)/length1
  483. lower12 = 100 * (ta.lowestbars(low, length+1) + length1)/length1
  484.  
  485. long_Condition = ta.crossover(upper12,lower12)
  486. short_Condition = ta.crossunder(upper12,lower12)
  487.  
  488. top = input.float(0.6, step=0.1)
  489. bottom = input.float(4, step=0.01)
  490. miningRevenue = request.security('QUANDL:BCHAIN/MIREV', 'D', close[1], barmerge.gaps_off, barmerge.lookahead_on)
  491. ma365 = request.security('QUANDL:BCHAIN/MIREV', 'D', ta.sma(close, 365)[1], barmerge.gaps_off, barmerge.lookahead_on)
  492. puellMultiple = miningRevenue / ma365
  493.  
  494. smonadnu = puellMultiple < top
  495. smonavrhu = puellMultiple > bottom
  496.  
  497. // User Inputsplot
  498. EEEEEE = input(37, 'LengthSTC', group="STC")
  499. BBBB = input(54, 'FastLengthSTC', group="STC")
  500. BBBBB = input(730, 'SlowLengthSTC', group="STC")
  501. AAA = input.float(0.19, title="STC Factor", group="STC", step = 0.01)
  502.  
  503. // STC Calculations
  504. AAAA(BBB, BBBB, BBBBB) =>
  505. fastMA = ta.ema(BBB, BBBB)
  506. slowMA = ta.ema(BBB, BBBBB)
  507. AAAA = fastMA - slowMA
  508. AAAA
  509.  
  510. AAAAA(EEEEEE, BBBB, BBBBB) =>
  511. var CCCCC = 0.0
  512. var DDD = 0.0
  513. var DDDDDD = 0.0
  514. var EEEEE = 0.0
  515. BBBBBB = AAAA(close, BBBB, BBBBB)
  516. CCC = ta.lowest(BBBBBB, EEEEEE)
  517. CCCC = ta.highest(BBBBBB, EEEEEE) - CCC
  518. CCCCC := CCCC > 0 ? (BBBBBB - CCC) / CCCC * 100 : nz(CCCCC[1])
  519. DDD := na(DDD[1]) ? CCCCC : DDD[1] + AAA * (CCCCC - DDD[1])
  520. DDDD = ta.lowest(DDD, EEEEEE)
  521. DDDDD = ta.highest(DDD, EEEEEE) - DDDD
  522. DDDDDD := DDDDD > 0 ? (DDD - DDDD) / DDDDD * 100 : nz(DDDDDD[1])
  523. EEEEE := na(EEEEE[1]) ? DDDDDD : EEEEE[1] + AAA * (DDDDDD - EEEEE[1])
  524. EEEEE
  525.  
  526. mAAAAA = AAAAA(EEEEEE, BBBB, BBBBB)
  527. mColor = mAAAAA > mAAAAA[1] ? color.new(color.green, 20) : color.new(color.red, 20)
  528.  
  529. stc_low = mAAAAA < 50
  530. stc_high = mAAAAA > 50
  531. stc_long = mAAAAA > mAAAAA[1]
  532. stc_short = mAAAAA < mAAAAA[1]
  533.  
  534. // ----- PSAR -----
  535. start = input.float(0.004, step=0.001, group = "PSAR")
  536. increment = input.float(0.009, step=0.001, group = "PSAR")
  537. maximum = input.float(0.5, step=0.01, group = "PSAR")
  538. out1 = ta.sar(start, increment, maximum)
  539. // plot(out, "ParabolicSAR", style=plot.style_cross, color=#2962FF)
  540. psarLong = out1 < close
  541. psarShort = out1 > close
  542.  
  543.  
  544. //Moving Average
  545. ma1 = ta.vwma(src,input.int(4, group = 'Moving Average'))
  546. malong = close > ma1
  547. mashort = close < ma1
  548. marise = ta.rising(ma1, 1)
  549. mafall = ta.falling(ma1, 1)
  550.  
  551.  
  552.  
  553.  
  554. // ----- QSTICK -----
  555. length2=input(4, group = "QSTICK")
  556. hline(0)
  557. s2=ta.sma((close-open),length2)
  558. qLong = s2 >= 0
  559. qShort = s2 < 0
  560.  
  561. // RSI Strat
  562. rsiLen = input( 5 )
  563. rsiBot = input( 5 )
  564. rsiTop = input( 99 )
  565. price = close
  566. vrsi = ta.rsi(price, rsiLen)
  567. co = ta.crossover(vrsi, rsiTop)
  568. cu = ta.crossunder(vrsi, rsiBot)
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575. LengthMAFast = input(19, title="Length MA Fast", group = "RAVI")
  576. LengthMASlow = input(65, title="Length MA Slow", group = "RAVI")
  577. TradeLine = input.float(0.14, title="Trade Line", step=0.01, group = "RAVI")
  578.  
  579. xMAF = ta.sma(close, LengthMAFast)
  580. xMAS = ta.sma(close, LengthMASlow)
  581. xRAVI = ((xMAF - xMAS) / xMAS) * 100
  582.  
  583. var float pos = na
  584. if xRAVI > TradeLine
  585. pos := 1
  586. else if xRAVI < TradeLine
  587. pos := -1
  588. else
  589. pos := nz(pos[1], 0)
  590.  
  591. RAVILONG = (ta.crossover(xRAVI, TradeLine) and pos == 1)
  592. rAVISHORT = (ta.crossunder(xRAVI, TradeLine) and pos == -1)
  593.  
  594. //TRIX Component
  595. TRIXLENGTH = input.int(18, minval=1, title = "TRIX Length", group = "TRIX")
  596.  
  597. // Calculate TRIX
  598. trixValue = 10000 * ta.change(ta.ema(ta.ema(ta.ema(math.log(close), TRIXLENGTH), TRIXLENGTH), TRIXLENGTH))
  599.  
  600.  
  601. // Define long and short conditions
  602. TRIXLONG = ta.crossover(trixValue, 0)
  603. TRIXSHORT = ta.crossunder(trixValue, 0)
  604. //END TRIX
  605.  
  606.  
  607. //ICHIMOKU CLOUD component
  608. conversionPeriods = input.int(9, minval=1, title="Conversion Line Length", group = "ICHO")
  609. basePeriods = input.int(26, minval=1, title="Base Line Length", group = "ICHO")
  610. laggingSpan2Periods = input.int(52, minval=1, title="Leading Span B Length", group = "ICHO")
  611. displacement = input.int(26, minval=1, title="Lagging Span", group = "ICHO")
  612. donchian(len) => math.avg(ta.lowest(len), ta.highest(len))
  613. conversionLine = donchian(conversionPeriods)
  614. baseLine = donchian(basePeriods)
  615. leadLine1 = math.avg(conversionLine, baseLine)
  616. leadLine2 = donchian(laggingSpan2Periods)
  617.  
  618. // Define buy and sell conditions
  619. ICHLONG = ta.crossover(conversionLine, baseLine) and close > leadLine1 and close > leadLine2
  620. ICHSHORT = ta.crossunder(conversionLine, baseLine) and close < leadLine1 and close < leadLine2
  621. //END ICHIMOKU CLOUD
  622. /// (buySignal and RSI_long ) //and (CoralLong and malong)
  623. //(sellSignal and RSI_short) //and (CoralShort or qShort) and (mafall or mashort ) or AROON_SHORT
  624. /////////
  625. longCondition = (buySignal and RSI_long ) and CoralLong and malong
  626.  
  627. shortCondition = (sellSignal and RSI_short or rAVISHORT or TRIXSHORT) and (CoralShort or qShort) and (mafall or mashort) or AROON_SHORT and RTIshort or HullShort
  628. if barstate.isconfirmed and isInTimeRange and longCondition
  629. strategy.entry("Long", strategy.long)
  630.  
  631.  
  632. if barstate.isconfirmed and isInTimeRange and shortCondition
  633. strategy.entry("Short", strategy.short)
  634.  
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