PureBytes Links
Trading Reference Links
|
Hi,
Gary wrote:
---
Tomasz has created this IIF function for these situations.
IIF(Sum(C > Ref(C, -1), 3) == 3, 1, -1);
Hope this helps as I'm not sure if you are trying to gate your code
with the condition (which IF will do barring the restriction to a
number not an array) or are just trying to generate some numbers from
the results of the condition (which IIF provides).
---
If the calcs depending on condition beeing true or false are more
complex, I think you can do this:
x=IIF(Sum(C > Ref(C, -1), 3) == 3, f1(), f2() );
where f1() and f2() are previously defined functions:
function f1()
{
what you want to do if cond is true
return something
}
function f2()
{
what you want to do if cond is false
return something
}
Johan
--- In amibroker@xxxxxxxxxxxxxxx, "Glen Haponek" <ghaponek@xxxx>
wrote:
> Gary,
>
> The credit goes to Johan, I would not have thought to do this in
this manner. I was stumped.
>
> Glen
> ----- Original Message -----
> From: Gary A. Serkhoshian
> To: amibroker@xxxxxxxxxxxxxxx
> Sent: Sunday, March 21, 2004 8:29 PM
> Subject: Re: [amibroker] Re: Help with referencing previous prices
>
>
> Glen,
>
> I just read through all the posts on this thread, and I'm not
exactly sure what you are after but from my impressions your solution
is straightforward.
>
> First, an explaination of the Error 3. IF, For, While only allow
for numbers NOT arrays. So, you can NOT do this:
>
> If (C > 5)
> {
> blah;
> }
>
> That is why you are getting an Error 3. You could, however, use
the LastValue function to convert an array to a number. The problem
is it only returns the last value of the calculation.
>
> You can do this:
>
> x = 1;
>
> If (x)
> {
> blahblah;
> }
>
> Tomasz has created this IIF function for these situations.
>
> IIF(Sum(C > Ref(C, -1), 3) == 3, 1, -1);
>
> Hope this helps as I'm not sure if you are trying to gate your
code with the condition (which IF will do barring the restriction to
a number not an array) or are just trying to generate some numbers
from the results of the condition (which IIF provides).
>
> Kind Regards,
> Gary
>
> Glen Haponek <ghaponek@xxxx> wrote:
> Johan,
>
> So you are defining the relationship between the three bars as
a mathematical function of the element subscript, and the condition
is identified as true when the numeric value of y equals 3 ?
>
> The first iteration through this is : x = C [ i - k ] >C [ i -
k -1 ];
> x = C [ 3 -
0 ] > C [ 3 - 0 -1];
> = C [ 3 ] >
C [ 2 ];
> y = 0 + 1 = 1
>
> The second : x = C [ 4 - 1] > C [
4 - 1 - 1]
> = C [ 3 ] >
C [ 2 ];
> y = y + x = 1
+ 1 = 2
>
> The third: x = C [5 -2] > C [
5 - 2 - 1] ;
> = C [ 3 ] > C
[ 2] ;
> y = y + x = 2
+ 1 = 3
>
> and Cond [ i ] or Cond [ 3 ] == 3, and is true, except that it
looks like only C [ 3 ] > C [ 2 ] has been tested.
>
> Is this what you have performed here?
>
> I initially described the relationship as : C [ 3 ] > C [ 2 ]
and C [ 2 ] > C [1 ] and C [ 1 ] > C [ 0 ] , which isn't exactly
what I think you have done, but the specific price relationship
wasn't the point of my question. Thank you for your insight in
this.
>
> If I my interpretation is correct, what would be changed to
perform the above?
>
> Might this work?
>
> for ( i=3; i<BarCount ; i++)
> {
> k = 0 ;
> y = 0 ;
> m = 0 ;
> while( k <= 2 )
> {
> x=C[i-k-m]>C[i-k-n-1];
> y=y+x;
> k++;
> m = m++;
> Cond[i]=y==3;
> }
> }
>
> First iteration : x = C [i-k-m]>C[i-k-m-1];
> = C [3-0-0] > C [3 -0 -0 -1]
> = C [ 3 ] > C [ 2 ]
>
> Second : x = C [i-k-m] > C[i-k-n];
> = C [4 -1 -1] > C [ 4 - 1 - 1 -1]
> = C [ 2 ] > C [ 1 ]
>
> Third : x = C [i-k-m] > C[i-k-n];
> = C [ 5 -2 -2] > C [ 5 - 2 -2 -1]
> = C [ 1 ] > C [ 0 ]
>
> If the initial relationship were : C [ 3 ] > C [ 2 ] and C [
2 ] > C [ 1 ] and C [ 1 ] < C [ 0 ]
>
> How would this be addressed? Wouldn't the algorithm have to be
split into 2 parts?
>
> Glen
>
> ----- Original Message -----
> From: johsun
> To: amibroker@xxxxxxxxxxxxxxx
> Sent: Sunday, March 21, 2004 2:34 PM
> Subject: [amibroker] Re: Help with referencing previous prices
>
>
> OK, guess I didn't read your message properly.
> Does this help you in any way:
>
> for(i=3;i<BarCount;i++)
> {
> k=0;
> y=0;
> while(k<=2)
> {
> x=C[i-k]>C[i-k-1];
> y=y+x;
> k++;
> Cond[i]=y==3;
> }
> }
> Plot(C,"",colorBlack,styleCandle);
> Plot(Cond,"",colorBlue,styleHistogram|styleOwnScale);
>
> Johan
>
>
>
>
> Send BUG REPORTS to bugs@xxxx
> Send SUGGESTIONS to suggest@xxxx
> -----------------------------------------
> Post AmiQuote-related messages ONLY to:
amiquote@xxxxxxxxxxxxxxx
> (Web page: http://groups.yahoo.com/group/amiquote/messages/)
> --------------------------------------------
> Check group FAQ at:
http://groups.yahoo.com/group/amibroker/files/groupfaq.html
>
>
>
> Send BUG REPORTS to bugs@xxxx
> Send SUGGESTIONS to suggest@xxxx
> -----------------------------------------
> Post AmiQuote-related messages ONLY to:
amiquote@xxxxxxxxxxxxxxx
> (Web page: http://groups.yahoo.com/group/amiquote/messages/)
> --------------------------------------------
> Check group FAQ at:
http://groups.yahoo.com/group/amibroker/files/groupfaq.html
>
>
>
> Do you Yahoo!?
> Yahoo! Finance Tax Center - File online. File on time.
>
> Send BUG REPORTS to bugs@xxxx
> Send SUGGESTIONS to suggest@xxxx
> -----------------------------------------
> Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx
> (Web page: http://groups.yahoo.com/group/amiquote/messages/)
> --------------------------------------------
> Check group FAQ at:
http://groups.yahoo.com/group/amibroker/files/groupfaq.html
>
>
>
>
>
> --------------------------------------------------------------------
----------
> Yahoo! Groups Links
>
> a.. To visit your group on the web, go to:
> http://groups.yahoo.com/group/amibroker/
>
> b.. To unsubscribe from this group, send an email to:
> amibroker-unsubscribe@xxxxxxxxxxxxxxx
>
> c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service.
Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|