[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] How do I subtract the difference between two horizontal study lines? (in AFL)



PureBytes Links

Trading Reference Links




Bruce,
 
The code I have given (and also Jayson's code) works correcly 
*IF* you draw the study lines
on DEFAULT PRICE chart and label them 
correctly.
 
This is so because Study by default refers to built-in price 
chart id which is zero
<A 
href="">http://www.amibroker.com/guide/afl/afl_view.php?name=STUDY
 
You are apparently using the formula NOT on the default price 
chart. But you did not mention it.
 
In that case you have to refer to given pane Chart ID which is 
displayed in the Indicator Builder.
 
As an alernative you can use GetChartID function to retrieve 
current chart ID automatically
<A 
href="">http://www.amibroker.com/guide/afl/afl_view.php?name=GETCHARTID
 
The version that works on any chart (not only built-in price 
chart) would look like this:

x=ValueWhen(NOT 
IsNull( <FONT 
color=#0000ff size=1>Study(<FONT color=#ff00ff 
size=1>"re",<FONT color=#0000ff 
size=1>GetChartID())),<FONT color=#0000ff 
size=1>Study(<FONT color=#ff00ff 
size=1>"re",<FONT 
face="Courier New" color=#0000ff size=1>GetChartID<FONT 
face="Courier New" size=1>()));
y=ValueWhen(NOT 
IsNull( <FONT 
color=#0000ff size=1>Study(<FONT color=#ff00ff 
size=1>"su",<FONT color=#0000ff 
size=1>GetChartID())),<FONT color=#0000ff 
size=1>Study(<FONT color=#ff00ff 
size=1>"su",<FONT color=#0000ff 
size=1>GetChartID()));<FONT face="Courier New" 
size=1>
Title = WriteVal<FONT 
size=1>(x) + <FONT 
face="Courier New" color=#ff00ff size=1>":"<FONT face="Courier New" 
size=1> + WriteVal<FONT 
size=1>(y) + <FONT 
face="Courier New" color=#ff00ff size=1>":"<FONT face="Courier New" 
size=1> + WriteVal<FONT 
size=1>(x-y);
 
Best regards,Tomasz Janeczkoamibroker.com
<BLOCKQUOTE 
>
  ----- Original Message ----- 
  <DIV 
  >From: 
  Bruce 
  Nutter 
  To: <A title=amibroker@xxxxxxxxxxxxxxx 
  href="">amibroker@xxxxxxxxxxxxxxx 
  Sent: Wednesday, October 15, 2003 3:07 
  AM
  Subject: RE: [amibroker] How do I 
  subtract the difference between two horizontal study lines? (in AFL)
  
  
  <SPAN 
  >Gurus, Jason & <SPAN 
  class=SpellE>Tomasz,
  <SPAN 
  >My result of <SPAN 
  class=SpellE>Tomasz&#8216;s example code (shown below) with horizontal study 
  lines labeled &#8220;re&#8221; and &#8220;su&#8221; is as 
  follows:
  <SPAN 
  > 
  <FONT face="Times New Roman" color=black 
  size=3><SPAN 
  >{EMPTY}<FONT 
  color=black>
  <FONT face="Times New Roman" color=black 
  size=3><SPAN 
  >{EMPTY}<FONT 
  color=black>
  <FONT face="Times New Roman" color=black 
  size=3><SPAN 
  >{EMPTY}<FONT 
  color=black>
  <SPAN 
  > 
  <SPAN 
  >Please 
  advise,
  <SPAN 
  >Bruce
  <SPAN 
  >-----Original 
  Message-----From: Tomasz 
  Janeczko [mailto:amibroker@xxxxxx] <SPAN 
  >Sent<SPAN 
  >: <st1:date Year="2003" 
  Day="14" Month="10"><SPAN 
  >Tuesday, October 14, 
  2003<SPAN 
  > <st1:time 
  Minute="27" Hour="14"><SPAN 
  >2:27 
  PM<SPAN 
  ><SPAN 
  >To: <A 
  href="">amibroker@xxxxxxxxxxxxxxx<SPAN 
  >Subject: Re: [amibroker] <SPAN 
  class=GramE>How do I subtract the difference between two horizontal 
  study lines? (in AFL)
  <FONT face="Times New Roman" 
  size=3> 
  
  <FONT face="Times New Roman" 
  size=2>Bruce,
  
  <FONT face="Times New Roman" 
  size=3> 
  
  <FONT face="Times New Roman" 
  size=2>Please use this 
  code:
  
  <FONT face="Times New Roman" 
  size=3> 
  
  <P class=MsoNormal 
  ><FONT 
  face="Courier New" color=black size=1><SPAN 
  >x=<FONT 
  face="Courier New" color=blue size=1><SPAN 
  >ValueWhen<FONT 
  face="Courier New" color=black size=1><SPAN 
  >(NOT IsNull( 
  <SPAN 
  >Study<FONT 
  face="Courier New" color=black size=1><SPAN 
  >(<FONT 
  face="Courier New" color=fuchsia size=1><SPAN 
  >"re"<FONT 
  face="Courier New" color=black size=1><SPAN 
  >)),<FONT 
  face="Courier New" color=blue size=1><SPAN 
  >Study<FONT 
  face="Courier New" color=black size=1><SPAN 
  >(<FONT 
  face="Courier New" color=fuchsia size=1><SPAN 
  >"re"<FONT 
  face="Courier New" color=black size=1><SPAN 
  >));
  <P class=MsoNormal 
  ><FONT 
  face="Courier New" color=black size=1><SPAN 
  >y=<FONT 
  face="Courier New" color=blue size=1><SPAN 
  >ValueWhen<FONT 
  face="Courier New" color=black size=1><SPAN 
  >(NOT IsNull( 
  <SPAN 
  >Study<FONT 
  face="Courier New" color=black size=1><SPAN 
  >(<FONT 
  face="Courier New" color=fuchsia size=1><SPAN 
  >"su"<FONT 
  face="Courier New" color=black size=1><SPAN 
  >)),<FONT 
  face="Courier New" color=blue size=1><SPAN 
  >Study<FONT 
  face="Courier New" color=black size=1><SPAN 
  >(<FONT 
  face="Courier New" color=fuchsia size=1><SPAN 
  >"su"<FONT 
  face="Courier New" color=black size=1><SPAN 
  >));
  <P class=MsoNormal 
  ><FONT 
  face="Courier New" color=blue size=1><SPAN 
  >WriteVal<FONT 
  face="Courier New" color=black size=1><SPAN 
  >(x);
  <P class=MsoNormal 
  ><FONT 
  face="Courier New" color=blue size=1><SPAN 
  >WriteVal<FONT 
  face="Courier New" color=black size=1><SPAN 
  >(y);
  <P class=MsoNormal 
  ><FONT 
  face="Courier New" color=blue size=1><SPAN 
  >WriteVal<FONT 
  face="Courier New" color=black size=1><SPAN 
  >(x-y);
  <P class=MsoNormal 
  ><FONT 
  face="Times New Roman" size=3><SPAN 
  > <FONT face="Courier New" 
  color=black size=1><SPAN 
  >
  
  <FONT face="Times New Roman" 
  size=3>Hope this 
  helps.
  
  <FONT face="Times New Roman" 
  size=3> 
  
  <FONT face="Times New Roman" 
  size=3>Best regards,Tomasz 
  Janeczkoamibroker.com
  <BLOCKQUOTE 
  >
    
    <SPAN 
    >----- Original Message ----- 
    
    
    <FONT 
    face=Arial size=2><SPAN 
    >From:<FONT 
    face=Arial size=2> <A 
    title=bdnutter@xxxxxxxxxxx href="">Bruce 
    Nutter 
    
    <FONT face=Arial 
    size=2><SPAN 
    >To:<FONT 
    face=Arial size=2> <A 
    title=amibroker@xxxxxxxxxxxxxxx 
    href="">amibroker@xxxxxxxxxxxxxxx 
    
    
    <FONT face=Arial 
    size=2><SPAN 
    >Sent:<FONT 
    face=Arial size=2> 
    <FONT face=Arial 
    size=2>Tuesday, October 
    14, 2003<SPAN 
    > <st1:time 
    Minute="9" Hour="22"><SPAN 
    >10:09 
    PM<SPAN 
    >
    
    <FONT face=Arial 
    size=2><SPAN 
    >Subject:<FONT 
    face=Arial size=2> RE: 
    [amibroker] How do I subtract the difference between two horizontal study 
    lines? (in AFL)
    
    <FONT face="Times New Roman" 
    size=3><SPAN 
    > 
    <P class=MsoNormal 
    ><FONT 
    face="Courier New" color=black size=1><SPAN 
    >Gurus and 
    Jayson
    <P class=MsoNormal 
    ><FONT 
    face="Courier New" color=black size=1><SPAN 
    >I tried 
    this code so I could see the difference between the two horizontal lines. 
    But the results I get in the interpretation window is shown below. Could 
    some guru please tell me why this does not work. (For those of you who might 
    ask yes the labels of my horizontal study lines are &#8220;re&#8221; and 
    &#8220;su&#8221;)
    <P class=MsoNormal 
    ><B 
    ><FONT face="Courier New" color=black 
    size=5><SPAN 
    >Formula 
    code:
    <P class=MsoNormal 
    ><FONT 
    face="Courier New" color=black size=1><SPAN 
    >x=<FONT 
    face="Courier New" color=blue size=1><SPAN 
    >LastValue<FONT 
    face="Courier New" color=black size=1><SPAN 
    >(<FONT 
    face="Courier New" color=blue size=1><SPAN 
    >Study<FONT 
    face="Courier New" color=black size=1><SPAN 
    >(<FONT 
    face="Courier New" color=fuchsia size=1><SPAN 
    >"re"<FONT 
    face="Courier New" color=black size=1><SPAN 
    >));
    <P class=MsoNormal 
    ><FONT 
    face="Courier New" color=black size=1><SPAN 
    >y=<FONT 
    face="Courier New" color=blue size=1><SPAN 
    >LastValue<FONT 
    face="Courier New" color=black size=1><SPAN 
    >(<FONT 
    face="Courier New" color=blue size=1><SPAN 
    >Study<FONT 
    face="Courier New" color=black size=1><SPAN 
    >(<FONT 
    face="Courier New" color=fuchsia size=1><SPAN 
    >"su"<FONT 
    face="Courier New" color=black size=1><SPAN 
    >));
    <P class=MsoNormal 
    ><FONT 
    face="Courier New" color=blue size=1><SPAN 
    >WriteVal<FONT 
    face="Courier New" color=black size=1><SPAN 
    >(x);
    <P class=MsoNormal 
    ><FONT 
    face="Courier New" color=blue size=1><SPAN 
    >WriteVal<FONT 
    face="Courier New" color=black size=1><SPAN 
    >(y);
    <P class=MsoNormal 
    ><FONT 
    face="Courier New" color=blue size=1><SPAN 
    >WriteVal<FONT 
    face="Courier New" color=black size=1><SPAN 
    >(x-y);
    <P class=MsoNormal 
    ><B 
    ><FONT face="Courier New" color=black 
    size=5><SPAN 
    >Interpretation 
    window result:
    <P class=MsoNormal 
    ><FONT 
    face="Courier New" color=black size=1><SPAN 
    >0
    <P class=MsoNormal 
    ><FONT 
    face="Courier New" color=black size=1><SPAN 
    >0
    <P class=MsoNormal 
    ><FONT 
    face="Courier New" color=black size=1><SPAN 
    >0
    <P class=MsoNormal 
    ><FONT 
    face="Courier New" color=black size=1><SPAN 
    > 
    <P class=MsoNormal 
    ><FONT 
    face="Courier New" color=black size=1><SPAN 
    > 
    <FONT face="Times New Roman" 
    color=black size=3><SPAN 
    >Bruce
    <FONT face="Times New Roman" 
    color=black size=3><SPAN 
    > 
    <SPAN 
    >-----Original 
    Message-----From: Jayson 
    [mailto:jcasavant@xxxxxxxxxxx] <SPAN 
    >Sent: <st1:date 
    Year="2003" Day="14" Month="10"><SPAN 
    >Tuesday, October 14, 
    2003<SPAN 
    > <st1:time 
    Minute="49" Hour="9"><SPAN 
    >9:49 
    AM<SPAN 
    ><SPAN 
    >To: 
    amibroker@xxxxxxxxxxxxxxx<SPAN 
    >Subject: RE: [amibroker] How do I 
    subtract the difference between two horizontal study lines? (in 
    AFL)
    <FONT face="Times New Roman" 
    size=3> 
    
    <FONT face=Arial color=blue 
    size=2><SPAN 
    >Brian,
    
    <FONT face=Arial color=blue 
    size=2>have a 
    look in the help files for Study(). You can name your trend line than call 
    its value in a code.
    
    <FONT face="Times New Roman" 
    size=3><SPAN 
    > 
    
    <FONT face=Arial color=blue 
    size=2>for 
    instance in this exploration I have named 2 study lines and called the last 
    value of each and subtracted one from the 
    other....
    
    <FONT face="Times New Roman" 
    size=3><SPAN 
    > 
    
    <FONT face="Times New Roman" 
    size=2><SPAN 
    > 
    
    <FONT face=Arial color=blue 
    size=2><SPAN 
    >Filter=C>0;<FONT 
    color=#282828 size=2><SPAN 
    >
    
    <FONT face=Arial color=blue 
    size=2><SPAN 
    >x=<FONT 
    color=blue size=2><SPAN 
    >LastValue(Study("s1"))<FONT 
    face=Arial color=blue size=2><SPAN 
    >;<FONT 
    face=Arial color=#282828 size=2><SPAN 
    >
    
    <FONT face=Arial color=blue 
    size=2><SPAN 
    >y=<FONT 
    color=blue size=2><SPAN 
    >LastValue(Study("s<FONT 
    face=Arial color=blue size=2><SPAN 
    >2<FONT 
    color=blue size=2><SPAN 
    >")<FONT face=Arial 
    color=blue size=2><SPAN 
    >);<FONT 
    face=Arial color=#282828 size=2><SPAN 
    >
    
    <FONT face=Arial color=blue 
    size=2><SPAN 
    >AddColumn<FONT 
    face=Arial color=#282828 size=2><SPAN 
    >(x,<FONT 
    face=Arial color=fuchsia size=2><SPAN 
    >""<FONT 
    face=Arial color=#282828 size=2><SPAN 
    >);<FONT 
    color=#282828 size=2><SPAN 
    >
    
    <FONT face=Arial color=blue 
    size=2><SPAN 
    >AddColumn<FONT 
    face=Arial color=#282828 size=2><SPAN 
    >(y,<FONT 
    face=Arial color=fuchsia size=2><SPAN 
    >""<FONT 
    face=Arial color=#282828 size=2><SPAN 
    >);
    
    <FONT face=Arial color=blue 
    size=2><SPAN 
    >AddColumn<FONT 
    face=Arial color=#282828 size=2><SPAN 
    >(x-y,<FONT 
    face=Arial color=fuchsia size=2><SPAN 
    >""<FONT 
    face=Arial color=#282828 size=2><SPAN 
    >);
    
    <FONT face="Times New Roman" 
    size=3><SPAN 
    > 
    
    <FONT face="Times New Roman" 
    size=3><SPAN 
    > 
    
    <FONT face=Arial color=blue 
    size=2><SPAN 
    >Regards, 
    
    <FONT face=Arial color=blue 
    size=2><SPAN 
    >Jayson 
    
    <P class=MsoNormal 
    ><FONT 
    face=Tahoma size=2><SPAN 
    >-----Original 
    Message-----From: Bruce 
    Nutter [mailto:bdnutter@xxxxxxxxxxx]<SPAN 
    >Sent: <st1:date 
    Year="2003" Day="14" Month="10"><SPAN 
    >Tuesday, October 14, 
    2003<SPAN 
    > <st1:time 
    Minute="26" Hour="12"><SPAN 
    >12:26 
    PM<SPAN 
    ><SPAN 
    >To: 
    amibroker@xxxxxxxxxxxxxxx<SPAN 
    >Subject: [amibroker] How do I subtract 
    the difference between two horizontal study lines? (in 
    AFL)
    <FONT face="Times New Roman" 
    color=black size=3><SPAN 
    >Gurus,
    <FONT face="Times New Roman" 
    color=black size=3>Does anybody 
    know how to subtract between two horizontal study lines in AFL code? I have 
    to study lines that I move around to calculate entry and exit points. What 
    I'd like to do is to show that vertical distance between these two 
    horizontal lines in the interpretation window. Would one of you gurus please 
    let me know how to do this?
    <FONT face="Times New Roman" 
    color=black size=3><SPAN 
    >Bruce
    <FONT face="Times New Roman" 
    size=3><FONT 
    face="Courier New" size=2>Send BUG REPORTS to 
    bugs@xxxxxxxxxxxxx<SPAN 
    ><FONT 
    face="Courier New">Send SUGGESTIONS to 
    suggest@xxxxxxxxxxxxx<FONT 
    face="Courier New">-----------------------------------------<FONT 
    face="Courier New">Post AmiQuote-related messages ONLY to: 
    amiquote@xxxxxxxxxxxxxxx (Web 
    page: <A 
    href="">http://groups.yahoo.com/group/amiquote/messages/)<FONT 
    face="Courier New">--------------------------------------------<FONT 
    face="Courier New">Check group FAQ at: <A 
    href="">http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
    <SPAN 
    >Your use of Yahoo! Groups is subject to the <A 
    href="">Yahoo! Terms of 
    Service. <BR 
    ><BR 
    >
    <FONT face="Courier New" 
    size=2>Send BUG REPORTS to 
    bugs@xxxxxxxxxxxxx<SPAN 
    ><FONT 
    face="Courier New">Send SUGGESTIONS to 
    suggest@xxxxxxxxxxxxx<FONT 
    face="Courier New">-----------------------------------------<FONT 
    face="Courier New">Post AmiQuote-related messages ONLY to: 
    amiquote@xxxxxxxxxxxxxxx (Web 
    page: <A 
    href="">http://groups.yahoo.com/group/amiquote/messages/)<FONT 
    face="Courier New">--------------------------------------------<FONT 
    face="Courier New">Check group FAQ at: <A 
    href="">http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
    <SPAN 
    >Your use of Yahoo! Groups is subject to the <A 
    href="">Yahoo! Terms of 
    Service. 
    <FONT face="Times New Roman" 
    size=3> 
    <FONT face="Times New Roman" 
    size=3><FONT 
    face="Courier New" size=2>Send BUG REPORTS to 
    bugs@xxxxxxxxxxxxx<SPAN 
    ><FONT 
    face="Courier New">Send SUGGESTIONS to 
    suggest@xxxxxxxxxxxxx<FONT 
    face="Courier New">-----------------------------------------<FONT 
    face="Courier New">Post AmiQuote-related messages ONLY to: 
    amiquote@xxxxxxxxxxxxxxx (Web 
    page: <A 
    href="">http://groups.yahoo.com/group/amiquote/messages/)<FONT 
    face="Courier New">--------------------------------------------<FONT 
    face="Courier New">Check group FAQ at: <A 
    href="">http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
    <SPAN 
    >Your use of Yahoo! Groups is subject to the <A 
    href="">Yahoo! Terms of 
    Service. 
  <FONT face="Times New Roman" 
  size=3><BR 
  ><BR 
  ><FONT 
  face="Courier New" size=2>Send BUG REPORTS to 
  bugs@xxxxxxxxxxxxx<SPAN 
  ><FONT 
  face="Courier New">Send SUGGESTIONS to 
  suggest@xxxxxxxxxxxxx<FONT 
  face="Courier New">-----------------------------------------<FONT 
  face="Courier New">Post AmiQuote-related messages ONLY to: 
  amiquote@xxxxxxxxxxxxxxx (Web 
  page: <A 
  href="">http://groups.yahoo.com/group/amiquote/messages/)<FONT 
  face="Courier New">--------------------------------------------<FONT 
  face="Courier New">Check group FAQ at: <A 
  href="">http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
  Your 
  use of Yahoo! Groups is subject to the <A 
  href="">Yahoo! Terms of 
  Service. 
  Send 
  BUG REPORTS to bugs@xxxxxxxxxxxxxSend SUGGESTIONS to 
  suggest@xxxxxxxxxxxxx-----------------------------------------Post 
  AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx (Web page: <A 
  href="">http://groups.yahoo.com/group/amiquote/messages/)--------------------------------------------Check 
  group FAQ at: <A 
  href="">http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
  Your use of Yahoo! Groups is subject to the <A 
  href="">Yahoo! Terms of Service. 







Yahoo! Groups Sponsor












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



Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.