Adding an alert condition to this trading view script - view

I am not very savvy on script but have been trying to understand and write an alert condition for a trading view indicator. I tried contacting the creator of the indicator but have heard nothing.
The script below changes from red to green and vice versa but i can't set an alert in tradingview. I'm hoping to add an alertcondition for when the indicator changes from red to green.
Any ideas on how to do this?
//#version=4
study("Donchian Trend Ribbon", precision = 0)
dlen = input(defval = 20, title = "Donchian Channel Period", minval = 10)
dchannel(len)=>
float hh = highest(len)
float ll = lowest(len)
int trend = 0
trend := close > hh[1] ? 1 : close < ll[1] ? -1 : nz(trend[1])
dchannelalt(len, maintrend)=>
float hh = highest(len)
float ll = lowest(len)
int trend = 0
trend := close > hh[1] ? 1 : close < ll[1] ? -1 : nz(trend[1])
maintrend == 1 ? trend == 1 ? #00FF00ff : #00FF009f :
maintrend == -1 ? trend == -1 ? #FF0000ff : #FF00009f :
na
maintrend = dchannel(dlen)
plot( 5, color = dchannelalt(dlen - 0, maintrend), style = plot.style_columns, histbase= 0)
plot(10, color = dchannelalt(dlen - 1, maintrend), style = plot.style_columns, histbase= 5)
plot(15, color = dchannelalt(dlen - 2, maintrend), style = plot.style_columns, histbase=10)
plot(20, color = dchannelalt(dlen - 3, maintrend), style = plot.style_columns, histbase=15)
plot(25, color = dchannelalt(dlen - 4, maintrend), style = plot.style_columns, histbase=20)
plot(30, color = dchannelalt(dlen - 5, maintrend), style = plot.style_columns, histbase=25)
plot(35, color = dchannelalt(dlen - 6, maintrend), style = plot.style_columns, histbase=30)
plot(40, color = dchannelalt(dlen - 7, maintrend), style = plot.style_columns, histbase=35)
plot(45, color = dchannelalt(dlen - 8, maintrend), style = plot.style_columns, histbase=40)
plot(50, color = dchannelalt(dlen - 9, maintrend), style = plot.style_columns, histbase=45)

Related

How do I select a line by clicking in Makie?

I want to be able to select a line on the plot by clicking on it. Ideally, when I click on any line, the number of that line will appear on the screen.
I wrote my code based on the tutorial, but there is no example with lines, so I did what I did. https://docs.makie.org/v0.19/documentation/events/index.html#point_picking
At the moment I have no idea what these numbers are telling me and why. They are not even coordinates of clicked points.
P.S. Actually it is just a starting point. I want to create event interaction on series and topoplots. But for now it would be great to find out the basics.
f = Figure(backgroundcolor = RGBf(0.98, 0.98, 0.98), resolution = (1500, 700))
ax = Axis(f[1, 1], xlabel = "Time [s]", ylabel = "Voltage amplitude [µV]")
N = 1:length(pos)
positions = Observable(rand(Point2f, 10))
xs = 0:0.01:10
ys = 0.5 .* sin.(xs)
lines!(xs, ys)
lines!(xs, ys * 2)
hidedecorations!(ax, label = false, ticks = false, ticklabels = false)
hidespines!(ax, :t, :r)
hlines!(0, color = :gray, linewidth = 1)
vlines!(0, color = :gray, linewidth = 1)
i = Observable(0)
on(events(f).mousebutton, priority = 2) do event
if event.button == Mouse.left && event.action == Mouse.press
plt, i[] = pick(f)
str = lift(i -> "$(i)", i)
text!(ax, 1, -0.5, text = str, align = (:center, :center))
end
end
f
Below are some examples of the interaction between clicking and the number displayed (the red dot is where I click).
Check out the mouseposition variable here:
https://docs.makie.org/stable/api/#Events
or the registerInteraction! function here:
https://docs.makie.org/v0.19/examples/blocks/axis/index.html#registering_and_deregistering_interactions
You can use them both as below:
using GLMakie
f = Figure(backgroundcolor = RGBf(0.98, 0.98, 0.98), resolution = (1500, 700))
ax = Axis(f[1, 1], xlabel = "Time [s]", ylabel = "Voltage amplitude [µV]")
#N = 1:length(pos)
positions = Observable(rand(Point2f, 10))
xs = 0:0.01:10
ys = 0.5 .* sin.(xs)
lines!(xs, ys)
lines!(xs, ys * 2)
hidedecorations!(ax, label = false, ticks = false, ticklabels = false)
hidespines!(ax, :t, :r)
hlines!(0, color = :gray, linewidth = 1)
vlines!(0, color = :gray, linewidth = 1)
register_interaction!(ax, :my_interaction) do event, axis
if event.type === MouseEventTypes.leftclick
println("Graph axis position: $(event.data)")
end
end
i = Observable(0)
on(events(f).mousebutton, priority = 2) do event
if event.button == Mouse.left && event.action == Mouse.press
plt, i[] = pick(f)
str = lift(i -> "$(i)", i)
text!(ax, 1, -0.5, text = str, align = (:center, :center))
#show mouseposition(f)
end
end
f
Note that for some reason (perhaps it sees the first click as a selection?) Makie does not start registering the interaction on the graph until the first click within the graph, unlike the clicks on the figure which are all shown even the first one.

How to add relevant scale bars on inset maps using tmap

I used tmap to create the plot attached. However, I would like to add a scale bar to the inset map, but I haven't been able to figured out how to do that. Can someone please help me?
Here are the codes that I used to create the attached map:
main_map <- tmap::tm_shape(main_map_df) +
tmap::tm_polygons(
col = "var.q5",
palette = c("#CCCCCC", "#999999", "#666666", "#333333", "#000000"),
#alpha = 0.7,
lwd = 0.5,
title = "") +
tmap::tm_layout(
frame = FALSE,
legend.outside = TRUE,
legend.hist.width = 5,
legend.text.size = 0.5,
fontfamily = "Verdana") +
tmap::tm_scale_bar(
position = c("LEFT", "BOTTOM"),
breaks = c(0, 10, 20),
text.size = 0.5
) +
tmap::tm_compass(position = c("LEFT", "TOP"))
inset_map <- tmap::tm_shape(inset_map_df) +
tmap::tm_polygons() +
tmap::tm_shape(main_map_df) +
tm_fill("grey50") +
tmap::tm_scale_bar(
position = c("LEFT", "BOTTOM"),
breaks = c(0, 10, 20),
text.size = 0.5
)
# Combine crude rate map (inset + main) =====
tiff(
"main_map_w_iset.tiff",
height = 1200,
width = 1100,
compression = "lzw",
res = 300
)
main_map
print(
inset_map,
vp = viewport(
x = 0.7,
y = 0.18,
width = 0.3,
height = 0.3,
clip = "off")
)
dev.off()
Thank you!
Here's a simple example using the World data set:
library(tidyverse)
library(tmap)
library(grid)
data("World")
# main map
tm_main <- World %>%
filter(name == "Australia") %>%
tm_shape() +
tm_polygons(col = "red",
alpha = .5) +
tm_scale_bar()
# inset map
tm_inset <- tm_shape(World) +
tm_polygons(col = "gray",
alpha = .5) +
tm_scale_bar()
vp <- viewport(x = .615, y = .5, width = .6, height = .6, just = c("right", "top"))
# final map
tmap_save(tm_main, filename = "test_inset.png", insets_tm = tm_inset, insets_vp = vp,
height = 200, width = 200, units = "mm")

Ruby-Sketchup change color of faces

I would like to color the top of this shape to rfClr, any ideas? I can change the whole thing Grey, but how to change the top to blue?
l=100
w=60
h=20
hl=8
slope=4
clr='Gray'
rfClr='blue'
ent = Sketchup.active_model.entities
#---------Clear All
Sketchup.active_model.entities.clear!
#----------------
model = Sketchup.active_model
model.start_operation "Create Box"
#-----------------------------------------------------------------------------
entities = model.active_entities
group = entities.add_group
entities = group.entities
group.name="Box"
#pt0 = [0, 0, 0]
#pt1 = [0, 0, h*12+hl]
#pt2 = [w*12/2, 0, 12*h+hl+(w/2)*slope]
#pt3 = [w*12, 0, 12*h+hl]
#pt4 = [w*12, 0, 0]
newface = entities.add_face(#pt0, #pt1, #pt2, #pt3 , #pt4)
newface.material=Sketchup::Color.new clr
#newface.reverse!
newface.pushpull l*12
I found this answer.
I guess it finds the faces that have a z value
vfaces = entities.grep(Sketchup::Face).find_all{|f| f.normal.z.abs != 0 }
vfaces.each{|f| f.material = rfClr }

crop Image in xamarin ios

I am getting an image and I want to remove the whitespace from it. so I have to check the color of every pixel, if the complete row is of white color then crop it. I am not able to get any solution,Please help.
You can try to capture the RGB for each pixel point of the image. When its RGB is equal to white color then modify its alpha to 0 to remove it. I make a method for you referring to:
UIImage imageToTransparent(UIImage image)
{
var imageWidth = (int)image.Size.Width;
var imageHeight = (int)image.Size.Height;
var bytesPerRow = imageWidth * 4;
var rgbImageBuf = new byte[bytesPerRow * imageHeight];
CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB();
CGContext context = new CGBitmapContext(rgbImageBuf, imageWidth, imageHeight, 8, bytesPerRow, colorSpace,
CGBitmapFlags.ByteOrder32Little | CGBitmapFlags.NoneSkipLast);
context.DrawImage(new CGRect(0, 0, imageWidth, imageHeight), image.CGImage);
int pixelNum = imageWidth * imageHeight * 4;
var pCurPtr = rgbImageBuf;
for (int i = 0; i < pixelNum; i = i + 4)
{
// You can modify this scope to choose which color you want to remove
if (pCurPtr[i + 1] > 240 && pCurPtr[i + 2] > 240 && pCurPtr[i + 3] > 240)
{
pCurPtr[i] = 0;
}
}
CGDataProvider dataProvider = new CGDataProvider(rgbImageBuf);
CGImage imageRef = new CGImage(imageWidth, imageHeight, 8, 32, bytesPerRow, colorSpace,
CGBitmapFlags.Last | CGBitmapFlags.ByteOrder32Little, dataProvider,
null, true, CGColorRenderingIntent.Default);
dataProvider.Dispose();
UIImage resultUIImage = new UIImage(imageRef);
imageRef.Dispose();
context.Dispose();
colorSpace.Dispose();
return resultUIImage;
}

Does XGetImage ever return a 32-bit depth XImage?

I am using XGetImage to read the pixels of an OpenGL window. The XImage that is returned shows a depth of 24-bits, but my OpenGL context has alpha values that I would like to be returned. Is there any way to get a 32-bit XImage from XGetImage, or does X already flatten the image to 24-bits?
Function call:
::XImage *winImage = XGetImage(dpy_i->dpy, wnd_i->wnd,
x, y, width, height, 0xffffffff, ZPixmap);
GDB output:
(gdb) print *winImage
$2 = {width = 640, height = 512, xoffset = 0, format = 2,
data = 0x7fffe72fd010 "\377\377\377", byte_order = 0,
bitmap_unit = 32, bitmap_bit_order = 0, bitmap_pad = 32,
depth = 24, bytes_per_line = 2560, bits_per_pixel = 32,
red_mask = 16711680, green_mask = 65280, blue_mask = 255,
obdata = 0x0, f = {create_image = 0x7ffff4b67810 <XCreateImage>,
destroy_image = 0x7ffff4b665b0, get_pixel = 0x7ffff4b67520,
put_pixel = 0x7ffff4b67450, sub_image = 0x7ffff4b67170,
add_pixel = 0x7ffff4b66650}}
I seem to always get a 32bit image. This is my code, js-ctypes, i take a screenshot of all monitors.
https://github.com/Noitidart/_scratchpad/blob/c41012b16842f0769595033bd51a3801451319be/x11%20new%20way%20skel%20non%20jsm.js
This is my XImage struct after XGetImage:
"width:" "1280" "height:" "919" "xoffset:" "0" "format:" "2" "data:" "ctypes.char.ptr(ctypes.UInt64("0x7f850fe00000"))" "byte_order:" "0" "bitmap_unit:" "32" "bitmap_bit_order:" "0" "bitmap_pad:" "32" "depth:" "24" "bytes_per_line:" "5120" "bits_per_pixel:" "32" "red_mask:" "16711680" "green_mask:" "65280" "blue_mask:" "255" "_END_"

Resources