table array security request Bollinger Pine script - arrays

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)`

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?

When i apply it it showing Script could not be translated from: |B|var rsiLength = 14|E|

// Inputs
var rsiLength = 14
var macdFastLength = 12
var macdSlowLength = 26
var macdSignalLength = 9
var atrLength = 14
var volumeFactor = 0.1
// Calculate indicators
var rsi = rsi(close, rsiLength)
var macd = macd(close, macdFastLength, macdSlowLength, macdSignalLength)
var atr = atr(atrLength)
var volume = volume * volumeFactor
// Define signals
var buySignal = rsi < 30 and macd.histogram > 0 and volume > atr
var sellSignal = rsi > 70 and macd.histogram < 0 and volume > atr
// Plot signals
plot(buySignal ? 50 : na, color=color.green, linewidth=3, style=plot.style_circles, title='Buy Signal')
plot(sellSignal ? 50 : na, color=color.red, linewidth=3, style=plot.style_circles, title='Sell Signal')
// Capital
strategy.risk = 0.01
strategy.entry("Long", strategy.long, when=buySignal, comment="Buy")
strategy.close("Long", when=sellSignal, comment="Sell")
Script could not be translated from: |B|var rsiLength = 14|E|
It tried to make a strategy which generates buy and sell signal but it showing this

Develope strategy Pinescript

I would transform this code in strategy, but I got continue errors about it.
Can u help me to fix?
Conditions:
open LONG: close >= simpleVMA
close LONG: crossunder and not na(vrsi) and isUp
open SHORT: close <= simpleVMA
close SHORT: crossover and not na(vrsi) and isDown
`//Input
showAMA=input(true, title="----------Show Averaged sma?")
showVMA =input(false, title="----------Show Simple sma?")
colorBlueSlate = #5674b9 //Slate blue
colorBlueDark = #311B92 //darkBlue
colorBlueLt = #2196F3 //Light Blue
colorYellow = #C1B82F //yellow
colorGreen = #007236 //Green
colorRed = #FF0000 //Red
colorWhite = #FFFFFF //White
colorGray = #dbdbdb //light gray
colorBlack = #000000 //Black
showVMA= ta.sma(ta.sma(hlc3), 50) //originale 55
simpleVMA= ta.sma(close)
plotsma = plot(showAVMA ? showVMA: na, color=colorRed, linewidth=3, title="Plot sma SMA")
plotsmaSimple = plot(showVMA ? simpleVMA: na, color=colorRed, linewidth=1, title="Plot sma Simple")
rsi = ta.rsi(close, 14)
isRsiOB = (close >= simplesma) and (rsi > 35)
isRsiOS = (close <= simplesma) and (rsi <= 65)
//showVMA= ta.sma(ta.sma(hlc3), 55)
//simpleVMA= ta.sma(close)
ma1 = ta.ema(close, 1)
//plotsma = plot(showAVMA ? showVMA: na, color=colorRed, linewidth=3, title="Plot sma SMA")
//plotsmaSimple = plot(showVMA ? simpleVMA: na, color=colorRed, linewidth=1, title="Plot sma Simple")
TrendUp1 = ma1 > showVMA //ma1 > averagedsma
TrendDown1 = ma1 <= showVMA//showVMA<= ma1
isUp = close >= simpleVMA
isDown = close <= simpleVMA
isInside = close < high[1] and low > low[1]
PULLUP = (close >= simplesma) and (rsi <= 65)
PULLDOWN = (close <= simplesma) and (rsi > 35)
barcolor(TrendUp1 ? color.yellow: TrendDown1 ? color.red: PULLUP ? color.black: PULLDOWN ? color.black: na)
length = input( 14 )
overSold = input( 30 )
overBought = input( 70 )
price = close
vrsi = ta.rsi(price, length)
crossover = ta.crossover(vrsi, overSold)
crossunder = ta.crossunder(vrsi, overBought)
long = crossover and not na(vrsi) and isDown
short = crossunder and not na(vrsi) and isUp
long1 = crossover and not na(vrsi) and isUp
short1 = crossunder and not na(vrsi) and isDown
plotshape(long, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, text='Tp', textcolor=color.new(color.white, 0)) //plotting up arrow when buy/long conditions met
plotshape(short, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, text='Tp', textcolor=color.new(color.white, 0)) //plotting down arrow when sell/short conditions met
plotshape(long1, style=shape.circle, location=location.belowbar, color=color.white, size=size.small, text='', textcolor=color.new(color.white, 0)) //plotting up arrow when buy/long conditions met
plotshape(short1, style=shape.circle, location=location.abovebar, color=color.white, size=size.small, text='', textcolor=color.new(color.white, 0)) //plotting down arrow when sell/short conditions met`

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

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

SQL Server Merge with case?

