Maurizio-Ciullo

Bot Swing-Trend-Trailing-Riot-P1 ETHUSDT.P BYBIT 4H LONG E SHORT

Sep 13th, 2025 (edited)
305
0
Never
7
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.                                                                 // Bot Swing Trend Trailing Riot Period 1 10-09-2025 ETHUSDT.P BYBIT 4H LONG E SHORT //
  2.                                             // Datafeed Cambiato / Periodi Backtest Cambiati / Inputs Cambiati / Stop Loss Limit Tolto //
  3.                                             // Condizione Long Tolta: and ((close[1] < (media_ema_1 + apertura_minima)) or (low[1] < (media_ema_1 + apertura_minima))) and close > open
  4.                                             // Condizione Short Tolta: and ((close[1] > (media_ema_1 - apertura_minima)) or (high[1] > (media_ema_1 - apertura_minima))) and close < open
  5.  
  6.                     // *** Attezione aclune operazioni potrebbero essere diverse da tradestation perchè tradingview
  7.                     // se esce in trailng stop e allo stesso tempo c'è la condizione di ingresso sulla stessa candela
  8.                     // non effettua uscite ed entrate nella stessa candela in questo caso specifico mentre tradestation si *** !!!
  9.  
  10. // RIOTTIMIZZAZIONE PERIODICA 1 DELLA ORIGINALE SWING TREND TRAILING   
  11. // IL DATAFEED COMPLETO = (18/08/2017 10/08/2025)                                              
  12. // NUOVI DATI DI SVILUPPO DATAFEED ETH/USDT BINANCE + ETH/USDT.P BYBIT 4H  STORICO INIZIALE BINANCE PER POI PROSEGUIRE CON BYBIT                                                                                                                       
  13. // (Sviluppo Dati Exchange = BINANCE + BYBIT) (BINANCE Dal=18/08/2017 Al 10/10/2020) (BYBIT Dal=21/10/2020 Al 10/08/2025)
  14. // SU TRADINGVIEW ORARIO BORSA GMT
  15. // BARSBACK TRADESTATION: 500
  16.  
  17. // NUOVE DATE IN SAMPLE E OUT OF SAMPLE
  18. //Il data feed completo: 18/08/2017 10/08/2025
  19. //In Sample: Inizio 18/08/2017 Fine 12/06/2023
  20. //Out Of Sample: Inizio 13/06/2023 Fine 10/08/2025
  21.  
  22.  
  23. // Il trading system completo - Bot Swing Trend Trailing Riot Period 1 10-09-2025 ETHUSDT.P BYBIT 4H LONG E SHORT
  24. // (Exchange= BYBIT) (Sottostante ETH-USDT.P) (Timeframe= 4H) (Direzione= LONG E SHORT) (Swing Posizione= SI) (Esclusione Ore=NO) (Esclusione Giorni=NO) (Esclusione Mesi=NO)
  25. // (Take Profit Long/Short Market = Trailing) (Take Profit Limit Long/Short= NO)
  26. // (Stop Loss Limit Long/Short= NO) (Stop Loss Market=SI) (Trailing Stop=SI) (Stop Emergenza: NO)
  27. // (Max DD Concesso = 15% Media Max Drawdown 2°nda Deviazione Standard Simulazione Montecalo Python
  28. // (Money Management = 25% Del Capitale Tradestation)  
  29. // (Money Management = 12,00% Del Capitale Tradingview) Preso Dal 15% Media Max Drawdown 2°nda Deviazione Standard Simulazione Montecarlo Python
  30.  
  31. // (In Sample Dal=17/08/2017 12/06/2023) (Out Of Sample Dal13/06/2023 Al 10-08-2025)
  32. // (Progettatta Il=10/09/25)
  33.  
  34.  
  35. //@version=5
  36. //1. Strategia
  37. strategy(title='Bot Swing-Trend-Trailing-Riot-P1 ETH/USDT.P BYBIT 4H LONG E SHORT', overlay=true,
  38.          max_bars_back=500, // Serve Per Caricare Più Storico Per Il Trailing Stop
  39.          pyramiding=0,
  40.          initial_capital=1000,
  41.          commission_type=strategy.commission.percent,
  42.          commission_value=0.1,
  43.          slippage=3,
  44.          default_qty_type=strategy.percent_of_equity,
  45.          precision=2,
  46.          default_qty_value=12)
  47.  
  48.  
  49. // Input
  50. input_ema = input.int(title='Media Ema', defval=130, minval=0, maxval=500)
  51. input_apertura_minima = input.float(title='perc_apertura_minima', defval=2, group='Filtri Posizione')
  52. input_apertura_massima = input.float(title='perc_apertura_massima', defval=3.7, group='Filtri Posizione ')
  53. input_chiusura_minima = input.float(title='perc_chiusura_minima', defval=0, group='Filtri Posizione')
  54. input_trailing_stop_trigger = input.float(title='input_trailing_stop_trigger', defval=10, group='trailing ')                   // Non Attivo !!!
  55. input_trailing_stop_close = input.float(title='input_trailing_stop_close', defval=6, group='trailing ')
  56. input_stop_loss_long = input.float(title='stop_loss_long', defval=100, minval=0, maxval=100, step=0.1, group='Stop Loss')      // Non Attivo !!!
  57. input_stop_loss_short= input.float(title='stop_loss_short', defval=100, minval=0, maxval=100, step=0.1, group='Stop Loss')     // Non Attivo !!!
  58. onlyLong = input.bool(title='Solo long', defval=false, inline='1', group='Direzione')
  59. onlyShort = input.bool(title='Solo short', defval=false, inline='1', group='Direzione')
  60. input_risk = input.float(title='Risk Per Trade %', defval=12.0, minval=0, maxval=100, step=0.01, group='Risk Per Trade %')     // Non Attivo !!!
  61.  
  62.  
  63. // Calcolo del range del backtest
  64. startDate = input.int(title="Start Date",
  65.      defval=17, minval=1, maxval=31, group="Periodo")
  66. startMonth = input.int(title="Start Month",
  67.      defval=08, minval=1, maxval=12, group="Periodo")
  68. startYear = input.int(title="Start Year",
  69.      defval=2000, minval=1800, maxval=2100, group="Periodo")
  70.  
  71. endDate = input.int(title="End Date",
  72.      defval=01, minval=1, maxval=31, group="Periodo")
  73. endMonth = input.int(title="End Month",
  74.      defval=01, minval=1, maxval=12, group="Periodo")
  75. endYear = input.int(title="End Year",
  76.      defval=2121, minval=1800, maxval=2150, group="Periodo")
  77.  
  78.  
  79. inDateRange = (time >= timestamp(syminfo.timezone, startYear,
  80.          startMonth, startDate, 0, 0)) and
  81.      (time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0))
  82.  
  83.  
  84. // Start Hour Range Trading Non Attivo /////////////////////
  85. //hourTrading = input(title='sessione valida di trading', defval='0600-2300:23456')
  86. //hourRangeTrading = time(timeframe.period, hourTrading)
  87.  
  88.  
  89. //Calcolo degli indicatori
  90.  
  91. // Variabili Medie Ema
  92. ema = ta.ema(close, input_ema)
  93. ema1 = ta.ema(close[1], input_ema)
  94.  
  95. plot(ema, color=color.new(color.green, 0), title='Media_Ema', linewidth=2)
  96.  
  97.  
  98. //Calcolo filtri apertura minima
  99. apertura_minima = ema / 100 * input_apertura_minima
  100. apertura_minima1 = ema1 / 100 * input_apertura_minima
  101. apertura_massima = ema / 100 * input_apertura_massima
  102. chiusura_minima = ema / 100 * input_chiusura_minima
  103.  
  104.  
  105. // Filtri Bande Long
  106. filtro_long_basso = ema + apertura_minima
  107. filtro_long_alto = ema + apertura_massima
  108. //filtro_chiusura_minima_long =(ema - chiusura_minima)
  109.  
  110. plot_filtro_long_basso = plot(filtro_long_basso, color=color.new(color.blue, 0), title='filtro_long_basso')
  111. plot_filtro_long_alto = plot(filtro_long_alto, color=color.new(color.blue, 0), title='filtro_long_alto')
  112. fill(plot_filtro_long_basso, plot_filtro_long_alto, title='Spazio di apertura', color=color.new(color.blue, 90))
  113.  
  114.  
  115. // Filtri Bande Short
  116. filtro_short_basso = ema - apertura_minima
  117. filtro_short_alto = ema - apertura_massima
  118. //filtro_chiusura_minima_short =(ema + chiusura_minima)
  119.  
  120. plot_filtro_short_basso = plot(filtro_short_basso, color=color.new(color.red, 0), title='filtro_short_basso')
  121. plot_filtro_short_alto = plot(filtro_short_alto, color=color.new(color.red, 0), title='filtro_short_alto')
  122. fill(plot_filtro_short_basso, plot_filtro_short_alto, title='Spazio di apertura', color=color.new(color.red, 90))
  123.  
  124. //plot_filtro_chiusura_minima_long=plot(filtro_chiusura_minima_long, color=color.blue, title="filtro_chiusura_minima_long")
  125. //plot_filtro_chiusura_minima_short=plot(filtro_chiusura_minima_short, color=color.red, title="filtro_chiusura_minima_short")
  126. //fill(p5,filtro_chiusura_minima_long, title = "Spazio di chiusura long", color = color.blue)
  127. //fill(p6,filtro_chiusura_minima_short, title = "Spazio di chiusura short", color = color.red)
  128.  
  129.  
  130. // Stop Loss Long E Short
  131. stop_loss_long_price = strategy.opentrades.entry_price(0) - (strategy.opentrades.entry_price(0) * input_stop_loss_long) / 100
  132. stop_loss_long = (strategy.opentrades.entry_price(0) - stop_loss_long_price) / syminfo.mintick
  133. // target_long_price = (strategy.opentrades.entry_price(0) + ((strategy.opentrades.entry_price(0) * input_take_profit_long) / 100))
  134. // target_long = (target_long_price - strategy.opentrades.entry_price(0)) / syminfo.mintick
  135. //plot(SLL, title = "stop ticks", color=color.purple)
  136.  
  137. stop_loss_short_price = strategy.opentrades.entry_price(0) + (strategy.opentrades.entry_price(0) * input_stop_loss_short) / 100
  138. stop_loss_short = (stop_loss_short_price - strategy.opentrades.entry_price(0)) / syminfo.mintick
  139. // target_short_price = (strategy.opentrades.entry_price(0) - ((strategy.opentrades.entry_price(0) * input_take_profit_short) / 100))
  140. // target_short =(strategy.opentrades.entry_price(0) - target_short_price) / syminfo.mintick
  141. //plot(SLS, title = "stop ticks", color=color.purple)
  142.  
  143.  
  144. // Trailing Stop Long E Short
  145. trailing_stop_trigger_long = strategy.opentrades.entry_price(0) + (strategy.opentrades.entry_price(0) * input_trailing_stop_trigger)/100
  146. trailing_stop_close_long = strategy.opentrades.entry_price(0) + (strategy.opentrades.entry_price(0) * input_trailing_stop_close)/100
  147. trailing_stop_trigger_short = strategy.opentrades.entry_price(0) - (strategy.opentrades.entry_price(0) * input_trailing_stop_trigger)/100
  148. trailing_stop_close_short = strategy.opentrades.entry_price(0) - (strategy.opentrades.entry_price(0) * input_trailing_stop_close)/100
  149.  
  150.  
  151. // Originale Usato Nel codice
  152. // condExitLong2 =  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
  153. //                  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
  154. //                  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
  155. //                  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
  156. //                  high[16] >= trailing_stop_trigger_long and close < trailing_stop_close_long and close[1] > trailing_stop_close_long
  157.  
  158. // condExitLong2 =  high >= trailing_stop_trigger_long and ta.crossunder(close, trailing_stop_close_long) and close[1] > trailing_stop_close_long  or high[1] >= trailing_stop_trigger_long and ta.crossunder(close, trailing_stop_close_long ) and close[1] > trailing_stop_close_long or  high[2] >= trailing_stop_trigger_long and  ta.crossunder(close, trailing_stop_close_long ) and close[1] > trailing_stop_close_long or high[3] >= trailing_stop_trigger_long and  ta.crossunder(close, trailing_stop_close_long ) and close[1] > trailing_stop_close_long or
  159. //                  high[4] >= trailing_stop_trigger_long and  ta.crossunder(close, trailing_stop_close_long ) and close[1] > trailing_stop_close_long or high[5] >= trailing_stop_trigger_long and  ta.crossunder(close, trailing_stop_close_long ) and close[1] > trailing_stop_close_long or high[6] >= trailing_stop_trigger_long and  ta.crossunder(close, trailing_stop_close_long ) and close[1] > trailing_stop_close_long or high[7] >= trailing_stop_trigger_long and ta.crossunder(close, trailing_stop_close_long ) and close[1] > trailing_stop_close_long or
  160. //                  high[8] >= trailing_stop_trigger_long and  ta.crossunder(close, trailing_stop_close_long ) and close[1] > trailing_stop_close_long or high[9] >= trailing_stop_trigger_long and  ta.crossunder(close, trailing_stop_close_long ) and close[1] > trailing_stop_close_long or high[10] >= trailing_stop_trigger_long and  ta.crossunder(close, trailing_stop_close_long ) and close[1] > trailing_stop_close_long or high[11] >= trailing_stop_trigger_long and  ta.crossunder(close, trailing_stop_close_long ) and close[1] > trailing_stop_close_long or
  161. //                  high[12] >= trailing_stop_trigger_long and  ta.crossunder(close, trailing_stop_close_long ) and close[1] > trailing_stop_close_long or high[13] >= trailing_stop_trigger_long and  ta.crossunder(close, trailing_stop_close_long ) and close[1] > trailing_stop_close_long or high[14] >= trailing_stop_trigger_long and  ta.crossunder(close, trailing_stop_close_long ) and close[1] > trailing_stop_close_long or high[15] >= trailing_stop_trigger_long and  ta.crossunder(close, trailing_stop_close_long ) and close[1] > trailing_stop_close_long or
  162. //                  high[16] >= trailing_stop_trigger_long and  ta.crossunder(close, trailing_stop_close_long ) and close[1] > trailing_stop_close_long
  163.  
  164.  
  165. // Originale Usato Nel Codice
  166. // condExitShort2 =  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
  167. //                   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
  168. //                   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
  169. //                   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
  170. //                   low[16] <= trailing_stop_trigger_short and close > trailing_stop_close_short and close[1] < trailing_stop_close_short
  171.  
  172. // condExitShort2 =  low <= trailing_stop_trigger_short and ta.crossover(close, trailing_stop_close_short) and close[1] < trailing_stop_close_short or low[1] <= trailing_stop_trigger_short and ta.crossover(close, trailing_stop_close_short) and close[1] < trailing_stop_close_short  or  low[2] <= trailing_stop_trigger_short and ta.crossover(close, trailing_stop_close_short) and close[1] < trailing_stop_close_short or low[3] <= trailing_stop_trigger_short and ta.crossover(close, trailing_stop_close_short) and close[1] < trailing_stop_close_short or
  173. //                   low[4] <= trailing_stop_trigger_short and ta.crossover(close, trailing_stop_close_short) and close[1] < trailing_stop_close_short or low[5] <= trailing_stop_trigger_short and ta.crossover(close, trailing_stop_close_short) and close[1] < trailing_stop_close_short or low[6] <= trailing_stop_trigger_short and ta.crossover(close, trailing_stop_close_short) and close[1] < trailing_stop_close_short or low[7] <= trailing_stop_trigger_short and ta.crossover(close, trailing_stop_close_short) and close[1] < trailing_stop_close_short or
  174. //                   low[8] <= trailing_stop_trigger_short and ta.crossover(close, trailing_stop_close_short) and close[1] < trailing_stop_close_short or low[9] <= trailing_stop_trigger_short and ta.crossover(close, trailing_stop_close_short) and close[1] < trailing_stop_close_short or low[10] <= trailing_stop_trigger_short and ta.crossover(close, trailing_stop_close_short) and close[1] < trailing_stop_close_short or low[11] <= trailing_stop_trigger_short and ta.crossover(close, trailing_stop_close_short) and close[1] < trailing_stop_close_short or
  175. //                   low[12] <= trailing_stop_trigger_short and ta.crossover(close, trailing_stop_close_short) and close[1] < trailing_stop_close_short or low[13] <= trailing_stop_trigger_short and ta.crossover(close, trailing_stop_close_short) and close[1] < trailing_stop_close_short or low[14] <= trailing_stop_trigger_short and ta.crossover(close, trailing_stop_close_short) and close[1] < trailing_stop_close_short or low[15] <= trailing_stop_trigger_short and ta.crossover(close, trailing_stop_close_short) and close[1] < trailing_stop_close_short or
  176. //                   low[16] <= trailing_stop_trigger_short and ta.crossover(close, trailing_stop_close_short) and close[1] < trailing_stop_close_short
  177.  
  178. // Plot Ingresso In Posizione
  179. plot(strategy.position_size != 0 ? strategy.opentrades.entry_price(0) : na , color=strategy.position_size > 0 ? color.blue : strategy.position_size < 0 ? color.red : na, style=plot.style_linebr, title="entry_price") // stampa l'entry price in rosso se short in blu se long
  180. plot(strategy.position_size > 0 ?  trailing_stop_trigger_long : strategy.position_size < 0 ? trailing_stop_trigger_short: na, color=color.blue, style=plot.style_cross, linewidth=2, title="trail_trigger")
  181. plot(strategy.position_size > 0 ?  trailing_stop_close_long : strategy.position_size < 0 ? trailing_stop_close_short: na, color=color.blue, style=plot.style_cross, linewidth=2, title="trail_close")
  182. plot(strategy.position_size > 0 ?  stop_loss_long_price : strategy.position_size < 0 ? stop_loss_short_price: na, color=color.red, style=plot.style_cross, linewidth=2, title="sl_limit")
  183.  
  184. bgcolor(strategy.position_size > 0 ? color.green : strategy.position_size < 0 ? color.red : na, transp=90) // sfondo verde quando siamo long, sfondo rosso quando siamo short, no sfondo quando non siamo in posizione
  185.  
  186.  
  187. // Calcolo Uscita Trailing Stop Long E Short
  188. // Bar_index = bar_index
  189. // plot(Bar_index, title = "Bar_index")
  190.  
  191. // entry_bar_index = strategy.opentrades.entry_bar_index(0) +1
  192. // plot(entry_bar_index, title = "entry_bar_index")
  193.  
  194. range_barre_trailing = bar_index - strategy.opentrades.entry_bar_index(0) +1
  195. //plot(lunghezza_trailing, title = 'lunghezza')
  196.  
  197. highesthigh = strategy.opentrades ==1 ? ta.highest(high, range_barre_trailing): na
  198. //plot(highesthigh)
  199.  
  200. lowestlow = strategy.opentrades ==1 ? ta.lowest(low, range_barre_trailing): na
  201. //plot(lowestlow)
  202.  
  203.  
  204. // >>>>>>>>>>>>>> Start Detecting No Trading Allowed <<<<<<<<<<<<<<<<<
  205.  
  206. // Plot No Trading Allowed giorni da 1 a 7, 1 è domenica Mesi da 1 a 12, 1 è Gennaio.
  207. //giorni_esclusi = dayofweek(time)
  208. //plotshape(giorni_esclusi[1] == 2 ? giorni_esclusi : na, color=color.green, title="giorni_esclusi")
  209. //mesi_esclusi = month(time)
  210. //plotshape(mesi_esclusi[1] == 9 ? mesi_esclusi : na, color=color.yellow, title="mesi_esclusi")
  211.  
  212. // >>>>>>>>>>>>>> End Detecting No Trading Allowed <<<<<<<<<<<<<<<<<
  213.  
  214.  
  215. // >>>>>>>>>>>>>> Start Calcolo Drawdown Operazion Chiuse <<<<<<<<<<<<<<<<<
  216.  
  217. // Blance Closed Equity
  218. balance = strategy.initial_capital + strategy.netprofit
  219. plot(balance, title="Balance Closed Equity", display = display.data_window)
  220.  
  221. // Highest Equity Closed Equity
  222. GetEquityHigh() =>
  223.     var highestEquity = strategy.initial_capital
  224.     highestEquity := math.max(highestEquity, (strategy.initial_capital + strategy.netprofit))
  225. plot(GetEquityHigh(), "Highest Equity Closed Equity", display = display.data_window)
  226.  
  227. // Drawdown Relativo In $ (Closed Equity)
  228. relativeDrawdownMonetary = GetEquityHigh() - balance
  229. plot(relativeDrawdownMonetary, title="Drawdown Relativo $ Closed Equity", display=display.data_window)
  230.  
  231. // Drawdown Relativo In % (Closed Equity)
  232. relativeDrawdownPercent = (GetEquityHigh() != 0) ? (GetEquityHigh() - balance) / GetEquityHigh() * 100 : 0.0
  233. plot(relativeDrawdownPercent, title="Drawdown Relativo % Closed Equity", display=display.data_window)
  234.  
  235. // Max Drawdown Absolute $ Closed Equity
  236. var float maxDrawdownMonetary = 0.0
  237. MaxDrawdownAbsoluteMonetary = (GetEquityHigh() - balance)
  238. maxDrawdownMonetary := math.max(maxDrawdownMonetary, MaxDrawdownAbsoluteMonetary)
  239. plot(maxDrawdownMonetary, title="Max Drawdown $ Closed Equity", display=display.data_window)
  240.  
  241. // Max Drawdown Percentuale Closed Equity
  242. var float maxDrawdownPercent = 0.0
  243. MaxDrawdownAbsolutePercent = (GetEquityHigh() != 0) ? (GetEquityHigh() - balance) / GetEquityHigh() * 100 : 0.0
  244. maxDrawdownPercent := math.max(maxDrawdownPercent, MaxDrawdownAbsolutePercent)
  245. plot(maxDrawdownPercent, title="Max Drawdown % Closed Equity", display=display.data_window)
  246.  
  247. // Plot Linee
  248. // plot(balance, title="Balance Closed Equity", style=plot.style_line)
  249. // plot(GetEquityHigh(), title="Highest Equity Closed Equity", style=plot.style_line)
  250. // plot(relativeDrawdownMonetary, title="Drawdown Relativo $ Closed Equity", style=plot.style_line)
  251. // plot(relativeDrawdownPercent, title="Drawdown Relativo % Closed Equity", style=plot.style_line)
  252. // plot(maxDrawdownMonetary, title="Max Drawdown $ Closed Equity", style=plot.style_line)
  253. // plot(maxDrawdownPercent, title="Max Drawdown % Closed Equity", style=plot.style_line)
  254.  
  255. // >>>>>>>>>>>>>> End Calcolo Drawdown Operazion Chiuse <<<<<<<<<<<<<<<<<
  256.  
  257.  
  258. //Condizione Entrata Long: Chiusura candela sopra media lenta con differenziale medie e media veloce maggiore media ExitLong
  259. condEntryLong = close > ema + apertura_minima and close < ema + apertura_massima and not onlyShort and inDateRange // and ((close[1] < (media_ema_1 + apertura_minima)) or (low[1] < (media_ema_1 + apertura_minima))) and close > open // and dayofweek != 7 and month !=10
  260.  
  261. //Condizione Uscita Long: Crossunder di due medie
  262. condExitLong = close < ema - chiusura_minima
  263.  
  264. // Condizione Uscita Trailing Stop Long
  265. condExitLong2 =  (highesthigh >= trailing_stop_trigger_long and close <= trailing_stop_close_long)
  266.  
  267. //Condizione Entrata Short: Crossunder di due medie con il prezzo di chiusura che è comunque sotto una terza media con differenziale delle medie
  268. condEntryShort = close < ema - apertura_minima and close > ema - apertura_massima  and not onlyLong and inDateRange // and ((close[1] > (media_ema_1 - apertura_minima)) or (high[1] > (media_ema_1 - apertura_minima))) and close < open // and dayofweek != 7 and month !=10
  269.  
  270. //Condizione Uscita Short: Crossover di medie con il prezzo di chiusura che è comunque sopra una terza media
  271. condExitShort = close > ema + chiusura_minima
  272.  
  273. // Condizione Uscita Trailing Stop Short
  274. condExitShort2 = (lowestlow <= trailing_stop_trigger_short and close >= trailing_stop_close_short)
  275.  
  276. barcolor(condEntryLong ? color.lime : condEntryShort ? color.purple : na)
  277.  
  278.  
  279. // Alerts
  280.              
  281. buy_command = 'BUY COMMAND'
  282. sell_command = 'SELL COMMAND'
  283. close_command = 'CLOSE COMMAND'
  284.  
  285.  
  286. //entrata e uscita Long
  287. if condEntryLong
  288.     strategy.entry('long', strategy.long, alert_message = "Open Long Position", comment = buy_command)
  289.     strategy.exit('stop loss long', from_entry='long', loss=stop_loss_long, alert_message = "Your Long SL Has Been Triggered.", comment = close_command)
  290.  
  291. if condExitLong
  292.     strategy.close(id='long', alert_message = "Close Long Position", comment = close_command)
  293.  
  294. if strategy.opentrades ==1 and condExitLong2
  295.     strategy.close(id='long', alert_message = "Trailing long", comment = close_command)    
  296.      
  297. //entrata e uscita Short
  298. if condEntryShort
  299.     strategy.entry('short', strategy.short, alert_message = "Open Short Position", comment = sell_command)
  300.     strategy.exit('stop loss short', from_entry='short', loss=stop_loss_short, alert_message = "Your Short SL Has Been Triggered.", comment = close_command)
  301.  
  302. if condExitShort
  303.     strategy.close(id='short', alert_message = "Close Short Position", comment = close_command)
  304.    
  305. if strategy.opentrades ==1 and condExitShort2
  306.     strategy.close(id='short', alert_message = "Trailing Short", comment = close_command)
  307.    
  308. // Nome Alert: Swing-Trend-Trailing-Riot-P1 ETH/USDT.P BYBIT 4H
  309. // Commento Alert: {{strategy.order.comment}}
  310. // Webhook Classico Più Sicuro Ma Più Lento: https://alerts.tv-hub.org  
  311. // Webhook Nuovo Meno Sicuro Ma Più Veloce: https://alerts.tv-hub.org/api/ExecuteTradeSignalClassic
  312.      
  313.    
  314. // ----------------- Inizio Tabella risultati mensili. Per visualizzare andare nelle impostazioni proprietà e spuntare ad ogni tick -----------------
  315.  
  316. // new_month = month(time) != month(time[1])
  317. // new_year  = year(time)  != year(time[1])
  318.  
  319. // eq = strategy.equity
  320.  
  321. // bar_pnl = eq / eq[1] - 1
  322.  
  323. // cur_month_pnl = 0.0
  324. // cur_year_pnl  = 0.0
  325.  
  326. // // Current Monthly P&L
  327. // cur_month_pnl := new_month ? 0.0 :
  328. //                  (1 + cur_month_pnl[1]) * (1 + bar_pnl) - 1
  329.  
  330. // // Current Yearly P&L
  331. // cur_year_pnl := new_year ? 0.0 :
  332. //                  (1 + cur_year_pnl[1]) * (1 + bar_pnl) - 1  
  333.  
  334. // // Arrays to store Yearly and Monthly P&Ls
  335. // var month_pnl  = array.new_float(0)
  336. // var month_time = array.new_int(0)
  337.  
  338. // var year_pnl  = array.new_float(0)
  339. // var year_time = array.new_int(0)
  340.  
  341. // last_computed = false
  342.  
  343. // if (not na(cur_month_pnl[1]) and (new_month or barstate.islast))
  344. //     if (last_computed[1])
  345. //         array.pop(month_pnl)
  346. //         array.pop(month_time)
  347.        
  348. //     array.push(month_pnl , cur_month_pnl[1])
  349. //     array.push(month_time, time[1])
  350.  
  351. // if (not na(cur_year_pnl[1]) and (new_year or barstate.islast))
  352. //     if (last_computed[1])
  353. //         array.pop(year_pnl)
  354. //         array.pop(year_time)
  355.        
  356. //     array.push(year_pnl , cur_year_pnl[1])
  357. //     array.push(year_time, time[1])
  358.  
  359. // last_computed := barstate.islast ? true : nz(last_computed[1])
  360.  
  361. // // Monthly P&L Table    
  362. // var monthly_table = table(na)
  363. // prec      = input(2, title = "Return Precision")
  364.  
  365. // if (barstate.islast)
  366. //     monthly_table := table.new(position.bottom_right, columns = 14, rows = array.size(year_pnl) + 1, bgcolor=#0F0F0F,border_width=1,border_color=#000000)
  367.  
  368. //     table.cell(monthly_table, 0,  0, "",     text_color=#D3D3D3, bgcolor=#0F0F0F)
  369. //     table.cell(monthly_table, 1,  0, "Jan",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  370. //     table.cell(monthly_table, 2,  0, "Feb",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  371. //     table.cell(monthly_table, 3,  0, "Mar",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  372. //     table.cell(monthly_table, 4,  0, "Apr",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  373. //     table.cell(monthly_table, 5,  0, "May",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  374. //     table.cell(monthly_table, 6,  0, "Jun",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  375. //     table.cell(monthly_table, 7,  0, "Jul",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  376. //     table.cell(monthly_table, 8,  0, "Aug",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  377. //     table.cell(monthly_table, 9,  0, "Sep",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  378. //     table.cell(monthly_table, 10, 0, "Oct",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  379. //     table.cell(monthly_table, 11, 0, "Nov",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  380. //     table.cell(monthly_table, 12, 0, "Dec",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  381. //     table.cell(monthly_table, 13, 0, "Year", text_color=#D3D3D3, bgcolor=#0F0F0F)
  382.  
  383.  
  384. //     for yi = 0 to array.size(year_pnl) - 1
  385. //         table.cell(monthly_table, 0,  yi + 1, str.tostring(year(array.get(year_time, yi))), text_color=#D3D3D3, bgcolor=#0F0F0F)
  386.        
  387. //         y_color = array.get(year_pnl, yi) > 0 ? color.lime : color.red
  388. //         table.cell(monthly_table, 13, yi + 1, str.tostring(math.round(array.get(year_pnl, yi) * 100, prec)), bgcolor = y_color)
  389.        
  390. //     for mi = 0 to array.size(month_time) - 1
  391. //         m_row   = year(array.get(month_time, mi))  - year(array.get(year_time, 0)) + 1
  392. //         m_col   = month(array.get(month_time, mi))
  393. //         m_color = array.get(month_pnl, mi) > 0 ? color.lime : color.red
  394.        
  395. //         table.cell(monthly_table, m_col, m_row, str.tostring(math.round(array.get(month_pnl, mi) * 100, prec)), bgcolor = m_color)
  396.  
  397. // ----------------- Fine Tabella risultati mensili. Per visualizzare andare nelle impostazioni proprietà e spuntare ad ogni tick -----------------
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment