Advertisement
amphibiantrading

combined

Nov 29th, 2023
370
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.94 KB | None | 0 0
  1. //@version=5
  2. indicator("My script",overlay=true)
  3.  
  4. atrPeriod = input(5, "ATR Length")
  5. factor = input.float(2.6, "Factor", step = 0.01)
  6.  
  7. [supertrend, direction] = ta.supertrend(factor, atrPeriod)
  8.  
  9. bodyMiddle = plot((open + close) / 2, display=display.none)
  10. upTrend = plot(direction < 0 ? supertrend : na, "Up Trend", color = color.green, style=plot.style_linebr)
  11. downTrend = plot(direction < 0? na : supertrend, "Down Trend", color = color.red, style=plot.style_linebr)
  12.  
  13. fill(bodyMiddle, upTrend, color.new(color.green, 90), fillgaps=false)
  14. fill(bodyMiddle, downTrend, color.new(color.red, 90), fillgaps=false)
  15.  
  16. sma10=ta.sma(close,10)
  17. sma20=ta.sma(close,20)
  18. sma50=ta.sma(close,50)
  19. sma05=ta.sma(close,5)
  20.  
  21. bbgFill = input.bool(true, 'Highlight Backgrond', inline = '1')
  22. bgCol = input.color(color.new(color.yellow,85), ' ', inline = '1')
  23. showShape = input.bool(true, 'Show Symbol', inline = '2')
  24. shapeLocation = input.string('Above Bar', ' ', options = ['Above Bar', 'Below Bar', 'Bottom', 'Top'], inline = '2')
  25.  
  26. //switches
  27. loc = switch shapeLocation
  28. 'Above Bar' => location.abovebar
  29. 'Below Bar' => location.belowbar
  30. 'Bottom' => location.bottom
  31. 'Top' => location.top
  32.  
  33. ///condition
  34. ext = high > sma50*1.5 and high > sma20*1.3 and high > sma10*1.14 and high > sma05*1.25 or high > sma50*1.5 and high > sma20*1.3 and high > sma10*1.14 and close < open
  35.  
  36. //plots
  37. plotshape(ext, 'Extended', loc == location.abovebar or loc == location.top ? shape.triangledown : shape.triangleup,loc, color.red, display = display.pane)
  38. bgcolor(bbgFill and ext ? bgCol : na)
  39.  
  40. //plotshape(ext, 'Extended', shape.labeldown, location.abovebar, color.rgb(82, 102, 255))
  41. //Table Options
  42.  
  43. string GRP1 = "════════ Modes ═════════"
  44. toggleDarkColors = input(title="Dark Mode", defval=false, group = GRP1, tooltip = 'Select this if you use a dark color theme')
  45. toggleMiniMode = input(title="Mini Mode", defval=false, group = GRP1, tooltip = 'Select this to get the Mini mode where the values are replaced by traffic lights for a quick visual')
  46. datasize = input.int(4, 'Long Mode ?', minval = 4, inline='line 3', group=GRP1, tooltip = 'Input the number of previous quarters to be displayed in the table') +5
  47.  
  48. string GRP2 = "════════ Table Options ═════════"
  49. string tablesize = input.string("small", "Size", inline = "21", group = GRP2, options = ["tiny", "small", "normal", "large", "huge", "auto"])
  50. string tableposY = input.string("bottom", "↕", inline = "21", group = GRP2, options = ["top", "middle", "bottom"])
  51. string tableposX = input.string("right", "↔", inline = "21", group = GRP2, options = ["left", "center", "right"])
  52.  
  53. string GRP3 = "════════ Inputs ═════════"
  54. per = input.string('FQ', 'Period', options=['FQ', 'FY'], inline='line 3', group=GRP3, tooltip = 'Option to change the data from Quarterly (FQ) to Yearly (FY)')
  55. topleft = input.string('FF','Top-left cell displays', group = GRP3, options = ['FF', 'Mcap'], tooltip = 'Option to display either the Free Float (FF) or the Marketcap (Mcap) of the stock')
  56.  
  57. FrameCol = toggleDarkColors ? color.new(#999999, 50) : color.rgb(241, 241, 241)
  58. BorderCol = toggleDarkColors ? color.new(#999999, 50) : color.rgb(241, 241, 241)
  59.  
  60. TextColor = toggleDarkColors ? color.new(color.white, 0): color.new(color.black, 0)
  61. BGColor = toggleDarkColors ? color.new(color.white, 100): color.new(color.black, 100)
  62. HeadColor = toggleDarkColors ? color.new(color.white, 100): color.new(color.black, 100)
  63. BodyColor = toggleDarkColors ? color.new(color.white, 100): color.new(color.black, 100)
  64. UpColor = toggleDarkColors ? color.new(color.lime, 0) : color.new(color.rgb(31, 12, 239, 16), 0)
  65. DownColor = toggleDarkColors ? color.new(color.red, 0) : color.new(color.rgb(213, 27, 182), 10)
  66. UnchangedColor = toggleDarkColors ? color.new(color.yellow, 0) : color.new(color.orange, 30)
  67.  
  68.  
  69. // Creating ID for Financials
  70.  
  71. financial01 = 'EPS'
  72. financial02 = 'Sales'
  73.  
  74. financial01id = 'EARNINGS_PER_SHARE_DILUTED'
  75. financial02id = 'TOTAL_REVENUE'
  76.  
  77.  
  78. // Creating functions to fetch financial data from Tradingview
  79.  
  80. getFinFQ(_id, _per) =>
  81. _financials = request.financial(syminfo.tickerid, _id, _per, barmerge.gaps_on, ignore_invalid_symbol = true)
  82. if _id == financial02id
  83. _financials := math.round(_financials / 10.0, 2)
  84. _financials
  85.  
  86.  
  87. f_array(arrayId, val) =>
  88. array.unshift(arrayId, val)
  89. array.pop(arrayId)
  90.  
  91.  
  92. finID1 = financial01
  93. finID2 = financial02
  94. get_finx(finID) =>
  95. finx = switch finID
  96. financial02 => financial02id
  97. financial01 => financial01id
  98. finx
  99.  
  100.  
  101. // Reference if data is true
  102. rev = request.financial(syminfo.tickerid,'TOTAL_REVENUE',per,barmerge.gaps_on, ignore_invalid_symbol=true)
  103.  
  104.  
  105. // Calculating
  106.  
  107. finx1 = get_finx(finID1)
  108. finx2 = get_finx(finID2)
  109. finData1 = getFinFQ(finx1, per)
  110. finData2 = getFinFQ(finx2, per)
  111.  
  112. var date = array.new_int(datasize) // Date
  113. var arrayFinData1 = array.new_float(datasize) // EPS
  114. var arrayFinData2 = array.new_float(datasize) // Sales
  115.  
  116.  
  117. if rev
  118. f_array(date, time)
  119. f_array(arrayFinData1, finData1)
  120. f_array(arrayFinData2, finData2)
  121.  
  122. ft(_table, _column, _row, _value) =>
  123. table.cell(table_id = _table, column = _column, row = _row, text = _value, bgcolor = HeadColor, text_color = TextColor, text_size = tablesize)
  124.  
  125. ftdate(_table, _column, _row, _value) =>
  126. _new_value = str.contains(_value, "70") ? "" : _value
  127. table.cell(table_id = _table, column = _column, row = _row, text = _new_value, bgcolor = BodyColor, text_color = TextColor, text_size = tablesize, text_halign = text.align_left )
  128.  
  129. fcell(finID, _table, _column, _row, _value, _i) =>
  130. divider = 0
  131. divider :=
  132. finID == 'EPS' ? 1 : 1000000
  133. suffix =
  134. finID == 'EPS' or finID == financial02 ? '' : ' M'
  135. strFormat =
  136. finID == 'EPS' ? '#.#' : finID == financial02 ? '#,###.#' : '#,##0'
  137. val = array.get(_value, _i)/ divider
  138. table.cell(table_id = _table, column = _column, row = _row, text = na(val) ? "" : str.tostring(val, strFormat) +suffix, text_color = TextColor, text_size = tablesize)
  139.  
  140.  
  141.  
  142. fyoy(_table, _column, _row, _value, _i, _cmpr) =>
  143. sym = ""
  144. dif = 0.0
  145. if na(_value)
  146. na
  147. else
  148. val1 = array.get(_value, _i)
  149. val2 = array.get(_value, _i+_cmpr)
  150. val1 := val1 == 0 ? 1 : val1
  151. val2 := math.round(val2, 1) == 0 or math.round(val2, 1) == -0 ? 0.1 : val2
  152. dif := math.round(((val1-val2) / math.abs(val2)) * 100) // Change to absolute value
  153. sym := na(dif) ? "" : dif > 0 ? '+'+str.tostring(dif)+'%' : str.tostring(dif)+'%'
  154.  
  155.  
  156. table.cell( table_id = _table, column = _column, row = _row, text = na(dif) ? "●" : toggleMiniMode ? "●" : sym,text_halign = text.align_right, text_color = na(dif) ? FrameCol : dif >0 ? UpColor : dif <0 ? DownColor : dif ==0 ? UnchangedColor : FrameCol,text_size = tablesize)
  157.  
  158.  
  159. // Free Float
  160. free_float = nz(syminfo.shares_outstanding_total)
  161. ff = na(ta.vwap) ? free_float / 10000000 : free_float * ta.vwap / 10000000
  162. validated_ff = na(ff) or nz(ff) == 0 ? '' : str.tostring(math.round(ff)) + ' Cr'
  163.  
  164. //Marketcap
  165. outstanding = request.financial(syminfo.tickerid, "TOTAL_SHARES_OUTSTANDING", "FQ")
  166. mc = outstanding*close / 10000000
  167. validated_mc = na(mc) or nz(mc) == 0 ? '' : str.tostring(math.round(mc,0)) + ' Cr'
  168.  
  169. // Creating the table with final outputs
  170.  
  171. var table t = table.new(tableposY + "_" + tableposX, columns = 7, rows = datasize, bgcolor = BGColor, frame_color=FrameCol, frame_width=1,border_color=BorderCol, border_width=1)
  172.  
  173. if barstate.islast and not toggleMiniMode
  174.  
  175. ft(t,0,0, topleft == 'FF' ? validated_ff : topleft == 'Mcap' ? validated_mc : '')
  176. ft(t,1,0,finID1)
  177. ft(t,2,0, per == 'FY' ? 'YoY' : '%Chg')
  178. ft(t,3,0,finID2)
  179. ft(t,4,0, per == 'FY' ? 'YoY' : '%Chg')
  180.  
  181.  
  182. if barstate.islast
  183.  
  184. if not toggleMiniMode
  185.  
  186. for i = 0 to datasize-5
  187. // Column #1 Date
  188. ftdate(t, 0, i+1, str.format('{0, date, MMM-yy}', array.get(date, i)))
  189. // Column #2 EPS Data
  190. fcell(finID=finID1, _table=t, _column=1, _row=i+1, _value=arrayFinData1, _i=i)
  191. // Column #3 EPS YoY
  192. fyoy(t, 2, i+1, arrayFinData1, i, per == 'FY' ? 1 : 4)
  193. // Column #4 Sales Data
  194. fcell(finID=finID2, _table=t, _column=3, _row=i+1, _value=arrayFinData2, _i=i)
  195. // Column #5 Sales YoY
  196. fyoy(t, 4, i+1, arrayFinData2, i, per == 'FY' ? 1 : 4)
  197. else if toggleMiniMode
  198.  
  199. for i = 0 to datasize-5
  200. // Column #1 Date
  201. ftdate(t, 0, i+1, str.format('{0, date, MMM-yy}', array.get(date, i)))
  202. // Column #2 EPS YoY
  203. fyoy(t, 2, i+1, arrayFinData1, i, per == 'FY' ? 1 : 4)
  204. // Column #3 Sales YoY
  205. fyoy(t, 4, i+1, arrayFinData2, i, per == 'FY' ? 1 : 4)
  206.  
Advertisement
Comments
  • # text 0.12 KB | 0 0
    1. download all types of premium tradingview indicators codes available on telegram - https://t.me/tradingview_premium_indicator
Add Comment
Please, Sign In to add comment
Advertisement