Plot a BOX in Day High and Low in Tradingview - pine-script-v5

[do_1, dh, dl] = request.security(syminfo.ticker, 'D', [open, high, low], lookahead=barmerge.lookahead_on)
plot(dh, title='H', style=plot.style_stepline, color=color. New(color.red, 0), linewidth=2, trackprice=true)
plot(do_1, title='O', style=plot.style_stepline, color=color.new(color.yellow, 0), linewidth=1, trackprice=true)
plot(dl, title='L', style=plot.style_stepline, color=color.new(color.green, 0), linewidth=2, trackprice=true)
With above this code possible to plot open, Day High and Day Low in the chart
i want plot a box in Day High and Day Low, separate for every day , Currently its not a break line.
Requesting help me add plot to my trading
plot(dh, title='H', style=plot.style_stepline, color=color. New(color.red, 0), linewidth=2, trackprice=true)
plot(do_1, title='O', style=plot.style_stepline, color=color.new(color.yellow, 0), linewidth=1, trackprice=true)
plot(dl, title='L', style=plot.style_stepline, color=color.new(color.green, 0), linewidth=2, trackprice=true)
Cant add any box code to this maybe i am wrong entry the code

Related

How do I get a signal only on the last candle on the chart

Newbie on PineScript on Tradingview, so please excuse if this is silly.
I am trying out the following script on Tradingview,
//#version=5
strategy("My Strategy", overlay=true)
shortSMA = ta.sma(close, 10)
longSMA = ta.sma(close, 30)
rsi = ta.rsi(close, 14)
longCondition = ta.crossover(shortSMA, longSMA)
if (longCondition)
strategy.entry("long", strategy.long, 100, when = rsi > 50)
When I save and add the script to my chart, it gives me a long signal only for the first instance where the condition was met.
So when I add pyramiding to the script,
//#version=5
strategy("My Strategy", overlay=true, pyramiding=250)
shortSMA = ta.sma(close, 10)
longSMA = ta.sma(close, 30)
rsi = ta.rsi(close, 14)
longCondition = ta.crossover(shortSMA, longSMA)
if (longCondition)
strategy.entry("long", strategy.long, 100, when = rsi > 50)
I get a signal for all the instances where the condition is met.
What I am trying to achieve is get a signal only on the last candle (if the condition is met, of course), the previous ones can just go. Is there any way to do this?

How to plot a 3d graph in Matlab with my data?

Right now I am doing a parameter sweep and I am trying to convert my data to a 3D graph to show the results in a very nice fashion. The problem is that I don't quite know how to plot it as I am having an issue with the result variable.
mute_rate = [0.5, 0.25, 0.125, 0.0625, 0.03125, 0.015625]
mute_step = linspace(-2.5, 2.5, 6)
results = [949.58, 293.53, 57.69, 53.65, 293.41, 1257.49;
279.19, 97.94, 32.60, 29.52, 90.52, 286.94;
32.96, 28.06, 19.56, 6.44, 13.47, 55.80;
2.01, 1.52, 5.38, 1.00, 0.89, 1.41;
0.61, 0.01, 18.59, 0.03, 0.56, 1.22;
1.85, 1.51, 18.64, 18.57, 18.54, 6.90]
So the first row in the result variable presents the results of the mute rate and mute step performed on the population from my genetic algorithm. For example:
0.5, -2.5 = 949.58,
0.5, -1.5 = 293.53,
0.5, -0.5 = 57.69
etc
It sounds like you want something akin to:
mesh(mute_step, mute_rate, results);
shading interp;
Other styles of plot would be surf or pcolor (for a 2d view).

SpriteKit - How to make a perspective scrolling background

I know how to make a endless scrolling background in SpriteKit, but I don't know how to make a perspective background.
Please look at the image below, the left is the origin resource, the right is what I want, and it should scrolling from top to bottom.
As #Simone Pistecchia and #Knight0fDragon said, I tried use SKWarpGeometryGrid
let src = [
float2(0, 0), float2(0.33, 0), float2(0.67, 0), float2(1, 0),
float2(0, 1), float2(0.33, 1), float2(0.67, 1), float2(1, 1)
]
let dst = [
float2(0, 0), float2(0.33, 0), float2(0.67, 0), float2(1, 0),
float2(0.33, 1), float2(0.33, 1), float2(0.67, 1), float2(0.67, 1)
]
let back = childNode(withName: "bgNode") as! SKSpriteNode
back.warpGeometry = SKWarpGeometryGrid(columns: 3, rows: 1, sourcePositions: src, destinationPositions: dst)
The code result is the middle image below, the left is origin resource, the right is what I want.
The result image

Program for specific sequence of Integers

I am solving steady state heat equation with the boundary condition varying like this 10,0,0,10,0,0,10,0,0,10,0,0,10.... and so on depending upon number of points i select.
I want to construct a matrix for these boundary conditions but unable to specify the logic for the sequence in terms of ith element for a matrix.
i am using mathematica for this however i need the formula only like for odd we can specify 2n+1 and for even 2n , something like this for the sequence 10,0,0,10,0,0,10,0,0,10,....
In MATLAB, it would be
M = zeros(1000, 1);
M(1:3:1000) = 10;
to make a 1000 long vector with such structure. 1:3:1000 is 1,4,7,....
Since you specifically want a mathematical formula let me suggest a method:
seq = PadRight[{}, 30, {10, 0, 0}];
func = FindSequenceFunction[seq]
10/3 (1 + Cos[2/3 \[Pi] (-1 + #1)] + Cos[4/3 \[Pi] (-1 + #1)]) &
Test it:
Array[func, 10]
{10, 0, 0, 10, 0, 0, 10, 0, 0, 10}
There are surely simpler programs to generate this sequence, such as:
Array[10 Boole[1 == Mod[#, 3]] &, 10]
{10, 0, 0, 10, 0, 0, 10, 0, 0, 10}
A way to do this in Mathematica:
Take[Flatten[ConstantArray[{10, 0, 0}, Ceiling[1000/3] ], 1],1000]
Another way
Table[Boole[Mod[i,3]==1]*10, {i,1,1000}]

Cairo Radial Gradient

I'm using a radial gradient in Cairo, but I'm not getting the expected results. The radial gradient I'm getting is much less fuzzy than I'd expect and I can't seem to fiddle with the color stops in order to get the desired results. Here is the code:
cairo_pattern_t *pat;
pat = cairo_pattern_create_radial(100.0, 100.0, 0.0, 100.0, 100.0, 20.0);
cairo_pattern_add_color_stop_rgba(pat, 0, 0, 0, 0, 1);
cairo_pattern_add_color_stop_rgba(pat, 1, 0, 0, 0, 0);
Here is an image of what I'm talking about.
The #cairo IRC channel suggested (Thanks Company!) to use cairo_mask() instead of cairo_paint() to draw the gradient. That results in a squared instead of linear progression.
I did the following in lua. Sorry for the language, but it's easier to prototype something. This maps 1:1 to the C API and shouldn't be hard to translate:
cairo = require("lgi").cairo
s = cairo.ImageSurface(cairo.Format.ARGB32, 200, 100)
c = cairo.Context(s)
c:set_source_rgb(1, 1, 1)
c:paint()
p = cairo.Pattern.create_radial(50, 50, 0, 50, 50, 20)
p:add_color_stop_rgba(0, 0, 0, 0, 1)
p:add_color_stop_rgba(1, 0, 0, 0, 0)
c:save()
c:rectangle(0, 0, 100, 100)
c:clip()
c.source = p
c:paint()
c:restore()
p = cairo.Pattern.create_radial(50, 50, 2, 50, 50, 25)
p:add_color_stop_rgba(0, 0, 0, 0, 1)
p:add_color_stop_rgba(1, 0, 0, 0, 0)
c:translate(100, 0)
c:save()
c:rectangle(0, 0, 100, 100)
c:clip()
c.source = p
c:mask(p)
c:restore()
s:write_to_png("test.png")
To me, the second circle (The one that was cairo_mask()'d with a black source) looks a lot more like what you want: