Advertisement
Guest User

Untitled

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