Advertisement
Maurizio-Ciullo

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

Oct 27th, 2022
1,290
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 / INGRESO MARKET   //////////////////////////////////
  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 Market = SI)
  12. // (Rischio Operazione 15% 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-Market 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=50,
  29.      default_qty_type=strategy.percent_of_equity,
  30.      default_qty_value=23)
  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. PtnBaseSA12  = ((highd0>(lowd0+lowd0*0.75/100)))                     // Sostituirlo Con Il Nome: PtnBaseSACrypto12
  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. PtnBaseSA4  = ((highd0-opend0)> ((highd1-opend1)*1))                            // Sostituirlo Con Il Nome: PtnBaseSACrypto4
  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. PtnBaseSA27  = ((lowd1>lowd2) and (lowd1>lowd3) and (lowd1<lowd4))              // Sostituirlo Con Il Nome: PtnBaseSACrypto27
  252. //plotshape(PtnBaseSA27, "PtnBaseSA27")
  253.  
  254.  
  255. PtnBaseSA6  = ((opend0-lowd0)> ((opend1-lowd1)*1))                              // Sostituirlo Con Il Nome: PtnBaseSACrypto6
  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. buy_command = '{"pair":"LEO-PERP","unitsPercent":"15","unitsType":"percentBalance","exchange":"Ftx","apiKey":"FTX","token":"e6d67d6e-1a5f-4e53-a9fd-6276dfa2a34b","isBuy":true,"isMarket":true,"stopLossPercent":"-12","stopLossType":"percent","leverage":1,"marginType":"ISOLATED","targets":[{"idx":1,"amount":"100","takeProfitPercent":"9"}],"targetType":"percent","targetAmountInPercent":true,"closeCurrentPosition":true,"preventPyramiding":true,"cancelAllOrders":true,"subAccount":"Get-Back1.6-LEO-PERP-FTX-45M"}'
  308. sell_command = '{"pair":"LEO-PERP","unitsPercent":"15","unitsType":"percentBalance","exchange":"Ftx","apiKey":"FTX","token":"e6d67d6e-1a5f-4e53-a9fd-6276dfa2a34b","isSell":true,"isMarket":true,"stopLossPercent":"-12","stopLossType":"percent","leverage":1,"marginType":"ISOLATED","targets":[{"idx":1,"amount":"100","takeProfitPercent":"9"}],"targetType":"percent","targetAmountInPercent":true,"closeCurrentPosition":true,"preventPyramiding":true,"cancelAllOrders":true,"subAccount":"Get-Back1.6-LEO-PERP-FTX-45M"}'
  309. close_command = '{"pair":"LEO-PERP","unitsPercent":"15","exchange":"Ftx","apiKey":"FTX","token":"e6d67d6e-1a5f-4e53-a9fd-6276dfa2a34b","isClose":true,"subAccount":"Get-Back1.6-LEO-PERP-FTX-45M"}'
  310.  
  311.  
  312. // Condizione Entrata Long
  313. condEntryLong = ta.crossover(close, LowerBand)  and PtnBaseSA12 == true and PtnBaseSA27 == false and inDateRange//and not only_Short and month != 4 and month != 8
  314.  
  315. // Entrata Long
  316. if condEntryLong //and strategy.opentrades == 0
  317.     strategy.entry('operazioneLong', strategy.long, alert_message = "Open Long Position", comment = buy_command)
  318.  
  319. // Uscita Long (stop/limit x prezzo) (loss/profit x ticks)
  320. if strategy.opentrades ==1
  321.     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
  322.  
  323. // Uscita Long Exit Count Bar
  324. if strategy.opentrades ==1 and MyEntryCountBar > input_MyExitCountBarL
  325.     strategy.close(id='operazioneLong', alert_message = "Close Long Position", comment = close_command)
  326.  
  327.  
  328. //Condizione Entrata Short
  329. condEntryShort = ta.crossunder(close, UpperBand)  and PtnBaseSA4 == true and PtnBaseSA6 == false and inDateRange//and not only_Long and month != 4 and month != 8 and not only_Short
  330.  
  331. // Entrata Short
  332. if condEntryShort //and strategy.opentrades == 0
  333.     strategy.entry('operazioneShort', strategy.short, alert_message = "Open Short Position", comment = sell_command)
  334.  
  335. // Uscita Short (stop/limit x prezzo) (loss/profit x ticks)
  336. if strategy.opentrades == 1
  337.     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    
  338.  
  339. // Uscita Short Exit Count Bar
  340. if strategy.opentrades ==1 and MyEntryCountBar > input_MyExitCountBarS
  341.     strategy.close(id='operazioneShort', alert_message = "Close Short Position", comment = close_command)
  342.  
  343.  
  344. // Nome Alert: Get-Back 1.6 LEO/PERP FTX 45M
  345. // Commento Alert: {{strategy.order.comment}}
  346.  
  347.  
  348. // ------- Inizio Calcolatore Size Posizioni Aperte E Size Posizioni Residue E Segna Con Una Croce Se Abbiamo Realizzato Un Profitto ------- //
  349.                                    // Il Segno Croce Profitto Realizzato Non Funziona Sullo Swing Posizione //
  350.  
  351. // bought = strategy.position_size[0]> strategy.position_size[1]
  352. // Close_TP = false    
  353. // Close_TP := strategy.position_size[1] - strategy.position_size[0] and strategy.position_size[1] != 0 and strategy.position_size[0] != 0
  354.    
  355. // plotshape(Close_TP,title="Close_TP", style=shape.xcross, color=color.blue, size =size.small, editable = true)
  356. // plot(strategy.position_size[1],"Position Old")
  357. // plot(strategy.position_size,"Position")
  358.  
  359. // ------- Fine Calcolatore Size Posizioni Aperte E Size Posizioni Residue E Segna Con Una Croce Se Abbiamo Realizzato Un Profitto ------- //
  360.  
  361.  
  362. // ----------------- Inizio Tabella risultati mensili. Per visualizzare andare nelle impostazioni proprietà e spuntare ad ogni tick -----------------
  363.  
  364. // new_month = month(time) != month(time[1])
  365. // new_year  = year(time)  != year(time[1])
  366.  
  367. // eq = strategy.equity
  368.  
  369. // bar_pnl = eq / eq[1] - 1
  370.  
  371. // cur_month_pnl = 0.0
  372. // cur_year_pnl  = 0.0
  373.  
  374. // // Current Monthly P&L
  375. // cur_month_pnl := new_month ? 0.0 :
  376. //                  (1 + cur_month_pnl[1]) * (1 + bar_pnl) - 1
  377.  
  378. // // Current Yearly P&L
  379. // cur_year_pnl := new_year ? 0.0 :
  380. //                  (1 + cur_year_pnl[1]) * (1 + bar_pnl) - 1  
  381.  
  382. // // Arrays to store Yearly and Monthly P&Ls
  383. // var month_pnl  = array.new_float(0)
  384. // var month_time = array.new_int(0)
  385.  
  386. // var year_pnl  = array.new_float(0)
  387. // var year_time = array.new_int(0)
  388.  
  389. // last_computed = false
  390.  
  391. // if (not na(cur_month_pnl[1]) and (new_month or barstate.islast))
  392. //     if (last_computed[1])
  393. //         array.pop(month_pnl)
  394. //         array.pop(month_time)
  395.  
  396. //     array.push(month_pnl , cur_month_pnl[1])
  397. //     array.push(month_time, time[1])
  398.  
  399. // if (not na(cur_year_pnl[1]) and (new_year or barstate.islast))
  400. //     if (last_computed[1])
  401. //         array.pop(year_pnl)
  402. //         array.pop(year_time)
  403.  
  404. //     array.push(year_pnl , cur_year_pnl[1])
  405. //     array.push(year_time, time[1])
  406.  
  407. // last_computed := barstate.islast ? true : nz(last_computed[1])
  408.  
  409. // // Monthly P&L Table    
  410. // var monthly_table = table(na)
  411. // prec      = input(2, title = "Return Precision")
  412.  
  413. // if (barstate.islast)
  414. //     monthly_table := table.new(position.bottom_right, columns = 14, rows = array.size(year_pnl) + 1, bgcolor=#0F0F0F,border_width=1,border_color=#000000)
  415.  
  416. //     table.cell(monthly_table, 0,  0, "",     text_color=#D3D3D3, bgcolor=#0F0F0F)
  417. //     table.cell(monthly_table, 1,  0, "Jan",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  418. //     table.cell(monthly_table, 2,  0, "Feb",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  419. //     table.cell(monthly_table, 3,  0, "Mar",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  420. //     table.cell(monthly_table, 4,  0, "Apr",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  421. //     table.cell(monthly_table, 5,  0, "May",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  422. //     table.cell(monthly_table, 6,  0, "Jun",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  423. //     table.cell(monthly_table, 7,  0, "Jul",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  424. //     table.cell(monthly_table, 8,  0, "Aug",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  425. //     table.cell(monthly_table, 9,  0, "Sep",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  426. //     table.cell(monthly_table, 10, 0, "Oct",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  427. //     table.cell(monthly_table, 11, 0, "Nov",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  428. //     table.cell(monthly_table, 12, 0, "Dec",  text_color=#D3D3D3, bgcolor=#0F0F0F)
  429. //     table.cell(monthly_table, 13, 0, "Year", text_color=#D3D3D3, bgcolor=#0F0F0F)
  430.  
  431.  
  432. //     for yi = 0 to array.size(year_pnl) - 1
  433. //         table.cell(monthly_table, 0,  yi + 1, str.tostring(year(array.get(year_time, yi))), text_color=#D3D3D3, bgcolor=#0F0F0F)
  434.  
  435. //         y_color = array.get(year_pnl, yi) > 0 ? color.lime : color.red
  436. //         table.cell(monthly_table, 13, yi + 1, str.tostring(math.round(array.get(year_pnl, yi) * 100, prec)), bgcolor = y_color)
  437.  
  438. //     for mi = 0 to array.size(month_time) - 1
  439. //         m_row   = year(array.get(month_time, mi))  - year(array.get(year_time, 0)) + 1
  440. //         m_col   = month(array.get(month_time, mi))
  441. //         m_color = array.get(month_pnl, mi) > 0 ? color.lime : color.red
  442.  
  443. //         table.cell(monthly_table, m_col, m_row, str.tostring(math.round(array.get(month_pnl, mi) * 100, prec)), bgcolor = m_color)
  444.  
  445. // ----------------- 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