Hello guys here with another question, regarding sql server 2008 r2 this time about the merge, is it possible to have a case inside the update portion of the merge?
Because its telling me
Msg 156, Level 15, State 1, Line 9
Incorrect syntax near the keyword 'CASE'.
MERGE INTO PERSONAFISICA AS TARGET
USING dbo.#temp1 AS SOURCE
ON TARGET.RFC = SOURCE.RFC AND TARGET.APATERNO = SOURCE.APELLIDO_PATERNO AND
TARGET.AMATERNO = SOURCE.Apellido_Materno
WHEN MATCHED THEN
UPDATE SET
TARGET.NUM_CLIENTE = 0,
TARGET.NOMBRE1 = LEFT(SOURCE.Nombre,CHARINDEX(' ', SOURCE.NOMBRE + ' ') -1),
CASE
WHEN LEN(SOURCE.NOMBRE) - LEN(REPLACE(SOURCE.NOMBRE,' ','')) >= 1
THEN
TARGET.NOMBRE2 = SUBSTRING(SOURCE.NOMBRE, CHARINDEX(' ', SOURCE.NOMBRE)+1, LEN(SOURCE.NOMBRE))
ELSE '' END,
TARGET.APATERNO = SOURCE.Apellido_Paterno,
TARGET.AMTERNO = SOURCE.Apellido_Materno,
CASE
WHEN SOURCE.SEXO = 'F'
THEN TARGET.IDGENERO = 2
WHEN SOURCE.SEXO = 'M'
THEN TARGET.IDGENERO = 1
ELSE TARGET.IDGENERO = 0
END,
CASE
WHEN SOURCE.ESTADO_CIVIL = '0'
THEN TARGET.idestado_civil = 0
WHEN SOURCE.ESTADO_CIVIL = 'C'
THEN TARGET.idestado_civil = 1
WHEN SOURCE.ESTADO_CIVIL = 'D'
THEN TARGET.idestado_civil = 2
WHEN SOURCE.ESTADO_CIVIL = 'S'
THEN TARGET.idestado_civil = 3
WHEN SOURCE.ESTADO_CIVIL = 'V'
THEN TARGET.idestado_civil = 5
WHEN SOURCE.ESTADO_CIVIL = 'U'
THEN TARGET.idestado_civil = 6
ELSE TARGET.idestado_civil = 0
END,
TARGET.idregimen = 0,
TARGET.saludo = SOURCE.SALUDO,
TARGET.conyuge_nombre1 = '',
TARGET.conyuge_nombre2 = '',
TARGET.conyuge_apaterno = '',
TARGET.conyuge_nombre2 = '',
TARGET.dependiente = 0,
TARGET.edad_dependiente = '',
TARGET.ididentificacion = 0,
TARGET.fecha_nacimiento = '1800-01-01',
TARGET.rfc = SOURCE.RFC,
TARGET.CURP = '',
TARGET.idnacionalidad = 0,
TARGET.email = SOURCE.Email_Personal,
TARGET.idescolaridad = SOURCE.Escolaridad
WHEN NOT MATCHED THEN
INSERT (num_cliente, nombre1, nombre2, apaterno, amaterno, idgenero, idestado_civil,
idregimen, saludo, conyuge_nombre1, conyuge_nombre2, conyuge_apaterno, conyuge_amaterno, dependiente,
edad_dependiente, ididentificacion, fecha_nacimiento, rfc, curp, idnacionalidad, email, idescolaridad)
VALUES (0, LEFT(nombre,CHARINDEX(' ',nombre + ' ')-1) AS [Primer Nombre],
CASE WHEN LEN(nombre) - LEN(REPLACE(nombre,' ','')) >= 1 THEN SUBSTRING(nombre, CHARINDEX(' ', nombre)+1, LEN(nombre)) ELSE '' END AS [Segundo Nombre],
Apellido_Paterno,Apellido_Materno)
CASE
WHEN SEXO = 'F' THEN 2
WHEN SEXO = 'M' THEN 1
ELSE 0
END,
CASE
WHEN Estado_Civil = '0' THEN 0
WHEN Estado_Civil = 'C' THEN 1
WHEN Estado_Civil = 'D' THEN 2
WHEN Estado_Civil = 'S' THEN 3
WHEN Estado_Civil = 'V' THEN 5
WHEN Estado_Civil = 'U' THEN 6
ELSE 0
END, 0, Saludo,'','','','',0,'',0,'1800-01-01',RFC,'',0,Email_Personal,Escolaridad
You can't use a case in that way in an update. It needs to be like ...
UPDATE table
SET value1 = CASE
WHEN a.blah = b.blah THEN foo
WHEN a.blah > b.blah THEN bar
ELSE NULL
END,
value2 = 5,
......

Resources