Entry only in the Strategy, if the previous color is different than the actual color - pine-script-v5

I am having some problems with using strategy.entry
//Condition
prev_color = hmacolor[1]
if (hmacolor == #00ccff and prev_color == #ff0055)
strategy.entry("Long", strategy.long)
if (hmacolor == #ff0055 and prev_color == #00ccff)
strategy.entry("Short", strategy.short)
I want to Entry only in the Strategy, if the previous color is different than the actual color.
Now I get an Alert for every candle, but I only want to get an alert if the color of the line changes.
I get an Alert for every candle, but I only want to get an alert if the color of the line changes. If it changes from red to green, it means Long, if it changes from green to red, it means Short Alert.

//Condition
if (hmacolor == #00ccff and hmacolor[1] != #00ccff)
strategy.entry("Long", strategy.long)
if (hmacolor == #ff0055 and hmacolor[1] != #ff0055)
strategy.entry("Short", strategy.short)

Related

I want to add required attribute in MUI TextField based on a condition

I want to add required attribute in MUI TextField based on a condition.
Var flag = false
If (investment>50000 && investment<5000){
flag = true
}
<TextField
required = {flag}
id="shop-name"
label="Shop Name"
variant="outlined" />
This doesn't seems to work
Seems you have your if statement in the wrong way and you wanted the investment number to be between 50000 and 5000. So change it to
if (investment > 5000 && investment < 50000) {
flag = true;
}

Tooltip not working correctly with activeIndex on pie charts(ReCharts)

Pie charts that utilize Tooltip and activeIndex do not work correctly. The tooltip will not show up unless you re-enter the same sector.
When you are not in the same sector it shows the
Warning: Failed prop type: Invalid prop activeIndex supplied to Pie.
<PieChart
className="pie-chart"
width={this.props.width ? this.props.width : 500}
height={375}
onMouseEnter={this.onPieEnter}
>
<Pie
dataKey="value"
data={data}
// cx={250}
// cy={100}
activeIndex={
this.state.activeIndex === undefined
? 0
: this.state.activeIndex
}
activeShape={this.renderActiveShape}
outerRadius={
this.state.width <= 1025 && this.state.width > 768 ? 80 : 100
}
innerRadius={
this.state.width <= 1025 && this.state.width > 768 ? 65 : 85
}
fill="#8884d8"
onMouseEnter={this.onPieEnter}
>
{data.map((entry, index) => (
<Cell
key={index}
fill={this.COLORS[index % this.COLORS.length]}
/>
))}
</Pie>
</PieChart>
Default active index always set so when you are not in the same sector
pie tooltip shows.
When you are not in the same sector then the activeIndex is changed automatically and it returns the object type, and actually, activeIndex is number type so I check for a shouldComponentUpdate method and it returns true if activeIndex is number only.
So if the activeIndex type is not a number then component will not be updated and activeIndex state is remains the same as the previous state, so tooltip is not hidden any time.
This code works for me.
shouldComponentUpdate(nextProps, nextState) {
return typeof nextState.activeIndex === "number";
}

CodeMirror custom mode - how to apply styles on keywords?

I'm trying to write my own CodeMirror mode as documented here.
My objective is to change the color of specific keywords. For example, any "aaa" word needs to be red and any "bbb" word needs to be blue. Any other words need to have the default color.
This is my unsuccessful attempt (see jsfiddle). How to make this work?
HTML:
<textarea rows="4" cols="30" id="cm" name="cm">aaa bbb ccc</textarea>
CSS:
.style1 { color: red; }
.style2 { color: blue; }
Javascript:
CodeMirror.defineMode("mymode", function() {
return {
token: function(stream,state) {
if (stream.match("aaa") ) {
console.log("aaa found");
while ((ch = stream.next()) != null)
if (ch == " " && stream.next() == " ") break;
return "style1";
}
else if (stream.match("bbb") ) {
console.log("bbb found");
while ((ch = stream.next()) != null)
if (ch == " " && stream.next() == " ") break;
return "style2";
}
else
return null;
}
};
});
var editor = CodeMirror.fromTextArea(document.getElementById('cm'), {
mode: "mymode",
lineNumbers: true
});
You had two problems.
CodeMirror prefixed cm- to classes used to style tokens. The styles in your CSS have to account for that.
You were skipping the rest of the line after finding "aaa" or "bbb", althrough your description of your goal sounds like you didn't want to do that.
I've fixed both in the jsfiddle. You may also want to only match full words (currently fooaaabar also has aaa highlighted). To do that, first have your tokenizer read a whole word (stream.eatWhile(/\w/)), and then see if the resulting word is one of the words you are looking for (stream.current() == "aaa").

How to provide dynamic hover color in highmaps?

see the below code:
states :{
hover: {
color: <dynamic color for each location>
}
}
You can alter point.pointAttr.hover.fill after creating the chart to give specific points their own hover color. For example:
var points = $('#container').highcharts().series[0].data;
for(var i = 0; i < points.length; i++) {
if(points[i].options.code == 'RU' || points[i].options.code == 'US')
points[i].pointAttr.hover.fill = 'pink';
}
See this JSFiddle demonstration which has special colors for Russia and the United States.

Distinguishing between the blog title and the post title when creating a custom theme for Tumblr?

Long time lurker, first time asker.
I am currently writing a custom theme for Tumblr blogs to embed a widget after every post, regardless of their type. This widget requires the post's title, and if there is none, then it takes the blog's title.
According to Tumblr, {Title} refers to the blog title. However, if we have a Text post or a Chat post, {Title} refers to the post title.
Here is my code:
var title;
if ('{PostType}' === 'text' || '{PostType}' === 'chat')
title = '{Title}';
else if ('{PostType}' === 'photo' || '{PostType}' === 'photoset' || '{PostType}' === 'audio' || '{PostType}' === 'video')
title = '{PlaintextCaption}';
else if ('{PostType}' === 'quote')
title = '{PlaintextQuote}';
else if ('{PostType}' === 'link')
title = '{PlaintextName}';
else if ('{PostType}' === 'answer')
title = '{PlaintextQuestion}';
if (title === '')
title = '{Title}';
If I have a Photo post with no caption for example, then title will be correctly set to the blog title. But if I have a Text post with no title, then title will be set to [empty string] instead of the blog title.
So my question is: how can I get the blog title when I am inside of a Text or Chat post?
What you can do is set the blog title as a variable before you enter into your {block:Posts}. So in your <head>, you can do this:
var blogTitle = '{Title}';
Then modify your code like this:
var title;
if ('{PostType}' === 'text' || '{PostType}' === 'chat')
title = blogTitle;
else if ('{PostType}' === 'photo' || '{PostType}' === 'photoset' || '{PostType}' === 'audio' || '{PostType}' === 'video')
title = '{PlaintextCaption}';
else if ('{PostType}' === 'quote')
title = '{PlaintextQuote}';
else if ('{PostType}' === 'link')
title = '{PlaintextName}';
else if ('{PostType}' === 'answer')
title = '{PlaintextQuestion}';
if (title === '')
title = '{Title}';
Also, be careful, as {PostType} will never == 'photoset'. Photoset post types always come out as 'photo'. What I usually do to counter that when making class names is this:
class="type-{PostType}{block:Photoset}set{/block:Photoset}
...and the output will be class="type-photoset".