Advertisement
Maurizio-Ciullo

Bot Get-Back-Limit 1.6 LEO/PERP FTX 45M LONG E SHORT

Oct 27th, 2022
1,297
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. ////////////////////////////////////////////      CREATO 1 TRADING SYSTEM CON TRE VERSIONI. ////////////////////////////////////////////
  5. //////////////////////////////////    2° VERSIONE 1.6: CON MYEXITCOUNTBAR / TAKE PROFIT / INGRESSO LIMIT   //////////////////////////////////
  6.  
  7. // Il trading system completo - Get-Back-Market 1.6 Ver-5 (Strategia Reversal/Swing)
  8. // (Exchange= FTX) (Sottostante LEO-PERP) (Timeframe= 45M) (Direzione= LONG E SHORT) (Swing Posizione= SI) (Esclusione Ore=NO) (Esclusione Giorni=NO') (Esclusione Mesi=NO)
  9. // (Take Profit Long/Short Market = NO) (Take Profit Limit Long/Short= 9%) (Stop Loss Limit Long/Short= -12% Tradingview-Hub)
  10. // (Stop Loss Market Long/Short= NO) (Trailing Stop=NO) (Stop Emergenza= NO) (Uscita Numero Candele Market Long/Short= SI)
  11. // (Ingressi Limit = SI)
  12. // (Rischio Operazione 11.92% Drawdown Massimo)
  13. // (In Sample Dal=19/02/21 Al 12/04/22) (Out Of Sample Dal=12/04/22 Al 25/08/22)
  14. // (Progettatta Il=25/08/22)
  15.  
  16. // Nota su tradestation caricare sessione 23:00 23:00 tutti e 7 i giorni, solo che mi da un problema e non mi fa caricare l'ultima sessione.
  17. // Per questo motivo invece di usare: highd0 = HighSession(0,0); stò usando: (HighD(0)); Sostituendo le sessioni con i giorni temporali.
  18. // Per FTX Su Tradestation: Exchange Time, Regular Session, 7x7 23:00 23:00, Session Hour.
  19.  
  20.  
  21. //@version=5
  22. strategy(title="Bot Get-Back-Limit 1.6 LEO/PERP FTX 45M LONG E SHORT", overlay=true, precision = 4,
  23.      //max_bars_back=5000, // Serve Per Caricare Più Storico Per Il Trailing Stop
  24.      pyramiding=0,
  25.      initial_capital=150,
  26.      commission_type=strategy.commission.percent,
  27.      commission_value=0.1,
  28.      slippage=3, // ATTENZIONE LO SLIPPAGE CON INGRESSI LIMIT NON VIENE SEGNATO SU TRADINGVIEW
  29.      default_qty_type=strategy.percent_of_equity,
  30.      default_qty_value=20)
  31.      
  32.  
  33. // Input
  34. input_sma = input.int(title='Media BB', defval=20, minval=0, maxval=50, group='Bande')
  35. input_deviazione_st = input.float(title='Deviazione_st', defval=2.0, step=0.1, group='Bande')
  36. input_stop_loss_long = input.float(title='stop_loss_long', defval=12, minval=0, maxval=100, step=0.1, group='Stop&Target')
  37. input_take_profit_long = input.float(title='take_profit_long', defval=9, minval=0, maxval=100, step=0.1, group='Take Profit')
  38. input_stop_loss_short = input.float(title='stop_loss_short', defval=12, minval=0, maxval=100, step=0.1, group='Stop&Target')
  39. input_take_profit_short = input.float(title='take_profit_short', defval=9, minval=0, maxval=100, step=0.1, group='Take Profit')
  40. input_MyExitCountBarL = input.int(title='MyExitCountBarL', defval=76, minval=0, maxval=500, group='Exit Bars Counter')
  41. input_MyExitCountBarS = input.int(title='MyExitCountBarS', defval=53, minval=0, maxval=500, group='Exit Bars Counter')
  42. // only_Long = input.bool(title='Solo long trade', defval=false, inline='1', group='Direzione')
  43. // only_Short = input.bool(title='Solo short trade', defval=false, inline='1', group='Direzione')
  44.  
  45.  
  46. // Calcolo del range del backtest
  47. startDate = input.int(title="Start Date",
  48.      defval=1, minval=1, maxval=31, group="Periodo")
  49. startMonth = input.int(title="Start Month",
  50.      defval=02, minval=1, maxval=12, group="Periodo")
  51. startYear = input.int(title="Start Year",
  52.      defval=2010, minval=1800, maxval=2150, group="Periodo")
  53.  
  54. endDate = input.int(title="End Date",
  55.      defval=01, minval=1, maxval=31, group="Periodo")
  56. endMonth = input.int(title="End Month",
  57.      defval=01, minval=1, maxval=12, group="Periodo")
  58. endYear = input.int(title="End Year",
  59.      defval=2121, minval=1800, maxval=2150, group="Periodo")
  60.  
  61.  
  62. inDateRange = (time >= timestamp(syminfo.timezone, startYear,
  63.          startMonth, startDate, 0, 0)) and
  64.      (time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0))
  65.  
  66.  
  67. // Start Hour Range Trading Non Attivo /////////////////////
  68. //hourTrading = input(title='sessione valida di trading', defval='0600-2300:23456')
  69. //hourRangeTrading = time(timeframe.period, hourTrading)
  70.  
  71.  
  72. ///////////////////  Start Detecting High0 Session  ///////////////////
  73.  
  74. // Configure session with inputs
  75. session_high  = input.session("0000-2300", title="Trading Session")
  76. timeZone_high = input.string("GMT", title="Time Zone")
  77.  
  78. // SessionHigh() returns the highest price during the specified
  79. // session, optionally corrected for the given time zone.
  80. // Returns 'na' when the session hasn't started or isn't on the chart.
  81. SessionHigh(sessionTime, sessionTimeZone=syminfo.timezone) =>
  82.     insideSession = not na(time(timeframe.period, sessionTime, sessionTimeZone))
  83.     var float sessionHighPrice = na
  84.  
  85.     if insideSession and not insideSession[1]
  86.         sessionHighPrice := high
  87.     else if not insideSession and high > sessionHighPrice // Inserito personalmente perchè se fuori sessione e massimo più alto non aggiornava
  88.         sessionHighPrice := high // // Inserito personalmente perchè se fuori sessione e massimo più alto non aggiornava
  89.     else if insideSession
  90.         sessionHighPrice := math.max(sessionHighPrice, high)
  91.    
  92.     sessionHighPrice
  93.  
  94. // InSession() returns 'true' when the current bar happens inside
  95. // the specified session, corrected for the given time zone (optional).
  96. // Returns 'false' when the bar doesn't happen in that time period,
  97. // or when the chart's time frame is 1 day or higher.
  98. InSessionHigh(sessionTimes, sessionTimeZone=syminfo.timezone) =>
  99.     not na(time(timeframe.period, sessionTimes, sessionTimeZone))
  100.  
  101. // Get the session high
  102. highd0 = SessionHigh(session_high, timeZone_high)
  103.  
  104. // Show the session high on the chart
  105. //plot(highd0, color=color.green, title="Highd0")
  106.  
  107. // For visual verification, highlight the background of session bars
  108. bgcolor(InSessionHigh(session_high, timeZone_high) ? color.new(color.orange, 90) : na)
  109.  
  110. // ///////////////////  End Detecting High0 Session  ///////////////////
  111.  
  112.  
  113. // ///////////////////  Start Detecting Low0 Session  ///////////////////
  114.  
  115. // Configure session with inputs
  116. session_low  = input.session("0000-2300", title="Trading Session")                                  
  117. timeZone_low = input.string("GMT", title="Time Zone")
  118.  
  119. // SessionLow() returns the lowest price during the specified
  120. // session, optionally corrected for the given time zone.
  121. // Returns 'na' when the session hasn't started or isn't on the chart.
  122. SessionLow(sessionTime, sessionTimeZone=syminfo.timezone) =>                                      
  123.     insideSession = not na(time(timeframe.period, sessionTime, sessionTimeZone))
  124.     var float sessionLowPrice = na
  125.  
  126.     if insideSession and not insideSession[1]
  127.         sessionLowPrice := low
  128.     else if not insideSession and low < sessionLowPrice // Inserito personalmente perchè se fuori sessione e minimo più basso non aggiornava
  129.         sessionLowPrice := low // // Inserito personalmente perchè se fuori sessione e minimo più basso non aggiornava
  130.     else if insideSession
  131.         sessionLowPrice := math.min(sessionLowPrice, low)
  132.    
  133.     sessionLowPrice
  134.  
  135. // InSession() returns 'true' when the current bar happens inside
  136. // the specified session, corrected for the given time zone (optional).
  137. // Returns 'false' when the bar doesn't happen in that time period,
  138. // or when the chart's time frame is 1 day or higher.
  139. InSessionLow(sessionTimes, sessionTimeZone=syminfo.timezone) =>
  140.     not na(time(timeframe.period, sessionTimes, sessionTimeZone))
  141.  
  142. // Get the session low
  143. lowd0 = SessionLow(session_low, timeZone_low)
  144.  
  145. // Show the session low on the chart
  146. //plot(lowd0, color=color.red, title="Lowd0")
  147.  
  148. // For visual verification, lowest the background of session bars
  149. //bgcolor(InSessionLow(session_low, timeZone_low) ? color.new(color.orange, 90) : na)
  150.  
  151. // ///////////////////  End Detecting Low0 Session  ///////////////////
  152.  
  153.  
  154. PtnBaseSACrypto12  = ((highd0>(lowd0+lowd0*0.75/100)))                    
  155. //plotshape(PtnBaseSA12, "PtnBaseSA12")
  156.  
  157.  
  158. ///////////////////  Start Detecting Open0 Session  ///////////////////
  159.  
  160. // Configure session with inputs
  161. session_open  = input.session("0000-2300", title="Trading Session")                                  
  162. timeZone_open = input.string("GMT", title="Time Zone")
  163.  
  164. // SessionOpen() returns the open price during the specified
  165. // session, optionally corrected for the given time zone.
  166. // Returns 'na' when the session hasn't started or isn't on the chart.
  167. SessionOpen(sessionTime, sessionTimeZone=syminfo.timezone) =>                                      
  168.     insideSession = not na(time(timeframe.period, sessionTime, sessionTimeZone))
  169.     var float sessionOpenPrice = na
  170.  
  171.     if insideSession and not insideSession[1]
  172.         sessionOpenPrice := open
  173.     //else if not insideSession and open < sessionOpenPrice // Inserito personalmente perchè se fuori sessione e minimo più basso non aggiornava
  174.         //sessionLowPrice := open // // Inserito personalmente perchè se fuori sessione e minimo più basso non aggiornava
  175.         // else if insideSession
  176.         //     sessionOpenPrice := (sessionOpenPrice, open)
  177.    
  178.     sessionOpenPrice
  179.  
  180. // InSession() returns 'true' when the current bar happens inside
  181. // the specified session, corrected for the given time zone (optional).
  182. // Returns 'false' when the bar doesn't happen in that time period,
  183. // or when the chart's time frame is 1 day or higher.
  184. InSessionOpen(sessionTimes, sessionTimeZone=syminfo.timezone) =>
  185.     not na(time(timeframe.period, sessionTimes, sessionTimeZone))
  186.  
  187. // Get the session open
  188. opend0 = SessionOpen(session_open, timeZone_open)
  189.  
  190. // Show the session open on the chart
  191. //plot(opend0, color=color.yellow, title="open0")
  192.  
  193. // For visual verification, lowest the background of session bars
  194. //bgcolor(InSessionOpen(session_open, timeZone_open) ? color.new(color.orange, 90) : na)
  195.      
  196. ///////////////////  End Detecting Open0 Session  ///////////////////
  197.  
  198.  
  199. ///////////////////  Start Detecting HighD1 Session  ///////////////////
  200.  
  201. highd1 = request.security(syminfo.tickerid, "D", high[1], lookahead = barmerge.lookahead_on)
  202. //plot(highd1, title="highd1")
  203.  
  204. // ///////////////////  End Detecting HighD1 Session  ///////////////////
  205.  
  206.  
  207. // ///////////////////  Start Detecting OpenD1 Session  ///////////////////
  208.  
  209. opend1 = request.security(syminfo.tickerid, "D", open[1], lookahead = barmerge.lookahead_on)
  210. //plot(opend1, title="opend1")
  211.  
  212. // ///////////////////  End Detecting OpenD1 Session  ///////////////////
  213.          
  214.  
  215. PtnBaseSACrypto4  = ((highd0-opend0)> ((highd1-opend1)*1))                            
  216. //plotshape(PtnBaseSA4, title="PtnBaseSA4")
  217.  
  218.  
  219. ///////////////////  Start Detecting LowD1 Session  ///////////////////
  220.      
  221. lowd1 = request.security(syminfo.tickerid, "D", low[1], lookahead = barmerge.lookahead_on)
  222. //plot(lowd1, title="lowd1")    
  223.      
  224.  ///////////////////  End Detecting LowD1 Session  ///////////////////    
  225.  
  226.  
  227.  ///////////////////  Start Detecting LowD2 Session  ///////////////////
  228.      
  229. lowd2 = request.security(syminfo.tickerid, "D", low[2], lookahead = barmerge.lookahead_on)
  230. //plot(lowd2, title="lowd2")    
  231.      
  232.  ///////////////////  End Detecting LowD2 Session  ///////////////////
  233.  
  234.  
  235.   ///////////////////  Start Detecting LowD3 Session  ///////////////////
  236.      
  237. lowd3 = request.security(syminfo.tickerid, "D", low[3], lookahead = barmerge.lookahead_on)
  238. //lot(lowd3, title="lowd3")    
  239.      
  240.  ///////////////////  End Detecting LowD3 Session  ///////////////////
  241.  
  242.  
  243.  ///////////////////  Start Detecting LowD4 Session  ///////////////////
  244.      
  245. lowd4 = request.security(syminfo.tickerid, "D", low[4], lookahead = barmerge.lookahead_on)
  246. //plot(lowd4, title="lowd4")    
  247.      
  248.  ///////////////////  End Detecting LowD4 Session  ///////////////////
  249.      
  250.  
  251. PtnBaseSACrypto27  = ((lowd1>lowd2) and (lowd1>lowd3) and (lowd1<lowd4))              
  252. //plotshape(PtnBaseSA27, "PtnBaseSA27")
  253.  
  254.  
  255. PtnBaseSACrypto6  = ((opend0-lowd0)> ((opend1-lowd1)*1))                              
  256. //plotshape(PtnBaseSA6, "PtnBaseSA6")
  257.  
  258.  
  259. // Calculate MyEntryCountBar
  260. MyEntryCountBar = bar_index - strategy.opentrades.entry_bar_index(0)
  261. MyEntryCountBar := MyEntryCountBar + 1
  262. //plot(MyEntryCountBar, title="MyEntryCountBar")
  263. // plot(bar_index, title="bar_index")
  264. // plot(strategy.opentrades.entry_bar_index(0), title="strategy.open")
  265. plotshape(MyEntryCountBar >  input_MyExitCountBarL and strategy.position_size > 0, text="MyExitCountBarL")
  266. plotshape(MyEntryCountBar > input_MyExitCountBarS and strategy.position_size < 0, text="MyExitCountBarS")
  267.  
  268.  
  269. //  Bollinger Bands
  270. middle_Band = ta.sma(close, input_sma)
  271. deviazione_st = input_deviazione_st * ta.stdev(close, input_sma)
  272. UpperBand = middle_Band + deviazione_st
  273. LowerBand = middle_Band - deviazione_st
  274. plot(middle_Band, color=color.new(color.green, 0), title='B_middle Band')
  275. plot(UpperBand, color=color.new(color.green, 0), title='UpperBand')
  276. plot(LowerBand, color=color.new(color.green, 0), title='LowerBand')
  277.  
  278.  
  279. // Variabili Stop E Take Profit Long
  280. stop_loss_long_price = (strategy.opentrades.entry_price(0) - (strategy.opentrades.entry_price(0) * input_stop_loss_long) / 100)
  281. stop_loss_long = (strategy.opentrades.entry_price(0) - stop_loss_long_price) / syminfo.mintick
  282. take_profit_long_price = (strategy.opentrades.entry_price(0) + ((strategy.opentrades.entry_price(0) * input_take_profit_long) / 100))
  283. take_profit_long = (take_profit_long_price - strategy.opentrades.entry_price(0)) / syminfo.mintick
  284.  
  285. // Variabili Stop E Take Profit Short
  286. stop_loss_short_price = (strategy.opentrades.entry_price(0) + (strategy.opentrades.entry_price(0) * input_stop_loss_short) / 100)
  287. stop_loss_short = (stop_loss_short_price - strategy.opentrades.entry_price(0)) / syminfo.mintick
  288. take_profit_short_price = (strategy.opentrades.entry_price(0) - ((strategy.opentrades.entry_price(0) * input_take_profit_short) / 100))
  289. take_profit_short =(strategy.opentrades.entry_price(0) - take_profit_short_price) / syminfo.mintick
  290.  
  291. 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
  292. plot(strategy.position_size > 0 ?  take_profit_long_price : strategy.position_size < 0 ? take_profit_short_price: na, color=color.green, style=plot.style_cross, linewidth=2, title="tk_limit")
  293. 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")
  294.  
  295.  
  296. 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 //color.new(color.red, 99): na)
  297.  
  298.  
  299. // Plot No Trading Allowed giorni da 1 a 7 1 è domenica. Mesi da 1 a 12 1 è Gennaio. //
  300.  
  301. // giorni_esclusi = dayofweek(time)
  302. // plotshape(giorni_esclusi[1] == 2 ? giorni_esclusi : na, color=color.green, title="giorni_esclusi")
  303. // mesi_esclusi = month(time)
  304. // plotshape(mesi_esclusi[1] == 9 ? mesi_esclusi : na, color=color.yellow, title="mesi_esclusi")
  305.  
  306.  
  307. // Qui abbiamo in delay buy, sell, close command: ,"delay":"15" per dare il tempo di cancellare prima eventuali ordini pendenti e poi entrare in posizione
  308. // Il cancel command non deve avere il delay.
  309. buy_command = 'BUY_COMMAND,"delay":"15"}'
  310. sell_command = 'SELL_COMMAND,"delay":"15"}'
  311. close_command = 'CLOSE_COMMAND,"delay":"15"}'
  312. //cancel_command = 'CANCEL_COMMAND, NO_DELAY'
  313.  
  314.  
  315. // Condizione Entrata Long
  316. condEntryLong = ta.crossover(close, LowerBand)  and PtnBaseSACrypto12 == true and PtnBaseSACrypto27 == false and inDateRange//and not only_Short and month != 4 and month != 8
  317. //Condizione Entrata Short
  318. condEntryShort = ta.crossunder(close, UpperBand)  and PtnBaseSACrypto4 == true and PtnBaseSACrypto6 == false and inDateRange//and not only_Long and month != 4 and month != 8 and not only_Short
  319.  
  320. // Long
  321. // Cancel the pending long/short entry orders if not filled or if filled, that happens only before the next signal "entry/exit/"
  322. // Se si riscontrano problemi con la cancellazione di ordini togliere il delay sul close command
  323. if condEntryLong and strategy.position_size <0 or condEntryLong and strategy.position_size ==0 //or strategy.position_size >0 and MyEntryCountBar > input_MyExitCountBarL
  324.     strategy.cancel_all()
  325.     alert(message='CANCEL_COMMAND, NO_DELAY', freq=alert.freq_once_per_bar_close)
  326. plotshape(condEntryLong and strategy.position_size <0 or condEntryLong and strategy.position_size ==0, text="Cancel_Pendings")
  327.  
  328. // Entrata Long
  329. if condEntryLong //and strategy.opentrades == 0
  330.     strategy.entry('operazioneLong', strategy.long, limit = close, alert_message = "Open Long Position", comment = buy_command)
  331.  
  332. // Uscita Long (stop/limit x prezzo) (loss/profit x ticks)
  333. if strategy.opentrades ==1
  334.     strategy.exit('SL e TP', from_entry='operazioneLong', loss=stop_loss_long, profit=take_profit_long, alert_message = "Your Long SL-TP Has Been Triggered.", comment = close_command) //limit=take_profit_long_price
  335.  
  336. // Uscita Long Exit Count Bar
  337. if strategy.opentrades ==1 and MyEntryCountBar > input_MyExitCountBarL
  338.     strategy.close(id='operazioneLong', alert_message = "Close Long Position", comment = close_command)
  339.  
  340.  
  341. // Short
  342. // Cancel the pending long/short entry orders if not filled or if filled, that happens only before the next signal "entry/exit/"
  343. // Se si riscontrano problemi con la cancellazione di ordini togliere il delay sul close command
  344. if condEntryShort and strategy.position_size >0 or condEntryShort and strategy.position_size ==0 //or strategy.position_size <0 and MyEntryCountBar > input_MyExitCountBarS
  345.     strategy.cancel_all()
  346.     alert(message='CANCEL_COMMAND, NO_DELAY', freq=alert.freq_once_per_bar_close)
  347. plotshape(condEntryShort and strategy.position_size >0 or condEntryShort and strategy.position_size ==0, text="Cancel_Pendings")
  348.  
  349. // Entrata Short
  350. if condEntryShort //and strategy.opentrades == 0
  351.     strategy.entry('operazioneShort', strategy.short, limit = close, alert_message = "Open Short Position", comment = sell_command)
  352.  
  353. // Uscita Short (stop/limit x prezzo) (loss/profit x ticks)
  354. if strategy.opentrades == 1
  355.     strategy.exit('SL e TP', from_entry='operazioneShort', loss=stop_loss_short, profit=take_profit_short, alert_message = "Your Long SL-TP Has Been Triggered.", comment = close_command) //limit=take_profit_short_price    
  356.  
  357. // Uscita Short Exit Count Bar
  358. if strategy.opentrades ==1 and MyEntryCountBar > input_MyExitCountBarS
  359.     strategy.close(id='operazioneShort', alert_message = "Close Short Position", comment = close_command)
  360.  
  361.  
  362. // Nome Alert: Get-Back-Limit 1.6 LEO/PERP FTX 45M
  363. // Commento Alert: {{strategy.order.comment}}
  364.  
  365.  
  366. // ------- Inizio Calcolatore Size Posizioni Aperte E Size Posizioni Residue E Segna Con Una Croce Se Abbiamo Realizzato Un Profitto ------- //
  367.                                    // Il Segno Croce Profitto Realizzato Non Funziona Sullo Swing Posizione //
  368.  
  369. // bought = strategy.position_size[0]> strategy.position_size[1]
  370. // Close_TP = false    
  371. // Close_TP := strategy.position_size[1] - strategy.position_size[0] and strategy.position_size[1] != 0 and strategy.position_size[0] != 0
  372.    
  373. // plotshape(Close_TP,title="Close_TP", style=shape.xcross, color=color.blue, size =size.small, editable = true)
  374. // plot(strategy.position_size[1],"Position Old")
  375. // plot(strategy.position_size,"Position")
  376.  
  377. // ------- Fine Calcolatore Size Posizioni Aperte E Size Posizioni Residue E Segna Con Una Croce Se Abbiamo Realizzato Un Profitto ------- //
  378.  
  379.  
  380. // ----------------- Inizio Tabella risultati mensili. Per visualizzare andare nelle impostazioni proprietà e spuntare ad ogni tick -----------------
  381.  
  382. // new_month = month(time) != month(time[1])
  383. // new_year  = year(time)  != year(time[1])
  384.  
  385. // eq = strategy.equity
  386.  
  387. // bar_pnl = eq / eq[1] - 1
  388.  
  389. // cur_month_pnl = 0.0
  390. // cur_year_pnl  = 0.0
  391.  
  392. // // Current Monthly P&L
  393. // cur_month_pnl := new_month ? 0.0 :
  394. //                  (1 + cur_month_pnl[1]) * (1 + bar_pnl) - 1
  395.  
  396. // // Current Yearly P&L
  397. // cur_year_pnl := new_year ? 0.0 :
  398. //                  (1 + cur_year_pnl[1]) * (1 + bar_pnl) - 1  
  399.  
  400. // // Arrays to store Yearly and Monthly P&Ls
  401. // var month_pnl  = array.new_float(0)
  402. // var month_time = array.new_int(0)
  403.  
  404. // var year_pnl  = array.new_float(0)
  405. // var year_time = array.new_int(0)
  406.  
  407. // last_computed = false
  408.  
  409. // if (not na(cur_month_pnl[1]) and (new_month or barstate.islast))
  410. //     if (last_computed[1])
  411. //         array.pop(month_pnl)
  412. //         array.pop(month_time)
  413.  
  414. //     array.push(month_pnl , cur_month_pnl[1])
  415. //     array.push(month_time, time[1])
  416.  
  417. // if (not na(cur_year_pnl[1]) and (new_year or barstate.islast))
  418. //     if (last_computed[1])
  419. //         array.pop(year_pnl)
  420. //         array.pop(year_time)
  421.  
  422. //     array.push(year_pnl , cur_year_pnl[1])
  423. //     array.push(year_time, time[1])
  424.  
  425. // last_computed := barstate.islast ? true : nz(last_computed[1])
  426.  
  427. // // Monthly P&L Table    
  428. // var monthly_table = table(na)
  429. // prec      = input(2, title = "Return Precision")
  430.  
  431. // if (barstate.islast)
  432. //     monthly_table := table.new(position.bottom_right, columns = 14, rows = array.size(year_pnl) + 1, bgcolor=#0F0F0F,border_width=1,border_color=#000000)
  433.  
  434. //     table.cell(monthly_table, 0,  0, "",     text_color=#D3D3D3, bgcolor=#0F0F0F)
  435. //     table.cell(monthly_table, 1,  0, "Jan",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  436. //     table.cell(monthly_table, 2,  0, "Feb",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  437. //     table.cell(monthly_table, 3,  0, "Mar",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  438. //     table.cell(monthly_table, 4,  0, "Apr",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  439. //     table.cell(monthly_table, 5,  0, "May",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  440. //     table.cell(monthly_table, 6,  0, "Jun",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  441. //     table.cell(monthly_table, 7,  0, "Jul",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  442. //     table.cell(monthly_table, 8,  0, "Aug",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  443. //     table.cell(monthly_table, 9,  0, "Sep",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  444. //     table.cell(monthly_table, 10, 0, "Oct",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  445. //     table.cell(monthly_table, 11, 0, "Nov",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  446. //     table.cell(monthly_table, 12, 0, "Dec",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  447. //     table.cell(monthly_table, 13, 0, "Year", text_color=#D3D3D3, bgcolor=#0F0F0F)
  448.  
  449.  
  450. //     for yi = 0 to array.size(year_pnl) - 1
  451. //         table.cell(monthly_table, 0,  yi + 1, str.tostring(year(array.get(year_time, yi))), text_color=#D3D3D3, bgcolor=#0F0F0F)
  452.  
  453. //         y_color = array.get(year_pnl, yi) > 0 ? color.lime : color.red
  454. //         table.cell(monthly_table, 13, yi + 1, str.tostring(math.round(array.get(year_pnl, yi) * 100, prec)), bgcolor = y_color)
  455.  
  456. //     for mi = 0 to array.size(month_time) - 1
  457. //         m_row   = year(array.get(month_time, mi))  - year(array.get(year_time, 0)) + 1
  458. //         m_col   = month(array.get(month_time, mi))
  459. //         m_color = array.get(month_pnl, mi) > 0 ? color.lime : color.red
  460.  
  461. //         table.cell(monthly_table, m_col, m_row, str.tostring(math.round(array.get(month_pnl, mi) * 100, prec)), bgcolor = m_color)
  462.  
  463. // ----------------- Fine Tabella risultati mensili. Per visualizzare andare nelle impostazioni proprietà e spuntare ad ogni tick -----------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement