Advertisement
Maurizio-Ciullo

Indicatore Trading Bias Analyzer Chart Ver5

Nov 19th, 2022 (edited)
705
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Script per analizzare i bias orari in termini di PnL
  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 chart", overlay=false)
  7.  
  8. fattoreArrotondamento = input.int(1, "Fattore di arrotondamento",options = [1,10,100,1000,10000,100000, 1000000, 10000000])
  9.  
  10. offset = input.int(1, "Distanza barre", 1, 9999, 1)
  11. spessoreBarre = input.int(20, "Spessore Barre", 1, 9999, 1)
  12.  
  13. coloreBarreBullish = input.color(color.rgb(47, 159, 68), "Colore barre bullish")
  14. coloreBarreBearish = input.color(color.rgb(227, 65, 65), "Colore barre bearish")
  15. coloreEtichetteSfondo = input.color(color.rgb(19, 50, 70), "Colore sfondo etichetta")
  16. coloreEtichetteTesto = input.color(color.rgb(255, 255, 255), "Colore testo etichetta")
  17.  
  18. dimensioneTesto = input.string("tiny", "Dimensione Carattere", options=["tiny", "small", "normal", "large", "huge"])
  19.  
  20. var orari = array.new_float(24, 0)
  21. var countPerHour = array.new_float(24, 0)
  22. var totalLongBarWinPerHour = array.new_float(24, 0)
  23. var minVal = 0.0
  24.  
  25. disegnaBarra(offset, volMedio, etichetta, minVal) =>
  26.     line.new(last_bar_index-offset, 0, last_bar_index - offset, volMedio, color=volMedio > 0 ? coloreBarreBullish : coloreBarreBearish, width=spessoreBarre)
  27.     label.new(x=last_bar_index-offset, y=minVal, color=coloreEtichetteSfondo, textcolor=coloreEtichetteTesto, style=label.style_label_up, size=dimensioneTesto, text=etichetta)
  28.  
  29. calcolaAmpiezzaBarra(ora) =>
  30.     ampiezzaBarra = close-open
  31.     array.set(orari, ora, array.get(orari, ora) + ampiezzaBarra)
  32.     array.set(totalLongBarWinPerHour, ora, ampiezzaBarra > 0 ? (array.get(totalLongBarWinPerHour, ora) + 1) : array.get(totalLongBarWinPerHour, ora))
  33.     array.set(countPerHour, ora, array.get(countPerHour, ora) + 1)
  34.  
  35. calcolaAmpiezzaBarra(hour(time))
  36.  
  37. if barstate.islastconfirmedhistory
  38.    
  39.     x = 24
  40.     minVal := array.min(orari) / array.avg(countPerHour)
  41.     listaBarre = array.size(line.all)
  42.     if listaBarre > x
  43.         for i = 0 to listaBarre - 1
  44.             line.delete(array.get(line.all, i))
  45.  
  46.     for i=0 to array.size(orari)-1
  47.         avgPnlHour = math.round(array.get(orari, i) / array.get(countPerHour, i), int(math.log10(fattoreArrotondamento/syminfo.mintick)))
  48.         valPercSuccessLong = (array.get(totalLongBarWinPerHour, i)/array.get(countPerHour, i))*100
  49.         valPercSuccessShort = ((array.get(countPerHour, i) - array.get(totalLongBarWinPerHour, i))/array.get(countPerHour, i))*100
  50.         disegnaBarra(offset * x, avgPnlHour, str.tostring(i) + "\nPnL: " + str.tostring(avgPnlHour)+ "\nProb: " + str.tostring(avgPnlHour > 0 ? valPercSuccessLong : valPercSuccessShort , format.percent), minVal)
  51.  
  52.         x := x-1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement