Advertisement
Maurizio-Ciullo

INVERSIONE DONCHIAN CHANNEL MATTIA THE QUANT CRYPTO

Nov 28th, 2021
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © Gaspipe94
  3.  
  4. //@version=4
  5. //
  6. //      STRATEGIA D'INVERSIONE DONCHIAN CHANNEL
  7. //      condizione long => low oltrepassa banda inferiore di Donchian di un determinato timeframe, il prezzo (prima di aprire una nuova operazione) deve prima avere toccato la linea di base.
  8. //      exit long => stop loss e target modificabili
  9. //      eventuale condizione short => high oltrepassa banda superiore di Donchian di un determinato timeframe, il prezzo (prima di aprire una nuova operazione) deve prima avere toccato la linea di base.
  10. //      exit short => stop loss e target modificabili (per ora gli stessi dei long)
  11. //
  12. // BTCUSDT 15min    BTCUSDTPERP 15 min
  13. //  leght  72         lenght 76
  14. //  stop 100000       stop 100000
  15. //  tp  280000        tp 230000
  16. //   1h               45 min
  17.  
  18. strategy(title="Donchian Reversal",
  19.      shorttitle="DR",
  20.      overlay=true,
  21.      initial_capital=100,
  22.      pyramiding=0,
  23.      default_qty_type=strategy.percent_of_equity,
  24.      default_qty_value=100,
  25.      commission_type=strategy.commission.percent,
  26.      commission_value=0.025,
  27.      slippage=3)
  28.  
  29. lenght= input(72, "Periodo")
  30. stop= input(10000, "Tick di Stop", step= 100)
  31. target= input(21000, "Tick di Target", step= 100)
  32. tf= input(defval= "45", title="Timeframe", type= input.resolution)
  33. size= input(0.1, "Size")
  34. solo_long= input(true, "Solo Long")
  35.  
  36.  
  37. upper= highest(lenght)
  38. lower= lowest(lenght)
  39. base= avg(upper, lower)
  40.  
  41. uppertf= security(syminfo.tickerid, tf, upper)
  42. lowertf= security(syminfo.tickerid, tf, lower)
  43. basetf= security(syminfo.tickerid, tf, base)
  44.  
  45. plot(uppertf, "Upper")
  46. plot(lowertf, "Lower")
  47. plot(basetf, "Base", color= color.orange)
  48.  
  49. var retBase = 0
  50.  
  51. if strategy.opentrades == 0 and retBase == 0 and high > uppertf and not solo_long
  52.    
  53.     strategy.entry("Short", false, qty= size, comment= "")
  54.     strategy.exit("Chiuso Short", "Short", profit= target, loss= stop, comment= "")
  55.     retBase := 1
  56.    
  57. if strategy.opentrades == 0 and retBase == 0 and low < lowertf
  58.    
  59.     strategy.entry("Long", true, qty= size, comment= "")
  60.     strategy.exit("Chiuso Long", "Long", profit= target, loss= stop, comment= "")
  61.     retBase := 2
  62.    
  63. if retBase != 0 //ritorna a 0 la variabile quando il prezzo torna sulla base
  64.    
  65.     if retBase == 1
  66.    
  67.         if low < basetf
  68.        
  69.             retBase := 0
  70.            
  71.     else if high > basetf
  72.    
  73.         retBase := 0
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement