xmd79

Fan Projections [theEccentricTrader]

Apr 7th, 2023
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.29 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © theEccentricTrader
  3. //@version=5
  4.  
  5.  
  6. indicator('Fan Projections [theEccentricTrader]', overlay = true, max_bars_back = 5000, max_lines_count = 500)
  7.  
  8.  
  9. //////////// anchor points ////////////
  10.  
  11.  
  12. selectAnchor = input.string(title = 'Anchor Point Type', defval = 'Swing High', options = ['Swing High', 'Swing Low', 'Swing High (HTF)', 'Swing Low (HTF)',
  13. 'Highest High', 'Lowest Low', 'Intraday Highest High', 'Intraday Lowest Low'], group = 'Anchor Points')
  14. shslOccurrence = input(title = 'Swing High/Low Occurrence (Current Timeframe)', defval = 0, group = 'Anchor Points')
  15. htf = input.timeframe(title = 'Higher Timeframe Resolution', defval = '1D', group = 'Anchor Points')
  16. lookbackHHLL = input(title = 'Lookback for Highest High/Lowest Low', defval = 100, group = 'Anchor Points')
  17.  
  18. shPrice = close[1] >= open[1] and close < open and high >= high[1] and barstate.isconfirmed ? high :
  19. close[1] >= open[1] and close < open and high <= high[1] and barstate.isconfirmed ? high[1] : na
  20. shPriceBarIndex = close[1] >= open[1] and close < open and high >= high[1] and barstate.isconfirmed ? bar_index :
  21. close[1] >= open[1] and close < open and high <= high[1] and barstate.isconfirmed ? bar_index - 1 : na
  22. slPrice = close[1] < open[1] and close >= open and low <= low[1] and barstate.isconfirmed ? low :
  23. close[1] < open[1] and close >= open and low >= low[1] and barstate.isconfirmed ? low[1] : na
  24. slPriceBarIndex = close[1] < open[1] and close >= open and low <= low[1] and barstate.isconfirmed ? bar_index :
  25. close[1] < open[1] and close >= open and low >= low[1] and barstate.isconfirmed ? bar_index - 1 : na
  26.  
  27. shPricePassThrough = close[1] >= open[1] and close < open and high >= high[1] ? high : close[1] >= open[1] and close < open and high <= high[1] ? high[1] : na
  28. slPricePassThrough = close[1] < open[1] and close >= open and low <= low[1] ? low : close[1] < open[1] and close >= open and low >= low[1] ? low[1] : na
  29. [shPriceHTF, slPriceHTF, closeHTF] = request.security(syminfo.tickerid, htf, [shPricePassThrough[1], slPricePassThrough[1], close[1]], lookahead = barmerge.lookahead_on)
  30. shOpenBarIndexHTF = ta.valuewhen(ta.change(closeHTF), bar_index, 2)
  31. shCloseBarIndexHTF = ta.valuewhen(shPriceHTF and not shPriceHTF[1], bar_index, 0)
  32. slOpenBarIndexHTF = ta.valuewhen(ta.change(closeHTF), bar_index, 2)
  33. slCloseBarIndexHTF = ta.valuewhen(slPriceHTF and not slPriceHTF[1], bar_index, 0)
  34. htfLookback = shPriceHTF ? bar_index - shOpenBarIndexHTF : slPriceHTF ? bar_index - slOpenBarIndexHTF : na
  35.  
  36. highestHigh = ta.highest(high, lookbackHHLL)
  37. highestHighBarIndex = bar_index + ta.highestbars(high, lookbackHHLL)
  38. lowestLow = ta.lowest(low, lookbackHHLL)
  39. lowestLowBarIndex = bar_index + ta.lowestbars(low, lookbackHHLL)
  40.  
  41. dailyClose = request.security(syminfo.tickerid, 'D', close[1], lookahead = barmerge.lookahead_on)
  42. dailyStartBarIndex = ta.valuewhen(ta.change(dailyClose), bar_index, 0)
  43. intradayHighestHigh = ta.highest(high, nz(bar_index - dailyStartBarIndex) + 1)
  44. intradayLowestLow = ta.lowest(low, nz(bar_index - dailyStartBarIndex) + 1)
  45. intradayHighestHighBarIndexcalc = high == intradayHighestHigh
  46. intradayHighestHighBarIndex = ta.valuewhen(intradayHighestHighBarIndexcalc, bar_index, 0)
  47. intradayLowestLowBarIndexcalc = low == intradayLowestLow
  48. intradayLowestLowBarIndex = ta.valuewhen(intradayLowestLowBarIndexcalc, bar_index, 0)
  49.  
  50. anchorPointHTF = selectAnchor == 'Swing High (HTF)' ? shPriceHTF : selectAnchor == 'Swing Low (HTF)' ? slPriceHTF : na
  51. variableAnchorBarIndexHTF = selectAnchor == 'Swing High (HTF)' ? shCloseBarIndexHTF : selectAnchor == 'Swing Low (HTF)' ? slCloseBarIndexHTF : na
  52. variableAnchorSourceHTF = selectAnchor == 'Swing High (HTF)' ? high : selectAnchor == 'Swing Low (HTF)' ? low : na
  53. variableAnchorSourcePassThroughHTF = variableAnchorSourceHTF[1]
  54.  
  55. anchorPoint = selectAnchor == 'Swing High' ? shPrice : selectAnchor == 'Swing Low' ? slPrice : selectAnchor == 'Highest High' ? highestHigh : selectAnchor == 'Lowest Low' ? lowestLow :
  56. selectAnchor == 'Intraday Highest High' ? intradayHighestHigh : selectAnchor == 'Intraday Lowest Low' ? intradayLowestLow :
  57. selectAnchor == 'Swing High (HTF)' or selectAnchor == 'Swing Low (HTF)' ? anchorPointHTF and not anchorPointHTF[1] : na
  58. variableAnchorPrice = selectAnchor == 'Swing High' ? ta.valuewhen(shPrice, shPrice, shslOccurrence) : selectAnchor == 'Swing Low' ? ta.valuewhen(slPrice, slPrice, shslOccurrence) :
  59. selectAnchor == 'Highest High' ? highestHigh : selectAnchor == 'Lowest Low' ? lowestLow : selectAnchor == 'Intraday Highest High' ? intradayHighestHigh :
  60. selectAnchor == 'Intraday Lowest Low' ? intradayLowestLow : selectAnchor == 'Swing High (HTF)' or selectAnchor == 'Swing Low (HTF)' ? anchorPointHTF : na
  61. variableAnchorBarIndex = selectAnchor == 'Swing High' ? ta.valuewhen(shPriceBarIndex, shPriceBarIndex, shslOccurrence) : selectAnchor == 'Swing Low' ? ta.valuewhen(slPriceBarIndex, slPriceBarIndex, shslOccurrence) :
  62. selectAnchor == 'Highest High' ? highestHighBarIndex : selectAnchor == 'Lowest Low' ? lowestLowBarIndex : selectAnchor == 'Intraday Highest High' ? intradayHighestHighBarIndex :
  63. selectAnchor == 'Intraday Lowest Low' ? intradayLowestLowBarIndex : selectAnchor == 'Swing High (HTF)' or selectAnchor == 'Swing Low (HTF)' ? variableAnchorBarIndexHTF : na
  64.  
  65. symbolMintickIntegerConversion = syminfo.mintick >= 0.1 ? 1 : syminfo.mintick == 0.01 ? 10 : syminfo.mintick == 0.001 ? 100 : syminfo.mintick == 0.0001 ? 1000 :
  66. syminfo.mintick == 0.00001 ? 10000 : syminfo.mintick == 0.000001 ? 100000 : syminfo.mintick == 0.0000001 ? 1000000 : syminfo.mintick == 0.00000001 ? 10000000 : na
  67.  
  68.  
  69. //////////// lines ////////////
  70.  
  71.  
  72. angleInput = input.float(title = 'Angle Degree', defval = 1, group = 'Lines')
  73. numberLines = input.int(title = 'Number of Lines', defval = 2, minval = 1, maxval = 500, group = 'Lines')
  74.  
  75. lineColour = input(title = 'Line Colour', defval = color.blue, group = 'Line Coloring')
  76.  
  77. selectExtend = input.string(title = 'Extend Line Type', defval = 'Right', options = ['None', 'Right', 'Left', 'Both'], group = "Line Extension")
  78. extendLines = selectExtend == 'None' ? extend.none : selectExtend == 'Right' ? extend.right : selectExtend == 'Left' ? extend.left : selectExtend == 'Both' ? extend.both : na
  79.  
  80. angle = angleInput / symbolMintickIntegerConversion
  81.  
  82. if anchorPoint
  83. for y = 1 to numberLines by 1
  84. for i = 2 to htfLookback by 1
  85. highLowPassThroughHTF = selectAnchor == 'Swing High (HTF)' ? variableAnchorSourceHTF[i] > variableAnchorSourcePassThroughHTF : variableAnchorSourceHTF[i] < variableAnchorSourcePassThroughHTF
  86. if highLowPassThroughHTF
  87. variableAnchorSourcePassThroughHTF := variableAnchorSourceHTF[i]
  88. htfLookback := i
  89. line1 = line.new(not(selectAnchor == 'Swing High (HTF)' or selectAnchor == 'Swing Low (HTF)') ? variableAnchorBarIndex : variableAnchorBarIndex - htfLookback, variableAnchorPrice,
  90. bar_index + 100, variableAnchorPrice + math.todegrees((y - 1) * angle), extend = extendLines, color = lineColour)
  91. var myArray = array.new_line()
  92. array.push(myArray, line1)
  93.  
  94. if array.size(myArray) > numberLines
  95. firstLine = array.remove(myArray, 0)
  96. line.delete(firstLine)
  97.  
  98.  
Advertisement
Add Comment
Please, Sign In to add comment