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

Re: Point & Figure Chart in AFL



PureBytes Links

Trading Reference Links

// PF Chart by Mirat Dave
// Copy and paste this as a custom indicator.

EnableScript("jscript");
<%

High = VBArray( AFL( "High" ) ).toArray();
Low = VBArray( AFL( "Low" ) ).toArray();

// Calculate running average stock price for use in calculating the Box size.

tot = new Array();
tot[0] = (High[0] + Low[0])/2;
for( i=1; i < High.length; i++ )
{
tot[i] = tot[i-1] + ((High[i] + Low[i])/2);
}
PFO = new Array();
PFC = new Array();

// initialize first element

j = 0;
PFO[j] = High[0];
PFC[j] = Low[0];
down = 1; // By default the first bar is a down bar.

up = 0;
swap = 0;

// perform the loop that produces PF Chart

for( i = 1; i < High.length; i++ )
{
// Calculate PF Chart Box size and minimum Reverse values

Box = ((tot[i]/(i+1))^.5)/7.3374;
Reverse = Box * 3;
if( Low[i] < PFC[j] - Box && down)
{
PFC[j] = Low[i];
}
else
{
if( High[i] >= PFC[j] + Reverse && down)
{
j++;
swap = 1;
PFO[j] = Low[i];
PFC[j] = High[i];
}
}
if( High[i] > PFC[j] + Box && up)
{
PFC[j] = High[i];
}
else
{
if( Low[i] <= PFC[j] - Reverse && up)
{
j++;
PFC[j] = Low[i];
PFO[j] = High[i];
swap = 1;
}
}
if( swap )
{
swap = 0;
if( up )
{
up = 0;
down = 1;
}
else
{
up = 1;
down = 0;
}
}
}

// Shift chart to the right to eliminate trailing empty data
// - PF charts are generally smaller/shorter then the full stock charts because they lack a time scale.

delta = High.length - PFO.length;
for( i = High.length; i > delta; i-- )
{
PFO[ i-1 ] = PFO[ i-delta-1];
PFC[ i-1 ] = PFC[ i-delta-1];
}
for( i = 0; i < delta; i++)
{
PFO[ i-1 ] = 0;
PFC[ i-1 ] = 0;
}
AFL.Var("PFO") = PFO;
AFL.Var("PFC") = PFC;
%>

O = PFO;
C = PFC;

H = (O+C)/2;
L = (O+C)/2;

GraphXSpace = 9;
Graph0Style = 64;

Graph0Color =1;
Graph0 = C;

Thanks in advance for any reply.
Dimitris Tsokakis

------=_NextPart_001_0008_01C22D0D.D2611E00
Content-Type: text/html;
charset="iso-8859-7"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-7" http-equiv=Content-Type>
<META content="MSHTML 5.00.3013.2600" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT size=2>Mirat,</FONT></DIV>
<DIV><FONT size=2>Here is P&amp;F charts for AMZN, MSFT and ORCL.</FONT></DIV>
<DIV><FONT size=2>Data since Jan 2000.</FONT></DIV>
<DIV><FONT size=2>Is it the expected picture ?</FONT></DIV>
<DIV><FONT size=2>The code, copied from files section</FONT></DIV>
<DIV><FONT color=#ffffe0 face=Verdana size=2>&nbsp;</DIV>
<DIV><FONT color=#000000 face="Times New Roman">// PF Chart by Mirat 
Dave</FONT></DIV>
<DIV><FONT color=#000000 face="Times New Roman">// Copy and paste this as a 
custom indicator.</FONT></DIV>
<DIV></FONT><FONT color=#000000 face=Verdana size=2></FONT><FONT color=#800080 
face=Verdana size=2>&nbsp;</DIV><FONT color=#000000><FONT 
face="Times New Roman">
<DIV>EnableScript</FONT><FONT size=2>(</FONT><FONT 
size=2>"jscript"</FONT></FONT><FONT face=Verdana size=2></FONT><FONT 
face="Times New Roman">);</FONT></DIV>
<DIV><FONT face="Times New Roman">&lt;%</FONT></DIV>
<DIV>&nbsp;</DIV><FONT face="Times New Roman">
<DIV>High = VBArray( AFL( </FONT><FONT size=2>"High"</FONT></FONT><FONT 
face=Verdana size=2><FONT face="Times New Roman"> ) 
).toArray();</FONT></DIV><FONT face="Times New Roman">
<DIV>Low = VBArray( AFL( </FONT><FONT size=2>"Low"</FONT><FONT face=Verdana 
size=2></FONT><FONT face="Times New Roman"> ) ).toArray();</FONT></DIV>
<DIV></FONT><FONT face=Verdana size=2>&nbsp;</DIV>
<DIV><FONT face="Times New Roman">// Calculate running average stock price for 
use in calculating the Box size.</FONT></DIV>
<DIV></FONT><FONT face=Verdana size=2>&nbsp;</DIV>
<DIV><FONT face="Times New Roman">tot = new Array();</FONT></DIV><FONT 
face="Times New Roman">
<DIV>tot[</FONT><FONT size=2>0</FONT><FONT size=2>] = (High[</FONT><FONT 
size=2>0</FONT><FONT size=2>] + Low[</FONT><FONT size=2>0</FONT><FONT 
size=2>])/</FONT><FONT size=2>2</FONT></FONT><FONT face=Verdana size=2><FONT 
face="Times New Roman">;</FONT></DIV><FONT face="Times New Roman">
<DIV>for( i=</FONT><FONT size=2>1</FONT></FONT><FONT face=Verdana size=2><FONT 
face="Times New Roman">; i &lt; High.length; i++ )</FONT></DIV>
<DIV><FONT face="Times New Roman">{</FONT></DIV><FONT face="Times New Roman">
<DIV>tot[i] = tot[i-</FONT><FONT size=2>1</FONT><FONT size=2>] + ((High[i] + 
Low[i])/</FONT><FONT size=2>2</FONT></FONT><FONT face=Verdana size=2><FONT 
face="Times New Roman">);</FONT></DIV>
<DIV><FONT face="Times New Roman">}</FONT></DIV>
<DIV><FONT face="Times New Roman">PFO = new Array();</FONT></DIV>
<DIV><FONT face="Times New Roman">PFC = new Array();</FONT></DIV>
<DIV></FONT><FONT face=Verdana size=2>&nbsp;</DIV>
<DIV><FONT face="Times New Roman">// initialize first element</FONT></DIV>
<DIV></FONT><FONT face=Verdana size=2>&nbsp;</DIV><FONT face="Times New Roman">
<DIV>j = </FONT><FONT size=2>0</FONT></FONT><FONT face=Verdana size=2><FONT 
face="Times New Roman">;</FONT></DIV><FONT face="Times New Roman">
<DIV>PFO[j] = High[</FONT><FONT size=2>0</FONT></FONT><FONT face=Verdana 
size=2><FONT face="Times New Roman">];</FONT></DIV><FONT face="Times New Roman">
<DIV>PFC[j] = Low[</FONT><FONT size=2>0</FONT></FONT><FONT face=Verdana 
size=2><FONT face="Times New Roman">];</FONT></DIV><FONT face="Times New Roman">
<DIV>down = </FONT><FONT size=2>1</FONT><FONT size=2>; </FONT><FONT face=Verdana 
size=2></FONT><FONT face="Times New Roman">// By default the first bar is a down 
bar.</FONT></DIV>
<DIV></FONT><FONT face=Verdana size=2>&nbsp;</DIV><FONT face="Times New Roman">
<DIV>up = </FONT><FONT size=2>0</FONT></FONT><FONT face=Verdana size=2><FONT 
face="Times New Roman">;</FONT></DIV><FONT face="Times New Roman">
<DIV>swap = </FONT><FONT size=2>0</FONT><FONT face=Verdana size=2></FONT><FONT 
face="Times New Roman">;</FONT></DIV>
<DIV></FONT><FONT face=Verdana size=2>&nbsp;</DIV>
<DIV><FONT face="Times New Roman">// perform the loop that produces PF 
Chart</FONT></DIV>
<DIV></FONT><FONT face=Verdana size=2>&nbsp;</DIV><FONT face="Times New Roman">
<DIV>for( i = </FONT><FONT size=2>1</FONT></FONT><FONT face=Verdana size=2><FONT 
face="Times New Roman">; i &lt; High.length; i++ )</FONT></DIV>
<DIV><FONT face="Times New Roman">{</FONT></DIV>
<DIV></FONT><FONT face=Verdana size=2><FONT face="Times New Roman">//Calculate 
PF Chart Box size and minimum Reverse values</FONT></DIV>
<DIV></FONT><FONT face=Verdana size=2>&nbsp;</DIV><FONT face="Times New Roman">
<DIV>Box = ((tot[i]/(i+</FONT><FONT size=2>1</FONT><FONT 
size=2>))^.5)/</FONT><FONT size=2>7.3374</FONT></FONT><FONT face=Verdana 
size=2><FONT face="Times New Roman">;</FONT></DIV><FONT face="Times New Roman">
<DIV>Reverse = Box * </FONT><FONT size=2>3</FONT></FONT><FONT face=Verdana 
size=2><FONT face="Times New Roman">;</FONT></DIV>
<DIV><FONT face="Times New Roman">if( Low[i] &lt; PFC[j] - Box &amp;&amp; 
down)</FONT></DIV>
<DIV><FONT face="Times New Roman">{</FONT></DIV>
<DIV><FONT face="Times New Roman">PFC[j] = Low[i];</FONT></DIV>
<DIV><FONT face="Times New Roman">}</FONT></DIV>
<DIV><FONT face="Times New Roman">else</FONT></DIV>
<DIV><FONT face="Times New Roman">{</FONT></DIV>
<DIV><FONT face="Times New Roman">if( High[i] &gt;= PFC[j] + Reverse &amp;&amp; 
down)</FONT></DIV>
<DIV><FONT face="Times New Roman">{</FONT></DIV>
<DIV><FONT face="Times New Roman">j++;</FONT></DIV><FONT face="Times New Roman">
<DIV>swap = </FONT><FONT size=2>1</FONT></FONT><FONT face=Verdana size=2><FONT 
face="Times New Roman">;</FONT></DIV>
<DIV><FONT face="Times New Roman">PFO[j] = Low[i];</FONT></DIV>
<DIV><FONT face="Times New Roman">PFC[j] = High[i];</FONT></DIV>
<DIV><FONT face="Times New Roman">}</FONT></DIV>
<DIV><FONT face="Times New Roman">}</FONT></DIV>
<DIV><FONT face="Times New Roman">if( High[i] &gt; PFC[j] + Box &amp;&amp; 
up)</FONT></DIV>
<DIV><FONT face="Times New Roman">{</FONT></DIV>
<DIV><FONT face="Times New Roman">PFC[j] = High[i];</FONT></DIV>
<DIV><FONT face="Times New Roman">}</FONT></DIV>
<DIV><FONT face="Times New Roman">else</FONT></DIV>
<DIV><FONT face="Times New Roman">{</FONT></DIV>
<DIV><FONT face="Times New Roman">if( Low[i] &lt;= PFC[j] - Reverse &amp;&amp; 
up)</FONT></DIV>
<DIV><FONT face="Times New Roman">{</FONT></DIV>
<DIV><FONT face="Times New Roman">j++;</FONT></DIV>
<DIV><FONT face="Times New Roman">PFC[j] = Low[i];</FONT></DIV>
<DIV><FONT face="Times New Roman">PFO[j] = High[i];</FONT></DIV><FONT 
face="Times New Roman">
<DIV>swap = </FONT><FONT size=2>1</FONT></FONT><FONT face=Verdana size=2><FONT 
face="Times New Roman">;</FONT></DIV>
<DIV><FONT face="Times New Roman">}</FONT></DIV>
<DIV><FONT face="Times New Roman">}</FONT></DIV>
<DIV><FONT face="Times New Roman">if( swap )</FONT></DIV>
<DIV><FONT face="Times New Roman">{</FONT></DIV><FONT face="Times New Roman">
<DIV>swap = </FONT><FONT size=2>0</FONT></FONT><FONT face=Verdana size=2><FONT 
face="Times New Roman">;</FONT></DIV>
<DIV><FONT face="Times New Roman">if( up )</FONT></DIV>
<DIV><FONT face="Times New Roman">{</FONT></DIV><FONT face="Times New Roman">
<DIV>up = </FONT><FONT size=2>0</FONT></FONT><FONT face=Verdana size=2><FONT 
face="Times New Roman">;</FONT></DIV><FONT face="Times New Roman">
<DIV>down = </FONT><FONT size=2>1</FONT></FONT><FONT face=Verdana size=2><FONT 
face="Times New Roman">;</FONT></DIV>
<DIV><FONT face="Times New Roman">}</FONT></DIV>
<DIV><FONT face="Times New Roman">else</FONT></DIV>
<DIV><FONT face="Times New Roman">{</FONT></DIV><FONT face="Times New Roman">
<DIV>up = </FONT><FONT size=2>1</FONT></FONT><FONT face=Verdana size=2><FONT 
face="Times New Roman">;</FONT></DIV><FONT face="Times New Roman">
<DIV>down = </FONT><FONT size=2>0</FONT></FONT><FONT face=Verdana size=2><FONT 
face="Times New Roman">;</FONT></DIV>
<DIV><FONT face="Times New Roman">}</FONT></DIV>
<DIV><FONT face="Times New Roman">}</FONT></DIV>
<DIV><FONT face="Times New Roman">}</FONT></DIV>
<DIV></FONT><FONT face=Verdana size=2>&nbsp;</DIV>
<DIV><FONT face="Times New Roman">// Shift chart to the right to eliminate 
trailing empty data</FONT></DIV>
<DIV><FONT face="Times New Roman">// - PF charts are generally smaller/shorter 
then the full stock charts because they lack a time scale.</FONT></DIV>
<DIV></FONT><FONT face=Verdana size=2>&nbsp;</DIV>
<DIV><FONT face="Times New Roman">delta = High.length - PFO.length;</FONT></DIV>
<DIV><FONT face="Times New Roman">for( i = High.length; i &gt; delta; i-- 
)</FONT></DIV>
<DIV><FONT face="Times New Roman">{</FONT></DIV><FONT face="Times New Roman">
<DIV>PFO[ i-</FONT><FONT size=2>1</FONT><FONT size=2> ] = PFO[ 
i-delta-</FONT><FONT size=2>1</FONT></FONT><FONT face=Verdana size=2><FONT 
face="Times New Roman">];</FONT></DIV><FONT face="Times New Roman">
<DIV>PFC[ i-</FONT><FONT size=2>1</FONT><FONT size=2> ] = PFC[ 
i-delta-</FONT><FONT size=2>1</FONT></FONT><FONT face=Verdana size=2><FONT 
face="Times New Roman">];</FONT></DIV>
<DIV><FONT face="Times New Roman">}</FONT></DIV><FONT face="Times New Roman">
<DIV>for( i = </FONT><FONT size=2>0</FONT></FONT><FONT face=Verdana size=2><FONT 
face="Times New Roman">; i &lt; delta; i++)</FONT></DIV>
<DIV><FONT face="Times New Roman">{</FONT></DIV><FONT face="Times New Roman">
<DIV>PFO[ i-</FONT><FONT size=2>1</FONT><FONT size=2> ] = </FONT><FONT 
size=2>0</FONT></FONT><FONT face=Verdana size=2><FONT 
face="Times New Roman">;</FONT></DIV><FONT face="Times New Roman">
<DIV>PFC[ i-</FONT><FONT size=2>1</FONT><FONT size=2> ] = </FONT><FONT 
size=2>0</FONT></FONT><FONT face=Verdana size=2><FONT 
face="Times New Roman">;</FONT></DIV>
<DIV><FONT face="Times New Roman">}</FONT></DIV><FONT face="Times New Roman">
<DIV>AFL.Var(</FONT><FONT size=2>"PFO"</FONT></FONT><FONT face=Verdana 
size=2><FONT face="Times New Roman">) = PFO;</FONT></DIV><FONT 
face="Times New Roman">
<DIV>AFL.Var(</FONT><FONT size=2>"PFC"</FONT></FONT><FONT face=Verdana 
size=2><FONT face="Times New Roman">) = PFC;</FONT></DIV>
<DIV><FONT face="Times New Roman">%&gt;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face="Times New Roman">O = PFO;</FONT></DIV>
<DIV><FONT face="Times New Roman">C = PFC;</FONT></DIV>
<DIV>&nbsp;</DIV><FONT face="Times New Roman">
<DIV>H = (O+C)/</FONT><FONT size=2>2</FONT></FONT><FONT face=Verdana 
size=2><FONT face="Times New Roman">;</FONT></DIV><FONT face="Times New Roman">
<DIV>L = (O+C)/</FONT><FONT size=2>2</FONT></FONT><FONT face=Verdana 
size=2><FONT face="Times New Roman">;</FONT></DIV>
<DIV>&nbsp;</DIV><FONT face="Times New Roman">
<DIV>GraphXSpace = </FONT><FONT size=2>9</FONT></FONT><FONT face=Verdana 
size=2><FONT face="Times New Roman">;</FONT></DIV><FONT face="Times New Roman">
<DIV>Graph0Style = </FONT><FONT size=2>64</FONT></FONT><FONT face=Verdana 
size=2><FONT face="Times New Roman">;</FONT></DIV>
<DIV>&nbsp;</DIV><FONT face="Times New Roman">
<DIV>Graph0Color =</FONT><FONT size=2>1</FONT></FONT><FONT face=Verdana 
size=2><FONT face="Times New Roman">;</FONT></DIV>
<DIV><FONT face="Times New Roman">Graph0 = C;</FONT></DIV><FONT 
face="Times New Roman">
<DIV>&nbsp;</DIV>
<DIV>Thanks in advance for any reply.</FONT></FONT></DIV>
<DIV><FONT size=2>Dimitris Tsokakis</FONT></DIV></BODY></HTML>

------=_NextPart_001_0008_01C22D0D.D2611E00--

Attachment:
gif00396.gif

Attachment: Description: "Description: GIF image"