Guest User

Untitled

a guest
Jun 3rd, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.18 KB | None | 0 0
  1. //@version=3
  2. strategy(title="Ask Ya Girl She Tell U", shorttitle="AI", overlay=false, pyramiding=3, default_qty_type=strategy.percent_of_equity, default_qty_value=100, currency=currency.USD, initial_capital=1500, commission_type= strategy.commission.percent, commission_value= 0.1)
  3.  
  4.  
  5. ////Ichimoku Cloud
  6. middleDonchian(Length) =>
  7. lower = lowest(Length)
  8. upper = highest(Length)
  9. avg(upper, lower)
  10. conversionPeriods = 9
  11. basePeriods = 26
  12. laggingSpan2Periods = 52
  13. displacement = 26
  14. Tenkan = middleDonchian(conversionPeriods)
  15. Kijun = middleDonchian(basePeriods)
  16. xChikou = close
  17. SenkouA = middleDonchian(laggingSpan2Periods)[displacement]
  18. SenkouB = (Tenkan[basePeriods] + Kijun[basePeriods]) / 2
  19.  
  20. ichiSignal = na
  21. ichiSignalScore = na
  22. ichiWasNeutral = false
  23. ichiWasNeutral := ((SenkouA[1] > SenkouB[1] ? (close[1] < SenkouA[1] and close[1] > SenkouB[1]) : (close[1] < SenkouB[1] and close[1] > SenkouA[1])) and not na(SenkouA) and not na(SenkouB)) or ichiWasNeutral[1]
  24. ichilong = close < Tenkan and (SenkouA < SenkouB ? close < SenkouA : close < SenkouB) ? 1 : 0
  25. ichishort = close > Tenkan and (SenkouA < SenkouB ? close > SenkouA : close > SenkouB) ? -1 : 0
  26.  
  27. // ichilong = ((crossunder(close, Tenkan) and (SenkouA < SenkouB ? SenkouA : SenkouB) and ichiSignalScore[1] <= 0 and ichiWasNeutral) ? 1 : 0) + ((crossunder(close, Tenkan) and (SenkouA < SenkouB ? SenkouB : SenkouA) and ichiSignalScore[1] <= -1 and ichiWasNeutral) ? 1 : 0)
  28. // ichishort = ((crossover(close, Tenkan) and (SenkouA < SenkouB ? SenkouB : SenkouA) and ichiSignalScore[1] >= 0 and ichiWasNeutral) ? -1 : 0) + ((crossover(close, Tenkan) and (SenkouA < SenkouB ? SenkouA : SenkouB) and ichiSignalScore[1] >= 1 and ichiWasNeutral) ? -1 : 0)
  29. ichiSignal := ichilong + ichishort
  30. // ichiSignalScore := nz(ichiSignalScore[1]) + nz(ichiSignal)
  31.  
  32. ////RSI
  33. rsisrc = close,
  34. rsilen = 14
  35. rsilen2 = 1
  36. rsiup = rma(max(change(rsisrc), 0), rsilen)
  37. rsidown = rma(-min(change(rsisrc), 0), rsilen)
  38. rsi = rsidown == 0 ? 100 : rsiup == 0 ? 0 : 100 - (100 / (1 + rsiup / rsidown))
  39. emaRSI = ema(rsi,rsilen2)
  40.  
  41. rsiSignal = na
  42. rsiSignalScore = na
  43. rsiWasNeutral = false
  44. rsiWasNeutral := nz(rsi[1]) < 70 and nz(rsi[1]) > 30 or rsiWasNeutral[1]
  45. rsilong = ((crossover(rsi, 30) and rsiSignalScore[1] <= 0 and rsiWasNeutral) ? 1 : 0) + ((crossover(rsi, 70) and rsiSignalScore[1] <= -1 and rsiWasNeutral) ? 1 : 0)
  46. rsishort = ((crossunder(rsi, 70) and rsiSignalScore[1] >= 0 and rsiWasNeutral) ? -1 : 0) + ((crossunder(rsi, 30) and rsiSignalScore[1] >= 1 and rsiWasNeutral) ? -1 : 0)
  47. rsiSignal := rsilong + rsishort
  48. rsiSignalScore := nz(rsiSignalScore[1]) + nz(rsiSignal)
  49.  
  50. ////MACD
  51.  
  52. macdfast_length = 12
  53. macdslow_length = 26
  54. macdsrc = close
  55. signal_length = 9
  56. sma_source = false
  57. sma_signal = false
  58.  
  59. col_grow_above = #26A69A
  60. col_grow_below = #FFCDD2
  61. col_fall_above = #B2DFDB
  62. col_fall_below = #EF5350
  63. col_macd = #0094ff
  64. col_signal = #ff6a00
  65.  
  66. fast_ma = sma_source ? sma(macdsrc, macdfast_length) : ema(macdsrc, macdfast_length)
  67. slow_ma = sma_source ? sma(macdsrc, macdslow_length) : ema(macdsrc, macdslow_length)
  68. macd = fast_ma - slow_ma
  69. signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)
  70. hist = macd - signal
  71.  
  72. macdSignal = na
  73. macdSignalScore = na
  74. macdWasNeutral = false
  75. macdWasNeutral := nz(macdSignal[1]) != 0 or macdWasNeutral[1]
  76. macdlong = ((crossunder(macd, 0) and macdSignalScore[1] <= 0) ? (macdWasNeutral ? 2 : 1) : 0)
  77. macdshort = ((crossover(macd, 0) and macdSignalScore[1] >= 0) ? (macdWasNeutral ? -2 : -1) : 0)
  78. macdSignal := macdlong + macdshort
  79. macdSignalScore := nz(macdSignalScore[1]) + nz(macdSignal)
  80.  
  81. ////KDJ
  82.  
  83. ilong = 21
  84. isig = 13
  85.  
  86. bcwsma(s,l,m) =>
  87. _s = s
  88. _l = l
  89. _m = m
  90. _bcwsma = na
  91. _bcwsma := (_m*_s+(_l-_m)*nz(_bcwsma[1]))/_l
  92. _bcwsma
  93.  
  94. c = close
  95. h = highest(high, ilong)
  96. l = lowest(low,ilong)
  97. RSV = 100*((c-l)/(h-l))
  98. pK = bcwsma(RSV, isig, 1)
  99. pD = bcwsma(pK, isig, 1)
  100. pJ = 3 * pK-2 * pD
  101.  
  102. kdjSignal = na
  103. kdjSignalScore = na
  104. kdjWasNeutral = false
  105. kdjWasNeutral := nz(pJ[1]) < 80 and nz(pJ[1]) > 20 or kdjWasNeutral[1]
  106. kdjlong = ((crossunder(pJ, 20) and kdjSignalScore[1] <= 0 and kdjWasNeutral) ? 1 : 0) + ((crossunder(pJ, 80) and kdjSignalScore[1] <= -1 and kdjWasNeutral) ? 1 : 0)
  107. kdjshort = ((crossover(pJ, 80) and kdjSignalScore[1] >= 0 and kdjWasNeutral) ? -1 : 0) + ((crossover(pJ, 20) and kdjSignalScore[1] >= 1 and kdjWasNeutral) ? -1 : 0)
  108. kdjSignal := kdjlong + kdjshort
  109. kdjSignalScore := nz(kdjSignalScore[1]) + nz(kdjSignal)
  110.  
  111.  
  112. ////OBV
  113.  
  114. obvsrc = close
  115. obv = cum(change(obvsrc) > 0 ? volume : change(obvsrc) < 0 ? -volume : 0*volume)
  116.  
  117. ////BollBand
  118.  
  119. BBlength = 20
  120. BBsrc = close
  121. BBmult = 2.0
  122. basis = sma(BBsrc, BBlength)
  123. BBdev = BBmult * stdev(BBsrc, BBlength)
  124. upperBB = basis + BBdev
  125. lowerBB = basis - BBdev
  126.  
  127. bbSignal = na
  128. bbSignalScore = na
  129. bbWasNeutral = false
  130. bbWasNeutral := nz(close[1]) < upperBB and nz(close[1]) > lowerBB or bbWasNeutral[1]
  131. bblong = ((crossunder(close, lowerBB) and bbSignalScore[1] <= 0 and bbWasNeutral) ? 1 : 0) + ((crossunder(close, upperBB) and bbSignalScore[1] <= -1 and bbWasNeutral) ? 1 : 0)
  132. bbshort = ((crossover(close, upperBB) and bbSignalScore[1] >= 0 and bbWasNeutral) ? -1 : 0) + ((crossover(close, lowerBB) and bbSignalScore[1] >= 1 and bbWasNeutral) ? -1 : 0)
  133. bbSignal := bblong + bbshort
  134. bbSignalScore := nz(bbSignalScore[1]) + nz(bbSignal)
  135.  
  136.  
  137. ////EMA's
  138.  
  139. M1=ema(close,13)
  140. M2=ema(close,48)
  141.  
  142. emaSignal = na
  143. emaSignalScore = na
  144. emaWasNeutral = false
  145. emaWasNeutral := nz(emaSignal[1]) != 0 or emaWasNeutral[1]
  146. emalong = ((crossover(M1, close) and emaSignalScore[1] <= 0) ? (emaWasNeutral ? 2 : 1) : 0)
  147. emashort = ((crossunder(M1, close) and emaSignalScore[1] >= 0) ? (emaWasNeutral ? -2 : -1) : 0)
  148. emaSignal := emalong + emashort
  149. emaSignalScore := nz(emaSignalScore[1]) + nz(emaSignal)
  150.  
  151. ////Stoch
  152.  
  153. periodK = 14
  154. periodD = 3
  155. smoothK = 3
  156. k = sma(stoch(close, high, low, periodK), smoothK)
  157. d = sma(k, periodD)
  158.  
  159. stochSignal = na
  160. stochSignalScore = na
  161. stochWasNeutral = false
  162. stochWasNeutral := nz(k[1]) < 90 and nz(k[1]) > 10 or stochWasNeutral[1]
  163. stochlong = ((crossunder(k, 10) and stochSignalScore[1] <= 0 and stochWasNeutral) ? 1 : 0) + ((crossunder(k, 90) and stochSignalScore[1] <= -1 and stochWasNeutral) ? 1 : 0)
  164. stochshort = ((crossover(k, 90) and stochSignalScore[1] >= 0 and stochWasNeutral) ? -1 : 0) + ((crossover(k, 10) and stochSignalScore[1] >= 1 and stochWasNeutral) ? -1 : 0)
  165. stochSignal := stochlong + stochshort
  166. stochSignalScore := nz(stochSignalScore[1]) + nz(stochSignal)
  167.  
  168.  
  169. ////CCI
  170.  
  171. ccilength = 20
  172. ccisrc = close
  173. ccima = sma(ccisrc, ccilength)
  174. cci = (ccisrc - ccima) / (0.015 * dev(ccisrc, ccilength))
  175.  
  176. cciSignal = na
  177. cciSignalScore = na
  178. cciWasNeutral = false
  179. cciWasNeutral := nz(cci[1]) < 250 and nz(cci[1]) > -250 or cciWasNeutral[1]
  180. ccilong = ((crossunder(cci, -250) and cciSignalScore[1] <= 0 and cciWasNeutral) ? 1 : 0) + ((crossunder(cci, 250) and cciSignalScore[1] <= -1 and cciWasNeutral) ? 1 : 0)
  181. ccishort = ((crossover(cci, 250) and cciSignalScore[1] >= 0 and cciWasNeutral) ? -1 : 0) + ((crossover(cci, -250) and cciSignalScore[1] >= 1 and cciWasNeutral) ? -1 : 0)
  182. cciSignal := ccilong + ccishort
  183. cciSignalScore := nz(cciSignalScore[1]) + nz(cciSignal)
  184.  
  185. ////VWMA
  186.  
  187. vwshortsrc = close, vwshortlen = 1
  188. vwlongsrc = close, vwlonglen = 72
  189. vwmashortlength = vwma(vwshortsrc, vwshortlen)
  190. vwmalonglength = vwma(vwlongsrc, vwlonglen)
  191.  
  192. vwmaSignal = na
  193. vwmaSignalScore = na
  194. vwmaWasNeutral = false
  195. vwmaWasNeutral := nz(vwmaSignal[1]) != 0 or vwmaWasNeutral[1]
  196. vwmalong = ((crossunder(close, vwmalonglength) and vwmaSignalScore[1] <= 0) ? (vwmaWasNeutral ? 2 : 1) : 0)
  197. vwmashort = ((crossover(close, vwmalonglength) and vwmaSignalScore[1] >= 0) ? (vwmaWasNeutral ? -2 : -1) : 0)
  198. vwmaSignal := vwmalong + vwmashort
  199. vwmaSignalScore := nz(vwmaSignalScore[1]) + nz(vwmaSignal)
  200.  
  201. ////TRIX
  202.  
  203. trixlength = 9
  204. trixout = 10000 * change(ema(ema(ema(log(close), trixlength), trixlength), trixlength))
  205.  
  206. trixSignal = na
  207. trixSignalScore = na
  208. trixWasNeutral = false
  209. trixWasNeutral := nz(trixout[1]) < 20 and nz(trixout[1]) > -20 or trixWasNeutral[1]
  210. trixlong = ((crossunder(trixout, -20) and trixSignalScore[1] <= 0 and trixWasNeutral) ? 1 : 0) + ((crossunder(trixout, 20) and trixSignalScore[1] <= -1 and trixWasNeutral) ? 1 : 0)
  211. trixshort = ((crossover(trixout, 20) and trixSignalScore[1] >= 0 and trixWasNeutral) ? -1 : 0) + ((crossover(trixout, -20) and trixSignalScore[1] >= 1 and trixWasNeutral) ? -1 : 0)
  212. trixSignal := trixlong + trixshort
  213. trixSignalScore := nz(trixSignalScore[1]) + nz(trixSignal)
  214.  
  215. ////Williams R
  216.  
  217. wrlength = 14
  218. upper = highest(wrlength)
  219. lower = lowest(wrlength)
  220. wrout = 100 * (close - upper) / (upper - lower)
  221.  
  222. wrSignal = na
  223. wrSignalScore = na
  224. wrWasNeutral = false
  225. wrWasNeutral := nz(wrout[1]) < -10 and nz(wrout[1]) > -90 or wrWasNeutral[1]
  226. wrlong = ((crossunder(wrout, -90) and wrSignalScore[1] <= 0 and wrWasNeutral) ? 1 : 0) + ((crossunder(wrout, -10) and wrSignalScore[1] <= -1 and wrWasNeutral) ? 1 : 0)
  227. wrshort = ((crossover(wrout, -10) and wrSignalScore[1] >= 0 and wrWasNeutral) ? -1 : 0) + ((crossover(wrout,-90) and wrSignalScore[1] >= 1 and wrWasNeutral) ? -1 : 0)
  228. wrSignal := wrlong + wrshort
  229. wrSignalScore := nz(wrSignalScore[1]) + nz(wrSignal)
  230.  
  231. ////DMI + ADX
  232.  
  233. dmilen = 14
  234. lensig = 14
  235.  
  236. dmiup = change(high)
  237. dmidown = -change(low)
  238. plusDM = na(dmiup) ? na : (dmiup > dmidown and dmiup > 0 ? dmiup : 0)
  239. minusDM = na(dmidown) ? na : (dmidown > dmiup and dmidown > 0 ? dmidown : 0)
  240. trur = rma(tr, dmilen)
  241. plus = fixnan(100 * rma(plusDM, dmilen) / trur)
  242. minus = fixnan(100 * rma(minusDM, dmilen) / trur)
  243. dmisum = plus + minus
  244. dmiadx = 100 * rma(abs(plus - minus) / (dmisum == 0 ? 1 : dmisum), lensig)
  245.  
  246. dmiSignal = na
  247. dmiSignalScore = na
  248. dmiWasNeutral = false
  249. dmiWasNeutral := nz(dmiSignal[1]) != 0 or dmiWasNeutral[1]
  250. dmilong = ((crossunder(plus,minus) and dmiSignalScore[1] <= 0) ? (dmiWasNeutral ? 2 : 1) : 0)
  251. dmishort = ((crossover(plus,minus) and dmiSignalScore[1] >= 0) ? (dmiWasNeutral ? -2 : -1) : 0)
  252. dmiSignal := dmilong + dmishort
  253. dmiSignalScore := nz(dmiSignalScore[1]) + nz(dmiSignal)
  254.  
  255. adxSignal = na
  256. adxSignalScore = na
  257. adxWasNeutral = false
  258. adxWasNeutral := nz(adxSignal[1]) != 0 or adxWasNeutral[1]
  259. adxlong = ((crossunder(dmiadx, 40) and adxSignalScore[1] <= 0) ? (adxWasNeutral ? 2 : 1) : 0)
  260. adxshort = ((crossover(dmiadx, 40) and adxSignalScore[1] >= 0) ? (adxWasNeutral ? -2 : -1) : 0)
  261. adxSignal := adxlong + adxshort
  262. adxSignalScore := nz(adxSignalScore[1]) + nz(adxSignal)
  263.  
  264. ////MOM
  265.  
  266. mtmlen = 10
  267. mtmsrc = close
  268. mom = mtmsrc - mtmsrc[mtmlen]
  269.  
  270. momSignal = na
  271. momSignalScore = na
  272. momWasNeutral = false
  273. momWasNeutral := nz(mom[1]) <4 and nz(mom[1]) > -4 or momWasNeutral[1]
  274. momlong = ((crossunder(mom, -4) and momSignalScore[1] <= 0 and momWasNeutral) ? 1 : 0) + ((crossunder(mom,4) and momSignalScore[1] <= -1 and momWasNeutral) ? 1 : 0)
  275. momshort = ((crossover(mom,4) and momSignalScore[1] >= 0 and momWasNeutral) ? -1 : 0) + ((crossover(mom, -4) and momSignalScore[1] >= 1 and momWasNeutral) ? -1 : 0)
  276. momSignal := momlong + momshort
  277. momSignalScore := nz(momSignalScore[1]) + nz(momSignal)
  278.  
  279. ////Parabolic SAR
  280.  
  281. sarstart = 0.02
  282. increment = 0.02
  283. maximum = 0.2
  284. sarout = sar(sarstart, increment, maximum)
  285.  
  286. sarSignal = na
  287. sarSignalScore = na
  288. sarWasNeutral = false
  289. sarWasNeutral := nz(sarSignal[1]) != 0 or sarWasNeutral[1]
  290. sarlong = ((crossunder(close, sarout) and sarSignalScore[1] <= 0) ? (sarWasNeutral ? 2 : 1) : 0)
  291. sarshort = ((crossover(close, sarout) and sarSignalScore[1] >= 0) ? (sarWasNeutral ? -2 : -1) : 0)
  292. sarSignal := sarlong + sarshort
  293. sarSignalScore := nz(sarSignalScore[1]) + nz(sarSignal)
  294.  
  295. ////EOM
  296.  
  297. emvdiv = 10000
  298. emvlength = 14
  299. eom = sma(emvdiv * change(hl2) * (high - low) / volume, emvlength)
  300. topBand = 0.5
  301. bottomBand = -0.5
  302.  
  303. eomSignal = na
  304. eomSignalScore = na
  305. eomWasNeutral = false
  306. eomWasNeutral := nz(eom[1]) < topBand and nz(eom[1]) > bottomBand or eomWasNeutral[1]
  307. eomlong = ((crossunder(eom, bottomBand) and eomSignalScore[1] <= 0 and eomWasNeutral) ? 1 : 0) + ((crossunder(eom,topBand) and eomSignalScore[1] <= -1 and eomWasNeutral) ? 1 : 0)
  308. eomshort = ((crossover(eom,topBand) and eomSignalScore[1] >= 0 and eomWasNeutral) ? -1 : 0) + ((crossover(eom, bottomBand) and eomSignalScore[1] >= 1 and eomWasNeutral) ? -1 : 0)
  309. eomSignal := eomlong + eomshort
  310. eomSignalScore := nz(eomSignalScore[1]) + nz(eomSignal)
  311.  
  312. ////AutoFib (FIX THIS BEFORE USING)
  313.  
  314. fiblength=265
  315. maxr = highest(close, fiblength)
  316. minr = lowest(close, fiblength)
  317. ranr = maxr - minr
  318.  
  319. autofiblong = 0 + (crossunder(close, (maxr - 0.786 * ranr)) ? 1 : 0) + (crossunder(close, (maxr - 0.236 * ranr)) ? 1 : 0)
  320. autofibshort = 0 - (crossover(close, (maxr - 0.236 * ranr)) ? 1 : 0) - (crossover(close, (maxr - 0.786 * ranr)) ? 1 : 0)
  321. autofibSignal = autofiblong + autofibshort
  322.  
  323. ////Vwap
  324.  
  325. vwapsrc = hlc3
  326. t = time("D")
  327. vwapstart = na(t[1]) or t > t[1]
  328.  
  329. vwapsumSrc = vwapsrc * volume
  330. vwapsumVol = volume
  331. vwapsumSrc := vwapstart ? vwapsumSrc : vwapsumSrc + vwapsumSrc[1]
  332. vwapsumVol := vwapstart ? vwapsumVol : vwapsumVol + vwapsumVol[1]
  333.  
  334. vWap= vwapsumSrc/vwapsumVol
  335.  
  336. vwapSignal = na
  337. vwapSignalScore = na
  338. vwapWasNeutral = false
  339. vwapWasNeutral := nz(vwapSignal[1]) != 0 or vwapWasNeutral[1]
  340. vwaplong = ((crossunder(close, vWap) and vwapSignalScore[1] <= 0) ? (vwapWasNeutral ? 2 : 1) : 0)
  341. vwapshort = ((crossover(close, vWap) and vwapSignalScore[1] >= 0) ? (vwapWasNeutral ? -2 : -1) : 0)
  342. vwapSignal := vwaplong + vwapshort
  343. vwapSignalScore := nz(vwapSignalScore[1]) + nz(vwapSignal)
  344.  
  345. ////Fisher Transform
  346.  
  347. fishlen = 9
  348.  
  349. fishhigh_ = highest(hl2, fishlen)
  350. fishlow_ = lowest(hl2, fishlen)
  351.  
  352. fishround_(val) => val > .99 ? .999 : val < -.99 ? -.999 : val
  353.  
  354. value = 0.0
  355. value := fishround_(.66 * ((hl2 - fishlow_) / max(fishhigh_ - fishlow_, .001) - .5) + .67 * nz(value[1]))
  356.  
  357. fish1 = 0.0
  358. fish1 := .5 * log((1 + value) / max(1 - value, .001)) + .5 * nz(fish1[1])
  359.  
  360. fish2 = fish1[1]
  361.  
  362. topFishLevel= 3
  363. bottomFishLevel= -3
  364.  
  365. fishSignal = na
  366. fishSignalScore = na
  367. fishWasNeutral = false
  368. fishWasNeutral := nz(fish1[1]) < topFishLevel and nz(fish1[1]) > bottomFishLevel or fishWasNeutral[1]
  369. fishlong = ((crossunder(fish1, bottomFishLevel) and fishSignalScore[1] <= 0 and fishWasNeutral) ? 1 : 0) + ((crossunder(fish1,topFishLevel) and fishSignalScore[1] <= -1 and fishWasNeutral) ? 1 : 0)
  370. fishshort = ((crossover(fish1,topFishLevel) and fishSignalScore[1] >= 0 and fishWasNeutral) ? -1 : 0) + ((crossover(fish1, bottomFishLevel) and fishSignalScore[1] >= 1 and fishWasNeutral) ? -1 : 0)
  371. fishSignal := fishlong + fishshort
  372. fishSignalScore := nz(fishSignalScore[1]) + nz(fishSignal)
  373.  
  374. ////VW Keltner bands
  375.  
  376. emaLenLong = 3
  377. emaLenShort = 3
  378. atrLen = 10
  379. multiplier = 1
  380. srcLong = low
  381. srcShort = high
  382.  
  383. emLong = vwma(srcLong, emaLenLong)
  384. emShort = vwma(srcShort, emaLenShort)
  385. mATRLong = multiplier * atr(atrLen)
  386. mATRShort = multiplier * atr(atrLen)
  387.  
  388. kcSignal = na
  389. kcSignalScore = na
  390. kcWasNeutral = false
  391. kcWasNeutral := nz(low[1]) > (emLong - mATRLong) and nz(high[1]) < (emShort + mATRShort) or kcWasNeutral[1]
  392. kclong = ((crossunder(low, (emLong - mATRLong)) and kcSignalScore[1] <= 0 and kcWasNeutral) ? 1 : 0) + ((crossunder(high, (emShort + mATRShort)) and kcSignalScore[1] <= -1 and kcWasNeutral) ? 1 : 0)
  393. kcshort = ((crossover(high, (emShort + mATRShort)) and kcSignalScore[1] >= 0 and kcWasNeutral) ? -1 : 0) + ((crossover(low, (emLong - mATRLong)) and kcSignalScore[1] >= 1 and kcWasNeutral) ? -1 : 0)
  394. kcSignal := kclong + kcshort
  395. kcSignalScore := nz(kcSignalScore[1]) + nz(kcSignal)
  396.  
  397. ////MFI
  398.  
  399. mfisource = hlc3
  400. mfilength = 14
  401. mfilower = 20
  402. mfiupper = 80
  403.  
  404. mfiupper_s = sum(volume * (change(mfisource) <= 0 ? 0 : mfisource), mfilength)
  405. mfilower_s = sum(volume * (change(mfisource) >= 0 ? 0 : mfisource), mfilength)
  406. mfi = rsi(mfiupper_s, mfilower_s)
  407.  
  408. mfiSignal = na
  409. mfiSignalScore = na
  410. mfiWasNeutral = false
  411. mfiWasNeutral := nz(mfi[1]) < 80 and nz(mfi[1]) > 20 or mfiWasNeutral[1]
  412. mfilong = ((crossunder(mfi, 20) and mfiSignalScore[1] <= 0 and mfiWasNeutral) ? 1 : 0) + ((crossunder(mfi, 80) and mfiSignalScore[1] <= -1 and mfiWasNeutral) ? 1 : 0)
  413. mfishort = ((crossover(mfi, 80) and mfiSignalScore[1] >= 0 and mfiWasNeutral) ? -1 : 0) + ((crossover(mfi, 20) and mfiSignalScore[1] >= 1 and mfiWasNeutral) ? -1 : 0)
  414. mfiSignal := mfilong + mfishort
  415. mfiSignalScore := nz(mfiSignalScore[1]) + nz(mfiSignal)
  416.  
  417. ////TDS
  418.  
  419. TD=na
  420. TS=na
  421.  
  422. TD := close > close[4] ?nz(TD[1])+1:0
  423. TS := close < close[4] ?nz(TS[1])+1:0
  424.  
  425. TDUp = TD - valuewhen(TD < TD[1], TD , 1 )
  426. TDDn = TS - valuewhen(TS < TS[1], TS , 1 )
  427.  
  428. tdsSignal = na
  429. tdsSignalScore = na
  430. tdsWasNeutral = false
  431. tdsWasNeutral := nz(TS[1])<9 and nz(TS[1])>9 and nz(TD[1])<9 and nz(TD[1])>9 or tdsWasNeutral[1]
  432. tdslong = (((TS==9) and tdsSignalScore[1] <= 0 and tdsWasNeutral) ? 1 : 0) + (((TD==9) and tdsSignalScore[1] <= -1 and tdsWasNeutral) ? 1 : 0)
  433. tdsshort = (((TD==9) and tdsSignalScore[1] >= 0 and tdsWasNeutral) ? -1 : 0) + (((TS==9) and tdsSignalScore[1] >= 1 and tdsWasNeutral) ? -1 : 0)
  434. tdsSignal := tdslong + tdsshort
  435. tdsSignalScore := nz(tdsSignalScore[1]) + nz(tdsSignal)
  436.  
  437.  
  438. ////////////////////////////////////////////////////////////////////////////////
  439. pastSignalScore = na
  440.  
  441. ////not in use: sarSignal + adxSignal + vwmaSignal + kdjSignal +
  442.  
  443. pastSignalScore := nz(pastSignalScore[1]) + bbSignal + cciSignal + eomSignal + stochSignal + trixSignal + dmiSignal + macdSignal + rsiSignal + wrSignal + momSignal + vwapSignal + fishSignal + kcSignal + emaSignal + mfiSignal
  444. //pastSignalScore := nz(pastSignalScore[1]) + tdsSignal
  445.  
  446. signalScore = pastSignalScore + ichiSignal
  447.  
  448.  
  449. //signalScoreSmoothed = vwma(signalScore, 10)
  450. //plot(signalScoreSmoothed, color=yellow)
  451.  
  452. plot(signalScore, color = signalScore >= 0 ? green : red, linewidth = 1, style = histogram)
  453. hline(0)
  454.  
  455. longEntryRequirment= input(title="Long entry requirment", type=integer, defval=13)
  456. longExitRequirment= input(title="Long exit requirment", type=integer, defval=-11)
  457.  
  458. //shortEntryRequirment= input(title="Short entry requirment", type=integer, defval=-100)
  459. //shortExitRequirment= input(title="Short exit requirment", type=integer, defval=100)
  460.  
  461. signalScoreLongEntry = (signalScore>=longEntryRequirment)
  462. signalScoreLongExit = (signalScore<=longExitRequirment) //and (signalScore < signalScore[1])
  463.  
  464. //signalScoreShortEntry = signalScore<=shortEntryRequirment
  465. //signalScoreShortExit = signalScore>=shortExitRequirment
  466.  
  467. previousSignalScoreLong = signalScoreLongEntry[1] or signalScoreLongEntry[2] or signalScoreLongEntry[3] or signalScoreLongEntry[4] or signalScoreLongEntry[5]
  468.  
  469. //previousSignalScoreShort = signalScoreShortEntry[1] or signalScoreShortEntry[2] or signalScoreShortEntry[3] or signalScoreShortEntry[4] or signalScoreShortEntry[5]
  470.  
  471. longEntryCondition= signalScoreLongEntry and not (previousSignalScoreLong or strategy.position_size < 0)
  472. longExitCondition= signalScoreLongExit and strategy.openprofit > 0
  473.  
  474. //shortEntryCondition= signalScoreShortEntry and not (previousSignalScoreShort or strategy.position_size > 0)
  475. //shortExitCondition= signalScoreShortExit and strategy.openprofit > 0
  476.  
  477. strategy.entry("Long", strategy.long, when= longEntryCondition)
  478. //strategy.entry("Short", strategy.short, when= shortEntryCondition)
  479. strategy.close("Long", when= longExitCondition)
  480. //strategy.close("Short", when= shortExitCondition)
Advertisement
Add Comment
Please, Sign In to add comment