How to display cursor values ​and not in real time in the panel ? Pinescript - cursor

I made a panel where I would like to display the values ​​when I move the mouse (like at the top left of the screen) and not in real time. Can you help me ?
like at the top left of the screen
//#version=5
indicator(title='DE40 DAX MTF PANEL 5', shorttitle='MTF PANEL DAX', overlay=true)
open_pos = open * 1
close_pos = close * 1
// Body size as a percentage of the total candle
diff = math.abs(close_pos - open_pos)
plot(diff, color=color.new(color.white, 0))
open_pos2 = high * 1
close_pos2 = low * 1
// Body size as a percentage of the total candle
diff2 = math.abs(close_pos2 - open_pos2)
plot(diff2, color=color.new(color.red, 0))
/////////// PANEL /////////////
i_position = input.string(title='Table Placement', defval='Bottom Right', options=['Top Right', 'Middle Right', 'Bottom Right'], group='Table Characteristics')
position = i_position == 'Top Right' ? position.top_right : i_position == 'Middle Right' ? position.middle_right : position.bottom_right
i_w = input.int(title='Width', defval=10, group='Table Characteristics')
i_h = input.int(title='Height', defval=3, group='Table Characteristics')
i_text_size = input.string(title='Text Size', defval='Normal', options=['Auto', 'Tiny', 'Small', 'Normal', 'Large', 'Huge'], group='Table Characteristics')
text_size = i_text_size == 'Normal' ? size.normal : i_text_size == 'Auto' ? size.auto : i_text_size == 'Auto' ? size.auto : i_text_size == 'Tiny' ? size.tiny : i_text_size == 'Small' ? size.small : i_text_size == 'Large' ? size.large : size.huge
row_3 = input.string(title='Row 3 Text', defval="diff", group='Texts')
row_4 = input.string(title='Row 3 Text', defval="diff2", group='Texts')
i_3 = input.bool(title='Row 3', defval=true, group='Enablers')
i_4 = input.bool(title='Row 4', defval=true, group='Enablers')
i_text_c = input.color(title='Text', defval=color.new(color.black, 0), group='Colours')
i_background_c = input.color(title='Bg', defval=color.new(color.yellow, 74), group='Colours')
var table perfTable = table.new(position, 1, 7, border_width=1)
if i_3
table.cell(perfTable, 0, 2, str.tostring(math.round(diff,3)), bgcolor=color.white, text_color=i_text_c, width=i_w, height=i_h, text_size=text_size)
if i_4
table.cell(perfTable, 0, 3, str.tostring(math.round(diff2,3)), bgcolor=color.orange, text_color=i_text_c, width=i_w, height=i_h, text_size=text_size)
Thanks

Related

pine cannot determine the referencing length of a series using barstate.islast

