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

Re: Andrews Pitchfork



PureBytes Links

Trading Reference Links

input: {proj1(0), proj2(0), proj3(0), proj4(0), diff(10), } Median(false),
TL_Thick(1);
{ ======================================
This is my implementation of some aspects of Andrews Pitchforks. You are
welcome to use this code freely.  You may redistribute it provided you
include this comment block, plus a description of any changes you make.

If you extend it, or adapt it to other uses, I'd appreciate a look at what
you've done.  Thanks.

     Gregory Wood
     SwissFranc@xxxxxxxxxxxxxxxx
  
12/18/96 v1.0 - Initial distribution
01/08/96 v1.1 - Added median lines
01/15/96 v1.2 - Added TL_Thick, user-customizable colors (see "SET COLORS
HERE")
01/16/96 v1.3 - Removed projections to make room for up to 7 pitchforks
========================================}

{ 
SETUP

Set Plot1 and Plot2 to be large points.
Note that the trendlines use the default trendline settings 

USAGE

Use the text tool to label swing high/lows with "A", "B" and "C", then
refresh the indicator (clicking "Status" twice causes the indicator to
recalculate).  Be sure to put the label above the bar's high for a swing
high, and below the low for a swing low.  

You can display other groups of points by using labels "Ax", "Bx" and "Cx",
where 'x' is 1, 2, or 3, e.g. "A3", "B3", "C3".

Note that you can use the pointer tool to move the points anytime. Then to
view the new Pitchfork, refresh the indicator.

Use the Proj values to place a dot at a time expansion.  Try values like
.618, 1.0, 1.618 etc.  Then use Diff to control how near the dot needs to
be to the close for it to be seen. (This keeps the chart from shrinking.)

Use Median to add median lines.

Set MyColor (below) to be the colors for each Pitchfork
}

if currentbar = 1 then begin { initialize control arrays }
   array:abc[3]("");  { The basic point labels }
      abc[0] = "A";
      abc[1] = "B";
      abc[2] = "C";
   array:nums[7]("");  { The way to distinguish one series of points from
another, A-B-C, A1-B1-C1, etc }
      nums[0] = "";
      nums[1] = "1";
      nums[2] = "2";
      nums[3] = "3";
      nums[4] = "4";
      nums[5] = "5";
      nums[6] = "6";
      var: inums(7);
{   array: proj[5](0); { fibonacci extensions along a level line - "0"
means "unused" }
      proj[0] = proj1;
      proj[1] = proj2;
      proj[2] = proj3;
      proj[3] = proj4;
      var: iproj(4); 
}
   array: MyColor[7](0);
      MyColor[0] = tool_red;        { <=========== SET COLORS HERE }
	MyColor[1] = tool_blue;
	MyColor[2] = tool_yellow;
	MyColor[3] = tool_cyan;
	MyColor[4] = tool_green;
	MyColor[5] = tool_white;
	MyColor[6] = tool_darkyellow;
end;

array:dd[3,7](0),tt[3,7](0),vv[3,7](0),bb[3,7](0),hh[3,7](0);
array:fb[7,4](0),fv[7,4](0); {fb[nums,proj], fv[nums,proj]}
var: tft(0), fdd(0), fvv(0), ptt(0), pdd(0), pvv(0), fbb(0), pbb(0), pvv2(0);
var: ii(0), jj(0), mm(0);
var: handl(0), handlA(0), handlB(0), handlC(0), handlB1(0), handlC1(0),
handlB2(0), handlC2(0);
var: ss("");
var: y1(0), y2(0);

if currentbar = 1 then begin { examine all the text strings and save some
info about the ones we recognize }
   handl = text_getfirst(2);
   while handl > 0 begin
      ss = text_getstring(handl);
      for ii = 0 to inums - 1 begin
         for jj = 0 to 2 begin { look for well-formed strings }
            if ss = abc[jj] + nums[ii] then begin { save the item's date,
time, value and handle }
               tt[jj,ii] = text_gettime(handl);
               dd[jj,ii] = text_getdate(handl);
               vv[jj,ii] = text_getvalue(handl);
               hh[jj,ii] = handl;
            end;
         end;
      end;
      handl = text_getnext(handl,2); { IMPORTANT -- infinite loop if this
is missing!  }
   end;
end;

for ii = 0 to inums - 1 begin { check each series... }
   for jj = 0 to 2 begin { check each point }
      if time = tt[jj,ii] and date = dd[jj,ii] then begin { we've found a
selected point }
         bb[jj,ii] = currentbar; { remember where we found it }
         if vv[jj,ii] > c then begin { move the label above the bar and
center it }
            vv[jj,ii] = h;

Text_SetLocation(hh[jj,ii],text_GetDate(hh[jj,ii]),text_GetTime(hh[jj,ii]),h);
            Text_SetStyle(hh[jj,ii],2,1);
         end else begin { move the label below the bar and center it }
            vv[jj,ii] = l;

Text_SetLocation(hh[jj,ii],text_GetDate(hh[jj,ii]),text_GetTime(hh[jj,ii]),l);
            Text_SetStyle(hh[jj,ii],2,0);
         end;
         plot1(vv[jj,ii],"Selection"); { show the user which point we used
for the calculations }
         if jj = 2 then begin { we're at the third point, generally the Cx }
		handl = TL_New(dd[0,ii],tt[0,ii],vv[0,ii],dd[1,ii],tt[1,ii],vv[1,ii]);
            TL_SetExtLeft(handl,false);
            TL_SetExtRight(handl,false);
		TL_SetColor(handl,MyColor[ii]);
		handl = TL_New(dd[0,ii],tt[0,ii],vv[0,ii],dd[2,ii],tt[2,ii],vv[2,ii]);
            TL_SetExtLeft(handl,false);
            TL_SetExtRight(handl,false);
		TL_SetColor(handl,MyColor[ii]);

            fbb = bb[1,ii] / 2 + bb[2,ii] / 2;
            fvv = vv[1,ii] / 2 + vv[2,ii] / 2;
            pvv = TLValue(vv[0,ii],bb[0,ii],fvv,fbb,currentbar);
            handlA = TL_New(dd[0,ii],tt[0,ii],vv[0,ii],date,time,pvv);
            TL_SetExtRight(handlA,TRUE);
		TL_SetColor(handlA,MyColor[ii]);
		TL_SetSize(handlA, TL_Thick);

            { show the related trident channel }
            pvv =
TLValue(vv[1,ii],bb[1,ii],fvv+vv[1,ii]-vv[0,ii],fbb+bb[1,ii]-bb[0,ii],curren
tbar);
            handlB = TL_New(dd[1,ii],tt[1,ii],vv[1,ii],date,time,pvv);
            TL_SetExtRight(handlB,TRUE);
		TL_SetColor(handlB, MyColor[ii]);
		TL_SetSize(handlB, TL_Thick);
		if Median then begin { save for later }
			handlB1 = TL_New(dd[1,ii],tt[1,ii],vv[1,ii],date,time,pvv);
	            TL_SetExtRight(handlB1,TRUE);
			TL_SetColor(handlB1, MyColor[ii]);
			TL_SetSize(handlB1, TL_Thick);
			handlB2 = TL_New(dd[1,ii],tt[1,ii],vv[1,ii],date,time,pvv);
	            TL_SetExtRight(handlB2,TRUE);
			TL_SetColor(handlB2, MyColor[ii]);
			TL_SetSize(handlB2, TL_Thick);
		end;
            pvv =
TLValue(vv[0,ii]-(fvv-vv[2,ii]),bb[0,ii]+(bb[2,ii]-fbb),vv[2,ii],bb[2,ii],bb
[1,ii]);
            handlC = TL_New(dd[1,ii],tt[1,ii],pvv,date,time,vv[2,ii]);
            TL_SetExtRight(handlC,TRUE);
		TL_SetColor(handlC, MyColor[ii]);
		TL_SetSize(handlC, TL_Thick);
		if Median then begin { save for later }
			handlC1 = TL_New(dd[1,ii],tt[1,ii],pvv,date,time,vv[2,ii]);
	            TL_SetExtRight(handlC1,TRUE);
			TL_SetColor(handlC1, MyColor[ii]);
			TL_SetSize(handlC1, TL_Thick);
			handlC2 = TL_New(dd[1,ii],tt[1,ii],pvv,date,time,vv[2,ii]);
	            TL_SetExtRight(handlC2,TRUE);
			TL_SetColor(handlC2, MyColor[ii]);
			TL_SetSize(handlC2, TL_Thick);
		end;

		if Median then begin { sorry these are hard-coded... you know what they
say about quick + dirty! }
			{ show the median lines }
			y1 = TL_GetValue(handlB, dd[1,ii], tt[1,ii]);
			y2 = TL_GetValue(handlA, dd[1,ii], tt[1,ii]);
			TL_SetBegin(handlB1, dd[1,ii], tt[1,ii], (y1 + y2) / 2);
			y1 = TL_GetValue(handlB, dd[2,ii], tt[2,ii]);
			y2 = TL_GetValue(handlA, dd[2,ii], tt[2,ii]);
			TL_SetEnd(handlB1, dd[2,ii], tt[2,ii], (y1 + y2) / 2);

			y1 = TL_GetValue(handlB, dd[1,ii], tt[1,ii]);
			y2 = TL_GetValue(handlA, dd[1,ii], tt[1,ii]);
			TL_SetBegin(handlB2, dd[1,ii], tt[1,ii], y1 + y1- (y1 + y2) / 2);
			y1 = TL_GetValue(handlB, dd[2,ii], tt[2,ii]);
			y2 = TL_GetValue(handlA, dd[2,ii], tt[2,ii]);
			TL_SetEnd(handlB2, dd[2,ii], tt[2,ii], y1 + y1 - (y1 + y2) / 2);

			y1 = TL_GetValue(handlC, dd[1,ii], tt[1,ii]);
			y2 = TL_GetValue(handlA, dd[1,ii], tt[1,ii]);
			TL_SetBegin(handlC1, dd[1,ii], tt[1,ii], (y1 + y2) / 2);
			y1 = TL_GetValue(handlC, dd[2,ii], tt[2,ii]);
			y2 = TL_GetValue(handlA, dd[2,ii], tt[2,ii]);
			TL_SetEnd(handlC1, dd[2,ii], tt[2,ii], (y1 + y2) / 2);

			y1 = TL_GetValue(handlC, dd[1,ii], tt[1,ii]);
			y2 = TL_GetValue(handlA, dd[1,ii], tt[1,ii]);
			TL_SetBegin(handlC2, dd[1,ii], tt[1,ii], y1 + y1 - (y1 + y2) / 2);
			y1 = TL_GetValue(handlC, dd[2,ii], tt[2,ii]);
			y2 = TL_GetValue(handlA, dd[2,ii], tt[2,ii]);
			TL_SetEnd(handlC2, dd[2,ii], tt[2,ii], y1 + y1 - (y1 + y2) / 2);
		end;

{            for mm = 0 to iproj-1 begin { for each projection }
               if proj[mm] > 0 then begin { calculate the fibonacci
price/time points }
                  fb[ii,mm] = intportion(fbb + (fbb - bb[0,ii]) * proj[mm]);
                  fv[ii,mm] = TLValue(vv[0,ii],bb[0,ii],fvv,fbb,fb[ii,mm]);
               end;
            end;
}
         end;
      end;
   end;
end;   

{ find out if this bar needs to show a time/price point }
{
for ii = 0 to inums - 1 begin
   for mm = 0 to iproj - 1 begin
      if fb[ii,mm] = currentbar then begin
         if c + diff > fv[ii,mm] and c - diff < fv[ii,mm] then
            plot2(fv[ii,mm],"Projection");
      end;
   end;
end;
}