Maurizio-Ciullo

Study Swing-Trend ETH/PERP FTX 4H LONG E SHORT

Jan 13th, 2022 (edited)
172
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.  
  3.  
  4. //Il trading system completo Study- Swing-Trend (Strategia Trend Following Con Swing Di Posizione) - parte 2
  5. // (Exchange= FTX) (Sottostante ETH-PERP) (Timeframe= 4H) (Direzione= LONG E SHORT) (Swing Posizione= SI) (Esclusione Giorni=Sabato) (Esclusione Mesi=Ottobre)
  6. // (Take Profit Long/Short= Market Close Sopra/Sotto Medie) (Stop Loss Limit= -2,5% Tradingview-Hub) (Stop Loss Emergenza Long/Short = Market Close Sopra/Sotto Medie)
  7. // Nello Study non c'è lo stop loss limit perchè è impostato a -2.5% su tradingview-hub
  8. //@version=4
  9.  
  10. study(title="Study Swing-Trend ETH/PERP FTX 4H LONG E SHORT", overlay=false)
  11.  
  12. input_ema_long_apertura = input(title="Media Long Apertura", type=input.integer, defval=45, minval=0, maxval=500, group="Medie")
  13. input_ema_long_chiusura = input(title="Media Long Chiusura", type=input.integer, defval=35, minval=0, maxval=500, group="Medie")
  14. input_ema_short_apertura = input(title="Media Short Apertura", type=input.integer, defval=40, minval=0, maxval=500, group="Medie")
  15. input_ema_short_chiusura = input(title="Media Short Chiusura", type=input.integer, defval=30, minval=0, maxval=500, group="Medie")
  16. perc_apertura_minima_long = input(title="perc_apertura_minima_long", type=input.float, defval=0, step=0.1, group="Filtri Posizione")
  17. perc_apertura_massima_long = input(title="perc_apertura_massima_long", type=input.float, defval=2, step=0.1, group="Filtri Posizione ")
  18. perc_chiusura_minima_long = input(title="perc_chiusura_minima_long", type=input.float,defval=1.5, step=0.1, group="Filtri Posizione")
  19. perc_apertura_minima_short = input(title="perc_apertura_minima_short", type=input.float, defval=0.75, step=0.01, group="Filtri Posizione")
  20. perc_apertura_massima_short = input(title="perc_apertura_massima_short", type=input.float, defval=2, step=0.1, group="Filtri Posizione")
  21. perc_chiusura_minima_short = input(title="perc_chiusura_minima_short", type=input.float, defval=1, step=0.1, group="Filtri Posizione")
  22. onlyLong = input(title="Solo long trade", type=input.bool, defval=false, inline="1", group="Direzione")
  23. onlyShort = input(title="Solo short trade", type=input.bool, defval=false, inline="1", group="Direzione")
  24. input_stop_loss = input(title="stop_loss_long", type=input.float, defval=2.5, minval=0, maxval=100, step=0.1, group="Stop")
  25. input_risk = input(title="Percentuale rischio", type=input.float, defval=27.5, minval=0, maxval=100, step = 0.01, group="Stop")
  26.  
  27.  
  28.  
  29.  
  30.  
  31. ema_long_apertura = ema(close, input_ema_long_apertura)
  32. ema_long_chiusura = ema(close, input_ema_long_chiusura)
  33. ema_short_apertura = ema(close,input_ema_short_apertura)
  34. ema_short_chiusura = ema(close,input_ema_short_chiusura)
  35.  
  36. //Calcolo filtri e stop loss
  37.  
  38. apertura_minima_long = (ema_long_apertura / 100) * perc_apertura_minima_long
  39. apertura_massima_long = (ema_long_apertura / 100) * perc_apertura_massima_long
  40. chiusura_minima_long = (ema_long_chiusura / 100) * perc_chiusura_minima_long
  41. apertura_minima_short = (ema_short_apertura / 100) * perc_apertura_minima_short
  42. apertura_massima_short = (ema_short_apertura / 100) * perc_apertura_massima_short
  43. chiusura_minima_short = (ema_short_chiusura / 100) * perc_chiusura_minima_short
  44.  
  45.  
  46.  
  47. //Entry/Exit Conditions
  48.  
  49.  
  50. //Condizione Entry Long: Chiusura candela sopra media lenta con differenziale medie e media veloce maggiore media ExitLong
  51. condEntryLong = close > (ema_long_apertura + apertura_minima_long) and close < (ema_long_apertura + apertura_massima_long) and close > open and not onlyShort and dayofweek != 7 and month !=10
  52. //Condizione Exit Long: Crossunder di due medie
  53. condExitLong = close < (ema_long_chiusura - chiusura_minima_long)
  54.  
  55. // Condizione Entry Short: Crossunder di due medie con il prezzo di chiusura che è comunque sotto una terza media con differenziale delle medie
  56. condEntryShort = close < (ema_short_apertura - apertura_minima_short) and close > (ema_short_apertura - apertura_massima_short) and close < open and not onlyLong and dayofweek != 7 and month !=10
  57. // Condizione Exit Short: Crossover di medie con il prezzo di chiusura che è comunque sopra una terza media
  58. condExitShort = close > (ema_short_chiusura + chiusura_minima_short)
  59.  
  60.  
  61. //definizione variabili posizioni aperte
  62.  
  63. IsLongOpen = false
  64. IsLongOpen := condEntryLong[1] ? true : condExitLong[1] ? false : condEntryShort[1] ? false : IsLongOpen[1]
  65.  
  66. IsShortOpen = false
  67. IsShortOpen := condEntryShort[1] ? true : condExitShort[1] ? false : condEntryLong[1] ? false : IsShortOpen[1]
  68.  
  69. IsFlat = true
  70. IsFlat := not IsLongOpen and not IsShortOpen
  71.  
  72. //conversione bool -> float, per debug
  73.  
  74. IsLongOpenFloat = if IsLongOpen == true
  75.     1
  76. else
  77.     0
  78.  
  79. IsShortOpenFloat = if IsShortOpen == true
  80.     1
  81. else
  82.     0
  83.  
  84. IsFlatFloat = if IsFlat == true
  85.     1
  86. else
  87.     0
  88.  
  89. //plot posizioni aperte, per debug
  90.  
  91. //plot (IsLongOpenFloat)
  92. //plot (IsShortOpenFloat,color=color.yellow)
  93. //plot (IsFlatFloat,color=color.red)
  94.  
  95. //variabili apertura e chiusura posizione
  96.  
  97. OpenLong = condEntryLong //and not IsLongOpen
  98. CloseLong = condExitLong and IsLongOpen and not condEntryShort
  99.  
  100. OpenShort = condEntryShort //and not IsShortOpen
  101. CloseShort = condExitShort and IsShortOpen and not condEntryLong
  102.  
  103. //conversione bool -> float, per debug
  104.  
  105. OpenShortFloat = if OpenShort == true
  106.     1
  107. else
  108.     0
  109.  
  110. CloseShortFloat = if CloseShort == true
  111.     1
  112. else
  113.     0
  114.  
  115. OpenLongFloat = if OpenLong == true
  116.     1
  117. else
  118.     0
  119.  
  120. CloseLongFloat = if CloseLong == true
  121.     1
  122. else
  123.     0
  124.  
  125. //plot aperture ordini, per debug
  126.  
  127. plot (OpenShortFloat,color=color.red)
  128. plot (CloseShortFloat,color=color.yellow)
  129. plot (OpenLongFloat,color=color.blue)
  130. plot (CloseLongFloat,color=color.white)
  131.  
  132. //alert
  133.  
  134.  
  135. // Plot entry ed exit degli allert
  136. //plotshape(series=OpenLong, text="entry_long", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
  137. //plotshape(series=CloseLong, text="close_long", style=shape.triangleup, location=location.belowbar, color=color.olive, size=size.small)
  138. //plotshape(series=OpenShort, text="entry_short", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)
  139. //plotshape(series=CloseShort, text="close_short", style=shape.triangledown, location=location.abovebar, color=color.purple, size=size.small)
  140.  
  141. alertcondition(OpenLong,title="Open Long")
  142. alertcondition(CloseLong,title="Close Long")
  143. alertcondition(OpenShort,title="Open Short")
  144. alertcondition(CloseShort,title="Close Short")
Add Comment
Please, Sign In to add comment