Portfolio of open positions ENG
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//▁▂▃▅▆█🅶🅴🅾-🅲🅰🆂🅿🅴🆁█▆▅▃▂▁

//@version=5
indicator('Portfolio of open positions ENG', overlay = true, format = format.volume)

// Input Parametr (Входной Параметр) {
// textsize (высота текста)
AUTO    = size.auto 
SMALL   = size.small 
NORMAL  = size.normal 
LARGE   = size.large 

//Label arrangement (Расположение таблицы)
Left   = position.top_left
Centr  = position.top_center     
Right  = position.top_right     
MLeft  = position.middle_left    
MCentr = position.middle_center 
MRight = position.middle_right   
BLeft  = position.bottom_left    
BCentr = position.bottom_center  
BRight = position.bottom_right 

//Label arrangement (Расположение этикеток)
xcross      = label.style_xcross
cross       = label.style_cross
triangleup  = label.style_triangleup
triangledown= label.style_triangledown
flag        = label.style_flag
circle      = label.style_circle
arrowup     = label.style_arrowup
arrowdown   = label.style_arrowdown
label_up    = label.style_label_up
label_down  = label.style_label_down
label_left  = label.style_label_left
label_right = label.style_label_right
lower_left  = label.style_label_lower_left
lower_right = label.style_label_lower_right
upper_left  = label.style_label_upper_left
upper_right = label.style_label_upper_right
center      = label.style_label_center
square      = label.style_square
diamond     = label.style_diamond
//}

// Tooltip (Подсказка) {
DataBuy     = 'Date of purchase of shares'
Name        = 'The ticker of the stock you bought. Unfortunately, it is only possible to insert a ticker, the company names cannot be inserted yet'
Currency    = 'The currency in which your company is traded, it is mandatory to specify and check'
Stocks      = 'The number of shares, not to be confused with lots. If there is more than 1 stock in the lot, then manually multiply by the amount in 
     the lot. The information can be found at the time of purchase or in the information about the tool'
PurchpriceI = 'The price you bought the shares for'
CurrpricI   = 'The current price of the stock. The cost is taken according to your subscription in TradingView (may be delayed)'
InitiCost   = 'The total value of your shares when buying' 
InitiCostP  = 'The total value of your shares when buying in rubles. You need it if you have not only Russian stocks in your portfolio'
Liquvalue   = 'The total (liquid) value of your shares if you sell right now'
LiquvalueP  = 'The total (liquid) value of your shares if you sell right now in rubles. You need it if you have not only Russian stocks in your portfolio'
MoreLos     = "Profit/loss expressed in three types, in %, in rubles and from the total portfolio. Hover over each cell you don't understand and there will be a hint"
MoreLoss    = 'Profit/loss as a % of the purchase price'
MoreLossI   = 'Profit/loss in rubles from the purchase price'
MoreLossK   = 'Profit loss as a % of the total portfolio (i.e. from the initial deposit, by default 1000000 ₽)'
Sharportfo  = 'The share of a single stock from the total portfolio, i.e. how many percent does this stock take from the entire portfolio'
// }

// Input data (Входные данные) {
initialCapital  = input.int(1000000, 'Initial capital in ₽')
Portfolioshare  = input.int(10, 'Share of 1 share in the portfolio', maxval = 100)

//Show the number of shares (Показать число акций)
ShowShare       = input.string('1-5', 'Show number of rows', options = ['1-5', '1-10', '1-15', '1-20'], inline = '1')
//}

// Table input parameters (входный параметры таблицы) {
GPTab           = 'Table' 
textsize        = input.string(NORMAL, 'Text height', options = [AUTO, SMALL, NORMAL, LARGE], inline = '2', group = GPTab)
Position        = input.string(MCentr, 'Position', options = [Left, Right, MLeft, MCentr, MRight, BLeft, BCentr, BRight, Centr], inline = '2', group = GPTab)

