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

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?

Related

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

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.

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

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.

Aggregate an Running Sum in Tableau?

I have a simple data set showing the number of points scored by a player. It is plotted across a [Week Number] x-axis. I added a Running Sum calculation, as a Line, split by Player (color).
For each week, I would like to identify the top player, by total points achieved to-date.
For example, in Week 3, the top player was GREEN with a running total of 8 points.
I tried creating a LOD function {FIXED [WEEK]: MAX(RunningSum)} but it complains that I cannot aggregate an aggregate.
I tried WINDOW_MAX(), RANK(), and tried adjusting the Table Calc, Advanced, Partitioning and Addressing feature.
Is there no way to identify the MAX of a collection of running totals, by discrete [Week Number]?
This can be done fairly easily in TSQL by wrapping a query in outer queries and applying Window functions with partitions defined.
You can absolutely just use RANK(), you just need to make sure the table calculation is being computed using Player. I imagine your [RunningSum] field looks something like this:
RUNNING_SUM(SUM([Points]))
Create a table calculation (let's call it [Player Rank]):
RANK([RunningSum])
Then we need to edit the table calculation. You can do this directly from the Calculated Field edit window (there's a blue link above the OK and Apply buttons that says something like "Default Table Calculation").
We want to compute the rank of our players, so we'll go into "Compute Using:" and select Player.
For a quick sanity check, drag [Player Rank] into Tooltip and check it out.

How to set my column at the center of the chart with ShinobiCharts

I have this column chart that has 2 modes, monthly visualization and yearly visualization, the monthly visualization works just fine with many column, however, my yearly visualization is broken because i can't get the only column that appears to be on the center of the chart, it's always being set to the first point on my XAxis.
If I were using a NumberAxis it would be easy to solve, just set the column to the middle point (in this case, position 6 among the total of 12 months). However I'm using CategoryAxis, since it isn't ordered as NumberAxis is, I'm unable to use the same solution....
How can I achieve this result with a CategoryAxis ?
PS: No matter the SChartRange I set to this Axis, the column will always be set to the first position in the XAxis.
Found a way to achieve the result I wanted.
I've altered the range to be around the first dataPoint only, this way the column got placed in the middle of the chart without having to be the "middle dataPoint", being the ONLY dataPoint. The code goes into my sChart: dataPointAtIndex forSeriesAtIndex as follows
-(id<SChartData>)sChart:(ShinobiChart *)chart dataPointAtIndex:(int)dataIndex forSeriesAtIndex:(int)seriesIndex{
.
.
.
SChartNumberRange * numberRange;
if(isYearlyChart){
numberRange = [[SChartNumberRange alloc] initWithMinimum:[NSNumber numberWithFloat:-0.9]andMaximum:[NSNumber numberWithInt:(1)]];
}
The normal NumberRange I was using was from 1 through 13.
Hope this helps others with similar problems regarding this subject :)
PS: I'll mark this as the correct answer as soon as possible.