I want to color candle which is not touching 5EMA - view

I want to highlight candle which is not touching 5EMA in trading view. kindly help me with it

Try this:
//#version=5
indicator("My Script", overlay=true)
EMA5 = ta.ema(close, 5)
bgcolor(low > EMA5 or high < EMA5 ? color.new(color.green, 90) : na)

Related

TextBox width dynamic adjustment fabric js

I want to modify to the textbox width according to the longest line that user enters, dynamically. I initialize the width = width of my canvas but as soon as user exits editing, the width must shorten to the width of the longest line in user's text written in the textBox.
obj.on(("editing:exited"),function() {
can.setActiveObject(textBox);
var largest = Math.max.apply(Math, can.getActiveObject().__lineWidths);
can.getActiveObject().set("width",largest);
})
Problem is that each time I exit editing, the width reduces and the top line is shifted below. I just cant understand what is happening. Please help at the earliest. Thanks in advance. Please also upload a demo so that I can see the effect of your code.
Update 1 : If I change the line
can.getActiveObject().set("width",largest);
to
can.getActiveObject().set("width",(largest + 1));
It works as desired. I have no idea why this is happening.
I have found the answer to this question by some coding myself.
https://jsfiddle.net/xpntggdo/8/
To all those who might be facing a similar issue, here is the fiddle and here is the code.
textBox.on(("changed"),function(){
var actualWidth = textBox.scaleX * textBox.width;
var largest = canvas.getActiveObject().__lineWidths[0];
var tryWidth = (largest + 15) * textBox.scaleX;
canvas.getActiveObject().set("width",tryWidth);
if((textBox.left + actualWidth) >= canvas.width - 10)
{
textBox.set("width", canvas.width - left - 10)
}
canvas.renderAll();
});
textBox.on(("modified"),function(){
left = textBox.left;
canvas.renderAll();
});

javascript teechart area series top border

Hi guys,
I need to draw area series border only on the top. I attached what I have today.
Thanks in advance.
The easiest would be to hide the Area pen:
areaSeries.format.stroke.fill = 'rgba(0, 0, 0, 0)';
and use a Line series to draw the top. Ie:
var s = new Tee.Line();
Chart1.addSeries(s);
s.data = areaSeries.data;
s.format.stroke.size = 3;

What is the error of saved frame using saveFrame()

Using the code shown at http://processing.org/reference/saveFrame_.html I seem to be getting a grey overlay on every frame I try and output from any number of different sketchs? The grey bar overlay seems to grow as the more frame are saved. Has anyone else experienced this? Have I done something incorrect?
The code that is doing this gray area in your sketch is this:
if (xport < 100) {
line(xport, 0, xport, 100);
xport = xport + 1;
}
I don't exactly know what you wanted to do, but its drawing a vertical line with xport as x and from 0 to 100 as y

d3 - Axis Label Transition

In Mike Bostock's cubism demo (http://bost.ocks.org/mike/cubism/intro/demo-stocks.html), there is a cursor which displays the values of all horizon charts on display. Furthermore, the cursor text shows the time axis point in time. As the cursor text obscures an axis label, the label fades.
I am working on a similar display with d3.js (but not cubism). I have all working except that fade portion. I have searched through the CSS in the developer's window, searched the source code (as best I could), but I don't understand what manner of magic is being used to accomplish this feat. I've even looked through SO "axis label transition" questions, but I have failed to connect the dots on xaxis label transitions.
How does that fade in/out when obscured by text happen?
UPDATE:
I think I located the event script area where this happens - its just a little over my head at the moment - can anyone help me decipher what this event listener is doing? Specifically, in the second g.selectAll in the else clause below - what data (d) is being used here? What is causing this event to fire?
This is the coolest part of the display (outside of the horizon charts), I would love to figure this out ...
context.on("focus.axis-" + id, function(i) {
if (tick) {
if (i == null) {
tick.style("display", "none");
g.selectAll("text").style("fill-opacity", null);
} else {
tick.style("display", null).attr("x", i).text(format(scale.invert(i)));
var dx = tick.node().getComputedTextLength() + 6;
g.selectAll("text").style("fill-opacity", function(d) { return Math.abs(scale(d) - i) < dx ? 0 : 1; });
}
}
});
I used this as reference to accomplish the same effect.
I'm not sure what the context variable is or how the id's are set or what the tick flag references but what I did was simply update the opacity of the ticks according to their proximity to the mouse. With this, the vertical tick fades as well as the label text.
svg.selectAll('.x.axis .tick').style('opacity', function (d) {
return Math.min(1, (Math.round(Math.abs(d3.mouse(svg.node())[0] - x(d))) - 10) / 15.0);
});
This way, the opacity is set to 0 if it's within 10 pixels, and fades from 1-0 between 10 and 25. Above 25, the opacity would be set to an increasingly large number, so I clamp it to 1.0 using the Math.min function.
My labels are slightly rotated, so I also added an offset not shown inside the formula above (a +3 after [0]) just to make it look a bit nicer. A year late to answer your only question, but hey it's a nice effect.
same answer as Kevin Branigan's post, but using the d3 scale to calculate the opacity value.
var tickFadeScale = d3.scale.linear().domain([10,15]).range([0,1]).clamp(true);
svg.selectAll('.x.axis .tick').style('opacity', function (d) {
return tickFadeScale(Math.abs(d3.mouse(svg.node())[0] - x(d)));
}

pygame rotatating image

I've been trying to make my turret rotate correctly, however, when I move my mouse (causing the rotation) the turret rotates above the tankbase, does anyone know an easy way to fix this? Help would be appreciated, please note this is my first attempt at pygame though
Code:
#Rotation
mousex,mousey = pygame.mouse.get_pos()
CalcHeight = cannonBase.y - mousey
CalcWidth = cannonBase.x - mousex
if CalcWidth == 0:
CalcWidth = 1
CalcRot = CalcHeight/float(CalcWidth)
rot = math.degrees(math.atan(CalcRot))
OldCenter = cannonBase.center
rot_image,rot_rect = rot_center(cannon_original, cannonBase, rot)
cannonBaseStretchedImage = rot_image
#Rot_center
def rot_center(image, rect, angle):
"""rotate an image while keeping its center"""
rot_image = pygame.transform.rotate(image, angle)
rot_rect = rot_image.get_rect(center=rect.center)
return rot_image,rot_rect
(my first time posting, please tell me if my post in anyway was hard to read or understand)
*Added pics
Thanks for the fast replys, here is 2 pics (Couldn't uploud via stackoverflow since I was to low of a grade)
http://imageshack.us/a/img266/606/prntscrnpygame.png
http://imageshack.us/a/img507/3848/prntscrnpygame2.png
Note that I'm very aware the the rotation is somewhat off, I just wanted to fix the location first, hope we can fix this!
Thanks for the e-mail. Your problem is that the center of rotation is off. You have to make it so the center of the turret is the exact center of the image. I'll e-mail you a picture of what I mean.

Resources