Advertisement
Maurizio-Ciullo

Indicatore Trading Bias Analyzer Table Ver5

Nov 19th, 2022 (edited)
907
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Script per analizzare i bias
  2. // Video Spiegazione in cartella: Python per Trading - Strategie, Backtest e ottimizzazioni [Webinar] Overview del processo: i 7 step dall'idea alla live
  3.  
  4. // © Quant Trader Academy
  5. //@version=5
  6. indicator("QTA Trading Bias Analyzer table", overlay=false)
  7.  
  8. fattoreArrotondamento = input.int(1, "Fattore di arrotondamento",options = [1,10,100,1000,10000,100000, 1000000, 10000000])
  9. posizione = input.string("middle_center", "posizione tabella", ["bottom_left", "bottom_center", "bottom_right", "middle_left", "middle_center", "middle_right", "top_left", "top_center", "top_right"])
  10. coloreBarreBullish = input.color(color.rgb(47, 159, 68), "Colore celle bullish")
  11. coloreBarreBearish = input.color(color.rgb(227, 65, 65), "Colore celle bearish")
  12. coloreSfondoTabella = input.color(color.rgb(53, 61, 68), "Colore sfondo tabella")
  13. coloreEtichetteSfondo = input.color(color.rgb(19, 50, 70), "Colore sfondo etichetta")
  14. coloreEtichetteTesto = input.color(color.rgb(255, 255, 255), "Colore testo etichetta")
  15. dimensioneTesto = input.string("normal", "Dimensione Carattere", options=["tiny", "small", "normal", "large", "huge"])
  16.  
  17. var tabellaInfo = table.new(position = posizione, columns = 26, rows = 3, bgcolor = coloreSfondoTabella)
  18. table.cell(tabellaInfo, 0, 0, "ore", text_color = coloreEtichetteTesto, text_size = dimensioneTesto, text_halign= text.align_center)
  19. table.cell(tabellaInfo, 0, 1, "PnL", text_color = coloreEtichetteTesto, text_size = dimensioneTesto, text_halign= text.align_center)
  20. table.cell(tabellaInfo, 0, 2, "Successo", text_color = coloreEtichetteTesto, text_size = dimensioneTesto, text_halign= text.align_center)
  21.  
  22. var orari = array.new_float(24, 0)
  23. var countPerHour = array.new_float(24, 0)
  24. var totalLongBarWinPerHour = array.new_float(24, 0)
  25.  
  26. calcolaAmpiezzaBarra(ora) =>
  27.     ampiezzaBarra = close-open
  28.     array.set(orari, ora, array.get(orari, ora) + ampiezzaBarra)
  29.     array.set(totalLongBarWinPerHour, ora, ampiezzaBarra > 0 ? (array.get(totalLongBarWinPerHour, ora) + 1) : array.get(totalLongBarWinPerHour, ora))
  30.     array.set(countPerHour, ora, array.get(countPerHour, ora) + 1)
  31.  
  32. calcolaAmpiezzaBarra(hour(time))
  33.  
  34. if barstate.islast
  35.    
  36.     for i=0 to array.size(orari)-1
  37.         avgPnlHour = math.round(array.get(orari, i) / array.get(countPerHour, i), int(math.log10(fattoreArrotondamento/syminfo.mintick)))
  38.         valPercSuccessLong = (array.get(totalLongBarWinPerHour, i)/array.get(countPerHour, i))*100
  39.         valPercSuccessShort = ((array.get(countPerHour, i) - array.get(totalLongBarWinPerHour, i))/array.get(countPerHour, i))*100
  40.  
  41.         table.cell(tabellaInfo, i+1, 0, str.tostring(i), text_color = coloreEtichetteTesto, text_size = dimensioneTesto, text_halign=text.align_center)
  42.         table.cell(tabellaInfo, i+1, 1, str.tostring(avgPnlHour), text_color = coloreEtichetteTesto, bgcolor= avgPnlHour> 0 ? coloreBarreBullish: coloreBarreBearish , text_size = dimensioneTesto, text_halign=text.align_center)
  43.         table.cell(tabellaInfo, i+1, 2, str.tostring(avgPnlHour > 0 ? valPercSuccessLong : valPercSuccessShort, format.percent), text_color = coloreEtichetteTesto, bgcolor = (avgPnlHour > 0 and valPercSuccessLong > 50) or (avgPnlHour <= 0 and valPercSuccessShort > 50) ? coloreBarreBullish : coloreBarreBearish, text_size = dimensioneTesto, text_halign=text.align_center)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement