Maurizio-Ciullo

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

May 7th, 2022 (edited)
191
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. // © Maurizio-Ciullo
  3.  
  4. //Il trading system completo - Swing-Trend-Trailing (Strategia Trend Following Con Swing Di Posizione) - parte 1
  5. // (Exchange= FTX) (Sottostante ETH-PERP) (Timeframe= 4H) (Direzione= LONG E SHORT) (Swing Posizione= SI) (Esclusione Ore=NO) (Esclusione Giorni=NO') (Esclusione Mesi=NO)
  6. // (Take Profit Long/Short Market = Trailing) (Take Profit Limit Long/Short= NO) (Stop Loss Limit Long/Short= -10%) (Stop Loss Market Long/Short= SI) (Trailing Stop=SI) (Stop Emergenza= NO)
  7. // (Rischio Operazione 2% Perdita Media)
  8. // (In Sample Dal=17/08/2017 Al 17/10/2020) (Out Of Sample Dal=18/10/2020 Al 15/03/2021)
  9.  
  10.  
  11. //@version=5
  12. //1. Strategia
  13. strategy(title='Bot Swing-Trend-Trailing ETH/PERP FTX 4H LONG E SHORT', overlay=true,
  14.          max_bars_back=5000, // Serve Per Caricare Più Storico Per Il Trailing Stop
  15.          pyramiding=0,
  16.          initial_capital=150,
  17.          commission_type=strategy.commission.percent,
  18.          commission_value=0.1, slippage=3,
  19.          default_qty_type=strategy.percent_of_equity,
  20.          precision=2,
  21.          default_qty_value=25.2)
  22.  
  23.  
  24. // Input
  25. input_ema = input.int(title='Media Ema', defval=90, minval=0, maxval=500)
  26. input_apertura_minima = input.float(title='perc_apertura_minima', defval=2, group='Filtri Posizione')
  27. input_apertura_massima = input.float(title='perc_apertura_massima', defval=4, group='Filtri Posizione ')
  28. input_chiusura_minima = input.float(title='perc_chiusura_minima', defval=0, group='Filtri Posizione')
  29. input_trailing_stop_trigger = input.float(title='input_trailing_stop_trigger', defval=12, group='trailing ')
  30. input_trailing_stop_close = input.float(title='input_trailing_stop_close', defval=6, group='trailing ')
  31. onlyLong = input.bool(title='Solo long', defval=false, inline='1', group='Direzione')
  32. onlyShort = input.bool(title='Solo short', defval=false, inline='1', group='Direzione')
  33. input_stop_loss_long = input.float(title='stop_loss_long', defval=10, minval=0, maxval=100, step=0.1, group='Stop Loss')
  34. input_stop_loss_short= input.float(title='stop_loss_short', defval=10, minval=0, maxval=100, step=0.1, group='Stop Loss')
  35. input_risk = input.float(title='Risk Per Trade %', defval=25.2, minval=0, maxval=100, step=0.01, group='Risk Per Trade %')
  36.  
  37.  
  38. // Calcolo del range del backtest
  39. startDate = input.int(title="Start Date",
  40.      defval=17, minval=1, maxval=31, group="Periodo")
  41. startMonth = input.int(title="Start Month",
  42.      defval=08, minval=1, maxval=12, group="Periodo")
  43. startYear = input.int(title="Start Year",
  44.      defval=2016, minval=1800, maxval=2100, group="Periodo")
  45.  
  46. endDate = input.int(title="End Date",
  47.      defval=01, minval=1, maxval=31, group="Periodo")
  48. endMonth = input.int(title="End Month",
  49.      defval=01, minval=1, maxval=12, group="Periodo")
  50. endYear = input.int(title="End Year",
  51.      defval=2121, minval=1800, maxval=2150, group="Periodo")
  52.  
  53.  
  54. inDateRange = (time >= timestamp(syminfo.timezone, startYear,
  55.          startMonth, startDate, 0, 0)) and
  56.      (time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0))
  57.  
  58.  
  59. // Start Hour Range Trading Non Attivo /////////////////////
  60. //hourTrading = input(title='sessione valida di trading', defval='0600-2300:23456')
  61. //hourRangeTrading = time(timeframe.period, hourTrading)
  62.  
  63.  
  64. //Calcolo degli indicatori
  65.  
  66. // Variabili Medie Ema
  67. ema = ta.ema(close, input_ema)
  68. ema1 = ta.ema(close[1], input_ema)
  69.  
  70. plot(ema, color=color.new(color.green, 0), title='Media_Ema', linewidth=2)
  71.  
  72.  
  73. //Calcolo filtri apertura minima
  74. apertura_minima = ema / 100 * input_apertura_minima
  75. apertura_minima1 = ema1 / 100 * input_apertura_minima
  76. apertura_massima = ema / 100 * input_apertura_massima
  77. chiusura_minima = ema / 100 * input_chiusura_minima
  78.  
  79.  
  80. // Filtri Bande Long
  81. filtro_long_basso = ema + apertura_minima
  82. filtro_long_alto = ema + apertura_massima
  83. //filtro_chiusura_minima_long =(ema - chiusura_minima)
  84.  
  85. plot_filtro_long_basso = plot(filtro_long_basso, color=color.new(color.blue, 0), title='filtro_long_basso')
  86. plot_filtro_long_alto = plot(filtro_long_alto, color=color.new(color.blue, 0), title='filtro_long_alto')
  87. fill(plot_filtro_long_basso, plot_filtro_long_alto, title='Spazio di apertura', color=color.new(color.blue, 90))
  88.  
  89.  
  90. // Filtri Bande Short
  91. filtro_short_basso = ema - apertura_minima
  92. filtro_short_alto = ema - apertura_massima
  93. //filtro_chiusura_minima_short =(ema + chiusura_minima)
  94.  
  95. plot_filtro_short_basso = plot(filtro_short_basso, color=color.new(color.red, 0), title='filtro_short_basso')
  96. plot_filtro_short_alto = plot(filtro_short_alto, color=color.new(color.red, 0), title='filtro_short_alto')
  97. fill(plot_filtro_short_basso, plot_filtro_short_alto, title='Spazio di apertura', color=color.new(color.red, 90))
  98.  
  99. //plot_filtro_chiusura_minima_long=plot(filtro_chiusura_minima_long, color=color.blue, title="filtro_chiusura_minima_long")
  100. //plot_filtro_chiusura_minima_short=plot(filtro_chiusura_minima_short, color=color.red, title="filtro_chiusura_minima_short")
  101. //fill(p5,filtro_chiusura_minima_long, title = "Spazio di chiusura long", color = color.blue)
  102. //fill(p6,filtro_chiusura_minima_short, title = "Spazio di chiusura short", color = color.red)
  103.  
  104.  
  105. // Stop Loss Long E Short
  106. stop_loss_long_price = strategy.opentrades.entry_price(0) - (strategy.opentrades.entry_price(0) * input_stop_loss_long) / 100
  107. stop_loss_long = (strategy.opentrades.entry_price(0) - stop_loss_long_price) / syminfo.mintick
  108. // target_long_price = (strategy.opentrades.entry_price(0) + ((strategy.opentrades.entry_price(0) * input_take_profit_long) / 100))
  109. // target_long = (target_long_price - strategy.opentrades.entry_price(0)) / syminfo.mintick
  110. //plot(SLL, title = "stop ticks", color=color.purple)
  111.  
  112. stop_loss_short_price = strategy.opentrades.entry_price(0) + (strategy.opentrades.entry_price(0) * input_stop_loss_short) / 100
  113. stop_loss_short = (stop_loss_short_price - strategy.opentrades.entry_price(0)) / syminfo.mintick
  114. // target_short_price = (strategy.opentrades.entry_price(0) - ((strategy.opentrades.entry_price(0) * input_take_profit_short) / 100))
  115. // target_short =(strategy.opentrades.entry_price(0) - target_short_price) / syminfo.mintick
  116. //plot(SLS, title = "stop ticks", color=color.purple)
  117.  
  118.  
  119. // Trailing Stop Long E Short
  120. trailing_stop_trigger_long = strategy.opentrades.entry_price(0) + (strategy.opentrades.entry_price(0) * input_trailing_stop_trigger)/100
  121. trailing_stop_close_long = strategy.opentrades.entry_price(0) + (strategy.opentrades.entry_price(0) * input_trailing_stop_close)/100
  122. trailing_stop_trigger_short = strategy.opentrades.entry_price(0) - (strategy.opentrades.entry_price(0) * input_trailing_stop_trigger)/100
  123. trailing_stop_close_short = strategy.opentrades.entry_price(0) - (strategy.opentrades.entry_price(0) * input_trailing_stop_close)/100
  124.  
  125.  
  126. // Originale Usato Nel codice
  127. // 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
  128. //                  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
  129. //                  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
  130. //                  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
  131. //                  high[16] >= trailing_stop_trigger_long and close < trailing_stop_close_long and close[1] > trailing_stop_close_long
  132.  
  133. // 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
  134. //                  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
  135. //                  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
  136. //                  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
  137. //                  high[16] >= trailing_stop_trigger_long and  ta.crossunder(close, trailing_stop_close_long ) and close[1] > trailing_stop_close_long
  138.  
  139.  
  140. // Originale Usato Nel Codice
  141. // 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
  142. //                   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
  143. //                   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
  144. //                   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
  145. //                   low[16] <= trailing_stop_trigger_short and close > trailing_stop_close_short and close[1] < trailing_stop_close_short
  146.  
  147. // 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
  148. //                   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
  149. //                   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
  150. //                   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
  151. //                   low[16] <= trailing_stop_trigger_short and ta.crossover(close, trailing_stop_close_short) and close[1] < trailing_stop_close_short
  152.  
  153. // Plot Ingresso In Posizione
  154. 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
  155. 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")
  156. 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")
  157. 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")
  158.  
  159. 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
  160.  
  161.  
  162. // Calcolo Uscita Trailing Stop Long E Short
  163. // Bar_index = bar_index
  164. // plot(Bar_index, title = "Bar_index")
  165.  
  166. // entry_bar_index = strategy.opentrades.entry_bar_index(0) +1
  167. // plot(entry_bar_index, title = "entry_bar_index")
  168.  
  169. range_barre_trailing = bar_index - strategy.opentrades.entry_bar_index(0) +1
  170. //plot(lunghezza_trailing, title = 'lunghezza')
  171.  
  172. highesthigh = strategy.opentrades ==1 ? ta.highest(high, range_barre_trailing): na
  173. //plot(highesthigh)
  174.  
  175. lowestlow = strategy.opentrades ==1 ? ta.lowest(low, range_barre_trailing): na
  176. //plot(lowestlow)
  177.  
  178.  
  179. // Plot No Trading Allowed giorni da 1 a 7, 1 è domenica Mesi da 1 a 12, 1 è Gennaio.
  180. //giorni_esclusi = dayofweek(time)
  181. //plotshape(giorni_esclusi[1] == 2 ? giorni_esclusi : na, color=color.green, title="giorni_esclusi")
  182. //mesi_esclusi = month(time)
  183. //plotshape(mesi_esclusi[1] == 9 ? mesi_esclusi : na, color=color.yellow, title="mesi_esclusi")
  184.  
  185.  
  186. //Condizione Entrata Long: Chiusura candela sopra media lenta con differenziale medie e media veloce maggiore media ExitLong
  187. condEntryLong = close > ema + apertura_minima and close < ema + apertura_massima and close > open  and not onlyShort and inDateRange and (close[1] < ema1 + apertura_minima or low[1] < ema1 + apertura_minima) // and dayofweek != 7 and month !=10
  188.  
  189. //Condizione Uscita Long: Crossunder di due medie
  190. condExitLong = close < ema - chiusura_minima
  191.  
  192. // Condizione Uscita Trailing Stop Long
  193. condExitLong2 =  (highesthigh > trailing_stop_trigger_long and close <= trailing_stop_close_long)
  194.  
  195. //Condizione Entrata Short: Crossunder di due medie con il prezzo di chiusura che è comunque sotto una terza media con differenziale delle medie
  196. condEntryShort = close < ema - apertura_minima and close > ema - apertura_massima and close < open  and not onlyLong and inDateRange and (close[1] > ema1 - apertura_minima or high[1] > ema1 - apertura_minima)  // and dayofweek != 7 and month !=10
  197.  
  198. //Condizione Uscita Short: Crossover di medie con il prezzo di chiusura che è comunque sopra una terza media
  199. condExitShort = close > ema + chiusura_minima
  200.  
  201. // Condizione Uscita Trailing Stop Short
  202. condExitShort2 = (lowestlow < trailing_stop_trigger_short and close >= trailing_stop_close_short)
  203.  
  204. barcolor(condEntryLong ? color.lime : condEntryShort ? color.purple : na)
  205.  
  206.  
  207. // Allerts
  208. buy_command = '{"BUY COMMAND"}'
  209. sell_command = '{"SELL COMMAND"}'
  210. close_command = '{"CLOSE COMMAND"}'
  211.  
  212.  
  213. //entrata e uscita Long
  214. if condEntryLong
  215.     strategy.entry('long', strategy.long, alert_message = "Open Long Position", comment = buy_command)
  216.     strategy.exit('stop loss long', from_entry='long', loss=stop_loss_long, alert_message = "Your Long SL Has Been Triggered.", comment = close_command)
  217.  
  218. if condExitLong
  219.     strategy.close(id='long', alert_message = "Close Long Position", comment = close_command)
  220.  
  221. if strategy.opentrades ==1 and condExitLong2
  222.     strategy.close(id='long', alert_message = "Trailing long", comment = close_command)    
  223.      
  224. //entrata e uscita Short
  225. if condEntryShort
  226.     strategy.entry('short', strategy.short, alert_message = "Open Short Position", comment = sell_command)
  227.     strategy.exit('stop loss short', from_entry='short', loss=stop_loss_short, alert_message = "Your Short SL Has Been Triggered.", comment = close_command)
  228.  
  229. if condExitShort
  230.     strategy.close(id='short', alert_message = "Close Short Position", comment = close_command)
  231.    
  232. if strategy.opentrades ==1 and condExitShort2
  233.     strategy.close(id='short', alert_message = "Trailing Short", comment = close_command)
  234.    
  235. // Nome Alert: Swing-Trend-Trailing ETH/PERP FTX 4H
  236. // Commento Alert: {{strategy.order.comment}}
  237.    
  238.    
  239. // ----------------- Inizio Tabella risultati mensili. Per visualizzare andare nelle impostazioni proprietà e spuntare ad ogni tick -----------------
  240.  
  241. // new_month = month(time) != month(time[1])
  242. // new_year  = year(time)  != year(time[1])
  243.  
  244. // eq = strategy.equity
  245.  
  246. // bar_pnl = eq / eq[1] - 1
  247.  
  248. // cur_month_pnl = 0.0
  249. // cur_year_pnl  = 0.0
  250.  
  251. // // Current Monthly P&L
  252. // cur_month_pnl := new_month ? 0.0 :
  253. //                  (1 + cur_month_pnl[1]) * (1 + bar_pnl) - 1
  254.  
  255. // // Current Yearly P&L
  256. // cur_year_pnl := new_year ? 0.0 :
  257. //                  (1 + cur_year_pnl[1]) * (1 + bar_pnl) - 1  
  258.  
  259. // // Arrays to store Yearly and Monthly P&Ls
  260. // var month_pnl  = array.new_float(0)
  261. // var month_time = array.new_int(0)
  262.  
  263. // var year_pnl  = array.new_float(0)
  264. // var year_time = array.new_int(0)
  265.  
  266. // last_computed = false
  267.  
  268. // if (not na(cur_month_pnl[1]) and (new_month or barstate.islast))
  269. //     if (last_computed[1])
  270. //         array.pop(month_pnl)
  271. //         array.pop(month_time)
  272.        
  273. //     array.push(month_pnl , cur_month_pnl[1])
  274. //     array.push(month_time, time[1])
  275.  
  276. // if (not na(cur_year_pnl[1]) and (new_year or barstate.islast))
  277. //     if (last_computed[1])
  278. //         array.pop(year_pnl)
  279. //         array.pop(year_time)
  280.        
  281. //     array.push(year_pnl , cur_year_pnl[1])
  282. //     array.push(year_time, time[1])
  283.  
  284. // last_computed := barstate.islast ? true : nz(last_computed[1])
  285.  
  286. // // Monthly P&L Table    
  287. // var monthly_table = table(na)
  288. // prec      = input(2, title = "Return Precision")
  289.  
  290. // if (barstate.islast)
  291. //     monthly_table := table.new(position.bottom_right, columns = 14, rows = array.size(year_pnl) + 1, bgcolor=#0F0F0F,border_width=1,border_color=#000000)
  292.  
  293. //     table.cell(monthly_table, 0,  0, "",     text_color=#D3D3D3, bgcolor=#0F0F0F)
  294. //     table.cell(monthly_table, 1,  0, "Jan",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  295. //     table.cell(monthly_table, 2,  0, "Feb",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  296. //     table.cell(monthly_table, 3,  0, "Mar",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  297. //     table.cell(monthly_table, 4,  0, "Apr",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  298. //     table.cell(monthly_table, 5,  0, "May",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  299. //     table.cell(monthly_table, 6,  0, "Jun",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  300. //     table.cell(monthly_table, 7,  0, "Jul",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  301. //     table.cell(monthly_table, 8,  0, "Aug",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  302. //     table.cell(monthly_table, 9,  0, "Sep",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  303. //     table.cell(monthly_table, 10, 0, "Oct",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  304. //     table.cell(monthly_table, 11, 0, "Nov",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  305. //     table.cell(monthly_table, 12, 0, "Dec",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  306. //     table.cell(monthly_table, 13, 0, "Year", text_color=#D3D3D3, bgcolor=#0F0F0F)
  307.  
  308.  
  309. //     for yi = 0 to array.size(year_pnl) - 1
  310. //         table.cell(monthly_table, 0,  yi + 1, str.tostring(year(array.get(year_time, yi))), text_color=#D3D3D3, bgcolor=#0F0F0F)
  311.        
  312. //         y_color = array.get(year_pnl, yi) > 0 ? color.lime : color.red
  313. //         table.cell(monthly_table, 13, yi + 1, str.tostring(math.round(array.get(year_pnl, yi) * 100, prec)), bgcolor = y_color)
  314.        
  315. //     for mi = 0 to array.size(month_time) - 1
  316. //         m_row   = year(array.get(month_time, mi))  - year(array.get(year_time, 0)) + 1
  317. //         m_col   = month(array.get(month_time, mi))
  318. //         m_color = array.get(month_pnl, mi) > 0 ? color.lime : color.red
  319.        
  320. //         table.cell(monthly_table, m_col, m_row, str.tostring(math.round(array.get(month_pnl, mi) * 100, prec)), bgcolor = m_color)
  321.  
  322. // ----------------- Fine Tabella risultati mensili. Per visualizzare andare nelle impostazioni proprietà e spuntare ad ogni tick -----------------
Add Comment
Please, Sign In to add comment