I receive the error "pine cannot determine the referencing length of a series. try using max_bars_back in the study or strategy function" when trying to perform a function on the barstate.islast condition.
I am using this condition in order to try and speed up my script as it does not need to perform all actions in the function until the last bar of the script. Even performing the function on the last bar is intensive, so I attempt to bypass unnecessary logic when able by using the stopPocIndexNo bool once the lines requested have been drawn.
If I remove the bool, then the loop on any particular bar takes to long > 500ms.
//#version=5
indicator("High Volume Candle Mid", overlay = true, max_lines_count = 100, max_labels_count = 100, max_bars_back = 5000)
maLengthInput = input.int(defval = 34, title = "Volume - Moving Average Length", group = "Options")
volLengthInput = input.int(defval = 5, title = "Volume - Look Back", group = "Options")
maMultiplierInput = input.float(defval = 2, title = "Volume - MA Multiplier", tooltip = "Filter's out weak volume candles that break MA", group = "Options")
qtyOfClosesInput = input.int(defval = 3, title = "(n) closes to cross POC to invalidate.", group = "Options")
qtyOfLinesInput = input.int(defval = 10, title = "(n) latest POC's to show", group = "Options")
qtyOfBrokenLinesInput = input.int(defval = 10, title = "(n) latest historical POC's to show", group = "Options")
barAlignInput = input.int(defval = 20, title = "Bar Index Offset", tooltip = "How many bars past price to extend labels/lines", group = "Options")
supplyColorInput = input.color(defval = #FF5252, title = "Supply Zone - POC's", group = "Options" )
demandColorInput = input.color(defval = #4CAF50, title = "Demand Zone - POC's", group = "Options")
///// Variables
var float maVol = na
var float highestVol = na
var bool pocCondition = false
var float[] barOpens = array.new_float()
var float[] barCloses = array.new_float()
var float[] barPocs = array.new_float()
var color[] barColors = array.new_color()
///// Functions
deleteLines() =>
a_allLines = line.all
if array.size(a_allLines) > 0
for i = 0 to array.size(a_allLines) - 1
line.delete(array.get(a_allLines, i))
deleteLabels() =>
a_allLabels = label.all
if array.size(a_allLabels) > 0
for i = 0 to array.size(a_allLabels) - 1
label.delete(array.get(a_allLabels, i))
createLines(arrayOfPocs, arrayOfOpens, arrayOfCloses, arrayOfColors, qtyOfCloses, maxLines, maxBrokenLines, barAlign, demandColor, supplyColor) =>
int qtyOfPocs = array.size(arrayOfPocs)
int supplyLinesCount = 0
int supplyBrokenLinesCount = 0
int demandLinesCount = 0
int demandBrokenLinesCount = 0
float lastClose = close[1]
bool stopPocIndexNo = false
deleteLines()
deleteLabels()
for pocIndexNo = (qtyOfPocs > 1 ? qtyOfPocs - 1 : na) to 0
int closeCount = 0
bool lineCrossed = false
int barsSince = (bar_index - pocIndexNo) - 1
float barPoc = array.get(arrayOfPocs, pocIndexNo)
cColor = array.get(arrayOfColors, pocIndexNo)
//string supplyCrossedCloses = na
//string demandCrossedCloses = na
if stopPocIndexNo == false
if barPoc > 0 and barsSince > 2
bool isDemand = barPoc < lastClose
int lineIndex = (bar_index - barsSince) > (bar_index - 2500) ? (bar_index - barsSince) : bar_index - 2500
for indexNo = barsSince to 1
if lineCrossed == false
fClose = array.get(arrayOfCloses, indexNo)
fOpen = array.get(arrayOfOpens, indexNo)
if (fClose > barPoc and fOpen < barPoc) or (fClose < barPoc and fOpen > barPoc)
closeCount := closeCount + 1
if (closeCount > qtyOfCloses)
lineCrossed := true
if lineCrossed
if isDemand and demandBrokenLinesCount < maxBrokenLines
line.new(lineIndex, barPoc, bar_index + barAlign, barPoc, color = color.new(color.white, 50), style = line.style_dotted, width = 1, extend = extend.none)
label.new(bar_index + barAlign, barPoc, text = str.tostring(barPoc), textcolor = color.new(color.white, 50), textalign = text.align_right, style = label.style_none)
demandBrokenLinesCount := demandBrokenLinesCount + 1
else
if supplyBrokenLinesCount < maxBrokenLines
line.new(lineIndex, barPoc, bar_index + barAlign, barPoc, color = color.new(color.white, 50), style = line.style_dotted, width = 1, extend = extend.none)
label.new(bar_index + barAlign, barPoc, text = str.tostring(barPoc), textcolor = color.new(color.white, 50), textalign = text.align_right, style = label.style_none)
supplyBrokenLinesCount := supplyBrokenLinesCount + 1
else
if lineCrossed == false
if isDemand and demandLinesCount < maxLines
line.new(lineIndex, barPoc, bar_index + barAlign, barPoc, color = cColor, style = line.style_dashed, width = 1, extend = extend.none)
label.new(bar_index + barAlign, barPoc, text = str.tostring(barPoc), textcolor = cColor, textalign = text.align_right, style = label.style_none)
demandLinesCount := demandLinesCount + 1
else
if supplyLinesCount < maxLines
line.new(lineIndex, barPoc, bar_index + barAlign, barPoc, color = cColor, style = line.style_dashed, width = 1, extend = extend.none)
label.new(bar_index + barAlign, barPoc, text = str.tostring(barPoc), textcolor = cColor, textalign = text.align_right, style = label.style_none)
supplyLinesCount := supplyLinesCount + 1
if supplyBrokenLinesCount == maxBrokenLines and demandBrokenLinesCount == maxBrokenLines and supplyLinesCount == maxLines and demandLinesCount == maxLines
stopPocIndexNo := true
///// Calculations
// Calculate moving average and highest volume bar in the last volLengthInput
maVol := ta.sma(volume, maLengthInput)
highestVol := ta.highest(volume, volLengthInput)
// Detect new POC Lines by finding vars that breached the Moving Average with Multiplier as well as being the most recent highest volume bar
pocCondition := (volume >= maVol * maMultiplierInput) and volume == highestVol
// Store bar POC's if poc condition is met, otherwise store nothing
if pocCondition
array.push(barPocs, (high + low)/2)
if close > open
array.push(barColors, demandColorInput)
else
array.push(barColors, supplyColorInput)
else
array.push(barPocs, 0)
array.push(barColors, na)
// Store opens/closes for later calculations to detect line crosses
array.push(barCloses, close)
array.push(barOpens, open)
// We don't want to calculate line breaches every bar as it would be too slow, so wait until its the last bar to look for POC's
if barstate.islast
aOpens = array.copy(barOpens)
aCloses = array.copy(barCloses)
array.reverse(aOpens)
array.reverse(aCloses)
createLines(barPocs, aOpens, aCloses, barColors, qtyOfClosesInput, qtyOfLinesInput/2, qtyOfBrokenLinesInput/2, barAlignInput, demandColorInput, supplyColorInput)
barcolor(color = pocCondition and close > open ? demandColorInput : pocCondition and open > close ? supplyColorInput : na)
If I remove some of the functionality to speed up the script, only checking for non crossed lines, it works without issue.
/#version=5
indicator("High Volume Candle Mid", overlay = true, max_lines_count = 100, max_labels_count = 100, max_bars_back = 5000)
maLengthInput = input.int(defval = 34, title = "Volume - Moving Average Length", group = "Options")
volLengthInput = input.int(defval = 5, title = "Volume - Look Back", group = "Options")
maMultiplierInput = input.float(defval = 2, title = "Volume - MA Multiplier", tooltip = "Filter's out weak volume candles that break MA", group = "Options")
qtyOfClosesInput = input.int(defval = 3, title = "(n) closes to cross POC to invalidate.", group = "Options")
qtyOfLinesInput = input.int(defval = 10, title = "(n) latest POC's to show", group = "Options")
qtyOfBrokenLinesInput = input.int(defval = 10, title = "(n) latest historical POC's to show", group = "Options")
barAlignInput = input.int(defval = 20, title = "Bar Index Offset", tooltip = "How many bars past price to extend labels/lines", group = "Options")
supplyColorInput = input.color(defval = #FF5252, title = "Supply Zone - POC's", group = "Options" )
demandColorInput = input.color(defval = #4CAF50, title = "Demand Zone - POC's", group = "Options")
///// Variables
var float maVol = na
var float highestVol = na
var bool pocCondition = false
var float[] barOpens = array.new_float()
var float[] barCloses = array.new_float()
var float[] barPocs = array.new_float()
var color[] barColors = array.new_color()
///// Functions
deleteLines() =>
a_allLines = line.all
if array.size(a_allLines) > 0
for i = 0 to array.size(a_allLines) - 1
line.delete(array.get(a_allLines, i))
deleteLabels() =>
a_allLabels = label.all
if array.size(a_allLabels) > 0
for i = 0 to array.size(a_allLabels) - 1
label.delete(array.get(a_allLabels, i))
createLines(arrayOfPocs, arrayOfOpens, arrayOfCloses, arrayOfColors, qtyOfCloses, maxLines, maxBrokenLines, barAlign, demandColor, supplyColor) =>
int qtyOfPocs = array.size(arrayOfPocs)
int supplyLinesCount = 0
int supplyBrokenLinesCount = 0
int demandLinesCount = 0
int demandBrokenLines = 0
float lastClose = close[1]
deleteLines()
deleteLabels()
for pocIndexNo = (qtyOfPocs > 1 ? qtyOfPocs - 1 : na) to 0
int supplyCloseCount = 0
int demandCloseCount = 0
bool supplyLineCrossed = false
bool demandLineCrossed = false
int barsSince = (bar_index - pocIndexNo) - 1
float barPoc = array.get(arrayOfPocs, pocIndexNo)
cColor = array.get(arrayOfColors, pocIndexNo)
//string supplyCrossedCloses = na
//string demandCrossedCloses = na
//if supplyLinesCount < maxLines or supplyBrokenLinesCount < maxBrokenLines
if barPoc > lastClose and barPoc > 0
if barsSince > 1
int lineIndex = (bar_index - barsSince) > (bar_index - 4999) ? (bar_index - barsSince) : bar_index - 4999
for indexNo = barsSince to 1
fClose = array.get(arrayOfCloses, indexNo)
fOpen = array.get(arrayOfOpens, indexNo)
if (fClose > barPoc and fOpen < barPoc) or (fClose < barPoc and fOpen > barPoc)
//supplyCrossedCloses := supplyCrossedCloses + "Crossed Count: " + str.tostring(supplyCloseCount) + "\n" + str.tostring(fClose) + " > " + str.tostring(barPoc) + " and " + str.tostring(fOpen) + " < " + str.tostring(barPoc) + " or " + str.tostring(fClose) + " < " + str.tostring(barPoc) + " and " + str.tostring(fOpen) + " > " + str.tostring(barPoc) + "\n"
supplyCloseCount := supplyCloseCount + 1
if (supplyCloseCount > qtyOfCloses)
supplyLineCrossed := true
// if supplyLineCrossed == true and supplyBrokenLinesCount < maxBrokenLines
// line.new(lineIndex, barPoc, bar_index + barAlign, barPoc, color = color.new(color.white, 50), style = line.style_dotted, width = 1, extend = extend.none)
// label.new(bar_index + barAlign, barPoc, text = str.tostring(barPoc) + " [" + str.tostring(lineIndex) + "]", textcolor = color.new(color.white, 50), textalign = text.align_right, style = label.style_none)
// supplyBrokenLinesCount := supplyBrokenLinesCount + 1
if supplyLineCrossed == false and supplyLinesCount < maxLines
//label.new(lineIndex, close + (supplyLines * 400), text = "barPoc: " + str.tostring(barPoc) + "\nsupplyLines: " + str.tostring(supplyLines) + "\nsupplyCloseCount: " + str.tostring(supplyCloseCount) + "\n" + supplyCrossedCloses, textcolor = color.aqua, style = label.style_label_down, color = color.new(color.white, 100))
line.new(lineIndex, barPoc, bar_index + barAlign, barPoc, color = cColor, style = line.style_dashed, width = 1, extend = extend.none)
label.new(bar_index + barAlign, barPoc, text = str.tostring(barPoc) + " [" + str.tostring(lineIndex) + "]", textcolor = cColor, textalign = text.align_right, style = label.style_none)
supplyLinesCount := supplyLinesCount + 1
///// Calculations
// Calculate moving average and highest volume bar in the last volLengthInput
maVol := ta.sma(volume, maLengthInput)
highestVol := ta.highest(volume, volLengthInput)
// Detect new POC Lines by finding vars that breached the Moving Average with Multiplier as well as being the most recent highest volume bar
pocCondition := (volume >= maVol * maMultiplierInput) and volume == highestVol
// Store bar POC's if poc condition is met, otherwise store nothing
if pocCondition
array.push(barPocs, (high + low)/2)
if close > open
array.push(barColors, demandColorInput)
else
array.push(barColors, supplyColorInput)
else
array.push(barPocs, 0)
array.push(barColors, na)
// Store opens/closes for later calculations to detect line crosses
array.push(barCloses, close)
array.push(barOpens, open)
// We don't want to calculate line breaches every bar as it would be too slow, so wait until its the last bar to look for POC's
if barstate.islast
aOpens = array.copy(barOpens)
aCloses = array.copy(barCloses)
array.reverse(aOpens)
array.reverse(aCloses)
createLines(barPocs, aOpens, aCloses, barColors, qtyOfClosesInput, qtyOfLinesInput/2, qtyOfBrokenLinesInput/2, barAlignInput, demandColorInput, supplyColorInput)
barcolor(color = pocCondition and close > open ? demandColorInput : pocCondition and open > close ? supplyColorInput : na)
Not sure what I am missing about the barstate.islast and how it affects series lengths that could be causing me issue. I stopped referencing bar_index in the arrays I was utilizing to find the historical Mids I needed, but I still use it to create lines. If this is not supported does anyone have a better idea for creating the lines? Or if there is some issue with creating lines under multiple conditionals?

table array security request Bollinger Pine script

I am attempting to create a scanner for higher time frame Bollingers to place in a table. I have the code working partially using variable. But have been unable to successfully add the data to a table array. My goal is to create a table array that list assets and color codes then in table when conditions are met i.e. price is above or below my signal bollinger deviation.
I have added the assets into arrays but have not been successful in getting them to plot as an array.
as a variable using table cell i get a single asset that plot.
`//#version=5
indicator('Matrix Radar test', overlay=true)
custom_tf = input.timeframe('', title='Timeframe for Screening')
lbl_col = color.new(color.gray, 100)
len3= input.int(50, minval=1, title="Ma Length 1")
len4= input.int(100, minval=1, title="Ma Length 2")
len5= input.int(200, minval=1, title="Ma Length 3")
BB_sdev25 = input.float(2.5, minval=0.001, maxval = 2.8, title="Signal")
//dev for signal 100
dev37 = BB_sdev25 * ta.stdev(close, len4)
//dev for signal 200
dev38 = BB_sdev25 * ta.stdev(close, len5)
//dev for signal 50
dev39 = BB_sdev25 * ta.stdev(close, len3)
//50 1h signals
dma50_up1hs=request.security(syminfo.tickerid, "60", ta.sma(close, len3) + dev39)
dma50_dwn1hs=request.security(syminfo.tickerid, "60", ta.sma(close, len3) - dev39)
//50 4hr signals
dma50_up4hs=request.security(syminfo.tickerid, "240", ta.sma(close, len3) + dev39)
dma50_dwn4hs=request.security(syminfo.tickerid, "240", ta.sma(close, len3) - dev39)
//50 day signals
dma50_upDs=request.security(syminfo.tickerid, "D", ta.sma(close, len3) + dev39)
dma50_dwnDs=request.security(syminfo.tickerid, "D", ta.sma(close, len3) - dev39)
// 100 1 hr signals
dma100_up1hs=request.security(syminfo.tickerid, "60", ta.sma(close, len4) + dev37)
dma100_dwn1hs=request.security(syminfo.tickerid, "60", ta.sma(close, len4) - dev37)
//100 4 hr signal 4hr
dma100s_up4=request.security(syminfo.tickerid, "240", ta.sma(close, len4) + dev37)
dma100s_dwn4=request.security(syminfo.tickerid, "240", ta.sma(close, len4) - dev37)
//100 day signals
dma100_upDs=request.security(syminfo.tickerid, "D", ta.sma(close, len4) + dev37)
dma100_dwnDs=request.security(syminfo.tickerid, "D", ta.sma(close, len4) - dev37)
//200 1h signal
dma200_up1hs=request.security(syminfo.tickerid, "60", ta.sma(close, len5) + dev38)
dma200_dwn1hs=request.security(syminfo.tickerid, "60", ta.sma(close, len5) - dev38)
// 200 4hr signal
dma200_up4s=request.security(syminfo.tickerid, "240", ta.sma(close, len5) + dev38)
dma200_dwn4s=request.security(syminfo.tickerid, "240", ta.sma(close, len5) - dev38)
//200 day signals
dma200_upDs=request.security(syminfo.tickerid, "D", ta.sma(close, len5) + dev38)
dma200_dwnDs=request.security(syminfo.tickerid, "D", ta.sma(close, len5) - dev38)
// plot for visual to check if working
upper10s = ta.sma(close, len4) + dev37
lower10s = ta.sma(close, len4) - dev37
var sma1label9Us = label.new(x = bar_index, y = dma100_up1hs, style = label.style_label_left, color=lbl_col, textcolor = color.yellow, text = "---- --1HUSignal-")
label.set_xy(sma1label9Us, x = bar_index, y = dma100_up1hs)
var sma1label9Ls = label.new(x = bar_index, y = dma100_dwn1hs, style = label.style_label_left, color=lbl_col, textcolor = color.yellow, text = "---- --1HLSignal-")
label.set_xy(sma1label9Ls, x = bar_index, y = dma100_dwn1hs)
// plot for visual to check if working end
indiSet = input(false, '═════════ MRC Parameter ════════')
screenSet = input(false, '═════════ Screening Setting ════════')
screenList = input(false, '═════════ Asset for Screening ════════')
asset_01 = input.symbol(title='Asset 01', defval='')
asset_02 = input.symbol(title='Asset 02', defval='')
asset_03 = input.symbol(title='Asset 03', defval='')
asset_04 = input.symbol(title='Asset 04', defval='')
asset_05 = input.symbol(title='Asset 05', defval='')
asset_06 = input.symbol(title='Asset 06', defval='')
asset_07 = input.symbol(title='Asset 07', defval='')
asset_08 = input.symbol(title='Asset 08', defval='')
asset_09 = input.symbol(title='Asset 09', defval='')
asset_10 = input.symbol(title='Asset 10', defval='')
asset_11 = input.symbol(title='Asset 11', defval='')
asset_12 = input.symbol(title='Asset 12', defval='')
asset_13 = input.symbol(title='Asset 13', defval='')
asset_14 = input.symbol(title='Asset 14', defval='')
asset_15 = input.symbol(title='Asset 15', defval='')
asset_16 = input.symbol(title='Asset 16', defval='')
asset_17 = input.symbol(title='Asset 17', defval='')
asset_18 = input.symbol(title='Asset 18', defval='')
asset_19 = input.symbol(title='Asset 19', defval='')
asset_20 = input.symbol(title='Asset 20', defval='')
asset_21 = input.symbol(title='Asset 21', defval='')
asset_22 = input.symbol(title='Asset 22', defval='')
screen_mrc() =>
int condition = 0
// if low < dma50_dwn1hs or low < dma50_dwn4hs or low < dma50_dwnDs
//condition := 1
//if high > dma50_up1hs or high > dma50_up4hs or high > dma50_upDs
//condition := 1
/// this line below the greater than and less than reversed to force signal for testing
if low > dma100_dwn1hs or high < dma100_up1hs /////////////////////////////////////////
condition := 1 /////////////////////////////////////////
/// this code above the greater than and less than reversed to force signal for testing
//if low < dma100s_dwn4 or high > dma100s_up4
//condition := 3
//if low < dma100_dwnDs or high > dma100_upDs
// condition := 4
//if low < dma200_dwn1hs or high > dma200_up1hs
// condition := 5
// if low < dma200_dwn4s or high > dma200_up4s
// condition := 6
// if low < dma200_dwnDs or high > dma200_upDs
//condition := 7
// Retrieves the names of the ticker
//************************************************************************************************** **********
// Screener Logic
//************************************************************************************************************
// set asset status {
asset_01_status = asset_01 == '' ? 0 : request.security(asset_01, custom_tf, screen_mrc())
asset_02_status = asset_02 == '' ? 0 : request.security(asset_02, custom_tf, screen_mrc())
asset_03_status = asset_03 == '' ? 0 : request.security(asset_03, custom_tf, screen_mrc())
asset_04_status = asset_04 == '' ? 0 : request.security(asset_04, custom_tf, screen_mrc())
asset_05_status = asset_05 == '' ? 0 : request.security(asset_05, custom_tf, screen_mrc())
asset_06_status = asset_06 == '' ? 0 : request.security(asset_06, custom_tf, screen_mrc())
asset_07_status = asset_07 == '' ? 0 : request.security(asset_07, custom_tf, screen_mrc())
asset_08_status = asset_08 == '' ? 0 : request.security(asset_08, custom_tf, screen_mrc())
asset_09_status = asset_09 == '' ? 0 : request.security(asset_09, custom_tf, screen_mrc())
asset_10_status = asset_10 == '' ? 0 : request.security(asset_10, custom_tf, screen_mrc())
asset_11_status = asset_11 == '' ? 0 : request.security(asset_11, custom_tf, screen_mrc())
asset_12_status = asset_12 == '' ? 0 : request.security(asset_12, custom_tf, screen_mrc())
asset_13_status = asset_13 == '' ? 0 : request.security(asset_13, custom_tf, screen_mrc())
asset_14_status = asset_14 == '' ? 0 : request.security(asset_14, custom_tf, screen_mrc())
asset_15_status = asset_15 == '' ? 0 : request.security(asset_15, custom_tf, screen_mrc())
asset_16_status = asset_16 == '' ? 0 : request.security(asset_16, custom_tf, screen_mrc())
asset_17_status = asset_17 == '' ? 0 : request.security(asset_17, custom_tf, screen_mrc())
asset_18_status = asset_18 == '' ? 0 : request.security(asset_18, custom_tf, screen_mrc())
asset_19_status = asset_19 == '' ? 0 : request.security(asset_19, custom_tf, screen_mrc())
asset_20_status = asset_20 == '' ? 0 : request.security(asset_20, custom_tf, screen_mrc())
asset_21_status = asset_21 == '' ? 0 : request.security(asset_21, custom_tf, screen_mrc())
asset_22_status = asset_22 == '' ? 0 : request.security(asset_22, custom_tf, screen_mrc())
//} end
//symbol name
s_arr = array.new_string(0)
array.push(s_arr, asset_01)
array.push(s_arr, asset_02)
array.push(s_arr, asset_03)
array.push(s_arr, asset_04)
array.push(s_arr, asset_05)
array.push(s_arr, asset_06)
array.push(s_arr, asset_07)
array.push(s_arr, asset_08)
array.push(s_arr, asset_09)
array.push(s_arr, asset_10)
array.push(s_arr, asset_11)
array.push(s_arr, asset_12)
array.push(s_arr, asset_13)
array.push(s_arr, asset_14)
array.push(s_arr, asset_15)
array.push(s_arr, asset_16)
array.push(s_arr, asset_17)
array.push(s_arr, asset_18)
array.push(s_arr, asset_19)
array.push(s_arr, asset_20)
array.push(s_arr, asset_21)
array.push(s_arr, asset_22)
//asset condition state
asset_condition = array.new_bool()
array.push(asset_condition, asset_01_status)
array.push(asset_condition, asset_02_status)
array.push(asset_condition, asset_03_status)
array.push(asset_condition, asset_04_status)
array.push(asset_condition, asset_05_status)
array.push(asset_condition, asset_06_status)
array.push(asset_condition, asset_07_status)
array.push(asset_condition, asset_08_status)
array.push(asset_condition, asset_09_status)
array.push(asset_condition, asset_10_status)
array.push(asset_condition, asset_11_status)
array.push(asset_condition, asset_12_status)
array.push(asset_condition, asset_13_status)
array.push(asset_condition, asset_14_status)
array.push(asset_condition, asset_15_status)
array.push(asset_condition, asset_16_status)
array.push(asset_condition, asset_17_status)
array.push(asset_condition, asset_18_status)
array.push(asset_condition, asset_19_status)
array.push(asset_condition, asset_20_status)
array.push(asset_condition, asset_21_status)
array.push(asset_condition, asset_22_status)
// set lower 1001h signal
lower_100hsignal = ''
lower_100hsignal := asset_01 != '' and asset_01_status == 1 ? lower_100hsignal + asset_01 + ' (100 Lower Signal) \n ' : lower_100hsignal
// set upper 1001h signal
upper_100hsignal = ''
upper_100hsignal := asset_01 != '' and asset_01_status == 1 ? upper_100hsignal + asset_01 + ' (100 Upper Signal) \n ' : upper_100hsignal
// Prep Label Value
//--------------
var assetcount = asset_01 == '' and asset_02 == '' and asset_03 == '' and asset_04 == '' and asset_05 == '' and asset_06 == '' and asset_07 == '' and asset_08 == '' and asset_09 == '' and asset_10 == '' and asset_11 == '' and asset_12 == '' and asset_13 == '' and asset_14 == '' and asset_15 == '' and asset_16 == '' and asset_17 == '' and asset_18 == '' and asset_19 == '' and asset_20 == '' and asset_21 == '' and asset_22 == '' ? 0 : 1
var tf = custom_tf == '' ? timeframe.period : custom_tf
var brl = '\n-----------------------\n'
title = 'Bollinger Band Signals:\nTimeframe = ' + tf + brl
var lowertable = table.new(position = position.bottom_left, columns = 1, rows = 40, bgcolor = color.blue, border_width = 3 )
if assetcount > 0
if lower_100hsignal + lower_100hsignal != ''
lower_100hsignal := '\lower100' + lower_100hsignal
lower_100hsignal
if barstate.islast
table.cell(lowertable, column = 0, row = 0, text=title + lower_100hsignal)
var upperTable = table.new(position = position.middle_left, columns = 1, rows = 40, bgcolor = color.red, border_width = 1)
if assetcount > 0
if upper_100hsignal + upper_100hsignal != ''
upper_100hsignal := '\upper100' + upper_100hsignal
upper_100hsignal
if barstate.islast
table.cell(table_id = upperTable, column = 0, row = 0, text=title + upper_100hsignal)`

Fixing Plotting of Initial Balance Indicator in AmiBroker AFL

I am using the following AFL code for "Initial Balance with Range Extension" in AmiBroker -
_SECTION_BEGIN("Initial Balance with Range Extensions");
P11 = Param("IB Start Time",091500, 0 , 235959, 1 ) ;
P12 = Param("IB END Time",101500, 0 , 235959, 1 ) ;
START = (TimeNum()>= P11);
END = (TimeNum()<= P12);
ZONE = START AND END;
ST = (TimeNum()>= P12);
NewTime = ZONE!= Ref(ZONE, -1);
highestoftheday = HighestSince(NewTime,H,1);
Lowestoftheday = LowestSince(NewTime,L,1);
IBHigh = ValueWhen(ZONE,highestoftheday,1);
IBLow = ValueWhen(ZONE,lowestoftheday,1);
ORBClose = ValueWhen(zone,C,1);
IBrange = IBHigh - IBLow; // First Hour Range
IBM = IBLow+IBrange/2;
IB1xh = IBHigh+IBrange ; // Target 1 for range extension upside
IB2xh = IBHigh+2*IBrange ;
IB3xh = IBHigh+3*IBrange ;
IB1xl = IBLow-IBrange ;
IB2xl = IBLow-2*IBrange ; // target 1 for range extension downside
IB3xl = IBLow-3*IBrange ;
PlotGrid(LastValue(IBHigh, True), colorPlum, pattern=10, width = 2, label = True);
PlotGrid(LastValue(IBLow, True), colorPlum, pattern=10, width = 2, label = True);
PlotGrid(LastValue(IBM, True), colorBrown, pattern=10, width = 2, label = True);
PlotGrid(LastValue(IB1xh, True), colorGreen, pattern=10, width = 2, label = True);
PlotGrid(LastValue(IB2xh, True), colorGreen, pattern=10, width = 2, label = True);
PlotGrid(LastValue(IB3xh, True), colorGreen, pattern=10, width = 2, label = True);
PlotGrid(LastValue(IB1xl, True), colorRed, pattern=10, width = 2, label = True);
PlotGrid(LastValue(IB2xl, True), colorRed, pattern=10, width = 2, label = True);
PlotGrid(LastValue(IB3xl, True), colorRed, pattern=10, width = 2, label = True);
_SECTION_END();
This code is plotting continuous horizontal lines. But I need disjointed horizontal lines for individual sessions. How can I get that? Please help me to fix this issue. Thanks for your time and effort. Regards.

Historical Market Screener: Processing Array Data

I have a question with respect to arrays & tables on PineScript, please. To give an overview of what I am intending to do, I want to create a screener that will go through a set of symbols and output the annual performance at a historical date.
The idea behind this concept is that I would be able to identify top performing symbols from a historical perspective. I have researched online, and I was not able to find such a tool.
The reason why I would need a tool like this, is so that I can back-test my strategy on historical top-performers, considering that I would be rebalancing my portfolio at a fixed interval e.g. once per quarter.
So my questions with regards to the code below are basically 2 –
How can I filter the arrays to output only values above 10% yearly performance?
How do I sort the table so that the top performers come to the top of the list?
I have shortened the code for this post. However, this screener can go through a max of 40 symbols as you all know. My plan is to run this on basically all the major and minor FX pairs and for stocks, I will pick a balanced portfolio with stocks from each of the 11 S&P sectors. As liquidity rotates through each of sectors, this should keep me running my strategy on stocks with positive alpha potential.
//#version=5
indicator('Annual Performance Historical Screener', overlay=true)
////////////
// INPUTS //
//Year Input
input_year = input(2022, "Year")
/////////////
// SYMBOLS //
u01 = input.bool(true, title = "", group = 'Symbols', inline = 's01')
u02 = input.bool(true, title = "", group = 'Symbols', inline = 's02')
u03 = input.bool(true, title = "", group = 'Symbols', inline = 's03')
u04 = input.bool(true, title = "", group = 'Symbols', inline = 's04')
u05 = input.bool(true, title = "", group = 'Symbols', inline = 's05')
s01 = input.symbol('XRPUSDT', group = 'Symbols', inline = 's01')
s02 = input.symbol('BTCUSDT', group = 'Symbols', inline = 's02')
s03 = input.symbol('DOGEUSDT', group = 'Symbols', inline = 's03')
s04 = input.symbol('BNBUSDT', group = 'Symbols', inline = 's04')
s05 = input.symbol('ETHUSDT', group = 'Symbols', inline = 's05')
//////////////////
// CALCULATIONS //
// Get only symbol
only_symbol(s) =>
array.get(str.split(s, ":"), 1)
//price at the input
price_input_year = timestamp(input_year,10,12)
period = time >= price_input_year and time[1] < price_input_year
periodPrice = ta.valuewhen(period, close, 0)
//price at 1 year preceeding input
price_prev_year = timestamp(input_year-1,10,12)
period_prev = time >= price_prev_year and time[1] < price_prev_year
periodPrice_prev = ta.valuewhen(period_prev, close, 0)
screener_func() =>
//Yearly performance from input date
annual_perf=(periodPrice-periodPrice_prev)*100/periodPrice
[math.round_to_mintick(close), annual_perf]
// Security call
[cl01, ap01] = request.security(s01, timeframe.period, screener_func())
[cl02, ap02] = request.security(s02, timeframe.period, screener_func())
[cl03, ap03] = request.security(s03, timeframe.period, screener_func())
[cl04, ap04] = request.security(s04, timeframe.period, screener_func())
[cl05, ap05] = request.security(s05, timeframe.period, screener_func())
////////////
// ARRAYS //
s_arr = array.new_string(0)
u_arr = array.new_bool(0)
cl_arr = array.new_float(0)
ap_arr = array.new_float(0)
// Add Symbols
array.push(s_arr, only_symbol(s01))
array.push(s_arr, only_symbol(s02))
array.push(s_arr, only_symbol(s03))
array.push(s_arr, only_symbol(s04))
array.push(s_arr, only_symbol(s05))
///////////
// FLAGS //
array.push(u_arr, u01)
array.push(u_arr, u02)
array.push(u_arr, u03)
array.push(u_arr, u04)
array.push(u_arr, u05)
///////////
// CLOSE //
array.push(cl_arr, cl01)
array.push(cl_arr, cl02)
array.push(cl_arr, cl03)
array.push(cl_arr, cl04)
array.push(cl_arr, cl05)
/////////
// Annual performance //
array.push(ap_arr, ap01)
array.push(ap_arr, ap02)
array.push(ap_arr, ap03)
array.push(ap_arr, ap04)
array.push(ap_arr, ap05)
///////////
// PLOTS //
var tbl = table.new(position.top_right, 6, 41, frame_color=#151715, frame_width=1, border_width=2, border_color=color.new(color.white, 100))
if barstate.islast
table.cell(tbl, 0, 0, 'Symbol', text_halign = text.align_center, bgcolor = color.gray, text_color = color.white, text_size = size.small)
table.cell(tbl, 1, 0, 'Price', text_halign = text.align_center, bgcolor = color.gray, text_color = color.white, text_size = size.small)
table.cell(tbl, 2, 0, 'Annual Performance', text_halign = text.align_center, bgcolor = color.gray, text_color = color.white, text_size = size.small)
for i = 0 to 4
if array.get(u_arr, i)
ap_col = array.get(ap_arr, i) >= 10 ? color.green : #aaaaaa
table.cell(tbl, 0, i + 1, array.get(s_arr, i), text_halign = text.align_left, bgcolor = color.gray, text_color = color.white, text_size = size.small)
table.cell(tbl, 1, i + 1, str.tostring(array.get(cl_arr, i)), text_halign = text.align_center, bgcolor = #aaaaaa, text_color = color.white, text_size = size.small)
table.cell(tbl, 2, i + 1, str.tostring(array.get(ap_arr, i), "#.##"), text_halign = text.align_center, bgcolor = ap_col, text_color = color.white, text_size = size.small)

div align right checkboxInput in shiny dashboard not working

My shiny dashboard has checkboxInput and I am trying to align it to right within the title of the box item. For smaller boxes (width of 6) the alignment is proper, however for boxes with width of 12, which ever way I realign the column values, the checkbox input remains at the middle of the box. The code is as follows:
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
skin = "green",
dashboardHeader(
title = "TEST", titleWidth = 225
),
dashboardSidebar(
menuItem("TRENDS", tabName = "vactr", icon = shiny::icon("line-chart"))
),
dashboardBody(
tabItems(
tabItem(
tabName = "vactr",
fluidRow(
box(
width = 12, status = "info", title =
fluidRow(
column(6, "Trend - Usage of space",br(),
div(downloadLink("downloadspacetrend", "Download this chart"), style = "font-size:70%", align = "left")),
column(6,
div(checkboxInput(inputId = "spacetrendcheck", "Add to reports", value = FALSE),style = "font-size:70%",float = "right", align = "right", direction = "rtl"))
),
div(plotOutput("spacetrend"), width = "100%", height = "400px", style = "font-size:90%;"),
uiOutput("spacetrendcomment")
)
)
)
)
)
)
server <- function(input, output, session) {
}
shinyApp(ui = ui, server = server)
I want the "Add to reports" check box to the right end of the box. I tried using float, direction arguments with and without, but not getting the desired output.
There is the following reason for you problem: The header title's width is not set to the whole width of the box. Instead, its width is calculated from the elements it contains. This makes the columns (which are 50% title width) also depend on the elements. Your elements however are not that big, so the resulting div is in itself well divided in two equally large columns, but they together don't span the whole box width.
You can just fix the title width to 100% (box header width), which as a result tells the columns to be that large, whatever their content might be.
This is a one line addition.
Note that the style addition in the code below affects all box titles. But I believe that this is never really a problem.
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
skin = "green",
dashboardHeader(
title = "TEST", titleWidth = 225
),
dashboardSidebar(
menuItem("TRENDS", tabName = "vactr", icon = shiny::icon("line-chart"))
),
dashboardBody(
tabItems(
tabItem(tabName = "vactr",
fluidRow(
box(width = 12, status = "info", title =
fluidRow(
tags$style(".box-title {width: 100%;}"),
column(6, "Trend - Usage of space",br(),
div(downloadLink("downloadspacetrend", "Download this chart"), style = "font-size:70%", align = "left")),
column(6,
div(checkboxInput(inputId = "spacetrendcheck", "Add to reports", value = FALSE),style = "font-size:70%",float = "right", align = "right", direction = "rtl"))
),
div(plotOutput("spacetrend"), width = "100%", height = "400px", style = "font-size:90%;"),
uiOutput("spacetrendcomment")
)
)
)
)
)
)
server <- function(input, output, session) {}
shinyApp(ui = ui, server = server)

Resources