color bar in pine script using plotshape using variables - variables

I am a newbie in programming, I am taking my first steps in pine script, but I got stuck in a problem that seems to be simple.
I have to paint with colors a bar (I try to use plotshape)
but this bar must be painted depending on whether or not it meets 4 variables (conditions), so I define it like this
// Definition
Condition1=*****
Condition2 =*****
Condition3 =*****
Condition4=*****
// define variables
Bullish=Condition1
Bearish=Condition2 ? Condition3 : Condition4
// assign the colors
if Bullish == true
trendcolor := (color.new(color.red,10))
if Bearish == true
trendcolor :=(color.new(color.blue,10))
else
trendcolor :=(color.new(color.white,10))
plotshape(true, title="Trendbar",style=shape.square, color=trendcolor, location=location.bottom,size=size.small)
Unfortunately, it is not taking all the colors.
Any advice is very welcome
Greetings from Patagonia!
I need the script to do nothing if none of the conditions are met
and if Bullish and Bearish are true, paint it another color

Related

Can't figure out how to group input settings into a preset so I don't have to keep changing the input settings on my indicator for each timeframe

I wrote a buy/sell indicator using PineScript and I have different values for each timeframe (moving average lengths, signal smoothing, period, etc). Basically, I wanna create a preset for each timeframe. Something like this:
preset = input.string(title='Preset', defval='Normal', options=['Normal', 'Sensitive', 'Very Sensitive'])
if preset == 'Normal'
length_ma1_normal := 50
length_ma2_normal := 200
plot(?)
if preset == 'Sensitive'
length_ma1_normal := 50
length_ma2_normal := 100
plot(?)
My buy/sell signals get triggered based on ema crossovers, macd, etc. Let's say I choose "Normal", I want the chart to plot labels based on 50/200 ema, "Sensitive" triggers 21/50 and so on. When I choose a different preset they all should plot only what the values for each preset are. Basically, the buy/sell signals are triggered based off 4 parameters and is it possible to plot all 4 (each preset has different values) for each preset?
I'm looking to do something like this:

Matplotlib bar chart different colors for each bar

I am trying to create a simple horizontal bar chart but I want to spruce it up with each bar using a teams color. I thought it would be as simple as passing each teams hex color to the color parameter as an array but what I get is each bar displaying as the first color provided in the array.
data.plot(kind="barh", color=['#A71930', '#DF4601', '#AB0003', '#003278', '#FF5910', '#0E3386', '#BA0021', '#E81828', '#473729', '#D31145', '#0C2340', '#005A9C', '#BD3039', '#EB6E1F', '#C41E3A', '#33006F', '#C6011F', '#004687', '#CE1141', '#134A8E', '#27251F', '#FDB827', '#0C2340', '#FD5A1E', '#00A3E0', '#ffc52f', '#003831', '#005C5C', '#E31937', '#8FBCE6'])
plt.title('Team Ranking Marginal Doller Spent per Marginal Win')
plt.ylabel('Team')
plt.xlabel('Marginal Doller Spent per Marginal Win')
plt.style.use('fivethirtyeight')
plt.gcf().set_size_inches(10, 12)
plt.show()
Here is the result
It looks like you are using pandas to plot, which returns an axis object. You can modify the color of each bar by iterating through the patches:
colors=['#A71930', '#DF4601', '#AB0003', '#003278', '#FF5910', '#0E3386', '#BA0021', '#E81828', '#473729', '#D31145', '#0C2340', '#005A9C', '#BD3039', '#EB6E1F', '#C41E3A', '#33006F', '#C6011F', '#004687', '#CE1141', '#134A8E', '#27251F', '#FDB827', '#0C2340', '#FD5A1E', '#00A3E0', '#ffc52f', '#003831', '#005C5C', '#E31937', '#8FBCE6']
ax=data.plot(kind='barh')
for patch,color in zip(ax.patches,colors):
patch.set_facecolor(color)
It's a bit of a work around, but its nice to get to know how to access the pandas generated figures in case the built-in functions leave something to be desired.
(Edited a variable name because someone in the comments said it was ugly)

How to assert value set by jQuery in Acceptance Test using Codeception?

I am writing an app in WordPress for managing dog adoptions. In one scenario, the user selects a primary breed from a select and a secondary breed from another select. When they choose the breed, an input (read-only) field is filled with the values of the 2 selects.
I wanted to test this and I have written an acceptance test that does just that. The dog breed from the select is chosen and the value is added to the input via jQuery:
Image of Field with Dog Value filled out
The trouble is that when I try to assert that the text exists, I continuously get an error and the test fails. The lines that follow are the ones I have tried:
$I->see('Kelpie X');
$I->seeElement( '#acf-field_mdr_dog_text_breed_name', ['value' => 'Kelpie X']);
$I->seeInField( 'input#acf-field_mdr_dog_text_breed_name', 'Kelpie X');
Why aren't these conditions passing? Does it have to do because jQuery set the value?
Thanks!
I am not sure why the first one did not work, but I noticed that the value in the input text field had a space after the X. Apparently seeInField & seeElement are very strict, so this did the trick:
// Note the space after the X
$I->seeElement( 'input#acf-field_mdr_dog_text_breed_name', ['value' => 'Kelpie X ']);
$I->seeInField( 'input#acf-field_mdr_dog_text_breed_name', 'Kelpie X ');

Can I give both an if and else statement another if and else statement?

enter image description here
So I am making a adventure game where you can choose your own path, but I don't know how I can assign the next row of options to one of the first two options and another row of options to the other option in the first option (look at picture for clearer understanding). So if you first choose plane, you get the two options for plane, but if you choose car, you get the options for car. But I don't know how to do that.
Does anyone know how I can do this?
Hi and welcome to programing #Valentinj.
You should use additional variables.
engine = input('plane/car')
if engine == 'plane':
direction = input('fly/go_back')
if direction == 'fly':
...
if direction == 'go_back':
...
if engine == 'car':
place = input('city/treasure')
if place == 'city':
...
if place == 'treasure':
...

Pentaho: logarithmic scale in charts

Is there a way to set a "logarithmic scale" in a Pentaho chart?
Result from my sql query has a very wide range (from 1 to 1000000).
I could change my sql query to something like this:
"Select LOG(10, wide_value)..."
But Y-axis scale changes the same way at Pentaho chart (1,2,3...). I need the original labels on Pentaho chart (10,100,1000...).
What I found on web are old forums talking about that this is still a feature request, or to try with "CCC" (too much documentation for something too simple) or to modify the source code (even worse). None of them useful.
Hint: I'm using a legacy implementation on Pentaho bi-server 6.0. If there is an option on newer versions it will be useful too, maybe there is something similar on my old version.
This is the solution in case someone else needs it.
My query originally delivered something like:
Select
   x_axis as "x_axis",
   y_axis_wide_value as "value"
From ...
It must be modified to:
Select
x_axis as "x_axis",
LOG(10, y_axis_wide_value) as "value"
From ...
My graphic in Pentaho's "Components Panel" is a "CCC Line Chart".
What I needed is for the Y axis to show the real values. That is achieved as follows:
In "Advanced Properties" you must locate "OrthoAxisThickFormatter" and enter the following function:
function fun (value)
{
     return Math.pow (10, value);
}
Some additional settings for better viewing:
orthoAxisOriginIsZero: false
orthoAxisZeroLine: false
And that was all. Now my graphs are displayed with logarithmic scale.