With Pine Script, I would like to visualize pivot points (highs and lows) on a microlevel, concerning 3 bars according with the following condition for pivot highs:
(high[1] > high[0]) and (high[1] > high[2])
Next, I would like to visualize higher order pivot highs following the condition:
(pivothigh[1] > pivothigh[0]) and (pivothigh[1] > pivothigh[2])
Finally, I would like to make the same process for one further level.
The first step has been done, however, I have problems with my second aims. How can I get the pivot high of the microlevel pivot highs?
study("Pivot points")
//Define the width to look for pivot highs
leftBars = input(1)
rightBars= input(1)
pivhigh = pivothigh(high,leftBars,rightBars)
//plotting the pivot highs on the micro level (however, with an additional offset)
plotshape(pivhigh, style = shape.xcross, location = location.abovebar, color=color.green, offset = -rightBars)
You can use arrays to store and evaluate the pivots and add the pivot high/low values to the higher order arrays as they occur.
var float[] first_order_pvhs = array.new_float()
var float[] second_order_pvhs = array.new_float()
var float[] third_order_pvhs = array.new_float()
if high[1] > high[0] and high[1] > high[2]
array.unshift(first_order_pvhs, high[1])
pvh1_0 = array.get(first_order_pvhs, 0)
pvh1_1 = array.get(first_order_pvhs, 1)
pvh1_2 = array.get(first_order_pvhs, 2)
if pvh1_1 > pvh1_0 and pvh1_1 > pvh1_2
array.unshift(second_order_pvhs, pvh1_1)
pvh2_0 = array.get(second_order_pvhs, 0)
pvh2_1 = array.get(second_order_pvhs, 1)
pvh2_2 = array.get(second_order_pvhs, 2)
if pvh2_1 > pvh2_0 and pvh2_1 > pvh2_2
array.unshift(third_order_pvhs, pvh2_1)
You can see my implementation here : Higher Order Pivots
Related
My table looks a little like this. The last column is what I'm trying to figure out how to calculate. I can easily do this in Excel - but not sure how to write my formula in PowerBI
I don't think you can count it without specifying the individual columns. if that is what you are looking for. I would do it something like this:
Data Missing =
COUNTBLANK([Project Title])
+ COUNTBLANK([Status])
+ COUNTBLANK([Object])
There may be a more clever way to do this, but a simple DAX expression can do the job.
CountBlanksInRow =
VAR data1blank = IF (ISBLANK(Sheet1[Data 1]), 1, 0)
VAR data2blank = IF (ISBLANK(Sheet1[Data 2]), 1, 0)
VAR data3blank = IF (ISBLANK(Sheet1[Data 3]), 1, 0)
RETURN data1blank + data2blank + data3blank
Rather then using DAX or Measure, The best option is you can create the custom column in Power Query and the code will be as below-
Number.From([Project Title] = null)
+ Number.From([Status] = null)
+ Number.From([Objective] = null)
Here below is the sample code window-
Can I make the builtin AStar choose the shortest path with the least direction changes?
I currently build my graph like so:
extends GridMap
var _astar = AStar.new()
func _ready():
var id = 0
for c in get_used_cells():
var weight = 1.0
if _get_cover(c.x, c.y, c.z):
weight = 9999.0 # impassable tile
_astar.add_point(id, Vector3(c.x, c.y, c.z), weight)
id += 1
for c in get_used_cells():
var center = _astar.get_closest_point(Vector3(c.x, c.y, c.z))
var above = _astar.get_closest_point(Vector3(c.x, c.y, c.z + 1))
var right = _astar.get_closest_point(Vector3(c.x + 1, c.y, c.z))
assert(id > 0)
if above >= 0:
_astar.connect_points(center, above, true)
if right >= 0:
_astar.connect_points(center, right, true)
It seems like you can only weight points, not edges, so I'm not sure how to prefer one direction over another.
The path it chooses always seems to maximize direction changes:
When you see 3 Nodes, if the direction is changed, then increase the F value of last Node.
Three Nodes will tell you that the direction changes.
I want to use the data of [x] to fill in [test] based on certain sequence:
x = matrix(rnorm(330),165,2)
origins = 130:157
horizon = 8
col = 1:2
test = array(0, c(length(origins)*length(col), horizon))
for( origin in origins){
for (c in col){
test[which(origin==origins), ] = x[(origin+1):(origin+8), c]
}
}
However, this code only helps extract the second column of [x] to fill in the first 28 rows of [test]. The following picture is only a part of a complete [test] table, showing the ineffective filling from row 29 to row 56.
enter image description here
Anyone who can help me fill in them completely? Thank you very much.
Here is a possible solution, but it is still not clear what you want the result to be. better to make much smaller data and show desired result.
The left hand side of the assignment, in the original code, does not vary with c, so each time through the loop for c the same rows of test will be overwrittem,
x = matrix(rnorm(330),165,2)
origins = 130:157
horizon = 8
col = 1:2
test = array(0, c(length(origins)*length(col), horizon))
for( origin in origins){
for (c in col){
# the left hand side must vary somehow with c as well.
test[(which(origin==origins)-1) + (c - 1) * length(origins) + 1, ] = x[(origin+1):(origin+8), c]
}
}
I have a weird question..
Essentially, I have a function which takes a data frame of dimension Nx(2k) and transforms it into an array of dimension Nx2xk. I then further use that array in various locations in the function.
My issue is this, when k == 2, I'm left with a matrix of degree Nx2, and even worse, if N = 1, I'm stuck with a matrix of degree 1x2.
I would like to write myArray[thisRow,,] to select that slice of the array, but this falls short for the N = 1, k = 2 case. I tried myArray[thisRow,,,drop = FALSE] but that gives an 'incorrect number of dimensions' error. This same issue arrises for the Nx2 case.
Is there a work around for this issue, or do I need to break my code into cases?
Sample Code Shown Below:
thisFunction <- function(myDF)
{
nGroups = NCOL(myDF)/2
afMyArray = myDF
if(nGroups > 1)
{
afMyArray = abind(lapply(1:nGroups, function(g){myDF[,2*(g-1) + 1:2]}),
along = 3)
}
sapply(1:NROW(myDF),
function(r)
{
thisSlice = afMyArray[r,,]
*some operation on thisSlice*
})
}
Thanks,
James
I am stuck at creating a matrix of a matrix (vector in this case)
What I have so far
index = zeros(size(A)) // This is some matrix but isn't important to the question
indexIndex = 1;
for rows=1:length(R)
for columns=1:length(K)
if(A(rows,columns)==x)
V=[rows columns]; // I create a vector holding the row + column
index(indexIndex) = V(1,2) // I want to store all these vectors
indexIndex = indexIndex + 1
end
end
end
I have tried various ways of getting the information out of V (such as V(1:2)) but nothing seems to work correctly.
In other words, I'm trying to get an array of points.
Thanks in advance
I do not understand your question exactly. What is the size of A? What is x, K and R? But under some assumptions,
Using list
You could use a list
// Create some matrix A
A = zeros(8,8)
//initialize the list
index = list();
// Get the dimensions of A
rows = size(A,1);
cols = size(A,2);
x = 0;
for row=1:rows
for col=1:cols
if(A(row,col)==x)
// Create a vector holding row and col
V=[row col];
// Append it to list using $ (last index) + 1
index($+1) = V
end
end
end
Single indexed matrices
Another approach would be to make use of the fact an multi-dimensional matrix can also be indexed by a single value.
For instance create a random matrix named a:
-->a = rand(3,3)
a =
0.6212882 0.5211472 0.0881335
0.3454984 0.2870401 0.4498763
0.7064868 0.6502795 0.7227253
Access the first value:
-->a(1)
ans =
0.6212882
-->a(1,1)
ans =
0.6212882
Access the second value:
-->a(2)
ans =
0.3454984
-->a(2,1)
ans =
0.3454984
So that proves how the single indexing works. Now to apply it to your problem and knocking out a for-loop.
// Create some matrix A
A = zeros(8,8)
//initialize the array of indices
index = [];
// Get the dimensions of A
rows = size(A,1);
cols = size(A,2);
x = 0;
for i=1:length(A)
if(A(i)==x)
// Append it to list using $ (last index) + 1
index($+1) = i;
end
end
Without for-loop
If you just need the values that adhere to a certain condition you could also do something like this
values = A(A==x);
Be carefull when comparing doubles, these are not always (un)equal when you expect.