|
Post by bobpit on May 11, 2015 23:51:51 GMT
I want to find the index of the array (ar) where the value is equal to the current value. I guess I will use ValueWhen. However I have trouble making a conditional expression to check past array values with current price.
x = ValueWhen(ar == current_value(ar), barindex(), 1);
I feel like my mind has stopped. I am sure I have done this before. How do I represent the current value of ar ?
|
|
fxshrat
Private Group
Posts: 566
Received Likes: 211
|
Post by fxshrat on May 12, 2015 7:40:30 GMT
condition = V < LastValue(V);
arrcompress = SparseCompress( condition, BarIndex() ); arrexpand = SparseExpand( condition, arrcompress );
Plot( arrexpand, "BI", colorRed, styleHistogram);
|
|
fxshrat
Private Group
Posts: 566
Received Likes: 211
|
Post by fxshrat on May 12, 2015 7:54:15 GMT
For equality you might rather uses AlmostEqual instead of ==
percentequal = 0.1;// % bi = BarIndex();
condition = AlmostEqual( C, LastValue( C ), percentequal*100000 );
arrcompress = SparseCompress( condition, bi ); arrexpand = SparseExpand( condition, arrcompress );
//SetBarsRequired( -2, -2 ); Plot( arrexpand, "BI", colorRed, styleHistogram );
|
|
fxshrat
Private Group
Posts: 566
Received Likes: 211
|
Post by fxshrat on May 12, 2015 8:27:39 GMT
Just have seen that you ask almost same one at Yahoo groups groups.yahoo.com/neo/groups/amibroker/conversations/messagespercentequal = 0.1; bi = BarIndex();
condition = AlmostEqual( C, LastValue( C ), percentequal*100000 );
arrcompress = SparseCompress( condition, bi ); arrexpand = SparseExpand( condition, arrcompress );
sequence = 6; Plot( sum(bi == Nz(arrexpand), sequence ) == sequence, "BIcond", colorRed, styleHistogram );
|
|
|
Post by bobpit on May 12, 2015 9:22:49 GMT
For equality you might rather uses AlmostEqual instead of == percentequal = 0.1;// % bi = BarIndex();
condition = AlmostEqual( C, LastValue( C ), percentequal*100000 );
arrcompress = SparseCompress( condition, bi ); arrexpand = SparseExpand( condition, arrcompress );
//SetBarsRequired( -2, -2 ); Plot( arrexpand, "BI", colorRed, styleHistogram ); Hello fxshrat Thank you for your answers. I see that SparseCompress/SparseExpand are new functions. I do understand what they are doing. I applied your code and I do see some lines on the chart. Could you please tell me what they mean? You are comparing C with LastValue( C ). Why? LastValue( C ) is looking into the future, right? I must be missing something.
|
|
|
Post by gaborkuti on May 12, 2015 9:34:28 GMT
Looking into the future -- in relation to what? For the item you selected, maybe. Depends on the use case.. LastValue() will give you the last available value (i.e. the one with the newest timestamp) in the array.
bob, you did not give much context what you are trying to achieve, in fact I am not sure I understand the problem.. (did you want to take a look at SelectedValue() as well, possibly?)
Fx, I was also wondering if the good old IIf would give the same results? (IIf(condition, bi, Null)).
|
|
fxshrat
Private Group
Posts: 566
Received Likes: 211
|
Post by fxshrat on May 12, 2015 9:36:53 GMT
You want to compare which values of the array are equal to current value, right? So it looks backwards from last value. For older AB versions you may use AFL version for sparse... www.amibroker.com/devlog/wp-content/uploads/2015/02/readme5910.htmlThe lines of 2nd code are the barindexes where past closes are almost equal to last value of close. The lines are plotted as histogram.
|
|
|
Post by bobpit on May 12, 2015 9:56:32 GMT
Hi
It's becoming more complicated than I expected. Let me clarify.
I am NOT interested in LastValue only. I want to know for every single array element, what is the distance from the previous element with the same value.
So for example if I have array with possible values: 1,2 and 3. And the array looks like this: 13322132111332132213212322212332123321232
The 4th from the last element is 1. Now I want to know that 5 bars behind there is another 1. The 2nd from the last element is 3. Now I want to know that 4 bars behind there is another 3.
Could you make a simple example of how this would work?
|
|
|
Post by bobpit on May 12, 2015 10:59:03 GMT
Guys
may I assume that it is not possible with AFL commands and I need to use FOR loop?
|
|
fxshrat
Private Group
Posts: 566
Received Likes: 211
|
Post by fxshrat on May 12, 2015 11:12:36 GMT
|
|