[R-SIG-Finance] Point and Figure Charting
veepsirtt
veepsirtt at gmail.com
Mon Oct 17 18:52:33 CEST 2011
I searched the web and found the following information
http://www.trade2win.com/boards/techies-corner/69572-building-text-based-point-figure-charts-matlab-r.html
http://www.trade2win.com/boards/techies-corner/69572-building-text-based-point-figure-charts-matlab-r.html
---------------------------------------------------------------------------------------------------------------
*P&F Algorithm*
---------------------------------------------------------------------------------------------------------------
INPUTS
Accept box_size, reversal_boxes inputs
Accept Date range in date_array and prices in H_array, L_array.
INITIAL CALCULATIONS
Calculate max and min of H_array and L_array to calculate number of Y-axis
intervals
max_range = round(Max(H_array) * 1.1)
min_range = round(Min(L_array) * 0.9)
Yaxis_array_size = (max_range – min_range) / box_size
Caclulate Yaxis_array
Yaxis_array(1) = round(min_range)
For n = 2 to Yaxis_array_size
Yaxis_array(n) = Yaxis_array(n-1)+box_size
Next n
PLOT P&F
Plot initial value:
for n=1 to Yaxis_array_size
If (H_array(1) > Yaxis_array(n) AND H_array(1) < Yaxis_array(n-1) THEN
PF_array(1,n) = 1
Else n = n+1
Construct PF_array with entire P&F plot
For iDay = 2 to no_days
current_column = 1
Reversal_Date(current_column) = iDay
If mod(current_column,2) = 1
If H_array(iDay) > n + box_size
Do
n = n + 1
PF_array(current_column, n) = 1
Loop Until (H_array(iDay) < n + box_size
iDay = iDay + 1
Else If L_array(iDay) < n – reversal_boxes * box_size
ReDim PF array to add new column (Preserve previous data)
Reversal_Date(current_column) = iDay
current_column = current_column+1
Do
n = n – 1
PF_array(current_column, n) = 0
Loop Until (L_array(iDay) > n – box_size
iDay = iDay + 1
Else
iDay = iDay + 1
End If
Else
If L_array(iDay) < n - box_size
Do
n = n - 1
PF_array(current_column, n) = 0
Loop Until (L_array(iDay) > n - box_size
iDay = iDay + 1
Else If H_array(iDay) > n + reversal_boxes * box_size
ReDim PF array to add new column (Preserve previous data)
Reversal_Date(current_column) = iDay
current_column = current_column+1
Do
n = n + 1
PF_array(current_column, n) = 1
Loop Until (H_array(iDay) < n + box_size
iDay = iDay + 1
Else
iDay = iDay + 1
End If
End If
End For
Plot PF_array on chart
Plot the dates on which the first new column entry was made below that
column
------------------------------------------------------------------------------------------------------------------------
*Here is the R
code*
------------------------------------------------------------------------------------------------------------------------
##make sure you have data in data.frame ticker [date price] and it is wit
rising dates (newest obs last)
##best run from here
## log scale with 2pct 3box rev
pnf=data.frame()
pnf[1,1]=ticker[1,2]*1.02^50
for (i in 2:100) pnf[i,1]=pnf[i-1,1]/1.02
##counters
s=2
start=pnf[51,1]
##first column
for(i in 2:length(ticker[,1])){
if (ticker[i,2]>=pnf[48,1]|ticker[i,2]<=pnf[54,1]){
if (ticker[i,2]>=pnf[48,1]) {
d=1
pnf[(51-3):50,s]=d
pos=48
break} else {
d=-1
pnf[52:(51+3),s]=d
pos=54
break}}
}
## continuation
for(j in (i+1):length(ticker[,1])){if (d>0){
if (ticker[j,2]>=pnf[(pos-1),1]) {while(ticker[j,2]>=pnf[(pos-1),1]
){pnf[(pos-1),s]=d
pos=pos-1}
}else{if (ticker[j,2]<=pnf[(pos+3),1]) {s=s+1
d=d*-1
{while(ticker[j,2]<=pnf[(pos+1),1]){pnf[(pos+1),s]=d
pos=pos+1}
}
}
}
}else{
if (ticker[j,2]<=pnf[(pos+1),1]) {while(ticker[j,2]<=pnf[(pos+1),1]
){pnf[(pos+1),s]=d
pos=pos+1}
}else{if (ticker[j,2]>=pnf[(pos-3),1]) {s=s+1
d=d*-1
{while(ticker[j,2]>=pnf[(pos-1),1]){pnf[(pos-1),s]=d
pos=pos-1}
}
}
}
}
}
final=replace(pnf[,],pnf[,]==-1,"O")
final=replace(final[,],final[,]==1,"X")
final[is.na(final)]="."
final
Try this ...
Thanks
veepsirtt
--
View this message in context: http://r.789695.n4.nabble.com/Point-and-Figure-Charting-tp3261384p3912644.html
Sent from the Rmetrics mailing list archive at Nabble.com.
More information about the R-SIG-Finance
mailing list