Guest User

Untitled

a guest
Apr 15th, 2023
70
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.77 KB | None | 0 0
  1. //@version=5
  2. strategy(title="thwlp Upgraded damn it-_-", overlay=true)
  3.  
  4. import ZenAndTheArtOfTrading/ZenLibrary/2 as l_zen
  5. import HeWhoMustNotBeNamed/RecursiveAlerts/2 as ra
  6. // Step 1: Get inputs
  7. lookback = input.int(defval =2, title="Lookback", minval=2)
  8. tp_percent = input.float(defval =1, title="Take Profit (%)", minval=0.01,step = 0.5)*0.01
  9. sl_percent = input.float(defval =1, title="Stop Loss (%)", minval=0.001,step = 0.5)*0.01
  10. atr_bool = input.bool(false,title = "Atr use")
  11. atr_multi = input.float(defval = 1.5, title="ATR Multiplier", minval=0.01,step = 0.5)
  12. atr_len = input.int(defval =14,title = "ATR Length",minval = 1)
  13.  
  14. var g_tester = 'Back tester table'
  15. i_startTime = input.time(title='Start Date', defval=timestamp('01 Jan 2020 00:00 +0100'), group=g_tester, tooltip='Date & time to begin trading from')
  16. i_endTime = input.time(title='End Date', defval=timestamp('1 Jan 2099 00:00 +0100'), group=g_tester, tooltip='Date & time to stop trading')
  17.  
  18. var g_pause = "Pause trades"
  19. i_tradePause = input.int(title= "For how many bars?", defval=0, minval = 0, group= g_pause, tooltip="Pauses trades for X bars after a closed trade\n0 = OFF")
  20. i_tradePauseLoss = input.bool(title= "Only loosing trades", defval = true, inline = "4", group= g_pause)
  21. i_tradeLossNum = input.int(title= "| How much?", defval=1, minval = 1, group= g_pause, inline = "4", tooltip="Number of loosing trades in a row")
  22.  
  23. i_drawTester = input.bool(title='Show back tester', defval=true, group=g_tester, tooltip='Turn on/off inbuilt backtester display', inline = "backtester1")
  24. i_testerPosition = input.string(title='', defval="Top right", options = ["Top right", "Top left", "Bottom right", "Bottom left"], group=g_tester, tooltip='Position of the backtester table', inline = "backtester1")
  25. i_rr = input.float(title='R:R', defval=1.0, group=g_tester, tooltip='Risk:Reward profile')
  26. startBalance = input.float(title='Starting Balance', defval=100.0, group=g_tester, tooltip='Your starting balance for the custom inbuilt tester system')
  27. riskPerTrade = input.float(title='Risk Per Trade', defval=1.0, group=g_tester, tooltip='Your desired % risk per trade (as a whole number)')
  28.  
  29.  
  30. atr = ta.atr(atr_len)
  31. entry = strategy.position_avg_price
  32. var int pos_bi = na
  33. // Step 2: Calculate TP and SL
  34. var atr_stop_loss_l = 0.0
  35. var atr_stop_loss_s = 0.0
  36. // sl_atr = 0.0
  37. float tp_s = entry * (1 - tp_percent)
  38. float sl_s = not atr_bool ? entry * (1 + sl_percent) : atr_stop_loss_s
  39. float tp_l = entry * (1 + tp_percent)
  40. float sl_l = not atr_bool ? entry * (1 - sl_percent) : atr_stop_loss_l
  41.  
  42. //-------------------------
  43.  
  44. //Alert Templates Creation
  45. keys = array.from("{entry}", "{stop}", "{target}")
  46. //Step 2. Create a default alert template for long trades
  47. long_template = '{\n
  48. \t"trade_type": "long",\n
  49. \t"entry": {entry},\n
  50. \t"stop_loss": {stop},\n
  51. \t"take_profit": {target}\n
  52. }'
  53.  
  54. //Step 3. Create a default alert template for short trades
  55. short_template = '{\n
  56. \t"trade_type": "short",\n
  57. \t"entry": {entry},\n
  58. \t"stop_loss": {stop},\n
  59. \t"take_profit": {target}\n
  60. }'
  61.  
  62. var alertme = '🔔 The Alerts Alertatron'
  63. alert_freq = input.string("Once per bar",title = "Alert Frequency",group = alertme,options = ["Once per bar","Once per close","All"])
  64. if alert_freq == "Once per bar"
  65. alert_freq := alert.freq_once_per_bar
  66. else if alert_freq =="Once per close"
  67. alert_freq := alert.freq_once_per_bar_close
  68. else if alert_freq == "All"
  69. alert_freq := alert.freq_all
  70. i_usemessage = input.bool(false, "Show Alertatron bot message", group = alertme)
  71. entry_long = input.text_area(title="API Entry - Long", defval=long_template, group = alertme)
  72. exit_long = input.text_area(title="API Exit - Long", defval=" ", group = alertme)
  73. entry_short = input.text_area(defval=short_template,title = "API Entry - Short",group = alertme)
  74. exit_short = input.text_area(defval=" ",title = "API Exit - Short",group = alertme)
  75.  
  76.  
  77. // Step 3: Entry condition for long
  78. long_condition = barstate.isconfirmed and close < low[1] and high[1] < high[lookback + 1] and strategy.position_size == 0
  79.  
  80. // Step 4: Entry condition for short
  81. short_condition = barstate.isconfirmed and close > high[1] and low[1] > low[lookback + 1] and strategy.position_size == 0
  82.  
  83. strategy.risk.allow_entry_in(strategy.direction.all)
  84. c_dateFilter = time >= i_startTime and time <= i_endTime
  85.  
  86. c_sinceLastTrade = ta.barssince(strategy.closedtrades > strategy.closedtrades[1])
  87. c_sinceLastLossTrade = ta.barssince(strategy.losstrades > strategy.losstrades[1])
  88.  
  89. var c_countLosstrades = 0
  90. switch
  91. strategy.losstrades > strategy.losstrades[1] => c_countLosstrades += 1
  92. strategy.wintrades > strategy.wintrades[1] => c_countLosstrades := 0
  93. c_countLosstrades == i_tradeLossNum and c_sinceLastLossTrade > i_tradePause => c_countLosstrades := 0
  94. long_condition or short_condition => c_countLosstrades := 0
  95.  
  96. c_longCondition = c_dateFilter and (i_tradePauseLoss ? (i_tradePause != 0 ? c_countLosstrades < i_tradeLossNum : true) and
  97. (strategy.losstrades != 0 ? c_sinceLastLossTrade >= i_tradePause : true) : (strategy.closedtrades != 0 ? c_sinceLastTrade >= i_tradePause : true)) and
  98. long_condition
  99.  
  100. c_shortCondition = c_dateFilter and (i_tradePauseLoss ? (i_tradePause != 0 ? c_countLosstrades < i_tradeLossNum : true) and
  101. (strategy.losstrades != 0 ? c_sinceLastLossTrade >= i_tradePause : true) : (strategy.closedtrades != 0 ? c_sinceLastTrade >= i_tradePause : true)) and
  102. short_condition
  103.  
  104.  
  105. if c_longCondition
  106. long_values = array.from(str.tostring(entry), str.tostring(sl_l), str.tostring(tp_l))
  107. long_alert_message = ra.updateAlertTemplate(entry_long, keys, long_values)
  108. strategy.entry("Long", strategy.long, alert_message = i_usemessage ? long_alert_message : "Enter Long")
  109. atr_stop_loss_l := close - (atr * atr_multi)
  110. alert(long_alert_message, alert_freq)
  111. if strategy.position_size > 0
  112. // tp_l := entry * (1 + tp_percent)
  113. // sl_l := not atr_bool ? entry * (1 - sl_percent) : atr_stop_loss_l
  114. strategy.exit("Take Profit", "Long", limit=tp_l, stop=sl_l, comment_profit="Take Profit", comment_loss="Stoploss", alert_message = i_usemessage ? exit_long : na)
  115. alert(exit_long, alert_freq)
  116.  
  117. if c_shortCondition
  118. short_values = array.from(str.tostring(entry), str.tostring(sl_s), str.tostring(tp_s))
  119. short_alert_message = ra.updateAlertTemplate(entry_short, keys, short_values)
  120. strategy.entry("Short", strategy.short, alert_message = i_usemessage ? short_alert_message : "Enter Short")
  121. atr_stop_loss_s := close + (atr * atr_multi)
  122. alert(short_alert_message, alert_freq)
  123. if strategy.position_size < 0
  124. // tp_s := entry * (1 - tp_percent)
  125. // sl_s := not atr_bool ? entry * (1 + sl_percent) : atr_stop_loss_s
  126. strategy.exit("Short Exit", "Short", limit=tp_s, stop=sl_s, comment_profit="Take profit", comment_loss="Stoploss", alert_message = i_usemessage ? exit_short : na)
  127. alert(exit_short, alert_freq)
  128. //-----------------------------------------------------------------------------
  129. // Step 5: Exit strategy with take profit or stop loss
  130. //TP LONG AND SHORT
  131.  
  132. // pos_bi := bar_index
  133.  
  134.  
  135. // pos_bi := bar_index
  136.  
  137. //ATR sl for long and short
  138. if atr_bool == true and strategy.position_size > 0
  139. strategy.exit("ATR SL", "Long", stop=atr_stop_loss_l)
  140. alert(exit_long, alert_freq)
  141. // pos_bi := bar_index
  142. if atr_bool == true and strategy.position_size < 0
  143. strategy.exit("ATR SL", "Short", stop=atr_stop_loss_s)
  144. alert(exit_short, alert_freq)
  145. // pos_bi := bar_index
  146.  
  147. // if not atr_bool
  148. // //Normal SL %
  149. // if strategy.position_size > 0
  150.  
  151. // strategy.exit("Stop Loss", "Long", stop=sl_l, alert_message = i_usemessage ? exit_long : na)
  152. // alert(exit_long, alert_freq)
  153. // // pos_bi := bar_index
  154. // if strategy.position_size < 0
  155. // strategy.exit("Stop Loss", "Short", stop=sl_s, alert_message = i_usemessage ? exit_short : na)
  156. // alert(exit_short, alert_freq)
  157.  
  158.  
  159. //-----------------------------------------------------------------------------
  160. //Box
  161. // if strategy.position_size[1] != 0 and strategy.position_size == 0
  162. // tn = strategy.closedtrades - 1
  163. // penp = strategy.closedtrades.entry_price(tn)
  164. // pexp = strategy.closedtrades.exit_price(tn)
  165. // box.new(pos_bi, math.max(pexp, penp), bar_index, math.min(penp, pexp), border_color=penp < pexp ? color.green : color.red, bgcolor=penp < pexp ? color.new(color.green, 75) : color.new(color.red, 75))
  166.  
  167. // Plot stop loss values for confirmation
  168. plot(series= sl_l, color=color.new(color.red, 0), style=plot.style_linebr, linewidth=2, title='Long Stop Loss')
  169. plot(series= sl_s, color=color.new(color.red, 0), style=plot.style_linebr, linewidth=2, title='Short Stop Loss')
  170. plot(series= tp_l, color=color.new(color.green, 0), style=plot.style_linebr, linewidth=2, title='Long Takeprofit')
  171. plot(series= tp_s, color=color.new(color.green, 0), style=plot.style_linebr, linewidth=2, title='Short Takeprofit')
  172.  
  173. // // Used for debug and check the ATR SL value
  174. // plot(atr_bool ==true and strategy.position_size != 0 ? atr_stop_loss_l : na, color=color.new(color.red, 100), title='ATR Stop Value')
  175.  
  176. // // Plot take profit values for confirmation
  177. // plot(series=strategy.position_size > 0 and useTakeProfit ? TP1longPrice : na, color=color.new(color.green, 0), style=plot.style_linebr, linewidth=3, title='Long Take Profit 1')
  178.  
  179. // plot(series=strategy.position_size < 0 and useTakeProfit ? TP1shortPrice : na, color=color.new(color.red, 0), style=plot.style_linebr, linewidth=3, title='Short Take Profit 1')
  180. // // Used for debug and check the ATR TP value
  181. // plot(use_TP_ATR and strategy.position_size != 0 ? RR_TP1_ATR * rewardRatioATR1 : na, color=color.new(color.green, 100), title='ATR TP1 Value')
  182.  
  183. // plot(strategy.position_size != 0 ? strategy.position_avg_price : na, title = "Entry Price", style = plot.style_linebr, linewidth = 2)
  184.  
  185.  
  186. // --- BEGIN TESTER CODE --- //
  187. // Declare performance tracking variables
  188. var balance = startBalance
  189. var maxBalance = 0.0
  190. var totalWins = 0
  191. var totalLoss = 0
  192.  
  193. // Detect winning trades
  194. if strategy.wintrades != strategy.wintrades[1]
  195. balance := balance + riskPerTrade / 100 * balance * i_rr
  196. totalWins := totalWins + 1
  197. if balance > maxBalance
  198. maxBalance := balance
  199. maxBalance
  200.  
  201. // Detect losing trades
  202. if strategy.losstrades != strategy.losstrades[1]
  203. balance := balance - riskPerTrade / 100 * balance
  204. totalLoss := totalLoss + 1
  205.  
  206. // // Prepare stats table
  207. // var table testTable = table.new(i_testerPosition == "Top right" ? position.top_right : i_testerPosition == "Top left" ? position.top_left : i_testerPosition == "Bottom right" ? position.bottom_right :position.bottom_left, 5, 2, border_width=2)
  208. // f_fillCell(_table, _column, _row, _title, _value, _bgcolor, _txtcolor) =>
  209. // _cellText = _title + '\n' + _value
  210. // table.cell(_table, _column, _row, _cellText, bgcolor=_bgcolor, text_color=_txtcolor)
  211.  
  212. // // Draw stats table
  213. // var bgcolor = color.new(color.black, 0)
  214. // if i_drawTester
  215. // if barstate.islastconfirmedhistory
  216. // // Update table
  217. // dollarReturn = balance - startBalance
  218. // f_fillCell(testTable, 0, 0, 'Total Trades:', str.tostring(strategy.closedtrades), bgcolor, color.white)
  219. // f_fillCell(testTable, 0, 1, 'Win Rate:', str.tostring(l_zen.truncate(strategy.wintrades / strategy.closedtrades * 100, 2)) + '%', (strategy.wintrades / strategy.closedtrades * 100) >= 50 ? color.green : bgcolor, color.white)
  220. // f_fillCell(testTable, 1, 0, 'Starting:', '$' + str.tostring(startBalance), bgcolor, color.white)
  221. // f_fillCell(testTable, 1, 1, 'Ending:', '$' + str.tostring(l_zen.truncate(balance, 2)), balance > startBalance ? color.green : bgcolor, color.white)
  222. // // --- END BACKTESTER CODE --- //
  223. // Dashboard Table Text Size
  224. i_tableTextSize = input.string(title="Dashboard Size", defval="Small", options=["Auto", "Huge", "Large", "Normal", "Small", "Tiny"], group="Dashboards")
  225. table_text_size(s) =>
  226. switch s
  227. "Auto" => size.auto
  228. "Huge" => size.huge
  229. "Large" => size.large
  230. "Normal" => size.normal
  231. "Small" => size.small
  232. => size.tiny
  233. tableTextSize = table_text_size(i_tableTextSize)
  234.  
  235. /// Performance Summary Dashboard
  236. // â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘
  237. // Inspired by https://www.tradingview.com/script/uWqKX6A2/ - Thanks VertMT
  238.  
  239. i_showDashboard = input.bool(title="Performance Summary", defval=true, group="Dashboards", inline="Show Dashboards")
  240.  
  241. f_fillCell(_table, _column, _row, _title, _value, _bgcolor, _txtcolor) =>
  242. _cellText = _title + "\n" + _value
  243. table.cell(_table, _column, _row, _cellText, bgcolor=_bgcolor, text_color=_txtcolor, text_size=tableTextSize)
  244.  
  245. // Draw dashboard table
  246. if i_showDashboard
  247. var bgcolor = color.new(color.black,0)
  248.  
  249. // Keep track of Wins/Losses streaks
  250. newWin = (strategy.wintrades > strategy.wintrades[1]) and (strategy.losstrades == strategy.losstrades[1]) and (strategy.eventrades == strategy.eventrades[1])
  251. newLoss = (strategy.wintrades == strategy.wintrades[1]) and (strategy.losstrades > strategy.losstrades[1]) and (strategy.eventrades == strategy.eventrades[1])
  252.  
  253. varip int winRow = 0
  254. varip int lossRow = 0
  255. varip int maxWinRow = 0
  256. varip int maxLossRow = 0
  257.  
  258. if newWin
  259. lossRow := 0
  260. winRow := winRow + 1
  261. if winRow > maxWinRow
  262. maxWinRow := winRow
  263.  
  264. if newLoss
  265. winRow := 0
  266. lossRow := lossRow + 1
  267. if lossRow > maxLossRow
  268. maxLossRow := lossRow
  269.  
  270. // Prepare stats table
  271. var table dashTable = table.new(position.top_right, 1, 15, border_width=1)
  272.  
  273. if barstate.islastconfirmedhistory
  274. // Update table
  275. dollarReturn = strategy.netprofit
  276. f_fillCell(dashTable, 0, 0, "Start:", str.format("{0,date,long}", strategy.closedtrades.entry_time(0)) , bgcolor, color.white) // + str.format(" {0,time,HH:mm}", strategy.closedtrades.entry_time(0))
  277. f_fillCell(dashTable, 0, 1, "End:", str.format("{0,date,long}", strategy.opentrades.entry_time(0)) , bgcolor, color.white) // + str.format(" {0,time,HH:mm}", strategy.opentrades.entry_time(0))
  278. _profit = (strategy.netprofit / strategy.initial_capital) * 100
  279. f_fillCell(dashTable, 0, 2, "Net Profit:", str.tostring(_profit, '##.##') + "%", _profit > 0 ? color.teal : color.maroon, color.white)
  280. _numOfDaysInStrategy = (strategy.opentrades.entry_time(0) - strategy.closedtrades.entry_time(0)) / (1000 * 3600 * 24)
  281. f_fillCell(dashTable, 0, 3, "Percent Per Day", str.tostring(_profit / _numOfDaysInStrategy, '#########################.#####')+"%", _profit > 0 ? color.teal : color.maroon, color.white)
  282. _winRate = ( strategy.wintrades / strategy.closedtrades ) * 100
  283. f_fillCell(dashTable, 0, 4, "Percent Profitable:", str.tostring(_winRate, '##.##') + "%", _winRate < 50 ? color.maroon : _winRate < 75 ? #999900 : color.teal, color.white)
  284. f_fillCell(dashTable, 0, 5, "Profit Factor:", str.tostring(strategy.grossprofit / strategy.grossloss, '##.###'), strategy.grossprofit > strategy.grossloss ? color.teal : color.maroon, color.white)
  285. f_fillCell(dashTable, 0, 6, "Total Trades:", str.tostring(strategy.closedtrades), bgcolor, color.white)
  286. f_fillCell(dashTable, 0, 8, "Max Wins In A Row:", str.tostring(maxWinRow, '######') , bgcolor, color.white)
  287. f_fillCell(dashTable, 0, 9, "Max Losses In A Row:", str.tostring(maxLossRow, '######') , bgcolor, color.white)
  288.  
  289. // Monthly Table Performance Dashboard By @QuantNomad
  290. // â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘â–‘
  291. i_showMonthlyPerformance = input.bool(true, 'Monthly Performance', group='Dashboards', inline="Show Dashboards")
  292. i_monthlyReturnPercision = 2
  293.  
  294. if i_showMonthlyPerformance
  295. new_month = month(time) != month(time[1])
  296. new_year = year(time) != year(time[1])
  297.  
  298. eq = strategy.equity
  299.  
  300. bar_pnl = eq / eq[1] - 1
  301.  
  302. cur_month_pnl = 0.0
  303. cur_year_pnl = 0.0
  304.  
  305. // Current Monthly P&L
  306. cur_month_pnl := new_month ? 0.0 :
  307. (1 + cur_month_pnl[1]) * (1 + bar_pnl) - 1
  308.  
  309. // Current Yearly P&L
  310. cur_year_pnl := new_year ? 0.0 :
  311. (1 + cur_year_pnl[1]) * (1 + bar_pnl) - 1
  312.  
  313. // Arrays to store Yearly and Monthly P&Ls
  314. var month_pnl = array.new_float(0)
  315. var month_time = array.new_int(0)
  316.  
  317. var year_pnl = array.new_float(0)
  318. var year_time = array.new_int(0)
  319.  
  320. last_computed = false
  321.  
  322. if (not na(cur_month_pnl[1]) and (new_month or barstate.islastconfirmedhistory))
  323. if (last_computed[1])
  324. array.pop(month_pnl)
  325. array.pop(month_time)
  326.  
  327. array.push(month_pnl , cur_month_pnl[1])
  328. array.push(month_time, time[1])
  329.  
  330. if (not na(cur_year_pnl[1]) and (new_year or barstate.islastconfirmedhistory))
  331. if (last_computed[1])
  332. array.pop(year_pnl)
  333. array.pop(year_time)
  334.  
  335. array.push(year_pnl , cur_year_pnl[1])
  336. array.push(year_time, time[1])
  337.  
  338. last_computed := barstate.islastconfirmedhistory ? true : nz(last_computed[1])
  339.  
  340. // Monthly P&L Table
  341. var monthly_table = table(na)
  342.  
  343. if (barstate.islastconfirmedhistory)
  344. monthly_table := table.new(position.bottom_right, columns = 14, rows = array.size(year_pnl) + 1, border_width = 1)
  345.  
  346. table.cell(monthly_table, 0, 0, "", bgcolor = #cccccc, text_size=tableTextSize)
  347. table.cell(monthly_table, 1, 0, "Jan", bgcolor = #cccccc, text_size=tableTextSize)
  348. table.cell(monthly_table, 2, 0, "Feb", bgcolor = #cccccc, text_size=tableTextSize)
  349. table.cell(monthly_table, 3, 0, "Mar", bgcolor = #cccccc, text_size=tableTextSize)
  350. table.cell(monthly_table, 4, 0, "Apr", bgcolor = #cccccc, text_size=tableTextSize)
  351. table.cell(monthly_table, 5, 0, "May", bgcolor = #cccccc, text_size=tableTextSize)
  352. table.cell(monthly_table, 6, 0, "Jun", bgcolor = #cccccc, text_size=tableTextSize)
  353. table.cell(monthly_table, 7, 0, "Jul", bgcolor = #cccccc, text_size=tableTextSize)
  354. table.cell(monthly_table, 8, 0, "Aug", bgcolor = #cccccc, text_size=tableTextSize)
  355. table.cell(monthly_table, 9, 0, "Sep", bgcolor = #cccccc, text_size=tableTextSize)
  356. table.cell(monthly_table, 10, 0, "Oct", bgcolor = #cccccc, text_size=tableTextSize)
  357. table.cell(monthly_table, 11, 0, "Nov", bgcolor = #cccccc, text_size=tableTextSize)
  358. table.cell(monthly_table, 12, 0, "Dec", bgcolor = #cccccc, text_size=tableTextSize)
  359. table.cell(monthly_table, 13, 0, "Year", bgcolor = #999999, text_size=tableTextSize)
  360.  
  361. for yi = 0 to array.size(year_pnl) - 1
  362. table.cell(monthly_table, 0, yi + 1, str.tostring(year(array.get(year_time, yi))), bgcolor = #cccccc, text_size=tableTextSize)
  363.  
  364. y_color = array.get(year_pnl, yi) > 0 ? color.new(color.teal, transp = 40) : color.new(color.gray, transp = 40)
  365. table.cell(monthly_table, 13, yi + 1, str.tostring(math.round(array.get(year_pnl, yi) * 100, i_monthlyReturnPercision)), bgcolor = y_color, text_color=color.new(color.white, 0),text_size=tableTextSize)
  366.  
  367. for mi = 0 to array.size(month_time) - 1
  368. m_row = year(array.get(month_time, mi)) - year(array.get(year_time, 0)) + 1
  369. m_col = month(array.get(month_time, mi))
  370. m_color = array.get(month_pnl, mi) > 0 ? color.new(color.teal, transp = 40) : color.new(color.maroon, transp = 40)
  371.  
  372. table.cell(monthly_table, m_col, m_row, str.tostring(math.round(array.get(month_pnl, mi) * 100, i_monthlyReturnPercision)), bgcolor = m_color, text_color=color.new(color.white, 0), text_size=tableTextSize)
  373.  
  374.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment