How do I create an alert for a plotshape with an offset of -10, such that when the plotshape is displayed on the chart, an alert would trigger - pine-script-v5

I tried creating a label with an offset and having the alert trigger from the label displayed on the chart but I'm stuck at this point
prd = input.int(defval=10, title='Pivot Period', minval=4, maxval=30, group='Setup')
float src1 = ppsrc == 'High/Low' ? high : math.max(close, open)
float src2 = ppsrc == 'High/Low' ? low : math.min(close, open)
float ph = ta.pivothigh(src1, prd, prd)
float pl = ta.pivotlow(src2, prd, prd)
plotshape(ph and src1, style=shape.triangledown, text='SELL(H)', color=na, textcolor=color.new(#eeff00, 0), location=location.abovebar, offset=-prd)
plotshape(pl and src2, style=shape.triangleup, text='BUY(L)', color=na, textcolor=color.new(#ffffff, 0), location=location.belowbar, offset=-prd)
Lstyle = linestyle == 'Dashed' ? line.style_dashed : linestyle == 'Solid' ? line.style_solid : line.style_dotted
labeloffset = prd
labelcolor = color.red
labeltext = "Sell(R)"
labelcolor2 = color.green
labeltext2 = "Buy(S)"
value1 = ph and src1
value2 = pl and src2
var label ourlabel = na
label_ph = label.new(x = bar_index - labeloffset, y = na, text = labeltext, color = labelcolor, xloc = xloc.bar_index, yloc = yloc.abovebar, textcolor = color.white, style = label.style_label_down, size = size.normal, tooltip = "pl_label_id")
label_pl = label.new(x = bar_index - labeloffset, y = na, text = labeltext2, color = labelcolor2, xloc = xloc.bar_index, yloc = yloc.belowbar, textcolor = color.white, style = label.style_label_up, size = size.normal, tooltip = "ph_label_id")
// Defined my conditions for the label
if ph and src1
label_ph
else
label.delete(ourlabel)
if pl and src2
label_pl
else
label.delete(ourlabel)

Related

Change a box to a plot or plotshape

I have this code for imbalance
//-----------------------------------------------------------------------------}
//Fair Value Gaps
//-----------------------------------------------------------------------------{
//Bullish
[bull_fvg, bull_fvg_count] = imbalance_detection(show_fvg, fvg_usewidth, fvg_method, fvg_gapwidth, low, high[2], low > high[2] and close[1] > high[2])
bull_fvg_filled = bull_filled(bull_fvg, high[2])
//Bearish
[bear_fvg, bear_fvg_count] = imbalance_detection(show_fvg, fvg_usewidth, fvg_method, fvg_gapwidth, low[2], high, high < low[2] and close[1] < low[2])
bear_fvg_filled = bear_filled(bear_fvg, low[2])
if bull_fvg
avg = math.avg(low, high[2])
box.new(n-2, low, n + fvg_extend, high[2], border_color = na, bgcolor = color.new(bull_fvg_css, 80))
line.new(n-2, avg, n + fvg_extend, avg, color = bull_fvg_css)
if bear_fvg
avg = math.avg(low[2], high)
box.new(n-2, low[2], n + fvg_extend, high, border_color = na, bgcolor = color.new(bear_fvg_css, 80))
line.new(n-2, avg, n + fvg_extend, avg, color = bear_fvg_css)
I try to change the box.new by a plot like this but error :Cannot use 'plotshape' in local scope
plotshape_bull = n-2, avg, n + fvg_extend, avg
plotshape(plotshape_bull, color = bull_fvg_css, "BB10 up", style=shape.labelup, color = #00ff0a, location = location.belowbar)
Thanks for your help
The solution
plotshape(bull_fvg_count ? bull_fvg : na ,"Bull", style=shape.arrowup, color = #00ff0a, location = location.top, offset = -1)
plotshape(bear_fvg_count ? bear_fvg : na ,"Bear", style=shape.arrowdown, color = color.red, location = location.top, offset = -1)

Increase the size of label at the top of plot using fviz_screeplot function: I want to increase the size of the label at the top of bar

My_Theme <- theme(axis.title.x = element_text(size = 24),axis.text.x =
element_text(size = 20),axis.text.y = element_text(size = 20),axis.title.y = element_text(size = 24),plot.title = element_text(size = 25))
tt <- fviz_screeplot(t3.mfa, choice = "variance", barfill = "white",
barcolor="steelblue",linecolor="red", ncp = 16, addlabels = TRUE, hjust = 0, main = NULL,
xlab = NULL, ylab = NULL)
mytt <- tt + My_Theme + theme(plot.title = element_text(hjust = 0.5))
myttt <- mytt + labs(title = "Variances - MFA", x = "Principal Components", y = "% of variances")
myttt + theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank())

Connect is not a valid member of TextButton

I wanted List of roblox players in ScrollingFrame, every player is in this list is a button, and when i click any player, his name Appears in Target box
Script:
for i, v in pairs(game.Players:GetChildren()) do ---gets players in list [PlayersList is a ScrollingFrame] when i join game
thc = i/25
local Player = Instance.new("TextButton")
Player.Name = v.Name
Player.Parent = PlayersList
Player.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
Player.BackgroundTransparency = 0.800
Player.Position = UDim2.new(-0.00711364765, 0, thc, 0)
Player.Size = UDim2.new(0, 100, 0, 30)
Player.Font = Enum.Font.FredokaOne
Player.Text = v.Name
Player.TextColor3 = Color3.fromRGB(255, 255, 255)
Player.TextScaled = true
Player.TextSize = 14.000
Player.TextWrapped = true
end
local plr = game.Players.LocalPlayer
game.Players.PlayerAdded:Connect(function(jplr) ---Adds new player in list
print(jplr, 'joined')
for a, b in pairs(PlayersList:GetChildren()) do
b:Destroy()
end
for i, v in pairs(game.Players:GetChildren()) do
thc = i/25
local Player = Instance.new("TextButton")
Player.Name = v.Name
Player.Parent = PlayersList
Player.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
Player.BackgroundTransparency = 0.800
Player.Position = UDim2.new(-0.00711364765, 0, thc, 0)
Player.Size = UDim2.new(0, 100, 0, 30)
Player.Font = Enum.Font.FredokaOne
Player.Text = v.Name
Player.TextColor3 = Color3.fromRGB(255, 255, 255)
Player.TextScaled = true
Player.TextSize = 14.000
Player.TextWrapped = true
end
end)
game.Players.PlayerRemoving:Connect(function(lplr) ---Remove's Players which leave the game
print(lplr, 'left')
for a, b in pairs(PlayersList:GetChildren()) do
b:Destroy()
end
for i, v in pairs(game.Players:GetChildren()) do
if v.Name ~= lplr.Name then
thc = i/25
local Player = Instance.new("TextButton")
Player.Name = v.Name
Player.Parent = PlayersList
Player.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
Player.BackgroundTransparency = 0.800
Player.Position = UDim2.new(-0.00711364765, 0, thc, 0)
Player.Size = UDim2.new(0, 100, 0, 30)
Player.Font = Enum.Font.FredokaOne
Player.Text = v.Name
Player.TextColor3 = Color3.fromRGB(255, 255, 255)
Player.TextScaled = true
Player.TextSize = 14.000
Player.TextWrapped = true
end
end
end)
for g, n in pairs(PlayersList:GetChildren()) do
local ind = n.Text
PlayersList[n.Text]:Connect(function()
TargBox.Text = n.Name
end)
end
Output: Connect is not a valid member of TextButton "Players.Artemka_KRYT.PlayerGui.PrisonByGhosty.MenuButton.BackGround.Taravatar.TargBox.PlayersList.Artemka_KRYT"
You need to connect to an event on the TextButton, not the button itself. I would recommend the Activated event as it fires when someone clicks on the button, and it works on mobile too.
for g, n in pairs(PlayersList:GetChildren()) do
local ind = n.Text
local btn = PlayersList[ind]
btn.Activated:Connect(function()
TargBox.Text = n.Name
end)
end

Move y axis labels to left side of heatmap.2

I would like to move the y-axis labels to the left side of heatmap.2. (This is similar, but not the same, as the question regarding moving the axis on heatmap)
While I am able to move the axis by editing line 290 of the heatmap.2 function, it the values then overwrite the actual heatmap.
if (is.null(srtRow) && is.null(colRow)) {
axis(4, iy, labels = labRow, las = 2, line = -0.5 + offsetRow,
tick = 0, cex.axis = cexRow, hadj = adjRow[1], padj = adjRow[2])
}
else {
if (is.null(srtRow) || is.numeric(srtRow)) {
xpd.orig <- par("xpd")
par(xpd = NA)
ypos <- axis(4, iy, labels = rep("", nr), las = 2, #change
line = -0.5, tick = 0)
text(x = par("usr")[2] + (1 + offsetRow) * strwidth("M"),
y = ypos, labels = labRow, adj = adjRow, cex = cexRow,
srt = srtRow, col = colRow)
par(xpd = xpd.orig)
}
I tried moving the location of the heatmap.2 by mucking about with the lwid and lhei options, but the overwrite problem persisted.
Thank you
Eric

Face detection using color feature

I am trying to detect faces in my picture. So I found a code that do this, but depending on my picture-input sometimes it finds the faces and for other pictures it doesn't work.
So I thought it because of the face's color of person that is on the picture. So when I change the thresholds value sometimes it make to work.
My thresholds value:
%Threshold
hlow = 0.0; hhigh = 0.4;
slow = 0.3; shigh = 0.8;
vlow = 0.4; vhigh = 0.9;
Blob_Threshold = 120;
Edge_Threshold = 650;
Edge_Tolerance = 500;
Percentage_Threshold = 35;
Tolerance = 0.25;
and it here is my code :
function [Faces_List inx_face] = FaceDetection(img)
%----------------Initialization----------------------
Temp_img = img;
img_height = size(Temp_img,1); % tedade satr
img_width = size(Temp_img,2); % tedade sotoona
Temp_img = im2double(Temp_img);
Skin = zeros(img_height,img_width);
%Threshold
hlow = 0.0; hhigh = 0.4;
slow = 0.3; shigh = 0.8;
vlow = 0.4; vhigh = 0.9;
Blob_Threshold = 120;
Edge_Threshold = 650;
Edge_Tolerance = 500;
Percentage_Threshold = 35;
Tolerance = 0.25;
goldenRatio = (1+sqrt(5))/2;
%----------------Convert Color Space From RGB2HSV----
Temp_img = rgb2hsv(Temp_img);
for i = 1:img_height
for j = 1:img_width
H = Temp_img(i,j,1);
S = Temp_img(i,j,2);
V = Temp_img(i,j,3);
bh = H >= hlow && H <= hhigh;
bs = S >= slow && S <= shigh;
bv = V >= vlow && V <= vhigh;
if (bh && bs && bv)
Skin(i,j) = 1;
end
end
end
figure;imshow(Skin);title('Skin Color Detection');
%----------------Initialization----------------------
%Skin_Blob = bwconncomp(Skin,8);
[Skin_Blob,Blob_Number] = bwlabel(Skin);
BlobData = regionprops(Skin_Blob,'all');
%Blob_Number = Skin_Blob.NumObjects;
inx_face = 0;
Faces_List = [];
%----------------Main Face Detection-----------------
for i = 1:Blob_Number
if (BlobData(i).Area > Blob_Threshold)
myFace = BlobData(i).Image;
figure;imshow(myFace);
%pause(1);
myHeight = size(myFace,1);%height
myWidth = size(myFace,2);%width
b1 = (myHeight/myWidth) >= goldenRatio - Tolerance;
b2 = (myHeight/myWidth) <= goldenRatio + Tolerance;
b3 = (myWidth/myHeight) >= goldenRatio - Tolerance;
b4 = (myWidth/myHeight) <= goldenRatio + Tolerance;
Percentage_skin = (sum(myFace(:)) / (myHeight * myWidth)) * 100;
b5 = Percentage_skin > Percentage_Threshold;
boundingBox = BlobData(i).BoundingBox;
x1 = fix(boundingBox(1));
y1 = fix(boundingBox(2));
x2 = fix(boundingBox(3));
y2 = fix(boundingBox(4));
edgeFace = imcrop(img,[x1 y1 x2 y2]);
imGray = rgb2gray(edgeFace);
imEdge = edge(imGray,'sobel');
sumEdge = sum(imEdge(:));
b6 = sumEdge >= Edge_Threshold - Edge_Tolerance;
b7 = sumEdge <= Edge_Threshold + Edge_Tolerance;
if (((b1 && b2) || (b3 && b4)) && b5 && (b6 && b7))
inx_face = inx_face + 1;
Faces_List(inx_face).x1 = x1;
Faces_List(inx_face).y1 = y1;
Faces_List(inx_face).x2 = x2;
Faces_List(inx_face).y2 = y2;
end
end %end if
end %for i
end%Function