xmd79

Argo II

Nov 15th, 2021
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.72 KB | None | 0 0
  1. // ▒█▀▀▀█ ▒█▀▀█ ▒█░ ▒█▀▀█ ▒█▀▀█ ▒▀▀█▀▀ ▒█░▒█ ▒█▀▀█
  2. // █░░▄▄ ▒█▄▄█ ▒█░ ▒█▄▄█ ▒█░ ▒░▒█ ▒█░▒█ ▒█▄▄▄
  3. // ▒█▄▄▄█ ▒█░▒█ ▒█▄▄█ ▒█░▒█ ▒█▄▄█ ▒░▒█ ░█▄▄█ ░▄▄▄█
  4.  
  5. //@version=5
  6.  
  7. indicator('Argo II', overlay=false)
  8.  
  9. // ================================== //
  10. // ---------> Bot details <----------- //
  11. // ================================== //
  12.  
  13. BotID = input.string(title='Bot ID', group='Bot details', defval='')
  14. EmailToken = input.string(title='Email Token', group='Bot details', defval='')
  15. Exchange = input.string(title='Exchange', group='Bot details', defval='BINANCE', options=['BINANCE', 'FTX', 'KUCOIN', 'HUOBI', 'BINANCEUS', 'COINBASE', 'BITTREX', 'BITMEX', 'GEMINI'])
  16. Quote = input.string(title='Quote currency', group='Bot details', defval='USDT', options=['USDT', 'BTC', 'USD', 'ETH', 'BUSD', 'EUR', 'USDC', 'ADA', 'BNB'])
  17. Signals = input.string(title='Signal type', group='Bot details', defval='Buy', options=['Buy', 'Buy + Sell', 'Sell'])
  18.  
  19. // ================================== //
  20. // -------> Coin selection <--------- //
  21. // ================================== //
  22.  
  23. /// ========== USER INPUT ========== \\\
  24.  
  25. c1 = input.string(title='Coin 1', group='Coin Selection', defval='ETH', inline='c1')
  26. c2 = input.string(title='Coin 2', group='Coin Selection', defval='ADA', inline='c2')
  27. c3 = input.string(title='Coin 3', group='Coin Selection', defval='ATOM', inline='c3')
  28. c4 = input.string(title='Coin 4', group='Coin Selection', defval='SOL', inline='c4')
  29. c5 = input.string(title='Coin 5', group='Coin Selection', defval='ALGO', inline='c5')
  30. c6 = input.string(title='Coin 6', group='Coin Selection', defval='FTT', inline='c6')
  31. c7 = input.string(title='Coin 7', group='Coin Selection', defval='IOTA', inline='c1')
  32. c8 = input.string(title='Coin 8', group='Coin Selection', defval='LUNA', inline='c2')
  33. c9 = input.string(title='Coin 9', group='Coin Selection', defval='ALGO', inline='c3')
  34. c10 = input.string(title='Coin 10', group='Coin Selection', defval='FTT', inline='c4')
  35. c11 = input.string(title='Coin 11', group='Coin Selection', defval='IOTA', inline='c5')
  36. c12 = input.string(title='Coin 12', group='Coin Selection', defval='LUNA', inline='c6')
  37.  
  38. /// ========== Extract TICKER IDs from coin names ========== \\\
  39.  
  40. // Ticker IDs are needed for security functions
  41.  
  42. ticker1 = Exchange + ':' + c1 + Quote
  43. ticker2 = Exchange + ':' + c2 + Quote
  44. ticker3 = Exchange + ':' + c3 + Quote
  45. ticker4 = Exchange + ':' + c4 + Quote
  46. ticker5 = Exchange + ':' + c5 + Quote
  47. ticker6 = Exchange + ':' + c6 + Quote
  48. ticker7 = Exchange + ':' + c7 + Quote
  49. ticker8 = Exchange + ':' + c8 + Quote
  50. ticker9 = Exchange + ':' + c9 + Quote
  51. ticker10 = Exchange + ':' + c10 + Quote
  52. ticker11 = Exchange + ':' + c11 + Quote
  53. ticker12 = Exchange + ':' + c12 + Quote
  54.  
  55.  
  56. /// ========== Extract PAIRS from coin names ========== \\\
  57.  
  58. // Pairs written in 3commas format are required for generating alerts in the right format.
  59.  
  60. c1Pair = Quote + '_' + c1
  61. c2Pair = Quote + '_' + c2
  62. c3Pair = Quote + '_' + c3
  63. c4Pair = Quote + '_' + c4
  64. c5Pair = Quote + '_' + c5
  65. c6Pair = Quote + '_' + c6
  66. c7Pair = Quote + '_' + c7
  67. c8Pair = Quote + '_' + c8
  68. c9Pair = Quote + '_' + c9
  69. c10Pair = Quote + '_' + c10
  70. c11Pair = Quote + '_' + c11
  71. c12Pair = Quote + '_' + c12
  72.  
  73. // ================================== //
  74. // ----------> Indicators <---------- //
  75. // ================================== //
  76. source = close
  77.  
  78. EnableBB = input.bool(false, 'Enable ?', group='Bollinger Bands')
  79.  
  80. BBlength = input.int(13, minval=1, maxval=50, group='Bollinger Bands', title='Lenght')
  81. BBmult = input.float(1.8, minval=0.001, maxval=50, group='Bollinger Bands', title='Deviation')
  82. BBBuyCondition = input.string(title='Buy if value', options=['is below the lower band', 'crosses over the lower band'], group='Bollinger Bands', defval='is below the lower band')
  83. BBSellCondition = input.string(title='Sell if value', options=['is above the upper band', 'crosses under the upper band'], group='Bollinger Bands', defval='is above the upper band')
  84.  
  85. basis = ta.sma(source, BBlength)
  86. dev = BBmult * ta.stdev(source, BBlength)
  87. upper = basis + dev
  88. lower = basis - dev
  89.  
  90. basis2 = ta.sma(source, 1)
  91. dev2 = 1 * ta.stdev(source, 1)
  92. upper2 = basis2 + dev2
  93. lower2 = basis2 - dev2
  94.  
  95. BB_Buy1a = EnableBB == true and BBBuyCondition == 'is below the lower band'
  96. BB_Buy1b = source < lower
  97. BB_Buy2a = EnableBB == true and BBBuyCondition == 'crosses over the lower band'
  98. BB_Buy2b = ta.crossover(source, lower)
  99. BB_neutral = source <= lower or source > lower
  100.  
  101. BBBuy = BB_Buy1a ? BB_Buy1b : BB_Buy2a ? BB_Buy2b : BB_neutral
  102.  
  103. BB_Sell1a = EnableBB == true and BBSellCondition == 'is above the upper band'
  104. BB_Sell1b = source > upper
  105. BB_Sell2a = EnableBB == true and BBSellCondition == 'crosses under the upper band'
  106. BB_Sell2b = ta.crossunder(source, upper)
  107.  
  108. BBSell = BB_Sell1a ? BB_Sell1b : BB_Sell2a ? BB_Sell2b : BB_neutral
  109.  
  110. /// ================ RSI =============== \\
  111.  
  112. RSI1_ON = input.bool(false, 'Enable RSI |', group='RELATIVE STRENGTH INDEX', inline='RSIL')
  113. //RSI1_TF = input(title="TF", type=input.resolution, defval="auto",group="RELATIVE STRENGTH INDEX", inline = "RSI1.1")
  114. RSI1_L = input.int(title='Length', group='RELATIVE STRENGTH INDEX', defval=14, inline='RSIL')
  115. RSI1_BuyType = input.string(title='Buy if value', options=['is below', 'crosses over'], group='RELATIVE STRENGTH INDEX', inline='RSI1.2', defval='is below')
  116. RSI1_BuyLimit = input.int(title=' ', group='RELATIVE STRENGTH INDEX', defval=30, inline='RSI1.2')
  117. RSI1_SellType = input.string(title='Sell if value', options=['is above', 'crosses under'], group='RELATIVE STRENGTH INDEX', inline='RSI1.3', defval='is above')
  118. RSI1_SellLimit = input.int(title=' ', group='RELATIVE STRENGTH INDEX', defval=75, inline='RSI1.3')
  119.  
  120. RSI1 = ta.rsi(close, RSI1_L)
  121.  
  122.  
  123. RSI_Buy1a = RSI1_ON == true and RSI1_BuyType == 'is below'
  124. RSI_Buy1b = RSI1 < RSI1_BuyLimit
  125. RSI_Buy2a = RSI1_ON == true and RSI1_BuyType == 'crosses over'
  126. RSI_Buy2b = ta.crossover(RSI1, RSI1_BuyLimit)
  127. RSI_neutral = RSI1 <= RSI1_BuyLimit or RSI1 > RSI1_BuyLimit
  128.  
  129. RSI1_Buy = RSI_Buy1a ? RSI_Buy1b : RSI_Buy2a ? RSI_Buy2b : RSI_neutral
  130.  
  131.  
  132. RSI_Sell1a = RSI1_ON == true and RSI1_SellType == 'is above'
  133. RSI_Sell1b = RSI1 > RSI1_SellLimit
  134. RSI_Sell2a = RSI1_ON == true and RSI1_SellType == 'crosses under'
  135. RSI_Sell2b = ta.crossunder(RSI1, RSI1_SellLimit)
  136.  
  137. RSI1_Sell = RSI_Sell1a ? RSI_Sell1b : RSI_Sell2a ? RSI_Sell2b : RSI_neutral
  138.  
  139.  
  140. //RISING & FALLING RSI
  141. RSI_rising = input.bool(false, 'RSI rising', group='RELATIVE STRENGTH INDEX', inline='rising1')
  142. RSI_falling = input.bool(false, 'RSI falling', group='RELATIVE STRENGTH INDEX', inline='falling1')
  143. RSI_risingCandles = input.int(title='Nb candles', group='RELATIVE STRENGTH INDEX', defval=1, inline='rising1')
  144. RSI_fallingCandles = input.int(title='Nb candles', group='RELATIVE STRENGTH INDEX', defval=2, inline='falling1')
  145.  
  146. rsiRising = ta.rising(RSI1, RSI_risingCandles)
  147. rsiFalling = ta.falling(RSI1, RSI_fallingCandles)
  148.  
  149. RSIBuy1 = RSI1_Buy and rsiRising
  150. RSIBuy2 = RSI1_Buy
  151.  
  152. RSISell1 = RSI1_Sell and rsiFalling
  153. RSISell2 = RSI1_Sell
  154.  
  155. RSIBuy = RSI_rising ? RSIBuy1 : RSIBuy2
  156. RSISell = RSI_falling ? RSISell1 : RSISell2
  157.  
  158. // Integrating RSI buy / sell conditions
  159.  
  160. //RSIBuy = RSI1_Buy
  161. //RSISell = RSI1_Sell
  162.  
  163. ///=========== Williams % ============///
  164.  
  165. EnableW = input.bool(false, 'Enable?', group='WILLIAMS %R')
  166.  
  167. W_length = input.int(title='Length', defval=14, group='WILLIAMS %R')
  168. WBuyCondition = input.string(title='Buy if value', options=['is below', 'crosses over'], group='WILLIAMS %R', inline='WBuycondition', defval='is below')
  169. WBuyLevel = input.float(title=' ', defval=-77, group='WILLIAMS %R', minval=-100, maxval=0, step=1, inline='WBuycondition')
  170. WSellCondition = input.string(title='Sell if value', options=['is above', 'crosses under'], group='WILLIAMS %R', inline='WSellcondition', defval='is above')
  171. WSellLevel = input.float(title=' ', defval=-20, group='WILLIAMS %R', minval=-100, maxval=0, step=1, inline='WSellcondition')
  172.  
  173. _pr(length) =>
  174. max = ta.highest(W_length)
  175. min = ta.lowest(W_length)
  176. 100 * (source - max) / (max - min)
  177. percentR = _pr(W_length)
  178.  
  179. W_Buy1a = EnableW == true and WBuyCondition == 'is below'
  180. W_Buy1b = percentR < WBuyLevel
  181. W_Buy2a = EnableW == true and WBuyCondition == 'crosses over'
  182. W_Buy2b = ta.crossover(percentR, WBuyLevel)
  183. W_neutral = percentR <= WBuyLevel or percentR > WBuyLevel
  184.  
  185. WBuy = W_Buy1a ? W_Buy1b : W_Buy2a ? W_Buy2b : W_neutral
  186.  
  187.  
  188. W_Sell1a = EnableW == true and WSellCondition == 'is above'
  189. W_Sell1b = percentR > WSellLevel
  190. W_Sell2a = EnableW == true and WSellCondition == 'crosses under'
  191. W_Sell2b = ta.crossunder(percentR, WSellLevel)
  192.  
  193. WSell = W_Sell1a ? W_Sell1b : W_Sell2a ? W_Sell2b : W_neutral
  194.  
  195.  
  196.  
  197. ///=========== SMA oscillator ============///
  198.  
  199. EnableSMA = input.bool(false, 'Enable?', group='SMA oscillator')
  200.  
  201. Wlen = input.int(14, minval=1, title='Length', group='SMA oscillator')
  202.  
  203. SMABuyCondition = input.string(title='Buy if value', options=['is below', 'crosses over'], group='SMA oscillator', inline='SMABuycondition', defval='is below')
  204. SMABuyLevel = input.float(title=' ', defval=-0.01, group='SMA oscillator', inline='SMABuycondition', minval=-0.50, maxval=0, step=0.001)
  205.  
  206. SMASellCondition = input.string(title='Sell if value', options=['is above', 'crosses under'], group='SMA oscillator', inline='SMASellcondition', defval='is above')
  207. SMASellLevel = input.float(title=' ', defval=0.020, group='SMA oscillator', inline='SMASellcondition', minval=0, maxval=0.50, step=0.001)
  208.  
  209. out = math.log(close / ta.sma(source, Wlen))
  210.  
  211. SMA_Buy1a = EnableSMA == true and SMABuyCondition == 'is below'
  212. SMA_Buy1b = out < SMABuyLevel
  213. SMA_Buy2a = EnableSMA == true and SMABuyCondition == 'crosses over'
  214. SMA_Buy2b = ta.crossover(out, SMABuyLevel)
  215. SMA_neutral = out <= SMABuyLevel or out > SMABuyLevel
  216.  
  217. SMABuy = SMA_Buy1a ? SMA_Buy1b : SMA_Buy2a ? SMA_Buy2b : SMA_neutral
  218.  
  219.  
  220. SMA_Sell1a = EnableSMA == true and SMASellCondition == 'is above'
  221. SMA_Sell1b = out > SMASellLevel
  222. SMA_Sell2a = EnableSMA == true and SMASellCondition == 'crosses under'
  223. SMA_Sell2b = ta.crossunder(out, SMASellLevel)
  224.  
  225. SMASell = SMA_Sell1a ? SMA_Sell1b : SMA_Sell2a ? SMA_Sell2b : SMA_neutral
  226.  
  227.  
  228. ///=========== EMA ============///
  229.  
  230. EMA_ON = input.bool(false, 'Trade when on EMA...', group='EMA TREND FILTER', inline='EMA1')
  231. EMA_SRC = input.source(title='EMA source', defval=close, group='EMA TREND FILTER')
  232. EMA_L = input.int(title='EMA length', group='EMA TREND FILTER', defval=200)
  233. EMA = ta.ema(EMA_SRC, EMA_L)
  234.  
  235. EMATrend = input.string(title='', options=['uptrend', 'downtrend'], group='EMA TREND FILTER', defval='uptrend', inline='EMA1')
  236.  
  237. EMA1 = EMA_ON == true and EMATrend == 'uptrend'
  238. EMA2 = EMA_ON == true and EMATrend == 'downtrend'
  239. EMAUptrend = EMA_SRC > EMA
  240. EMADowntrend = EMA_SRC < EMA
  241. EMAneutral = EMA_SRC < EMA or EMA_SRC > EMA
  242.  
  243. EMASIgnal = EMA1 ? EMAUptrend : EMA2 ? EMADowntrend : EMAneutral
  244.  
  245.  
  246. /// ================ Inverse Fisher Transform =============== \\
  247.  
  248. wmalength = input.int(9, title='Smoothing length', group='Inverse Fisher Transform')
  249.  
  250. // IFT RSI
  251. RSIon = input.bool(false, title='RSI, lenght', group='Inverse Fisher Transform', inline='IFRSI')
  252. rsilength = input.int(5, title=' ', group='Inverse Fisher Transform', inline='IFRSI')
  253. v1 = 0.1 * (ta.rsi(close, rsilength) - 50)
  254. v2 = ta.wma(v1, wmalength)
  255.  
  256. INV1Calc = (math.exp(2 * v2) - 1) / (math.exp(2 * v2) + 1)
  257. INV1 = RSIon ? INV1Calc : 0
  258.  
  259. AV1 = INV1 ? 1 : 0
  260.  
  261. // IFT CCI
  262. CCIon = input.bool(false, title='CCI, lenght', group='Inverse Fisher Transform', inline='IFCCI')
  263. ccilength = input.int(5, '', group='Inverse Fisher Transform', inline='IFCCI')
  264. v11 = 0.1 * (ta.cci(close, ccilength) / 4)
  265. v21 = ta.wma(v11, wmalength)
  266.  
  267. INV2Calc = (math.exp(2 * v21) - 1) / (math.exp(2 * v21) + 1)
  268. INV2 = CCIon ? INV2Calc : 0
  269.  
  270. AV2 = INV2 ? 1 : 0
  271.  
  272. // IFT STOCH
  273. STOCHon = input.bool(false, title='STOCH, lenght', group='Inverse Fisher Transform', inline='IFSTOCH')
  274. stochlength = input.int(5, '', group='Inverse Fisher Transform', inline='IFSTOCH')
  275. v12 = 0.1 * (ta.stoch(close, high, low, stochlength) - 50)
  276. v22 = ta.wma(v1, wmalength)
  277.  
  278. INV3Calc = (math.exp(2 * v22) - 1) / (math.exp(2 * v22) + 1)
  279. INV3 = STOCHon ? INV3Calc : 0
  280.  
  281. AV3 = INV3 ? 1 : 0
  282.  
  283. // IFT MFI
  284. MFIon = input.bool(false, title='MFI, lenght', group='Inverse Fisher Transform', inline='IFMFI')
  285. mfilength = input.int(5, '', group='Inverse Fisher Transform', inline='IFMFI')
  286. MFIsource = hlc3
  287. upMFI = math.sum(volume * (ta.change(MFIsource) <= 0 ? 0 : MFIsource), mfilength)
  288. loMFI = math.sum(volume * (ta.change(MFIsource) >= 0 ? 0 : MFIsource), mfilength)
  289. mfi = 100.0 - 100.0 / (1.0 + upMFI / loMFI)
  290. v13 = 0.1 * (mfi - 50)
  291. v23 = ta.wma(v13, wmalength)
  292.  
  293. INV4Calc = (math.exp(2 * v23) - 1) / (math.exp(2 * v23) + 1)
  294. INV4 = MFIon ? INV4Calc : 0
  295.  
  296. AV4 = INV4 ? 1 : 0
  297.  
  298. AVcount = AV1 + AV2 + AV3 + AV4
  299.  
  300. AVCond = AVcount > 0
  301. AVCalc = (INV1 + INV2 + INV3 + INV4) / AVcount
  302.  
  303. AVINV = AVCond ? AVCalc : 0
  304.  
  305.  
  306. buyLevel = input.float(-0.9, 'buy level', group='Inverse Fisher Transform')
  307. sellLevel = input.float(0.996, 'sell level', group='Inverse Fisher Transform')
  308. buyLevelMinAge = input.int(defval=0, title='Buy level min candle age', minval=0, group='Inverse Fisher Transform', tooltip='For how many candles do you want the buy condition to be true before actually firing a buy signal. The longer a buy signal remains true the higher the likelihood of a reversal to the upside.')
  309. buyOnSignalReversal = input.bool(false, title='Buy on signal reversal', tooltip='Buy only on the last candle where the buy conditions are still met. This can help prevent buying a falling knife but can harm profits too. This option overrides both "second buy level" and "min candle age".')
  310. sellOnSignalReversal = input.bool(false, title='Sell on signal reversal', tooltip='Sell only on the last candle where the sell conditions are still met. This option overrides both "second sell level" and "min candle age".')
  311.  
  312. candlesBuyCond = buyLevelMinAge == 0 ? true : ta.barssince(AVINV > buyLevel) > buyLevelMinAge
  313.  
  314. IFT_Buy1a = buyOnSignalReversal and AVcount > 0
  315. IFT_Buy1b = ta.crossover(AVINV, buyLevel)
  316. IFT_Buy2a = AVcount > 0 and not buyOnSignalReversal
  317. IFT_Buy2b = AVINV < buyLevel and candlesBuyCond
  318. IFT_neutral = AVINV <= buyLevel or AVINV > buyLevel
  319.  
  320. IFTBuy = IFT_Buy1a ? IFT_Buy1b : IFT_Buy2a ? IFT_Buy2b : IFT_neutral
  321.  
  322. IFT_Sell1a = sellOnSignalReversal and AVcount > 0
  323. IFT_Sell1b = ta.crossunder(AVINV, sellLevel)
  324. IFT_Sell2a = AVcount > 0 and not sellOnSignalReversal
  325. IFT_Sell2b = AVINV > sellLevel
  326.  
  327. IFTSell = IFT_Sell1a ? IFT_Sell1b : IFT_Sell2a ? IFT_Sell2b : IFT_neutral
  328.  
  329. // ================================== //
  330. // ---------> Protections <---------- //
  331. // ================================== //
  332.  
  333. // BTC 1h
  334.  
  335. BTC1H_ON = input.bool(false, 'BTC RSI Protection', group='PROTECTIONS')
  336. BTC1H_TF = input.timeframe(title='TF', defval='60', group='PROTECTIONS', inline='BTC1h')
  337. BTC1H_L = input.int(title='L', group='PROTECTIONS', defval=7, inline='BTC1h')
  338. BTC1H_BuyLimit = input.int(title='ONLY buy if BTC RSI is BELOW. ', group='PROTECTIONS', defval=70, inline='BTC1h1')
  339. BTC1H_RSI_Calc = ta.rsi(close, BTC1H_L)
  340. BTC1H_rsi = request.security('BINANCE:BTCUSDT', BTC1H_TF, BTC1H_RSI_Calc)
  341.  
  342. BTC_1hCondition1 = BTC1H_rsi < BTC1H_BuyLimit
  343. BTC_1hCondition2 = BTC1H_rsi > BTC1H_BuyLimit or BTC1H_rsi < BTC1H_BuyLimit
  344.  
  345. BTC_1h = BTC1H_ON ? BTC_1hCondition1 : BTC_1hCondition2
  346.  
  347. //TOTAL2
  348. T24H_ON = input.bool(false, 'TOTAL2 RSI Protection', group='PROTECTIONS')
  349. T24H_TF = input.timeframe(title='TF', defval='240', group='PROTECTIONS', inline='T2.1')
  350. T24H_L = input.int(title='L', group='PROTECTIONS', defval=7, inline='T2.1')
  351. T24H_BuyLimit = input.int(title='ONLY buy if T2 RSI is BELOW... ', group='PROTECTIONS', defval=70, inline='T2.2')
  352. T24H_RSI_Calc = ta.rsi(close, T24H_L)
  353. T24H_rsi = request.security('CRYPTOCAP:TOTAL2', T24H_TF, T24H_RSI_Calc)
  354.  
  355. T2_4hCondition1 = T24H_rsi < T24H_BuyLimit
  356. T2_4hCondition2 = T24H_rsi > T24H_BuyLimit or T24H_rsi < T24H_BuyLimit
  357.  
  358. T2_4h = T24H_ON ? T2_4hCondition1 : T2_4hCondition2
  359.  
  360.  
  361.  
  362. BuyProtection = BTC_1h and T2_4h
  363.  
  364.  
  365. // ======================================== //
  366. // --------> Deal start conditions <------- //
  367. // ======================================== //
  368.  
  369. //Deal start/close conditions for the composite bot (for the actual alerts, not backtesting)
  370. BuySignalFunc() =>
  371. BBBuy and WBuy and SMABuy and RSIBuy and EMASIgnal and IFTBuy and BuyProtection
  372.  
  373. SellSignalFunc() =>
  374. BBSell and WSell and SMASell and RSISell and IFTSell
  375.  
  376. SignalFunc() =>
  377. [BuySignalFunc(), SellSignalFunc()]
  378.  
  379.  
  380. //Deal start/close conditions for current chart (for backtesting, not alerts)
  381. Buy = WBuy and SMABuy and BBBuy and EMASIgnal and RSIBuy and IFTBuy and BuyProtection
  382.  
  383. Sell = WSell and SMASell and BBSell and RSISell and IFTSell
  384.  
  385.  
  386. // ======================================================== //
  387. // --------> Link deal start conditions to tickers <------- //
  388. // ======================================================== //
  389.  
  390. //Listed pairs
  391. [c1_Buy, c1_Sell] = request.security(ticker1, timeframe.period, SignalFunc())
  392. [c2_Buy, c2_Sell] = request.security(ticker2, timeframe.period, SignalFunc())
  393. [c3_Buy, c3_Sell] = request.security(ticker3, timeframe.period, SignalFunc())
  394. [c4_Buy, c4_Sell] = request.security(ticker4, timeframe.period, SignalFunc())
  395. [c5_Buy, c5_Sell] = request.security(ticker5, timeframe.period, SignalFunc())
  396. [c6_Buy, c6_Sell] = request.security(ticker6, timeframe.period, SignalFunc())
  397. [c7_Buy, c7_Sell] = request.security(ticker7, timeframe.period, SignalFunc())
  398. [c8_Buy, c8_Sell] = request.security(ticker8, timeframe.period, SignalFunc())
  399. [c9_Buy, c9_Sell] = request.security(ticker9, timeframe.period, SignalFunc())
  400. [c10_Buy, c10_Sell] = request.security(ticker10, timeframe.period, SignalFunc())
  401. [c11_Buy, c11_Sell] = request.security(ticker11, timeframe.period, SignalFunc())
  402. [c12_Buy, c12_Sell] = request.security(ticker12, timeframe.period, SignalFunc())
  403.  
  404.  
  405.  
  406. // ================================== //
  407. // ------------> Alerts <----------- //
  408. // ================================== //
  409.  
  410. BuySetting = Signals == 'Buy' or Signals == 'Buy + Sell'
  411. SellSetting = Signals == 'Sell' or Signals == 'Buy + Sell'
  412.  
  413.  
  414. //BUY alerts
  415.  
  416. if c1_Buy and BuySetting
  417. alert('{"message_type": "bot", "bot_id": "' + BotID + '", "email_token": "' + EmailToken + '", "delay_seconds": 1, "pair": "' + c1Pair + '"}', alert.freq_once_per_bar_close)
  418.  
  419. if c2_Buy and BuySetting
  420. alert('{"message_type": "bot", "bot_id": "' + BotID + '", "email_token": "' + EmailToken + '", "delay_seconds": 2, "pair": "' + c2Pair + '"}', alert.freq_once_per_bar_close)
  421.  
  422. if c3_Buy and BuySetting
  423. alert('{"message_type": "bot", "bot_id": "' + BotID + '", "email_token": "' + EmailToken + '", "delay_seconds": 3, "pair": "' + c3Pair + '"}', alert.freq_once_per_bar_close)
  424.  
  425. if c4_Buy and BuySetting
  426. alert('{"message_type": "bot", "bot_id": "' + BotID + '", "email_token": "' + EmailToken + '", "delay_seconds": 4, "pair": "' + c4Pair + '"}', alert.freq_once_per_bar_close)
  427.  
  428. if c5_Buy and BuySetting
  429. alert('{"message_type": "bot", "bot_id": "' + BotID + '", "email_token": "' + EmailToken + '", "delay_seconds": 5, "pair": "' + c5Pair + '"}', alert.freq_once_per_bar_close)
  430.  
  431. if c6_Buy and BuySetting
  432. alert('{"message_type": "bot", "bot_id": "' + BotID + '", "email_token": "' + EmailToken + '", "delay_seconds": 6, "pair": "' + c6Pair + '"}', alert.freq_once_per_bar_close)
  433.  
  434. if c7_Buy and BuySetting
  435. alert('{"message_type": "bot", "bot_id": "' + BotID + '", "email_token": "' + EmailToken + '", "delay_seconds": 7, "pair": "' + c7Pair + '"}', alert.freq_once_per_bar_close)
  436.  
  437. if c8_Buy and BuySetting
  438. alert('{"message_type": "bot", "bot_id": "' + BotID + '", "email_token": "' + EmailToken + '", "delay_seconds": 8, "pair": "' + c8Pair + '"}', alert.freq_once_per_bar_close)
  439.  
  440. if c9_Buy and BuySetting
  441. alert('{"message_type": "bot", "bot_id": "' + BotID + '", "email_token": "' + EmailToken + '", "delay_seconds": 5, "pair": "' + c9Pair + '"}', alert.freq_once_per_bar_close)
  442.  
  443. if c10_Buy and BuySetting
  444. alert('{"message_type": "bot", "bot_id": "' + BotID + '", "email_token": "' + EmailToken + '", "delay_seconds": 6, "pair": "' + c10Pair + '"}', alert.freq_once_per_bar_close)
  445.  
  446. if c11_Buy and BuySetting
  447. alert('{"message_type": "bot", "bot_id": "' + BotID + '", "email_token": "' + EmailToken + '", "delay_seconds": 7, "pair": "' + c11Pair + '"}', alert.freq_once_per_bar_close)
  448.  
  449. if c12_Buy and BuySetting
  450. alert('{"message_type": "bot", "bot_id": "' + BotID + '", "email_token": "' + EmailToken + '", "delay_seconds": 8, "pair": "' + c12Pair + '"}', alert.freq_once_per_bar_close)
  451.  
  452.  
  453. // SELL alerts
  454.  
  455. if c1_Sell and SellSetting
  456. alert('{"action": "close_at_market_price", "message_type": "bot", "bot_id": "' + BotID + '", "email_token": "' + EmailToken + '", "delay_seconds": 1, "pair": "' + c1Pair + '"}', alert.freq_once_per_bar_close)
  457.  
  458. if c2_Sell and SellSetting
  459. alert('{"action": "close_at_market_price", "message_type": "bot", "bot_id": "' + BotID + '", "email_token": "' + EmailToken + '", "delay_seconds": 2, "pair": "' + c2Pair + '"}', alert.freq_once_per_bar_close)
  460.  
  461. if c3_Sell and SellSetting
  462. alert('{"action": "close_at_market_price", "message_type": "bot", "bot_id": "' + BotID + '", "email_token": "' + EmailToken + '", "delay_seconds": 3, "pair": "' + c3Pair + '"}', alert.freq_once_per_bar_close)
  463.  
  464. if c4_Sell and SellSetting
  465. alert('{"action": "close_at_market_price", "message_type": "bot", "bot_id": "' + BotID + '", "email_token": "' + EmailToken + '", "delay_seconds": 4, "pair": "' + c4Pair + '"}', alert.freq_once_per_bar_close)
  466.  
  467. if c5_Sell and SellSetting
  468. alert('{"action": "close_at_market_price", "message_type": "bot", "bot_id": "' + BotID + '", "email_token": "' + EmailToken + '", "delay_seconds": 5, "pair": "' + c5Pair + '"}', alert.freq_once_per_bar_close)
  469.  
  470. if c6_Sell and SellSetting
  471. alert('{"action": "close_at_market_price", "message_type": "bot", "bot_id": "' + BotID + '", "email_token": "' + EmailToken + '", "delay_seconds": 6, "pair": "' + c6Pair + '"}', alert.freq_once_per_bar_close)
  472.  
  473. if c7_Sell and SellSetting
  474. alert('{"action": "close_at_market_price", "message_type": "bot", "bot_id": "' + BotID + '", "email_token": "' + EmailToken + '", "delay_seconds": 7, "pair": "' + c7Pair + '"}', alert.freq_once_per_bar_close)
  475.  
  476. if c8_Sell and SellSetting
  477. alert('{"action": "close_at_market_price", "message_type": "bot", "bot_id": "' + BotID + '", "email_token": "' + EmailToken + '", "delay_seconds": 8, "pair": "' + c8Pair + '"}', alert.freq_once_per_bar_close)
  478.  
  479. if c9_Sell and SellSetting
  480. alert('{"action": "close_at_market_price", "message_type": "bot", "bot_id": "' + BotID + '", "email_token": "' + EmailToken + '", "delay_seconds": 5, "pair": "' + c9Pair + '"}', alert.freq_once_per_bar_close)
  481.  
  482. if c10_Sell and SellSetting
  483. alert('{"action": "close_at_market_price", "message_type": "bot", "bot_id": "' + BotID + '", "email_token": "' + EmailToken + '", "delay_seconds": 6, "pair": "' + c10Pair + '"}', alert.freq_once_per_bar_close)
  484.  
  485. if c11_Sell and SellSetting
  486. alert('{"action": "close_at_market_price", "message_type": "bot", "bot_id": "' + BotID + '", "email_token": "' + EmailToken + '", "delay_seconds": 7, "pair": "' + c11Pair + '"}', alert.freq_once_per_bar_close)
  487.  
  488. if c12_Sell and SellSetting
  489. alert('{"action": "close_at_market_price", "message_type": "bot", "bot_id": "' + BotID + '", "email_token": "' + EmailToken + '", "delay_seconds": 8, "pair": "' + c12Pair + '"}', alert.freq_once_per_bar_close)
  490.  
  491.  
  492.  
  493. // ================================== //
  494. // ---------> Plot shapes <---------- //
  495. // ================================== //
  496.  
  497. // This part will plot a simple chart to identify entry or/and exit points, compatible with Gavin's backtester
  498.  
  499. purple = color.new(color.purple, 0)
  500. blue = color.new(color.blue, 0)
  501. red = color.new(color.red, 0)
  502. yellow = color.new(color.yellow, 0)
  503. yellow2 = color.new(color.yellow, 50)
  504. green = color.new(color.green, 0)
  505. maroon = color.new(color.olive, 0)
  506. fuschia = color.new(color.fuchsia, 0)
  507.  
  508. plot(AVINV ? AVINV : na, color=yellow, linewidth=2, title='AVERAGE')
  509. plot(INV1 ? INV1 : na, color=yellow2, linewidth=1, title='RSI')
  510. plot(INV2 ? INV2 : na, color=yellow2, linewidth=1, title='CCI')
  511. plot(INV3 ? INV3 : na, color=yellow2, linewidth=1, title='STOCH')
  512. plot(INV4 ? INV4 : na, color=yellow2, linewidth=1, title='MFI')
  513.  
  514. plot(Buy and Signals == 'Buy' ? 1 : 0, 'Buy', color=Buy ? color.green : color.gray)
  515.  
  516. plot(Buy and Signals == 'Buy + Sell' ? 1 : 0 or Sell and Signals == 'Buy + Sell' ? 2 : 0, 'Buy/Sell', color=Buy ? color.green : Sell ? color.red : color.gray)
  517.  
  518. plot(Sell and Signals == 'Sell' ? 2 : 0, 'Sell', color=Sell ? color.red : color.gray)
  519.  
  520.  
  521.  
Advertisement
Add Comment
Please, Sign In to add comment