How to hide Pivot Points HL if outside a range of candles count - charts

I am trying to modify the TradingView "Pivot Points HL" indicator code to hide pivots if the Right value (count of new candles to the right) is outside a range. For example, If I set it to "10/15" now it just prints the Pivot as soon as 15 candles appeared and they are all lower (for pivot high). I want to make it basically go back and hide it if that count say becomes "30".. so "10/30" will hide the pivot (so a Pivot will be shown as long as the right count of candles is >= 10 and <= 30). Is there a way to do that in Pinescript? What modifications to make on the Pivot Points HL source code to achieve that? Thanks.

Related

When a new pivot point is found, how can i compare the value with the previous one?

If a pivothigh is calculated using "ta.pviothigh" in pinescript_v5
Can we use pH[1] to indicate the previous pivot high or how can I get the value of the previous one when a new pivot high is found? As I want to check whether the close price of the new found pivot high is higher or lower than the previous pivot high.
I tried the script below and ran it:
pH = ta.pivothigh (close, 5, 5)
pH_fall = pH < pH[1]
plotshape (pH, "pH", shape.triangledown, color=color.aqua, size=size.tiny)
plotshape (pH_fall, "fall", shape.xcross, color=color.black, size=size.small)
It didn't say there is any mistake in the script but it just not showing the black Xcross that should be indicating a falling pivothigh. How should I amend it?

How to sort pivot based on measure and create a stacked bar chart

I am trying to create a stacked bar chart between 2 dimensions (one being week, other is a string - more below) and 1 measure. I am new to Looker.
But in order to get the stacked bar chart I figure that I need to
Create a pivot
Transpose the data
Create stacked bar chart
I am stuck with step 2 and 3.
The above steps is what I have thought could help me arrive at the visualization I want but would appreciate if there is any other solution for this.
Scenario:
I have a digital marketing data with me, where I am trying to create a visualization on ‘Leads’ generated,
I have 2 dimensions, 1 measure
Lead Created Week - Week on which a lead was created
Reason2 - reason a lead was created or what reason attracted the user most
Leads - count of leads
I have plotted the below visualization where I have created a pivot of week with Reason2 and Lead count under it and have plotted it on a stacked bar chart (as below).
Where each bar is a Reason (X-axis) and each color is the Week dimension, leads (count of leads) is in the Y-axis
Even though this is help what would be helpful is having ‘Week’ on X-axis, ‘Leads’ (count of leads) on Y-axis and ‘Reasons2’ dimension as a legend.
There is also one catch i.e., there are more than 100 distinct values in ‘Reason2’ field but I need to pick on Top 10 Reasons (i.e., the reasons that generated the most leads), which in the above screenshot I have achieved by limiting the display rows to 10 as the measure was already sorted.
I tried to flip around the pivot by having reason in pivot and Week as dimension, but if now the pivot is sorted in alphabetical manner and not by value of measures (screenshot below), I need the top 10 reasons which most leads per week.
How do I achieve the desired visualization of having week on X-axis with leads on Yaxis but only the top 10 Reasons should be generated.

Tableau Percentage calculation

I am learning Tableau using sample dataset Sample Superstore. I am trying to find out, For a given period let us say January 2012, what percentage of sales were shipped using a specific product container (e.g. Jumbo Box)
When containers are in Rows, I get 2.22% and when I flip row to column and vice-versa I get 9.17%. Would appreciate some inputs to clarify this.
2.22%
9.17%
When you use table calculation the values will differ according to the viz and what type of calculation you have used. For example table down will calculate from top to bottom and table across will calculate from left to right. Like this you will see many other options for calculations.
In below example I have used running total with table across that is direction from Left to Right column values (2014,2015,2016,2017,2018).
Example:
Image1 - Original Data(without table calculation)
Data with table calculation - running total(table across)
In below image, Left to Right values are Ship Dates against Segments. Look at the Yellow color highlighted row. Year 2015 for Consumer Segment the sales value is 40,656 but in the original data(Image1) it is 24,635. The reason it is showing 40,656 is because table calculation is performed with running total by table across(left to right), so the original value 24,635 is added with previous Year's(2014) value 16,021. Hence 16021 + 24635 = 40656. It means Left value(16021) is added with the Right value(24635). This pattern will continue till the right most value.
Image2
Columns and rows are switched
In below image(Image3) Left to Right values are Segments against Ship Dates. The Columns and rows are switched. The value of Corporate Segment for the Year 2014 is changed to 25950(blue circle) because the left side value 16021 is added with the original value 9929(Image1).
Image3

Conditional formatting numbers in Tableau

I have some basic spreadsheet info and I need to compare it to previous quarters. I just want a crosstab or heatmap type visualization showing if we are up or down from previous quarter.
Something like this:
So leads and closings have increased quarter over quarter so those should be color coded green. Referrals should be coded green for the first two but code red for Q22018 since the number went down. Is this possible in Tableau? I played around with a calculated field but I'm not sure how to compare the number to a previous quarter info number and not a set number.
I'd like it to look something like this:
Adding screenshot:
This can be done using a Table Calculation in Color shelf.
First create a table calculation as below and drag it to Color. Change the mark type to Square.
Edit the color like below.(If you do not want to play with the color, you can create a custom calculation to return red or green)

Calculating % Complete

enter image description here
From the Image I need to calculate % complete for the order number 1.
Calculation for complete will be
(total number of points for status 'Delivered' / total number of points)*100
The value should be 57%
Can some one help with the calculated field?
Look at IIF in help files
SUM(IIF([Status]="Delivered",[Point],NULL)) / SUM([Point])
I assume your column named Order No. extends all the way down each row (i.e., each row should have a 1 as Order No. but the screenshot does not show that.
Also, the above only works if the status of "Delivered" is consistently cased, which it is not in the screenshot. If it is not consistently cased, wrap [Status] in an Upper function:
SUM(IIF(UPPER([Status])="DELIVERED",[Point],NULL)) / SUM([Point])
You can also get the effect you want, just by manipulating the Tableau user interface -- without needed to write calculated fields as #S. User18 showed. Both approaches work, but it helps to understand both alternatives.
As with #S. User18, I assume your column named Order No. is consistently filled in. I also assume [Order No.] is a dimension.
Place [Order No.] on a shelf, say Rows
Place [Status] on another shelf, say Columns
Place Sum([Point]) on a shelf, say Text
This shows the sum of the number of Points for each combination of the two dimensions: [Order No.] and [Status]
To convert the number of Points to a percentage, right click on Sum([Point]) on the marks card, and choose Quick Table calculation->Percent of Total
Similarly, right click on Sum([Point]) and experiment with different "Compute Using" settings to get the effect you want -- i.e. percent of each row, column, table etc. You can instead Edit the Table Calc if the preset Compute Using options don't get the effect you want.
Right click on any row or column headers that you want to hide - so if you only want to display the percentages for the Completed Status, hide the others. Don't exclude the others as that will change the calculations.
To understand more about Table Calculations, see the online help.