Advertisement
JustUncleL

8 Pair Strength R2.4 updated by JustUncleL

Dec 8th, 2017
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.40 KB | None | 0 0
  1. //@version=3
  2.  
  3. study("8 Pair Strength R2.4 updated by JustUncleL", shorttitle="8 Pair Strength", overlay=false,max_bars_back=100)
  4.  
  5. //
  6. // Author: Glaz
  7. // Date: 17 Feb 2015
  8. //
  9. // Description:
  10. // This study is a version of Currency Strength Meter, that utilises TradingViews
  11. // built-in "True Strength Index" (TSI) function. The TSI uses moving averages
  12. // of the underlying momentum of a financial instrument.
  13. //
  14. // Modifications:
  15. // 08-Dec-2017 R2.4 by JustUncleL
  16. // - Added ZAR and TRY exotic pairs
  17. // - Changed all security calls to include FX_IDC exchange in ID.
  18. //
  19. // 19-Nov-2017 R2.2 by JustUncleL
  20. // - Improved labelling options.
  21. // - Added option to use ATR weighted (default) pair influences in the Strength calculations,
  22. // the overall results compared with stardard calculation though is only minor, but may help.
  23. //
  24. // 17-Nov-2017 R2.1 by JustUncleL
  25. // - Added max_bars_back=100 parameter to study. This should prevent
  26. // "index out depth" errors.
  27. // - Added minval/maxval limits to fast and slow.
  28. // - Changed order of plots so they show up in alpabetic order in the "Style"
  29. // parameters of the script.
  30. // - Added optional Currency labels at end of Currency strenth line.
  31. //
  32. // 10-Nov-2017 by JustUncleL
  33. // - Corrected the weighting on JPY pairs, divide the close values by 100 to
  34. // bring them within 1.0 range of the pairs.
  35. // - Added option to use different Data Source, eg hl2, hlc3, ohlc4 etc.
  36. // - Updated to PineScript version 3.
  37. //
  38. // -----------------------------------------------------------------------------
  39. // Copyright 2015 Glaz
  40. // Copyright 2017 JustUncleL
  41. //
  42. // This program is free software: you can redistribute it and/or modify
  43. // it under the terms of the GNU General Public License as published by
  44. // the Free Software Foundation, either version 3 of the License, or
  45. // any later version.
  46. //
  47. // This program is distributed in the hope that it will be useful,
  48. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  49. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  50. // GNU General Public License for more details.
  51. //
  52. // The GNU General Public License can be found here
  53. // <http://www.gnu.org/licenses/>.
  54. //
  55. // -----------------------------------------------------------------------------
  56.  
  57.  
  58. // === INPUTS ===
  59.  
  60. fast= input(10,minval=1,maxval=150)
  61. slow= input(40,minval=2,maxval=300)
  62. src = input(close,title="Source")
  63. uWghts = input(true,title="Use ATR weighted Averages in Strength Calculation")
  64. ShowLabels = input(true)
  65. ShowFixed = input(true,title="Show labels as a Fixed List, instead of Strength following")
  66.  
  67. // === /INPUTS ===
  68.  
  69. // === SERIES ===
  70. // Current source values
  71. audcad = security("FX_IDC:AUDCAD", period, src, barmerge.gaps_off, barmerge.lookahead_on)
  72. audchf = security("FX_IDC:AUDCHF", period, src, barmerge.gaps_off, barmerge.lookahead_on)
  73. audjpy = security("FX_IDC:AUDJPY", period, src/100, barmerge.gaps_off, barmerge.lookahead_on)
  74. audnzd = security("FX_IDC:AUDNZD", period, src, barmerge.gaps_off, barmerge.lookahead_on)
  75. audusd = security("FX_IDC:AUDUSD", period, src, barmerge.gaps_off, barmerge.lookahead_on)
  76. //
  77. cadchf = security("FX_IDC:CADCHF", period, src, barmerge.gaps_off, barmerge.lookahead_on)
  78. cadjpy = security("FX_IDC:CADJPY", period, src/100, barmerge.gaps_off, barmerge.lookahead_on)
  79. //
  80. chfjpy = security("FX_IDC:CHFJPY", period, src/100, barmerge.gaps_off, barmerge.lookahead_on)
  81. //
  82. euraud = security("FX_IDC:EURAUD", period, src, barmerge.gaps_off, barmerge.lookahead_on)
  83. eurcad = security("FX_IDC:EURCAD", period, src, barmerge.gaps_off, barmerge.lookahead_on)
  84. eurchf = security("FX_IDC:EURCHF", period, src, barmerge.gaps_off, barmerge.lookahead_on)
  85. eurgbp = security("FX_IDC:EURGBP", period, src, barmerge.gaps_off, barmerge.lookahead_on)
  86. eurjpy = security("FX_IDC:EURJPY", period, src/100, barmerge.gaps_off, barmerge.lookahead_on)
  87. eurnzd = security("FX_IDC:EURNZD", period, src, barmerge.gaps_off, barmerge.lookahead_on)
  88. eurusd = security("FX_IDC:EURUSD", period, src, barmerge.gaps_off, barmerge.lookahead_on)
  89. //
  90. gbpaud = security("FX_IDC:GBPAUD", period, src, barmerge.gaps_off, barmerge.lookahead_on)
  91. gbpcad = security("FX_IDC:GBPCAD", period, src, barmerge.gaps_off, barmerge.lookahead_on)
  92. gbpchf = security("FX_IDC:GBPCHF", period, src, barmerge.gaps_off, barmerge.lookahead_on)
  93. gbpjpy = security("FX_IDC:GBPJPY", period, src/100, barmerge.gaps_off, barmerge.lookahead_on)
  94. gbpnzd = security("FX_IDC:GBPNZD", period, src, barmerge.gaps_off, barmerge.lookahead_on)
  95. gbpusd = security("FX_IDC:GBPUSD", period, src, barmerge.gaps_off, barmerge.lookahead_on)
  96. //
  97. nzdcad = security("FX_IDC:NZDCAD", period, src, barmerge.gaps_off, barmerge.lookahead_on)
  98. nzdchf = security("FX_IDC:NZDCHF", period, src, barmerge.gaps_off, barmerge.lookahead_on)
  99. nzdjpy = security("FX_IDC:NZDJPY", period, src/100, barmerge.gaps_off, barmerge.lookahead_on)
  100. nzdusd = security("FX_IDC:NZDUSD", period, src, barmerge.gaps_off, barmerge.lookahead_on)
  101. //
  102. usdcad = security("FX_IDC:USDCAD", period, src, barmerge.gaps_off, barmerge.lookahead_on)
  103. usdchf = security("FX_IDC:USDCHF", period, src, barmerge.gaps_off, barmerge.lookahead_on)
  104. usdjpy = security("FX_IDC:USDJPY", period, src/100, barmerge.gaps_off, barmerge.lookahead_on)
  105. //
  106. eurzar = security("FX_IDC:EURZAR", period, src, barmerge.gaps_off, barmerge.lookahead_on)
  107. gbpzar = security("FX_IDC:GBPZAR", period, src, barmerge.gaps_off, barmerge.lookahead_on)
  108. usdzar = security("FX_IDC:USDZAR", period, src, barmerge.gaps_off, barmerge.lookahead_on)
  109.  
  110. //
  111. eurtry = security("FX_IDC:EURTRY", period, src, barmerge.gaps_off, barmerge.lookahead_on)
  112. usdtry = security("FX_IDC:USDTRY", period, src, barmerge.gaps_off, barmerge.lookahead_on)
  113.  
  114. // Estimate Currency Strength based on the Average Influence Rates
  115. // Scaling factor
  116. sf = uWghts? 14.29 : 0.1429
  117.  
  118. //Calculate Currency strength ATR weighted (default) or no weighting.
  119. EUR = uWghts? (eurusd/80 + eurgbp/75 + euraud/125 + eurjpy/105 + eurcad/120 + eurchf/50 + eurnzd/135)*sf :
  120. (eurusd + eurgbp + euraud + eurjpy + eurcad + eurchf + eurnzd)*sf
  121. USD = uWghts? (usdjpy/100 + usdcad/90 + usdchf/70 - audusd/60 - gbpusd/120 - eurusd/80 - nzdusd/65)*sf :
  122. (usdjpy + usdcad + usdchf - audusd - gbpusd - eurusd - nzdusd)*sf
  123. JPY = uWghts? -(audjpy/85 + cadjpy/60 + chfjpy/90 + eurjpy/105 + gbpjpy/160 + usdjpy/100 + nzdjpy/80)*sf :
  124. -(audjpy + cadjpy + chfjpy + eurjpy + gbpjpy + usdjpy + nzdjpy)*sf
  125. GBP = uWghts? (gbpjpy/160 + gbpcad/160 + gbpchf/110 - eurgbp/75 + gbpusd/120 + gbpaud/170 + gbpnzd/200)*sf :
  126. (gbpjpy + gbpcad + gbpchf - eurgbp + gbpusd + gbpaud + gbpnzd)*sf
  127. AUD = uWghts? (audjpy/85 + audcad/75 + audchf/70 - euraud/125 - gbpaud/160 + audusd/60 + audnzd/70)*sf :
  128. (audjpy + audcad + audchf - euraud - gbpaud + audusd + audnzd)*sf
  129. CAD = uWghts? (cadjpy/90 + cadchf/60 - audcad/75 - eurcad/120 - gbpcad/160 - usdcad/90 - nzdcad/80)*sf :
  130. (cadjpy + cadchf - audcad - eurcad - gbpcad - usdcad - nzdcad)*sf
  131. CHF = uWghts? (chfjpy/90 - cadchf/60 - audchf/70 - eurchf/50 - gbpchf/110 - usdchf/70 - nzdchf/65)*sf :
  132. (chfjpy - cadchf - audchf - eurchf - gbpchf - usdchf - nzdchf)*sf
  133. NZD = uWghts? (nzdjpy/80 + nzdchf/65 + nzdcad/80 + nzdusd/65 - gbpnzd/200 - eurnzd/135 - audnzd/70)*sf :
  134. (nzdjpy + nzdchf + nzdcad + nzdusd - gbpnzd - eurnzd - audnzd)*sf
  135. // Exotics
  136. ZAR = uWghts? (-eurzar/220 - gbpzar/265 - usdzar/1960)*sf : (-eurzar - gbpzar - usdzar)*sf
  137. TRY = uWghts? (-eurtry/520 - usdtry/420)*sf : (-eurtry - usdtry)*sf
  138.  
  139. // Use True Strength Index, to calculate Currency Strength.
  140. eur=tsi(EUR,fast,slow)
  141. gbp=tsi(GBP,fast,slow)
  142. jpy=tsi(JPY,fast,slow)
  143. usd=tsi(USD,fast,slow)
  144. aud=tsi(AUD,fast,slow)
  145. cad=tsi(CAD,fast,slow)
  146. chf=tsi(CHF,fast,slow)
  147. nzd=tsi(NZD,fast,slow)
  148. try=tsi(TRY,fast,slow)
  149. zar=tsi(ZAR,fast,slow)
  150.  
  151. // === /SERIES ===
  152.  
  153. // === PLOTTING ===
  154.  
  155. // Plot Strength on chart
  156. plot(aud,color=blue,title='AUD',linewidth=2,transp=0,join=true)
  157. plot(cad,color=fuchsia,title='CAD',linewidth=2,transp=0,join=true)
  158. plot(chf,color=black,title='CHF',linewidth=2,transp=0,join=true)
  159. plot(eur,color=orange,title='EUR',linewidth=2,transp=0,join=true)
  160. plot(gbp,color=teal,title='GBP',linewidth=2,transp=0,join=true)
  161. plot(jpy,color=red,title='JPY',linewidth=2,transp=0,join=true)
  162. plot(nzd,color=aqua,title='NZD',linewidth=2,transp=0,join=true)
  163. plot(usd,color=green,title='USD',linewidth=2,transp=0,join=true)
  164. plot(try,color=gray,title='TRY',linewidth=2,transp=0,join=true)
  165. plot(zar,color=purple,title='ZAR',linewidth=2,transp=0,join=true)
  166.  
  167. hline(0,"Zero",color=navy,linestyle=dotted,linewidth=2)
  168. hline(0.5,"Upper Line",color=gray,linestyle=dashed,linewidth=1)
  169. hline(-0.5,"Lower Line",color=gray,linestyle=dashed,linewidth=1)
  170. //
  171. Fixed = ShowFixed and ShowLabels and barstate.islast
  172. plotshape(Fixed?0.525:na,location=location.absolute,style=shape.labeldown,title="TRY txt",
  173. color=gray,text="TRY",textcolor=white,show_last=1,transp=0,offset=5,size=size.auto)
  174. plotshape(Fixed?0.400:na,location=location.absolute,style=shape.labeldown,title="AUD txt",
  175. color=blue,text="AUD",textcolor=white,show_last=1,transp=0,offset=5,size=size.auto)
  176. plotshape(Fixed?0.275:na,location=location.absolute,style=shape.labeldown,title="CAD txt",
  177. color=fuchsia,text="CAD",textcolor=white,show_last=1,transp=0,offset=5,size=size.auto)
  178. plotshape(Fixed?0.150:na,location=location.absolute,style=shape.labeldown,title="CHF txt",
  179. color=black,text="CHF",textcolor=white,show_last=1,transp=0,offset=5,size=size.auto)
  180. plotshape(Fixed?0.025:na,location=location.absolute,style=shape.labeldown,title="EUR txt",
  181. color=orange,text="EUR",textcolor=white,show_last=1,transp=0,offset=5,size=size.auto)
  182. plotshape(Fixed?-0.025:na,location=location.absolute,style=shape.labelup,title="GBP txt",
  183. color=teal,text="GBP",textcolor=white,show_last=1,transp=0,offset=5,size=size.auto)
  184. plotshape(Fixed?-0.150:na,location=location.absolute,style=shape.labelup,title="JPY txt",
  185. color=red,text="JPY",textcolor=white,show_last=1,transp=0,offset=5,size=size.auto)
  186. plotshape(Fixed?-0.275:na,location=location.absolute,style=shape.labelup,title="NZD txt",
  187. color=aqua,text="NZD",textcolor=white,show_last=1,transp=0,offset=5,size=size.auto)
  188. plotshape(Fixed?-0.400:na,location=location.absolute,style=shape.labelup,title="USD txt",
  189. color=green,text="USD",textcolor=white,show_last=1,transp=0,offset=5,size=size.auto)
  190. plotshape(Fixed?-0.525:na,location=location.absolute,style=shape.labelup,title="ZAR txt",
  191. color=purple,text="ZAR",textcolor=white,show_last=1,transp=0,offset=5,size=size.auto)
  192. //
  193. Dynamic = not ShowFixed and ShowLabels and barstate.islast
  194. plotshape(Dynamic?aud:na,location=location.absolute,style=shape.labeldown,title="AUD d.txt",
  195. color=blue,text="AUD",textcolor=white,show_last=1,transp=0,offset=2)
  196. plotshape(Dynamic?cad:na,location=location.absolute,style=shape.labeldown,title="CAD d.txt",
  197. color=fuchsia,text="CAD",textcolor=white,show_last=1,transp=0,offset=2)
  198. plotshape(Dynamic?chf:na,location=location.absolute,style=shape.labeldown,title="CHF d.txt",
  199. color=black,text="CHF",textcolor=white,show_last=1,transp=0,offset=2)
  200. plotshape(Dynamic?eur:na,location=location.absolute,style=shape.labeldown,title="EUR d.txt",
  201. color=orange,text="EUR",textcolor=white,show_last=1,transp=0,offset=2)
  202. plotshape(Dynamic?gbp:na,location=location.absolute,style=shape.labeldown,title="GBP d.txt",
  203. color=teal,text="GBP",textcolor=white,show_last=1,transp=0,offset=2)
  204. plotshape(Dynamic?jpy:na,location=location.absolute,style=shape.labeldown,title="JPY d.txt",
  205. color=red,text="JPY",textcolor=white,show_last=1,transp=0,offset=2)
  206. plotshape(Dynamic?nzd:na,location=location.absolute,style=shape.labeldown,title="NZD d.txt",
  207. color=aqua,text="NZD",textcolor=white,show_last=1,transp=0,offset=2)
  208. plotshape(Dynamic?usd:na,location=location.absolute,style=shape.labeldown,title="USD d.txt",
  209. color=green,text="USD",textcolor=white,show_last=1,transp=0,offset=2)
  210. plotshape(Dynamic?usd:na,location=location.absolute,style=shape.labeldown,title="TRY d.txt",
  211. color=gray,text="TRY",textcolor=white,show_last=1,transp=0,offset=2)
  212. plotshape(Dynamic?usd:na,location=location.absolute,style=shape.labeldown,title="ZAR d.txt",
  213. color=purple,text="ZAR",textcolor=white,show_last=1,transp=0,offset=2)
  214.  
  215. // === /PLOTTING ===
  216.  
  217. //eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement