Try this code:
{ Created: 10.30.2002
Revised: 10.30.2002
Revision: 1.0
}
Array: PFTab[500,500](0); {Table that holds High/Low for each P&F row in chart}
Input: BSize (1), {Box Size}
BNum (3); {Number of boxes for reversal}
Vars: Color (0), {Color of Plot}
Init(0), {Used to initialize array}
PFHigh (0), {High price for each row in PFTab}
PFLow (0), {Low price for each row in PFTab}
PFRow (0), {Row number for PFTab}
PFRev (0), {Value that creates a Reversal}
PlotValue (0), {Value of plot}
XOn (True); {Determines if column is 'X' or 'O'}
If Init = 0 Then Begin {Initialize first row in PFTab}
PFTab[0,0] = H;
PFTab[0,1] = L;
Init = 1; {Turn initialize off}
End;
{=============================== Create P&F Table =========================================}
If XOn = True Then Begin
{HiTest}
PFHigh = PFTab[PFRow,0] + BSize;
If H > PFTab[PFRow,0] Then {If today's high > PFTab High}
PFTab[PFRow,0] = H; {Set High value}
IF H < PFHigh Then Begin {If today's H is lower than PFHigh, then test for reversal}
{Hi2Test}
PFRev = PFTab[PFRow,0] - BSize * BNum; {Determine value of reversal}
If L < PFRev Then Begin {If this is a reversal}
XOn = False; {Switch to O column}
PFRow = PFRow + 1; {Move down one row in table}
PFTab[PFRow,0] = PFTab[PFRow - 1,0] - BSize; {Set High of O column}
PFTab[PFRow,1] = L; {Set initial Low of O column}
End;
End;
End
Else Begin
{LoTest}
PFLow = PFTab[PFRow,1] - BSize;
If L < PFTab[PFRow,1] Then {If current low < PFTabLow}
PFTab[PFRow,1] = L; {Set Low value}
If L > PFLow Then Begin
{Lo2Test}
PFRev = PFTab[PFRow,1] + (BSize * BNum); {Determine reversal}
If H > PFRev Then Begin {If this is a reversal}
XOn = True; {Switch to X column}
PFRow = PFRow + 1; {Move down one row in table}
PFTab[PFRow,0] = H; {Set initialHigh of X column}
PFTab[PFRow,1] = PFTab[PFRow - 1,1] + BSize; {Set Low of X column}
End;
End;
End;
{================ SIMPLE ShowMe Indicator =================================}
If PFRow > 2 Then Begin {Make sure you don't reference data beyond array!}
If XOn = True Then Begin
If H > PFTab[PFRow-2,0] Then {If H > Last high - generate buy}
Color = 2
Else
Color = 4;
PlotValue = H+BSize;
End Else Begin
If L < PFTAb[PFRow-2,1] Then {If L < Last low - generate sell}
Color = 6
Else
Color = 8;
PlotValue = L-BSize;
End;
End;
Plot1(PlotValue, "P&F",Color); {Plot the symbol of choice}