GPTab1          = 'Table Colors'
Textcolor       = input.color(#000000, 'Text', inline ='0', group = GPTab1)
ColumColor      = input.color(color.new(#FFFFFF, 30), 'Background', inline = '0', group = GPTab1)
HeadColor       = input.color(color.new(#65b3ff, 50), 'Heading', inline = '1', group = GPTab1)
HeadTXTColor    = input.color(color.new(#000000, 30), 'Title Text', inline = '1', group = GPTab1)

GPTab2          = 'Color difference in the table'
More            = input.color(#4CAF50, title = 'Profit', inline = '1' , group = GPTab2)
Less            = input.color(#ff0000, title = 'Loss', inline = '1' , group = GPTab2)
// }

// Input data tiker (Входные данные компаний){
GP1             = '1 simbol'
Tiker1          = input.symbol('MOEX:GAZP', 'Stock selection', inline = '0', group = GP1)
Currency1       = input.string('₽', 'Currency of circulation', options = ['＄', '₽'], inline = '0', group = GP1)
QuanStock1      = input.int(1, 'Number of shares', step = 1, inline = '1', group = GP1)
Purchprice1     = input.float(100.0, 'Price', inline = '1', group = GP1)
Date1           = input.time(timestamp('01 May 2022'), 'Date of purchase', inline = '2', group = GP1)

GP2             = '2 simbol'
Tiker2          = input.symbol('MOEX:SBER', 'Stock selection', inline = '0', group = GP2)
Currency2       = input.string('₽', 'Currency of circulation', options = ['＄', '₽'], inline = '0', group = GP2)
QuanStock2      = input.int(0, 'Number of shares', step = 1, inline = '1', group = GP2)
Purchprice2     = input.float(0.0, 'Price', inline = '1', group = GP2)
Date2           = input.time(timestamp('01 May 2022'), 'Date of purchase', inline = '2', group = GP2)

GP3             = '3 simbol'
Tiker3          = input.symbol('MOEX:SBERP', 'Stock selection', inline = '0', group = GP3)
Currency3       = input.string('₽', 'Currency of circulation', options = ['＄', '₽'], inline = '0', group = GP3)
QuanStock3      = input.int(0, 'Number of shares', step = 1, inline = '1', group = GP3)
Purchprice3     = input.float(0.0, 'Price', inline = '1', group = GP3)
Date3           = input.time(timestamp('01 May 2022'), 'Date of purchase', inline = '2', group = GP3)

GP4             = '4 simbol'
Tiker4          = input.symbol('MOEX:GMKN', 'Stock selection', inline = '0', group = GP4)
Currency4       = input.string('₽', 'Currency of circulation', options = ['＄', '₽'], inline = '0', group = GP4)
QuanStock4      = input.int(0, 'Number of shares', step = 1, inline = '1', group = GP4)
Purchprice4     = input.float(0.0, 'Price', inline = '1', group = GP4)
Date4           = input.time(timestamp('01 May 2022'), 'Date of purchase', inline = '2', group = GP4)

GP5             = '5 simbol'
Tiker5          = input.symbol('MOEX:YNDX', 'Stock selection', inline = '0', group = GP5)
Currency5       = input.string('₽', 'Currency of circulation', options = ['＄', '₽'], inline = '0', group = GP5)
QuanStock5      = input.int(0, 'Number of shares', step = 1, inline = '1', group = GP5)
Purchprice5     = input.float(0.0, 'Price', inline = '1', group = GP5)
Date5           = input.time(timestamp('01 May 2022'), 'Date of purchase', inline = '2', group = GP5)

GP6             = '6 simbol'
Tiker6          = input.symbol('MOEX:LKOH', 'Stock selection', inline = '0', group = GP6)
Currency6       = input.string('₽', 'Currency of circulation', options = ['＄', '₽'], inline = '0', group = GP6)
QuanStock6      = input.int(0, 'Number of shares', step = 1, inline = '1', group = GP6)
Purchprice6     = input.float(0.0, 'Price', inline = '1', group = GP6)
Date6           = input.time(timestamp('01 May 2022'), 'Date of purchase', inline = '2', group = GP6)

GP7             = '7 simbol'
Tiker7          = input.symbol('MOEX:ALRS', 'Stock selection', inline = '0', group = GP7)
Currency7       = input.string('₽', 'Currency of circulation', options = ['＄', '₽'], inline = '0', group = GP7)
QuanStock7      = input.int(0, 'Number of shares', step = 1, inline = '1', group = GP7)
Purchprice7     = input.float(0.0, 'Price', inline = '1', group = GP7)
Date7           = input.time(timestamp('01 May 2022'), 'Date of purchase', inline = '2', group = GP7)

GP8             = '8 simbol'
Tiker8          = input.symbol('MOEX:TCSG', 'Stock selection', inline = '0', group = GP8)
Currency8       = input.string('₽', 'Currency of circulation', options = ['＄', '₽'], inline = '0', group = GP8)
QuanStock8      = input.int(0, 'Number of shares', step = 1, inline = '1', group = GP8)
Purchprice8     = input.float(0.0, 'Price', inline = '1', group = GP8)
Date8           = input.time(timestamp('01 May 2022'), 'Date of purchase', inline = '2', group = GP8)

GP9             = '9 simbol'
Tiker9          = input.symbol('MOEX:AFKS', 'Stock selection', inline = '0', group = GP9)
Currency9       = input.string('₽', 'Currency of circulation', options = ['＄', '₽'], inline = '0', group = GP9)
QuanStock9      = input.int(0, 'Number of shares', step = 1, inline = '1', group = GP9)
Purchprice9     = input.float(0.0, 'Price', inline = '1', group = GP9)
Date9           = input.time(timestamp('01 May 2022'), 'Date of purchase', inline = '2', group = GP9)

GP10            = '10 simbol'
Tiker10         = input.symbol('MOEX:SNGSP', 'Stock selection', inline = '0', group = GP10)
Currency10      = input.string('₽', 'Currency of circulation', options = ['＄', '₽'], inline = '0', group = GP10)
QuanStock10     = input.int(0, 'Number of shares', step = 1, inline = '1', group = GP10)
Purchprice10    = input.float(0.0, 'Price', inline = '1', group = GP10)
Date10          = input.time(timestamp('01 May 2022'), 'Date of purchase', inline = '2', group = GP10)

GP11            = '11 simbol'
Tiker11         = input.symbol('MOEX:VTBR', 'Stock selection', inline = '0', group = GP11)
Currency11      = input.string('₽', 'Currency of circulation', options = ['＄', '₽'], inline = '0', group = GP11)
QuanStock11     = input.int(0, 'Number of shares', step = 1, inline = '1', group = GP11)
Purchprice11    = input.float(0.0, 'Price', inline = '1', group = GP11)
Date11          = input.time(timestamp('01 May 2022'), 'Date of purchase', inline = '2', group = GP11)

GP12            = '12 simbol'
Tiker12         = input.symbol('MOEX:VKCO', 'Stock selection', inline = '0', group = GP12)
Currency12      = input.string('₽', 'Currency of circulation', options = ['＄', '₽'], inline = '0', group = GP12)
QuanStock12     = input.int(0, 'Number of shares', step = 1, inline = '1', group = GP12)
Purchprice12    = input.float(0.0, 'Price', inline = '1', group = GP12)
Date12          = input.time(timestamp('01 May 2022'), 'Date of purchase', inline = '2', group = GP12)

GP13            = '13 simbol'
Tiker13         = input.symbol('MOEX:MTSS', 'Stock selection', inline = '0', group = GP13)
Currency13      = input.string('₽', 'Currency of circulation', options = ['＄', '₽'], inline = '0', group = GP13)
QuanStock13     = input.int(0, 'Number of shares', step = 1, inline = '1', group = GP13)
Purchprice13    = input.float(0.0, 'Price', inline = '1', group = GP13)
Date13          = input.time(timestamp('01 May 2022'), 'Date of purchase', inline = '2', group = GP13)

GP14            = '14 simbol'
Tiker14         = input.symbol('NASDAQ:TSLA', 'Stock selection', inline = '0', group = GP14)
Currency14      = input.string('＄', 'Currency of circulation', options = ['＄', '₽'], inline = '0', group = GP14)
QuanStock14     = input.int(0, 'Number of shares', step = 1, inline = '1', group = GP14)
Purchprice14    = input.float(0.0, 'Price', inline = '1', group = GP14)
Date14          = input.time(timestamp('01 May 2022'), 'Date of purchase', inline = '2', group = GP14)

GP15            = '15 simbol'
Tiker15         = input.symbol('NYSE:SPCE', 'Stock selection', inline = '0', group = GP15)
Currency15      = input.string('＄', 'Currency of circulation', options = ['＄', '₽'], inline = '0', group = GP15)
QuanStock15     = input.int(0, 'Number of shares', step = 1, inline = '1', group = GP15)
Purchprice15    = input.float(0.0, 'Price', inline = '1', group = GP15)
Date15          = input.time(timestamp('01 May 2022'), 'Date of purchase', inline = '2', group = GP15)

GP16            = '16 simbol'
Tiker16         = input.symbol('NYSE:BABA', 'Stock selection', inline = '0', group = GP16)
Currency16      = input.string('＄', 'Currency of circulation', options = ['＄', '₽'], inline = '0', group = GP16)
QuanStock16     = input.int(100, 'Number of shares', step = 1, inline = '1', group = GP16)
Purchprice16    = input.float(100.0, 'Price', inline = '1', group = GP16)
Date16          = input.time(timestamp('01 May 2022'), 'Date of purchase', inline = '2', group = GP16)

GP17            = '17 simbol'
Tiker17         = input.symbol('NASDAQ:AAPL', 'Stock selection', inline = '0', group = GP17)
Currency17      = input.string('＄', 'Currency of circulation', options = ['＄', '₽'], inline = '0', group = GP17)
QuanStock17     = input.int(0, 'Number of shares', step = 1, inline = '1', group = GP17)
Purchprice17    = input.float(0.0, 'Price', inline = '1', group = GP17)
Date17          = input.time(timestamp('01 May 2022'), 'Date of purchase', inline = '2', group = GP17)

GP18            = '18 simbol'
Tiker18         = input.symbol('NASDAQ:AMZN', 'Stock selection', inline = '0', group = GP18)
Currency18      = input.string('＄', 'Currency of circulation', options = ['＄', '₽'], inline = '0', group = GP18)
QuanStock18     = input.int(0, 'Number of shares', step = 1, inline = '1', group = GP18)
Purchprice18    = input.float(0.0, 'Price', inline = '1', group = GP18)
Date18          = input.time(timestamp('01 May 2022'), 'Date of purchase', inline = '2', group = GP18)

GP19            = '19 simbol'
Tiker19         = input.symbol('NASDAQ:BIDU', 'Stock selection', inline = '0', group = GP19)
Currency19      = input.string('＄', 'Currency of circulation', options = ['＄', '₽'], inline = '0', group = GP19)
QuanStock19     = input.int(0, 'Number of shares', step = 1, inline = '1', group = GP19)
Purchprice19    = input.float(0.0, 'Price', inline = '1', group = GP19)
Date19          = input.time(timestamp('01 May 2022'), 'Date of purchase', inline = '2', group = GP19)

GP20            = '20 simbol'
Tiker20         = input.symbol('NASDAQ:AMD', 'Stock selection', inline = '0', group = GP20)
Currency20      = input.string('＄', 'Currency of circulation', options = ['＄', '₽'], inline = '0', group = GP20)
QuanStock20     = input.int(0, 'Number of shares', step = 1, inline = '1', group = GP20)
Purchprice20    = input.float(0.0, 'Price', inline = '1', group = GP20)
Date20          = input.time(timestamp('01 May 2022'), 'Date of purchase', inline = '2', group = GP20)
//}

// Displaying only the ticker (Отображение только тикера) {
var Tik1    = syminfo.ticker(Tiker1)
var Tik2    = syminfo.ticker(Tiker2)
var Tik3    = syminfo.ticker(Tiker3)
var Tik4    = syminfo.ticker(Tiker4)
var Tik5    = syminfo.ticker(Tiker5)
var Tik6    = syminfo.ticker(Tiker6)
var Tik7    = syminfo.ticker(Tiker7)
var Tik8    = syminfo.ticker(Tiker8)
var Tik9    = syminfo.ticker(Tiker9)
var Tik10   = syminfo.ticker(Tiker10)
var Tik11   = syminfo.ticker(Tiker11)
var Tik12   = syminfo.ticker(Tiker12)
var Tik13   = syminfo.ticker(Tiker13)
var Tik14   = syminfo.ticker(Tiker14)
var Tik15   = syminfo.ticker(Tiker15)
var Tik16   = syminfo.ticker(Tiker16)
var Tik17   = syminfo.ticker(Tiker17)
var Tik18   = syminfo.ticker(Tiker18)
var Tik19   = syminfo.ticker(Tiker19)
var Tik20   = syminfo.ticker(Tiker20)
// }

// Calculating and adding values to the table (Расчет и добавление в таблицу значений) {
Table(_table_Id, _row, _Data, _TikID, _curren, _QuanStock, _QuanStock1, _Purchprice, _initialCapital)=>
    Currentprice    = 0.0
    Currentprice    := request.security(_TikID, timeframe.period, close, ignore_invalid_symbol=true) 
    InitialCost     = 0.0
    InitialCost     := (_Purchprice * _QuanStock)
    InitialCost1     = 0.0
    InitialCost1    := (_Purchprice * _QuanStock) * request.security('USDRUB_TOM', timeframe.period, close, ignore_invalid_symbol=true)
    Liquidvalue     = 0.0
    Liquidvalue     := Currentprice * _QuanStock
    Liquidvalue1     = 0.0
    Liquidvalue1    := (Currentprice * _QuanStock) * request.security('USDRUB_TOM', timeframe.period, close, ignore_invalid_symbol=true)
    priceChange     = 0.0
    priceChange     :=  (1 - (_Purchprice / Currentprice)) * 100
    chang           =   0.0 
    chang           := ((Liquidvalue - InitialCost) / InitialCost) * 100
    ChangePercent   = 0.0
    ChangePercent   := (Currentprice * _QuanStock) - (_Purchprice * _QuanStock)
    ChangePercent1  = 0.0
    ChangePercent1  := Liquidvalue1 - InitialCost1 
    changes         = 0.0 
    changes         := Liquidvalue - InitialCost
    percentagetotal = 0.0
    percentagetotal := (ChangePercent / _initialCapital) * 100
    percentagetota1 = 0.0
    percentagetota1 := (ChangePercent1 / _initialCapital) * 100
    Shareoftotal    = 0.0
    Shareoftotal    := (InitialCost / _initialCapital) * 100
    Shareoftotal1   = 0.0
    Shareoftotal1   := (InitialCost1 / _initialCapital) * 100
    Suf = Currentprice < _Purchprice ? '😱' : '🔥'
    table.cell(table_id = _table_Id, column = 0 , row = _row, text = str.format('{0, date, dd-MMM-yyyy}', _Data), text_color=Textcolor, text_size = textsize)
    
    table.cell(table_id = _table_Id, column = 1 , row = _row, text = str.tostring(_TikID), text_color=Textcolor, text_size = textsize)
    
    table.cell(table_id = _table_Id, column = 2 , row = _row, text = str.tostring(_curren), text_color=Textcolor, text_size = textsize)
    
    table.cell(table_id = _table_Id, column = 3 , row = _row, text = str.tostring(_QuanStock, '# ##0'), text_color=Textcolor, text_size = textsize)
    
    table.cell(table_id = _table_Id, column = 4 , row = _row, text = str.tostring(_Purchprice, '# ##0.00'), text_color=Textcolor, text_size = textsize)    
    
    table.cell(table_id = _table_Id, column = 5 , row = _row, text = str.tostring(Currentprice, '# ##0.00') + Suf, text_color = Currentprice >= _Purchprice ? More : Less, text_size = textsize)
    
    if _curren == '₽' 
        table.cell(table_id = _table_Id, column = 6 , row = _row, text = str.tostring(InitialCost, '# ### ###0'), text_color=Textcolor, text_size = textsize)
        table.cell(table_id = _table_Id, column = 7 , row = _row, text = str.tostring(InitialCost, '# ### ###0'), text_color=Textcolor, text_size = textsize)
    else 
        table.cell(table_id = _table_Id, column = 6 , row = _row, text = str.tostring(InitialCost, '# ### ###0'), text_color=Textcolor, text_size = textsize)
        table.cell(table_id = _table_Id, column = 7 , row = _row, text = str.tostring(InitialCost1, '# ### ###0'), text_color=Textcolor, text_size = textsize)
    
    if _curren == '₽'
        table.cell(table_id = _table_Id, column = 8 , row = _row, text = str.tostring(Liquidvalue, '# ### ###0'), text_color=Textcolor, text_size = textsize)
        table.cell(table_id = _table_Id, column = 9 , row = _row, text = str.tostring(Liquidvalue, '# ### ###0'), text_color=Textcolor, text_size = textsize)
    else 
        table.cell(table_id = _table_Id, column = 8 , row = _row, text = str.tostring(Liquidvalue, '# ### ###0'), text_color=Textcolor, text_size = textsize)
        table.cell(table_id = _table_Id, column = 9 , row = _row, text = str.tostring(Liquidvalue1, '# ### ###0'), text_color=Textcolor, text_size = textsize)
  
    table.cell(table_id = _table_Id, column = 10 , row = _row, text = str.tostring(priceChange, format.percent), text_color = chang >= 0 ? More : Less, text_size = textsize, bgcolor = ColumColor)
    
    if _curren == '₽'  
        table.cell(table_id = _table_Id, column = 11 , row = _row, text = str.tostring(ChangePercent, '# ### ###0' ), text_color = chang >= 0 ? More : Less, text_size = textsize, bgcolor = ColumColor )
    else  
        table.cell(table_id = _table_Id, column = 11 , row = _row, text = str.tostring(ChangePercent1, '# ### ###0' ), text_color = chang >= 0 ? More : Less, text_size = textsize, bgcolor = ColumColor )
    
    if _curren == '₽' 
        table.cell(table_id = _table_Id, column = 12 , row = _row, text = str.tostring(percentagetotal, format.percent), text_color = percentagetotal >= 0 ? More : Less, text_size = textsize)
    else 
        table.cell(table_id = _table_Id, column = 12 , row = _row, text = str.tostring(percentagetota1, format.percent), text_color = percentagetota1 >= 0 ? More : Less, text_size = textsize)
   
    if _curren == '₽'
        table.cell(table_id = _table_Id, column = 13, row = _row, text = str.tostring(Shareoftotal, format.percent), text_color=Textcolor, text_size = textsize, bgcolor = Shareoftotal > Portfolioshare  ? #FF5252 : #4CAF50)
    else  
        table.cell(table_id = _table_Id, column = 13, row = _row, text = str.tostring(Shareoftotal1, format.percent), text_color=Textcolor, text_size = textsize, bgcolor = Shareoftotal1 > Portfolioshare  ? #FF5252 : #4CAF50)
// }

//plot table (отрисовка таблицы)
TableNum(_table_id, _column, _row, _value, _tool) =>
    table.cell(table_id = _table_id, column = _column, row = _row, text = _value, bgcolor = HeadColor, text_color = HeadTXTColor , text_size = textsize, tooltip = _tool)    

var table summary = table.new(position = Position, columns = 15, rows = 25, bgcolor = ColumColor, frame_color = #000000, frame_width = 2, border_color = #000000, border_width = 1)

// Header Input data (Входные данные заголовка) {
if barstate.islast
    TableNum(summary, 0, 0, 'Date', DataBuy)
    TableNum(summary, 1, 0, 'Simbol', Name)
    TableNum(summary, 2, 0, 'Currency', Currency)
    TableNum(summary, 3, 0, 'Quantity', Stocks)
    TableNum(summary, 4, 0, 'Price ', PurchpriceI)
    TableNum(summary, 5, 0, 'Current', CurrpricI)
    TableNum(summary, 6, 0, 'Balance', InitiCost)
    TableNum(summary, 7, 0, 'Balance', InitiCostP)
    TableNum(summary, 8, 0, 'Market', Liquvalue)
    TableNum(summary, 9, 0, 'Market', LiquvalueP)
    TableNum(summary, 10, 0, 'Profit/Loss ₽', MoreLos)
    TableNum(summary, 13, 0, 'Share of', Sharportfo)

    TableNum(summary, 3, 1, 'stocks', Stocks)
    TableNum(summary, 4, 1, 'buy', PurchpriceI)
    TableNum(summary, 5, 1, 'Price', CurrpricI)    
    TableNum(summary, 6, 1, 'cost', InitiCost)
    TableNum(summary, 7, 1, 'cost ₽', InitiCostP)
    TableNum(summary, 8, 1, 'cost', Liquvalue)
    TableNum(summary, 9, 1, 'cost ₽', LiquvalueP)
    TableNum(summary, 10, 1, 'in %', MoreLoss)
    TableNum(summary, 11, 1, 'in money ₽', MoreLossI)
    TableNum(summary, 12, 1, '% of portfolio', MoreLossK)
    TableNum(summary, 13, 1, 'total portfolio', Sharportfo)
//}

// Merging cells (объединение ячеек) {
table.merge_cells(summary, 0, 0, 0, 1)
table.merge_cells(summary, 1, 0, 1, 1)
table.merge_cells(summary, 2, 0, 2, 1)
table.merge_cells(summary, 10, 0, 12, 0)
//}

// The initial data to fill in the table (Исходные данные для заполнения в таблицу) {
// Show the table in parts (Показывать таблицу по частям)
if barstate.islast 
    if ShowShare == '1-5' 
        Table(summary, 2, Date1, Tik1, Currency1, QuanStock1, QuanStock1, Purchprice1, initialCapital)
        Table(summary, 3, Date2, Tik2, Currency2, QuanStock2, QuanStock2, Purchprice2, initialCapital)
        Table(summary, 4, Date3, Tik3, Currency3, QuanStock3, QuanStock3, Purchprice3, initialCapital)
        Table(summary, 5, Date4, Tik4, Currency4, QuanStock4, QuanStock4, Purchprice4, initialCapital)
        Table(summary, 6, Date5, Tik5, Currency5, QuanStock5, QuanStock5, Purchprice5, initialCapital)
    if ShowShare == '1-10'  
        Table(summary, 2, Date1, Tik1, Currency1, QuanStock1, QuanStock1, Purchprice1, initialCapital)
        Table(summary, 3, Date2, Tik2, Currency2, QuanStock2, QuanStock2, Purchprice2, initialCapital)
        Table(summary, 4, Date3, Tik3, Currency3, QuanStock3, QuanStock3, Purchprice3, initialCapital)
        Table(summary, 5, Date4, Tik4, Currency4, QuanStock4, QuanStock4, Purchprice4, initialCapital)
        Table(summary, 6, Date5, Tik5, Currency5, QuanStock5, QuanStock5, Purchprice5, initialCapital)
        Table(summary, 7, Date6, Tik6, Currency6, QuanStock6, QuanStock6, Purchprice6, initialCapital)
        Table(summary, 8, Date7, Tik7, Currency7, QuanStock7, QuanStock7, Purchprice7, initialCapital)
        Table(summary, 9, Date8, Tik8, Currency8, QuanStock8, QuanStock8, Purchprice8, initialCapital)
        Table(summary, 10, Date9, Tik9, Currency9, QuanStock9, QuanStock9, Purchprice9, initialCapital)
        Table(summary, 11, Date10, Tik10, Currency10, QuanStock10, QuanStock10, Purchprice10, initialCapital)
    if ShowShare == '1-15' 
        Table(summary, 2, Date1, Tik1, Currency1, QuanStock1, QuanStock1, Purchprice1, initialCapital)
        Table(summary, 3, Date2, Tik2, Currency2, QuanStock2, QuanStock2, Purchprice2, initialCapital)
        Table(summary, 4, Date3, Tik3, Currency3, QuanStock3, QuanStock3, Purchprice3, initialCapital)
        Table(summary, 5, Date4, Tik4, Currency4, QuanStock4, QuanStock4, Purchprice4, initialCapital)
        Table(summary, 6, Date5, Tik5, Currency5, QuanStock5, QuanStock5, Purchprice5, initialCapital)
        Table(summary, 7, Date6, Tik6, Currency6, QuanStock6, QuanStock6, Purchprice6, initialCapital)
        Table(summary, 8, Date7, Tik7, Currency7, QuanStock7, QuanStock7, Purchprice7, initialCapital)
        Table(summary, 9, Date8, Tik8, Currency8, QuanStock8, QuanStock8, Purchprice8, initialCapital)
        Table(summary, 10, Date9, Tik9, Currency9, QuanStock9, QuanStock9, Purchprice9, initialCapital)
        Table(summary, 11, Date10, Tik10, Currency10, QuanStock10, QuanStock10, Purchprice10, initialCapital)
        Table(summary, 12, Date11, Tik10, Currency11, QuanStock11, QuanStock11, Purchprice11, initialCapital)
        Table(summary, 13, Date12, Tik10, Currency12, QuanStock12, QuanStock12, Purchprice12, initialCapital)
        Table(summary, 14, Date13, Tik10, Currency13, QuanStock13, QuanStock13, Purchprice13, initialCapital)
        Table(summary, 15, Date14, Tik10, Currency14, QuanStock14, QuanStock14, Purchprice14, initialCapital)
        Table(summary, 16, Date15, Tik10, Currency15, QuanStock15, QuanStock15, Purchprice15, initialCapital)
    if ShowShare == '1-20' 
        Table(summary, 2, Date1, Tik1, Currency1, QuanStock1, QuanStock1, Purchprice1, initialCapital)
        Table(summary, 3, Date2, Tik2, Currency2, QuanStock2, QuanStock2, Purchprice2, initialCapital)
        Table(summary, 4, Date3, Tik3, Currency3, QuanStock3, QuanStock3, Purchprice3, initialCapital)
        Table(summary, 5, Date4, Tik4, Currency4, QuanStock4, QuanStock4, Purchprice4, initialCapital)
        Table(summary, 6, Date5, Tik5, Currency5, QuanStock5, QuanStock5, Purchprice5, initialCapital)
        Table(summary, 7, Date6, Tik6, Currency6, QuanStock6, QuanStock6, Purchprice6, initialCapital)
        Table(summary, 8, Date7, Tik7, Currency7, QuanStock7, QuanStock7, Purchprice7, initialCapital)
        Table(summary, 9, Date8, Tik8, Currency8, QuanStock8, QuanStock8, Purchprice8, initialCapital)
        Table(summary, 10, Date9, Tik9, Currency9, QuanStock9, QuanStock9, Purchprice9, initialCapital)
        Table(summary, 11, Date10, Tik10, Currency10, QuanStock10, QuanStock10, Purchprice10, initialCapital)
        Table(summary, 12, Date11, Tik11, Currency11, QuanStock11, QuanStock11, Purchprice11, initialCapital)
        Table(summary, 13, Date12, Tik12, Currency12, QuanStock12, QuanStock12, Purchprice12, initialCapital)
        Table(summary, 14, Date13, Tik13, Currency13, QuanStock13, QuanStock13, Purchprice13, initialCapital)
        Table(summary, 15, Date14, Tik14, Currency14, QuanStock14, QuanStock14, Purchprice14, initialCapital)
        Table(summary, 16, Date15, Tik15, Currency15, QuanStock15, QuanStock15, Purchprice15, initialCapital)
        Table(summary, 17, Date16, Tik16, Currency16, QuanStock16, QuanStock16, Purchprice16, initialCapital)
        Table(summary, 18, Date17, Tik17, Currency17, QuanStock17, QuanStock17, Purchprice17, initialCapital)
        Table(summary, 19, Date18, Tik18, Currency18, QuanStock18, QuanStock18, Purchprice18, initialCapital)
        Table(summary, 20, Date19, Tik19, Currency19, QuanStock19, QuanStock19, Purchprice19, initialCapital)
        Table(summary, 21, Date20, Tik20, Currency20, QuanStock20, QuanStock20, Purchprice20, initialCapital)
// }
