Advertisement
Maurizio-Ciullo

Bot Utente QTA JohnnyTYX Diverg Prezz E RSI BTC-USDT 4H

Dec 14th, 2023
794
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.                                                               // Strategia Utente Quant Trader Academy BTC/USDT 4H //
  2.                                   // Bot Utente QTA JohnnyTYX Diverg Prezz E RSI BTC-USDT 4H //
  3.                                   // Trovi strategia e report sul formum qta o in cartella //
  4.  
  5. // Buonasera a tutti, sto smanettando un po su pinescript, l’idea della strategia é agire sia su divergenze ribassiste sia rialziste del prezzo in confronto all’indicatore rsi.
  6. // La strategia si comporta bene su stocks e crypto in particolare su BTC/USD cambiando alcuni parametri, fatemi sapere cosa ne pensate
  7. // e volevo sapere se é possibile che abbia overfittato i parametri, grazie
  8. // mille in anticipo
  9.  
  10.  
  11. //@version=4
  12. strategy("RSI Divergence Strategy Bitcoin H4", overlay=true)
  13.  
  14. // Input rsi
  15. rsiLength = input(7, title="RSI Period", minval=1)
  16. rsiSource = input(close, title="RSI Source")
  17. priceHigh = highest(high, rsiLength)
  18. priceLow = lowest(low, rsiLength)
  19.  
  20. // Input Generali
  21. in_valuta = input("EUR", title="Valuta", options=['EUR', 'USD', 'CAD'])
  22. riskPerTrade = input(1.0, title="Risk Per Trade %", minval=0.1, maxval=100)
  23. in_atr_periodo = input(6, title="Periodicità ATR", minval=5, maxval=500)
  24. in_atr_min = input(0.0015, title="Min ATR", minval=0.0001, maxval=500)
  25. in_tp_short = input(1.8, title="TP short")
  26. in_tp_long = input(2.5, title="TP Long")
  27. in_solo_long = input(false, title="Solo Long")
  28. emaPeriod = input(26, title="EMA period", minval=1)
  29.  
  30. // Input per la percentuale dell'impulso
  31. percentualeImpulso = input(2, title="Percentuale Impulso", minval=1, maxval=100,step = 0.1)
  32.  
  33. //Input sessione Trading
  34. hourTrading = input(title="Sessione valida di trading", type=input.string, defval="0000-0000:1234567")
  35. rangeTrading = time(timeframe.period, hourTrading)
  36. bgcolor(rangeTrading ? color.green : color.red)
  37.  
  38. // Calcolo degli indicatori
  39. rsi = rsi(rsiSource, rsiLength)
  40. rsiHigh = highest(rsi, rsiLength)
  41. rsiLow = lowest(rsi, rsiLength)
  42. atr = atr(in_atr_periodo)
  43. ema = ema(close, emaPeriod)
  44.  
  45. // Definizione dell'impulso rialzista
  46. isBullishImpulse(candles, percentuale) =>
  47.     changePercent = (close - close[candles]) / close[candles] * 100
  48.     bullishImpulse = changePercent > percentuale  
  49. //Definizione impulso ribassista
  50. isBearishImpulse(candles, percentuale) =>
  51.     changePercent = (close - close[candles]) / close[candles] * 100
  52.     bearishImpulse = changePercent < -percentuale
  53.  
  54. firstImpulse = isBullishImpulse(1, percentualeImpulso)
  55. secondImpulse = isBullishImpulse(2, percentualeImpulso)
  56.  
  57. firstBearishImpulse = isBearishImpulse(1, percentualeImpulso)
  58. secondBearishImpulse = isBearishImpulse(2, percentualeImpulso)
  59.  
  60. // Calcolo dell'RSI per il primo e il secondo impulso rialzista
  61. rsiFirstImpulse = rsi(rsiSource, rsiLength)
  62. rsiSecondImpulse = security(syminfo.tickerid, "D", rsi(rsiSource, rsiLength))
  63.  
  64. rsiFirstBearishImpulse = rsi(rsiSource, rsiLength)
  65. rsiSecondBearishImpulse = security(syminfo.tickerid, "D", rsi(rsiSource, rsiLength))
  66.  
  67. // Confronto dell'RSI durante i due impulsi
  68. rsiBullishDivergence = (secondImpulse and rsiSecondImpulse < rsiFirstImpulse)
  69. rsiBearishDivergence = (secondBearishImpulse and rsiSecondBearishImpulse > rsiFirstBearishImpulse)
  70.  
  71. //Position size
  72. valutabaseuguale = in_valuta == syminfo.basecurrency
  73. valutaSecondariaUguale = in_valuta == syminfo.currency
  74. nessunavaluta = not valutaSecondariaUguale and not valutabaseuguale
  75. conversionecoppia = valutaSecondariaUguale ? syminfo.tickerid : in_valuta + syminfo.currency
  76. conversioneTassocambio = security(symbol=conversionecoppia, resolution="D", expression=close)
  77.  
  78. getVolumePosizione(stopLossSizePoints) =>
  79.     riskAmount = (strategy.equity * (riskPerTrade / 100)) * (valutabaseuguale or nessunavaluta ? conversioneTassocambio : 1.0)
  80.     riskPerPoint = (stopLossSizePoints * syminfo.pointvalue)
  81.     positionSize = (riskAmount / riskPerPoint) / (syminfo.mintick * 10)
  82.     round(positionSize)
  83.  
  84. // Esecuzione delle operazioni
  85. if (rsiBearishDivergence)  and not in_solo_long and rangeTrading and close < close [1]
  86.     slPrice = high + atr
  87.     slPips = ((slPrice - high) / syminfo.mintick / 10)
  88.     size = getVolumePosizione(slPips)
  89.     strategy.entry("Sell", strategy.short, qty=size)
  90.     strategy.exit("Sell", profit=slPips * in_tp_short * 10, stop=slPrice)
  91.  
  92. if rsiBullishDivergence and close > close [1] and rangeTrading and close > close [1]
  93.     slPrice = low - atr
  94.     slPips = ((low - slPrice) / syminfo.mintick / 10)
  95.     size = getVolumePosizione(slPips)
  96.     strategy.entry("Buy", strategy.long, qty=size)
  97.     strategy.exit("Buy", profit=slPips * in_tp_long * 10, stop=slPrice)
  98.  
  99. // Visualizzazione grafica
  100. plotshape(firstImpulse, color=color.green, style=shape.triangleup, location=location.belowbar, size=size.small, title="First Bullish Impulse")
  101. plotshape(secondImpulse, color=color.green, style=shape.triangleup, location=location.belowbar, size=size.small, title="Second Bullish Impulse")
  102.  
  103. plotshape(firstBearishImpulse, color=color.red, style=shape.triangledown, location=location.abovebar, size=size.small, title="First Bearish Impulse")
  104. plotshape(secondBearishImpulse, color=color.red, style=shape.triangledown, location=location.abovebar, size=size.small, title="Second Bearish Impulse")
  105.  
  106. plot(ema, title="EMA", color=color.purple)
Advertisement
Comments
  • tradingviewcodes
    162 days
    # 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