Advertisement
Guest User

Untitled

a guest
May 25th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.22 KB | None | 0 0
  1. //@version=3
  2. //
  3. //This script is for measuring the strength of all currencies in the market, it's similar to indexes, but it's calculated differently and allows for customization to some degree.
  4. //For example, you can show the bar change of all currencies, or the SMA or EMA for customizable periods, or you can select one currency and check three SMAs or EMAs for comparison.
  5. //All currencies use 1 as the base, currencies over 1 are strong while the ones below one are weak.
  6. //
  7. //You can customize the range of the short, medium and long moving averages, and you can decide whether to use EMA or SMA
  8. //If you select a symbol different from SHOW_ALL and deactive all other views the chart will show the triple SMA or EMA for that currency.
  9. //
  10. //
  11.  
  12. study("Simple Currency Strength Measurer", shorttitle="SCSM",overlay=false,precision=5)
  13.  
  14.  
  15. currency1 = input("EUR", title = "1st currency to show", type = string)
  16. currency2 = input("USD", title = "2nd currency to show", type = string)
  17.  
  18. tfbool = input(false, title = "Use an alternative timefame ?", type = bool)
  19. timeframe = input("D", title = "Timeframe", type = resolution)
  20. tf = tfbool ? timeframe:period
  21.  
  22. shortma=input(10,title="short MA", type=integer)
  23. mediumma=input(100,title="medium MA",type=integer)
  24. longma=input(200,title="large MA",type=integer)
  25.  
  26. useEma=input(true,"Use EMA",bool)
  27. smooth = input(7, "MA smoothing", type = integer)
  28.  
  29. ShortMAView=input(false,"Short MA view",bool)
  30. MediumMAView=input(true,"Medium MA view",bool)
  31. LongMAView=input(false,"Long MA view",bool)
  32.  
  33. line1=na
  34. line2=na
  35.  
  36. curr1=na
  37. curr2=na
  38.  
  39.  
  40. //Currency 1
  41. EUCl= security("FX_IDC:" + currency1 + "USD",,close,lookahead=barmerge.lookahead_off)
  42. SMAEU=sma(EUCl,shortma)
  43. MMAEU=sma(EUCl,mediumma)
  44. LMAEU=sma(EUCl,longma)
  45. SEMAEU=ema(EUCl,shortma)
  46. MEMAEU=ema(EUCl,mediumma)
  47. LEMAEU=ema(EUCl,longma)
  48.  
  49. EGCl= security("FX_IDC:" + currency1 + "GBP",,close,lookahead=barmerge.lookahead_off)
  50. SMAEG=sma(EGCl,shortma)
  51. MMAEG=sma(EGCl,mediumma)
  52. LMAEG=sma(EGCl,longma)
  53. SEMAEG=ema(EGCl,shortma)
  54. MEMAEG=ema(EGCl,mediumma)
  55. LEMAEG=ema(EGCl,longma)
  56.  
  57. EACl= security("FX_IDC:" + currency1 + "AUD",,close,lookahead=barmerge.lookahead_off)
  58. SMAEA=sma(EACl,shortma)
  59. MMAEA=sma(EACl,mediumma)
  60. LMAEA=sma(EACl,longma)
  61. SEMAEA=ema(EACl,shortma)
  62. MEMAEA=ema(EACl,mediumma)
  63. LEMAEA=ema(EACl,longma)
  64.  
  65. ENCl= security("FX_IDC:" + currency1 + "NZD",,close,lookahead=barmerge.lookahead_off)
  66. SMAEN=sma(ENCl,shortma)
  67. MMAEN=sma(ENCl,mediumma)
  68. LMAEN=sma(ENCl,longma)
  69. SEMAEN=ema(ENCl,shortma)
  70. MEMAEN=ema(ENCl,mediumma)
  71. LEMAEN=ema(ENCl,longma)
  72.  
  73. ECCl= security("FX_IDC:" + currency1 + "CAD",,close,lookahead=barmerge.lookahead_off)
  74. SMAEC=sma(ECCl,shortma)
  75. MMAEC=sma(ECCl,mediumma)
  76. LMAEC=sma(ECCl,longma)
  77. SEMAEC=ema(ECCl,shortma)
  78. MEMAEC=ema(ECCl,mediumma)
  79. LEMAEC=ema(ECCl,longma)
  80.  
  81. ESCl= security("FX_IDC:" + currency1 + "CHF",,close,lookahead=barmerge.lookahead_off)
  82. SMAES=sma(ESCl,shortma)
  83. MMAES=sma(ESCl,mediumma)
  84. LMAES=sma(ESCl,longma)
  85. SEMAES=ema(ESCl,shortma)
  86. MEMAES=ema(ESCl,mediumma)
  87. LEMAES=ema(ESCl,longma)
  88.  
  89. EJCl= security("FX_IDC:" + currency1 + "JPY",,close,lookahead=barmerge.lookahead_off)
  90. SMAEJ=sma(EJCl,shortma)
  91. MMAEJ=sma(EJCl,mediumma)
  92. LMAEJ=sma(EJCl,longma)
  93. SEMAEJ=ema(EJCl,shortma)
  94. MEMAEJ=ema(EJCl,mediumma)
  95. LEMAEJ=ema(EJCl,longma)
  96.  
  97.  
  98.  
  99. //Currency 2
  100.  
  101. UECl= security("FX_IDC:" + currency2 + "EUR",,close,lookahead=barmerge.lookahead_off)
  102. SMAUE=sma(UECl,shortma)
  103. MMAUE=sma(UECl,mediumma)
  104. LMAUE=sma(UECl,longma)
  105. SEMAUE=ema(UECl,shortma)
  106. MEMAUE=ema(UECl,mediumma)
  107. LEMAUE=ema(UECl,longma)
  108.  
  109. UGCl= security("FX_IDC:" + currency2 + "GBP",,close,lookahead=barmerge.lookahead_off)
  110. SMAUG=sma(UGCl,shortma)
  111. MMAUG=sma(UGCl,mediumma)
  112. LMAUG=sma(UGCl,longma)
  113. SEMAUG=ema(UGCl,shortma)
  114. MEMAUG=ema(UGCl,mediumma)
  115. LEMAUG=ema(UGCl,longma)
  116.  
  117. UACl= security("FX_IDC:" + currency2 + "AUD",,close,lookahead=barmerge.lookahead_off)
  118. SMAUA=sma(UACl,shortma)
  119. MMAUA=sma(UACl,mediumma)
  120. LMAUA=sma(UACl,longma)
  121. SEMAUA=ema(UACl,shortma)
  122. MEMAUA=ema(UACl,mediumma)
  123. LEMAUA=ema(UACl,longma)
  124.  
  125. UNCl= security("FX_IDC:" + currency2 + "NZD",,close,lookahead=barmerge.lookahead_off)
  126. SMAUN=sma(UNCl,shortma)
  127. MMAUN=sma(UNCl,mediumma)
  128. LMAUN=sma(UNCl,longma)
  129. SEMAUN=ema(UNCl,shortma)
  130. MEMAUN=ema(UNCl,mediumma)
  131. LEMAUN=ema(UNCl,longma)
  132.  
  133. UCCl= security("FX_IDC:" + currency2 + "CAD",,close,lookahead=barmerge.lookahead_off)
  134. SMAUC=sma(UCCl,shortma)
  135. MMAUC=sma(UCCl,mediumma)
  136. LMAUC=sma(UCCl,longma)
  137. SEMAUC=ema(UCCl,shortma)
  138. MEMAUC=ema(UCCl,mediumma)
  139. LEMAUC=ema(UCCl,longma)
  140.  
  141. USCl= security("FX_IDC:" + currency2 + "CHF",,close,lookahead=barmerge.lookahead_off)
  142. SMAUS=sma(USCl,shortma)
  143. MMAUS=sma(USCl,mediumma)
  144. LMAUS=sma(USCl,longma)
  145. SEMAUS=ema(USCl,shortma)
  146. MEMAUS=ema(USCl,mediumma)
  147. LEMAUS=ema(USCl,longma)
  148.  
  149. UJCl= security("FX_IDC:" + currency2 + "JPY",,close,lookahead=barmerge.lookahead_off)
  150. SMAUJ=sma(UJCl,shortma)
  151. MMAUJ=sma(UJCl,mediumma)
  152. LMAUJ=sma(UJCl,longma)
  153. SEMAUJ=ema(UJCl,shortma)
  154. MEMAUJ=ema(UJCl,mediumma)
  155. LEMAUJ=ema(UJCl,longma)
  156.  
  157.  
  158.  
  159. if(useEma)
  160. if(ShortMAView)
  161. curr1:=(EUCl/SEMAEU + EGCl/SEMAEG +EACl/SEMAEA +ENCl/SEMAEN +ECCl/SEMAEC +ESCl/SEMAES +EJCl/SEMAEJ)/7
  162. curr2:= (UECl/SEMAUE + UGCl/SEMAUG +UACl/SEMAUA +UNCl/SEMAUN +UCCl/SEMAUC +USCl/SEMAUS +UJCl/SEMAUJ)/7
  163. else
  164. if(MediumMAView)
  165. curr1:=(EUCl/MEMAEU + EGCl/MEMAEG +EACl/MEMAEA +ENCl/MEMAEN +ECCl/MEMAEC +ESCl/MEMAES +EJCl/MEMAEJ)/7
  166. curr2:= (UECl/MEMAUE + UGCl/MEMAUG +UACl/MEMAUA +UNCl/MEMAUN +UCCl/MEMAUC +USCl/MEMAUS +UJCl/MEMAUJ)/7
  167. else
  168. if(LongMAView)
  169. curr1:=(EUCl/LEMAEU + EGCl/LEMAEG +EACl/LEMAEA +ENCl/LEMAEN +ECCl/LEMAEC +ESCl/LEMAES +EJCl/LEMAEJ)/7
  170. curr2:= (UECl/LEMAUE + UGCl/LEMAUG +UACl/LEMAUA +UNCl/LEMAUN +UCCl/LEMAUC +USCl/LEMAUS +UJCl/LEMAUJ)/7
  171. else
  172. if(ShortMAView)
  173. curr1:=(EUCl/SMAEU + EGCl/SMAEG +EACl/SMAEA +ENCl/SMAEN +ECCl/SMAEC +ESCl/SMAES +EJCl/SMAEJ)/7
  174. curr2:= (UECl/SMAUE + UGCl/SMAUG +UACl/SMAUA +UNCl/SMAUN +UCCl/SMAUC +USCl/SMAUS +UJCl/SMAUJ)/7
  175. else
  176. if(MediumMAView)
  177. curr1:=(EUCl/MMAEU + EGCl/MMAEG +EACl/MMAEA +ENCl/MMAEN +ECCl/MMAEC +ESCl/MMAES +EJCl/MMAEJ)/7
  178. curr2:= (UECl/MMAUE + UGCl/MMAUG +UACl/MMAUA +UNCl/MMAUN +UCCl/MMAUC +USCl/MMAUS +UJCl/MMAUJ)/7
  179. else
  180. if(LongMAView)
  181. curr1:=(EUCl/LMAEU + EGCl/LMAEG +EACl/LMAEA +ENCl/LMAEN +ECCl/LMAEC +ESCl/LMAES +EJCl/LMAEJ)/7
  182. curr2:= (UECl/LMAUE + UGCl/LMAUG +UACl/LMAUA +UNCl/LMAUN +UCCl/LMAUC +USCl/LMAUS +UJCl/LMAUJ)/7
  183.  
  184.  
  185.  
  186. useSmoothedEma=input(true,"Use Smoothed version",bool)
  187. eml=input(20,"em",integer)
  188. if(useSmoothedEma)
  189. curr1:=ema(curr1,eml)
  190. curr2:=ema(curr2,eml)
  191.  
  192. if(useEma)
  193. line1:= ema(curr1, smooth)
  194. line2:= ema(curr2, smooth)
  195. else
  196. line1:= sma(curr1, smooth)
  197. line2:= sma(curr2, smooth)
  198.  
  199. plot(curr1,title="Currency 1", color=blue, linewidth = 2, transp = 0)
  200. plot(line1,title="MA",color=black, transp = 20)
  201. plot(curr2, title="Currency 2", color=red, linewidth = 2, transp = 0)
  202. plot(line2,title="MA",color=black, transp = 20)
  203.  
  204.  
  205. condup = false
  206. if curr1 > line1 and curr2 < line2
  207. condup := true
  208. conddown = false
  209. if curr1 < line1 and curr2 > line2
  210. conddown := true
  211.  
  212. bgcolor(condup? blue:white, transp=85)
  213. bgcolor(conddown? red:white, transp=85)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement