Advertisement
Maurizio-Ciullo

Study Break-in-New Ver-4 ETH/PERP FTX 4H LONG E SHORT

Jan 13th, 2022 (edited)
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Il trading system completo - Study Break-in-New Ver-4 (Strategia Breakout) - parte 2
  2. // (Exchange= FTX) (Sottostante ETH-PERP) (Timeframe= 4H) (Direzione= LONG E SHORT) (Swing Posizione= SI) (Esclusione Ore=NO) (Esclusione Giorni=LUNEDI') (Esclusione Mesi=SETTEMBRE)
  3. // (Take Profit Long/Short Market = Non Definito) (Take Profit Limit Long/Short= +20% Tradingview-Hub) (Stop Loss Limit Long/Short= -11% Tradingview-Hub) (Stop Emergenza= No)
  4. //@version=4
  5. study(title="Study Break-in-New Ver-4 ETH/PERP FTX 4H LONG E SHORT", overlay=false)
  6.  
  7.  
  8. //input SL e TP Long e Short
  9. input_stop_loss_long = input(title="stop_loss_long", type=input.float, defval=11, minval=0, maxval=100, step=0.1, group="Stop")
  10. input_take_profit_long = input(title="take_profit_long", type=input.float, defval=20, minval=0, maxval=100, step=0.1, group="Stop")
  11. input_stop_loss_short = input(title="stop_loss_short", type=input.float, defval=11, minval=0, maxval=100, step=0.1, group="Stop")
  12. input_take_profit_short = input(title="take_profit_short", type=input.float, defval=20, minval=0, maxval=100, step=0.1, group="Stop")
  13. input_lunghezza_ema = input(title="lunghezza ema", type=input.integer, defval=125, minval=0, maxval=300, step=5)
  14.  
  15. riskPerTrade = input(title="Risk Per Trade %", type=input.float, minval=0.1, maxval=100, defval=27.5, step=0.5)
  16.  
  17. in_atr_periodo = input(title="Periodicitร  ATR", type=input.integer, minval=5, maxval=500, defval=10, step=1)
  18. in_atr_Mult = input(title="atr_Mult", type=input.float, minval=1, maxval=5, defval=1, step=0.5)
  19. //in_tpPips = input(title="TP", type=input.integer, defval=40)
  20. //in_slPips = input(title="SL", type=input.integer, defval=30)
  21.  
  22. //Input solo long o solo short
  23. in_solo_long = input(title="Solo long", type=input.bool, defval=false, inline="1", group="Direzione")
  24. in_solo_short = input(title="Solo short", type=input.bool, defval=false, inline="1", group="Direzione")
  25.  
  26. // Calcolo del range del backtest
  27.  
  28. startDate = input(title="Start Date", type=input.integer,
  29.      defval=11, minval=1, maxval=31, group="Periodo")
  30. startMonth = input(title="Start Month", type=input.integer,
  31.      defval=02, minval=1, maxval=12, group="Periodo")
  32. startYear = input(title="Start Year", type=input.integer,
  33.      defval=2018, minval=1800, maxval=2100, group="Periodo")
  34.  
  35. endDate = input(title="End Date", type=input.integer,
  36.      defval=01, minval=1, maxval=31, group="Periodo")
  37. endMonth = input(title="End Month", type=input.integer,
  38.      defval=01, minval=1, maxval=12, group="Periodo")
  39. endYear = input(title="End Year", type=input.integer,
  40.      defval=2121, minval=1800, maxval=2100, group="Periodo")
  41.  
  42.  
  43. inDateRange = (time >= timestamp(syminfo.timezone, startYear,
  44.          startMonth, startDate, 0, 0)) and
  45.      (time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0))
  46.  
  47. atr   = atr(in_atr_periodo)
  48. media = ema(close, input_lunghezza_ema)
  49.  
  50. hourTrading = input(title="sessione valida di trading", type=input.string, defval="0600-2300:23456")
  51.  
  52. rangeTrading = time(timeframe.period, hourTrading)
  53.  
  54.  
  55.  
  56. // giorni da 1 a 7 1 รจ domenica
  57.  
  58.  
  59. //Condizione Long
  60. condEntryLong = (abs(open-close)>(atr*in_atr_Mult)) and close > open  and close > media and month!=9 and dayofweek !=2 and not in_solo_short and inDateRange
  61.  
  62. //Condizione Short
  63. condEntryShort = (abs(open-close)>(atr*in_atr_Mult)) and close < open  and close < media and month!=9 and dayofweek !=2 and not in_solo_long and inDateRange
  64.  
  65.  
  66.  
  67. //definizione variabili posizioni aperte
  68.  
  69. IsLongOpen = false
  70. IsLongOpen := condEntryLong[1] ? true :  false
  71.  
  72. IsShortOpen = false
  73. IsShortOpen := condEntryShort[1] ? true : false
  74.  
  75. IsFlat = true
  76. IsFlat := not IsLongOpen and not IsShortOpen
  77.  
  78. //conversione bool -> float, per debug
  79.  
  80. IsLongOpenFloat = if IsLongOpen == true
  81.     1
  82. else
  83.     0
  84.  
  85. IsShortOpenFloat = if IsShortOpen == true
  86.     1
  87. else
  88.     0
  89.  
  90. IsFlatFloat = if IsFlat == true
  91.     1
  92. else
  93.     0
  94.  
  95. //plot posizioni aperte, per debug
  96.  
  97. //plot (IsLongOpenFloat)
  98. //plot (IsShortOpenFloat,color=color.yellow)
  99. //plot (IsFlatFloat,color=color.red)
  100.  
  101. //variabili apertura e chiusura posizione
  102.  
  103. OpenLong = condEntryLong and not IsLongOpen
  104. //CloseLong = condExitLong and IsLongOpen and not condEntryShort
  105.  
  106. OpenShort = condEntryShort and not IsShortOpen
  107. //CloseShort = condExitShort and IsShortOpen and not condEntryLong
  108.  
  109. //conversione bool -> float, per debug
  110.  
  111. OpenShortFloat = if OpenShort == true
  112.     1
  113. else
  114.     0
  115.  
  116. //CloseShortFloat = if CloseShort == true
  117.   //  1
  118. //else
  119.  //   0
  120.  
  121. OpenLongFloat = if OpenLong == true
  122.     1
  123. else
  124.     0
  125.  
  126. //CloseLongFloat = if CloseLong == true
  127.  //   1
  128. //else
  129.   //  0
  130.  
  131. //plot aperture ordini, per debug
  132.  
  133. plot (OpenShortFloat,color=color.red)
  134. //plot (CloseShortFloat,color=color.yellow)
  135. plot (OpenLongFloat,color=color.blue)
  136. //plot (CloseLongFloat,color=color.white)
  137.  
  138. //alert
  139.  
  140.  
  141. // Plot entry ed exit degli allert
  142. //plotshape(series=OpenLong, text="entry_long", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
  143. //plotshape(series=CloseLong, text="close_long", style=shape.triangleup, location=location.belowbar, color=color.olive, size=size.small)
  144. //plotshape(series=OpenShort, text="entry_short", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)
  145. //plotshape(series=CloseShort, text="close_short", style=shape.triangledown, location=location.abovebar, color=color.purple, size=size.small)
  146.  
  147. alertcondition(OpenLong,title="Open Long")
  148. //alertcondition(CloseLong,title="Close Long")
  149. alertcondition(OpenShort,title="Open Short")
  150. //alertcondition(CloseShort,title="Close Short")
  151.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement