Advertisement
Maurizio-Ciullo

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

Mar 20th, 2022
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.                                                       //   ATTENZIONE !!!  //
  2.                            
  3. // Questo study a differenza della strategia reale non entra nella candela boom bar successiva dopo aver preso un takeprofit
  4. // di conseguenza per farlo funzionare bisogna cambiare il codice sull strategy.
  5. // Questo è dovuto perchè sullo strategy non si possono avere 2 segnali simultanei close e open position sulla stessa candela
  6.  
  7. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  8.  
  9. //Il trading system completo - Study Break-in-New-Trailing-Ganriele Ver-5 (Strategia Breakout) Parte 2
  10. // (Exchange= FTX) (Sottostante ETH-PERP) (Timeframe= 4H) (Direzione= LONG E SHORT) (Swing Posizione= SI) (Esclusione Ore=NO) (Esclusione Giorni=NO') (Esclusione Mesi=NO)
  11. // (Take Profit Long/Short Market = Trailing) (Take Profit Limit Long/Short= +18%) (Stop Loss Limit Long/Short= -12%) (Stop Loss Market Long/Short= NO) (Trailing Stop=SI) (Stop Emergenza= NO)
  12. // (Rischio Operazione 2% Perdita Media)
  13. // (In Sample Dal=17/08/2017 Al 17/10/2020) (Out Of Sample Dal=18/10/2020 Al 15/03/2021)
  14.  
  15.  
  16. //@version=5
  17. //2. Study
  18. indicator(title='Study Break-in-New-Trailing-Gabriele Ver-5 ETH/PERP FTX 4H LONG E SHORT', overlay=false)
  19.  
  20.  
  21. // Input
  22. input_stop_loss_long = input.float(title='stop_loss_long', defval=12, minval=0, maxval=100, step=0.1, group='Stop Loss')
  23. input_take_profit_long = input.float(title='take_profit_long', defval=18, minval=0, maxval=100, step=0.1, group='Take Profit')
  24. input_stop_loss_short = input.float(title='stop_loss_short', defval=12, minval=0, maxval=100, step=0.1, group='Stop Loss')
  25. input_take_profit_short = input.float(title='take_profit_short', defval=18, minval=0, maxval=100, step=0.1, group='Take Profit')
  26. input_trailing_stop_trigger = input.float(title='trail_trigger', defval=60, minval=0, maxval=100, step=1, group='Traling Stop')
  27. input_trailing_stop_close = input.float(title='trail_close', defval=54, minval=0, maxval=100, step=1, group='Traling Stop')
  28. input_lunghezza_ema_long = input.int(title='lunghezza_ema_long', defval=240, minval=0, maxval=300, step=5, group='Medie')
  29. input_lunghezza_ema_short = input.int(title='lunghezza_ema_short', defval=240, minval=0, maxval=300, step=5, group='Medie')
  30. in_solo_long = input.bool(title='Solo long', defval=false, inline='1', group='Direzione')
  31. in_solo_short = input.bool(title='Solo short', defval=false, inline='1', group='Direzione')
  32. riskPerTrade = input.float(title='Risk Per Trade %', minval=0.1, maxval=100, defval=27.5, step=0.5)
  33.  
  34.  
  35. // Start Hour Range Trading Non Attivo /////////////////////
  36. //hourTrading = input(title='sessione valida di trading', defval='0600-2300:23456')
  37. //hourRangeTrading = time(timeframe.period, hourTrading)
  38.  
  39.  
  40. // Start Detecting ATR Long ///////////////////////////////////////////////////////
  41. length_long = input.int(title="Atr Length_long", defval=11, minval=0)
  42. smoothing_long = input.string(title="Smoothing_long", defval="SMA", options=["RMA", "SMA", "EMA", "WMA"])
  43. ma_function_long(source, length_long) =>
  44.     switch smoothing_long
  45.         "RMA" => ta.rma(source, length_long)
  46.         "SMA" => ta.sma(source, length_long)
  47.         "EMA" => ta.ema(source, length_long)
  48.         => ta.wma(source, length_long)
  49. // plot(ma_function_long(ta.tr(true), length_long), title = "ATR_long", color=color.new(#B71C1C, 0))
  50. // End Detecting ATR Long ///////////////////////////////////////////////////////
  51.  
  52.  
  53. // Start Detecting ATR Short ///////////////////////////////////////////////////////
  54. length_short = input.int(title="Atr Length_short", defval=11, minval=0)
  55. smoothing_short = input.string(title="Smoothing_short", defval="SMA", options=["RMA", "SMA", "EMA", "WMA"])
  56. ma_function_short(source, length_short) =>
  57.     switch smoothing_short
  58.         "RMA" => ta.rma(source, length_short)
  59.         "SMA" => ta.sma(source, length_short)
  60.         "EMA" => ta.ema(source, length_short)
  61.         => ta.wma(source, length_short)
  62. // plot(ma_function_short(ta.tr(true), length_short), title = "ATR_short", color=color.new(#B71C1C, 0))
  63. // End Detecting ATR Short ///////////////////////////////////////////////////////
  64.  
  65.  
  66. // Variabili ATR Long e Short e Variabili Multiplier Long e Short  
  67. in_atr_Mult_long = input.float(title='atr_Mult_long', minval=0, maxval=5, defval=1, step=0.5)
  68. in_atr_Mult_short = input.float(title='atr_Mult_short', minval=0, maxval=5, defval=1, step=0.5)
  69. atr_long = ma_function_long(ta.tr(true), length_long)
  70. atr_short = ma_function_short(ta.tr(true), length_short)
  71.  
  72.  
  73. //Variabili Medie Long e Short
  74. media_long = ta.ema(close, input_lunghezza_ema_long)
  75. media_short = ta.ema(close, input_lunghezza_ema_short)
  76.  
  77. // plot(media_long, title = "media_long", color=color.blue)
  78. // plot(media_short, title = "media_short", color=color.purple)
  79.  
  80.  
  81. // giorni da 1 a 7 1 è domenica. Entrambe le possibilità sono disponibili sia il cross, sia la close del livello trailing stop close
  82.  
  83. //Condizione Entrata Long
  84. condEntryLong = math.abs(open - close) > atr_long * in_atr_Mult_long and close > open and close > media_long and not in_solo_short // and month != 9 and dayofweek != 2
  85.  
  86. //Condizione Entrata Short
  87. condEntryShort = math.abs(open - close) > atr_short * in_atr_Mult_short and close < open and  close < media_short and not in_solo_long // and month != 9 and dayofweek != 2
  88.  
  89.  
  90. IsLongOpen = false
  91. IsLongOpen := condEntryLong[1] ? true : condEntryShort[1] ? false : IsLongOpen[1]
  92.  
  93.  
  94. IsShortOpen = false
  95. IsShortOpen := condEntryShort[1] ? true : condEntryLong[1] ? false : IsShortOpen[1]
  96.  
  97. IsFlat = true
  98. IsFlat := not IsLongOpen and not IsShortOpen
  99.  
  100. //conversione bool -> float, per debug
  101.  
  102. IsLongOpenFloat = 0
  103. IsLongOpenFloat:= if IsLongOpen == true
  104.     1
  105. else
  106.     0
  107. IsShortOpenFloat = 0
  108. IsShortOpenFloat:= if IsShortOpen == true
  109.     1
  110. else
  111.     0
  112. IsFlatFloat = 0
  113. IsFlatFloat:= if IsFlat == true
  114.     1
  115. else
  116.     0
  117.  
  118.  
  119. //plot posizioni aperte, per debug non deve essere plottato plottare il 2
  120.  
  121. // plot (IsLongOpenFloat)
  122. // plot (IsShortOpenFloat,color=color.red)
  123. // plot (IsFlatFloat,color=color.yellow)
  124.  
  125.  
  126. OpenLong = false
  127. OpenLong:= condEntryLong and not IsLongOpen
  128. //CloseLong = condExitLong and IsLongOpen // and not condEntryShort DA VERIFICARE
  129.  
  130. OpenShort = false
  131. OpenShort:= condEntryShort and not IsShortOpen
  132. //CloseShort = condExitShort and IsShortOpen // and not condEntryLong  DA VERIFICARE
  133.  
  134.  
  135. entryprice = 0.0
  136. // entryprice := IsLongOpen ? ta.valuewhen(condEntryLong[1] and not IsLongOpen[1], open, 0) + 0.3 : IsShortOpen ? ta.valuewhen(condEntryShort[1] and not IsShortOpen[1], close[1], 0) - 0.3 : na
  137.  
  138.  
  139. entryprice := OpenLong == true ? ta.valuewhen(OpenLong, close, 0) + 0.3 : OpenShort ==true ? ta.valuewhen(OpenShort, close, 0) - 0.3 : entryprice[1]
  140.  
  141.  
  142. //Variabili Trailing Stop Long e Short
  143. trailing_stop_trigger_long = entryprice + (entryprice * input_take_profit_long  / 100) * (input_trailing_stop_trigger / 100)
  144. trailing_stop_close_long = entryprice + (entryprice * input_take_profit_long  / 100) * (input_trailing_stop_close / 100)
  145. trailing_stop_trigger_short = entryprice - ( entryprice * input_take_profit_short  / 100) * (input_trailing_stop_trigger / 100)
  146. trailing_stop_close_short = entryprice - ( entryprice * input_take_profit_short  / 100) * (input_trailing_stop_close / 100)
  147.  
  148. // Condizione Uscita Cross Trailing Stop Long E Short
  149. //cond_exit_long = high >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low) or high[1] >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low) or high[2] >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low) or high[3] >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low) or
  150. //                 high[4] >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low) or high[5] >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low) or high[6] >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low) or high[7] >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low) or
  151. //                 high[8] >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low) or high[9] >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low) or  high[10] >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low) or high[11] >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low) or
  152. //                 high[12] >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low) or high[13] >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low) or  high[14] >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low) or high[15] >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low) or
  153. //                 high[16] >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low)
  154.  
  155.  
  156. //cond_exit_short = low <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high) or low[1] <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high) or low[2] <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high) or low[3] <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high) or
  157. //                  low[4] <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high) or low[5] <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high) or low[6] <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high) or low[7] <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high) or  
  158. //                  low[8] <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high) or low[9] <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high) or low[10] <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high) or low[11] <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high) or
  159. //                  low[12] <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high) or low[13] <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high) or low[14] <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high) or low[15] <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high) or
  160. //                  low[16] <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high)
  161.  
  162.  
  163. // Condizione Uscita Close Trailing Stop Long E Short                  
  164. // condExitLong = high >= trailing_stop_trigger_long and close < trailing_stop_close_long or high[1] >= trailing_stop_trigger_long and close < trailing_stop_close_long or high[2] >= trailing_stop_trigger_long and close < trailing_stop_close_long or high[3] >= trailing_stop_trigger_long and close < trailing_stop_close_long or
  165. //                  high[4] >= trailing_stop_trigger_long and close < trailing_stop_close_long or high[5] >= trailing_stop_trigger_long and close < trailing_stop_close_long or high[6] >= trailing_stop_trigger_long and close < trailing_stop_close_long or high[7] >= trailing_stop_trigger_long and close < trailing_stop_close_long or
  166. //                  high[8] >= trailing_stop_trigger_long and close < trailing_stop_close_long or high[9] >= trailing_stop_trigger_long and close < trailing_stop_close_long or  high[10] >= trailing_stop_trigger_long and close < trailing_stop_close_long or high[11] >= trailing_stop_trigger_long and close < trailing_stop_close_long or
  167. //                  high[12] >= trailing_stop_trigger_long and close < trailing_stop_close_long or high[13] >= trailing_stop_trigger_long and close < trailing_stop_close_long or  high[14] >= trailing_stop_trigger_long and close < trailing_stop_close_long or high[15] >= trailing_stop_trigger_long and close < trailing_stop_close_long or
  168. //                  high[16] >= trailing_stop_trigger_long and close < trailing_stop_close_long
  169.  
  170. // condExitShort =  low <= trailing_stop_trigger_short and close >= trailing_stop_close_short or low[1] <= trailing_stop_trigger_short and close >= trailing_stop_close_short or  low[2] <= trailing_stop_trigger_short and close >= trailing_stop_close_short or low[3] <= trailing_stop_trigger_short and close >= trailing_stop_close_short or
  171. //                   low[4] <= trailing_stop_trigger_short and close >= trailing_stop_close_short  or low[5] <= trailing_stop_trigger_short and close >= trailing_stop_close_short or low[6] <= trailing_stop_trigger_short and close >= trailing_stop_close_short or low[7] <= trailing_stop_trigger_short and close >= trailing_stop_close_short or
  172. //                   low[8] <= trailing_stop_trigger_short and close >= trailing_stop_close_short  or low[9] <= trailing_stop_trigger_short and close >= trailing_stop_close_short  or low[10] <= trailing_stop_trigger_short and close >= trailing_stop_close_short or low[11] <= trailing_stop_trigger_short and close >= trailing_stop_close_short or
  173. //                   low[12] <= trailing_stop_trigger_short and close >= trailing_stop_close_short  or low[13] <= trailing_stop_trigger_short and close >= trailing_stop_close_short or low[14] <= trailing_stop_trigger_short and close >= trailing_stop_close_short or low[15] <= trailing_stop_trigger_short and close >= trailing_stop_close_short or
  174. //                   low[16] <= trailing_stop_trigger_short and close >= trailing_stop_close_short
  175.  
  176.  
  177. // Condizione Uscita Close Trailing Stop E Close [1] > < Long E Short
  178. condExitLong = false
  179. condExitLong :=  high >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long or high[1] >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long  or  high[2] >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long or high[3] >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long or
  180.                  high[4] >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long or high[5] >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long or high[6] >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long or high[7] >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long or
  181.                  high[8] >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long or high[9] >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long or high[10] >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long or high[11] >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long or
  182.                  high[12] >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long or high[13] >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long or high[14] >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long or high[15] >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long or
  183.                  high[16] >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long
  184.  
  185. condExitShort = false
  186. condExitShort :=  low <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short or low[1] <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short  or  low[2] <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short or low[3] <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short or
  187.                   low[4] <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short or low[5] <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short or low[6] <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short or low[7] <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short or
  188.                   low[8] <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short or low[9] <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short or low[10] <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short or low[11] <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short or
  189.                   low[12] <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short or low[13] <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short or low[14] <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short or low[15] <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short or
  190.                   low[16] <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short
  191.  
  192.  
  193. //Variabili Take Profit E Stop Loss Long e Short
  194. stoplosslong = 0.0
  195. stoplosslong:= entryprice - (entryprice * input_stop_loss_long  / 100)
  196. condExitLongStop= false
  197. condExitLongStop:= low <= stoplosslong
  198. stoplossshort = 0.0
  199. stoplossshort:= entryprice + (entryprice * input_stop_loss_short  / 100)
  200. condExitShortStop = false
  201. condExitShortStop:= high >= stoplossshort
  202.  
  203. take_profit_long=0.0
  204. take_profit_long:= entryprice + (entryprice * input_take_profit_long  / 100)
  205. condExitTargetLong = false
  206. condExitTargetLong:= high >= take_profit_long
  207. take_profit_short = 0.0
  208. take_profit_short:= entryprice - (entryprice * input_take_profit_short  / 100)
  209. condExitTargetShort = false
  210. condExitTargetShort:= low <= take_profit_short
  211.  
  212.  
  213. condEntryLong2 = false
  214. condEntryLong2:= condEntryLong and not IsLongOpen and not IsLongOpen[1] and not condEntryShort[1]
  215. condEntryShort2 = false
  216. condEntryShort2:= condEntryShort and not IsShortOpen and not IsShortOpen[1] and not condEntryLong[1]
  217.  
  218.  
  219. IsLongOpen :=  condEntryLong2[1] ? true : condEntryShort[1] and condEntryLong[2] ? true : condExitLong[1] ? false : condEntryShort[1] and not condEntryLong[2] ? false : condExitLongStop[1] ? false : condExitTargetLong[1] ? false : IsLongOpen[1]
  220. IsShortOpen := condEntryShort2[1] ? true : condEntryLong[1] and condEntryShort[2] ? true : condExitShort[1] ? false : condEntryLong[1] and not condEntryShort[2] ? false : condExitShortStop[1] ? false : condExitTargetShort[1] ? false : IsShortOpen[1]
  221. IsFlat := not IsLongOpen and not IsShortOpen
  222.  
  223.  
  224. //conversione bool -> float, per debug
  225.  
  226. IsLongOpenFloat:= if IsLongOpen == true
  227.     1
  228. else
  229.     0
  230.  
  231. IsShortOpenFloat:= if IsShortOpen == true
  232.     1
  233. else
  234.     0
  235.  
  236. IsFlatFloat:= if IsFlat == true
  237.     1
  238. else
  239.     0
  240.  
  241.  
  242. //plot posizioni aperte, per debug
  243.  
  244. // plot (IsLongOpenFloat)
  245. // plot (IsShortOpenFloat,color=color.red)
  246. // plot (IsFlatFloat,color=color.yellow)
  247. // plot (entryprice,color=color.white, title = 'Entryprice')
  248. // plot (trailing_stop_trigger_long,color=color.green, title = 'trigger long')
  249. // plot (trailing_stop_close_long,color=color.green,title = 'trailing close long')
  250. // plot (stoplosslong,color=color.red, title = 'stop long')
  251. // plot (take_profit_long,color=color.blue,title = 'target long')
  252. // plot (trailing_stop_trigger_short,color=color.green, title = 'trigger short')
  253. // plot (trailing_stop_close_short,color=color.green,title = 'trailing close short')
  254. // plot (stoplossshort,color=color.red, title = 'stop short')
  255. // plot (take_profit_short,color=color.blue,title = 'target_short')
  256.  
  257.  
  258. OpenLong:= condEntryLong and not IsLongOpen
  259. //CloseLong2 = condExitLong and IsLongOpen2 and not condEntryShort
  260.  
  261. OpenShort:= condEntryShort and not IsShortOpen
  262. //CloseShort2 = condExitShort and IsShortOpen2 and not condEntryLong
  263.  
  264. entryprice := OpenLong == true ? ta.valuewhen(OpenLong, close, 0) + 0.3 : OpenShort ==true ? ta.valuewhen(OpenShort, close, 0) - 0.3 : entryprice[1]
  265.  
  266.  
  267. stoplosslong:= entryprice - (entryprice * input_stop_loss_long  / 100)
  268. condExitLongStop:= low <= stoplosslong
  269. take_profit_long:= entryprice + (entryprice * input_take_profit_long  / 100)
  270. condExitTargetLong:= high >= take_profit_long
  271. stoplossshort:= entryprice + (entryprice * input_stop_loss_short  / 100)
  272. condExitShortStop:= high >= stoplossshort
  273. take_profit_short:= entryprice - (entryprice * input_take_profit_short  / 100)
  274. condExitTargetShort:= low <= take_profit_short
  275.  
  276.  
  277. condEntryLong2:= condEntryLong and not IsLongOpen and not IsLongOpen[1] and not condEntryShort[1]
  278. condEntryShort2:= condEntryShort and not IsShortOpen and not IsShortOpen[1] and not condEntryLong[1]
  279.  
  280.  
  281. IsLongOpen :=  condEntryLong2[1] ? true : condEntryShort[1] and condEntryLong[2] ? true : condExitLong[1] ? false : condEntryShort[1] and not condEntryLong[2] ? false : condExitLongStop[1] ? false : condExitTargetLong[1] ? false : IsLongOpen[1]
  282. IsShortOpen := condEntryShort2[1] ? true : condEntryLong[1] and condEntryShort[2] ? true : condExitShort[1] ? false : condEntryLong[1] and not condEntryShort[2] ? false : condExitShortStop[1] ? false : condExitTargetShort[1] ? false : IsShortOpen[1]
  283. IsFlat := not IsLongOpen and not IsShortOpen
  284.  
  285.  
  286. //conversione bool -> float, per debug
  287.  
  288. IsLongOpenFloat:= if IsLongOpen == true
  289.     1
  290. else
  291.     0
  292.  
  293. IsShortOpenFloat:= if IsShortOpen == true
  294.     1
  295. else
  296.     0
  297.  
  298. IsFlatFloat:= if IsFlat == true
  299.     1
  300. else
  301.     0
  302.  
  303. //plot posizioni aperte, per debug
  304.  
  305. plot (IsLongOpenFloat)
  306. plot (IsShortOpenFloat,color=color.red)
  307. plot (IsFlatFloat,color=color.yellow)
  308. // plot (entryprice,color=color.white, title = 'Entryprice')
  309. // plot (trailing_stop_trigger_long,color=color.green, title = 'trigger long')
  310. // plot (trailing_stop_close_long,color=color.green,title = 'trailing close long')
  311. // plot (stoplosslong,color=color.red, title = 'stop long')
  312. // plot (take_profit_long,color=color.blue,title = 'target long')
  313. // plot (trailing_stop_trigger_short,color=color.green, title = 'trigger short')
  314. // plot (trailing_stop_close_short,color=color.green,title = 'trailing close short')
  315. // plot (stoplossshort,color=color.red, title = 'stop short')
  316. // plot (take_profit_short,color=color.blue,title = 'target_short')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement