It's difficult in QP2, because you have to set the period for the peaks and troughs, and there isn't a good way to do that.
But you could try the scan below. It's for 61.8% retracements over various periods, and it can easily be changed to get 38.2% and 50% retracements.
This line looks for 61.8% retracements:
if (close(0)<=(1+percentage)*sixoneeight and close(0)>=(1-percentage)*sixoneeight) then
Change it to this, for example, for 38.2:
if (close(0)<=(1+percentage)*threeeighttwo and close(0)>=(1-percentage)*threeeighttwo) then
This is the whole scan, which is flawed because of the problem of finding peaks and troughs, but you could use it for a start.
// input="8080.lst"; output="retrace.lst"; float trendpeak,trendtrough,sixoneeight,threeeighttwo, fifty,twelve,eightyseven,period,percentage;
period:=8; // SET PERIOD FOR PEAK AND TROUGH OF TREND percentage:=.03; // SET PERCENTAGE FOR HOW NEAR // YOU WANT PRICE TO RETRACEMENT
trendpeak:=max(0,-(period-1),hi); trendtrough:=min(0,-(period-1),lo); sixoneeight:=(.382*(trendpeak-trendtrough))+trendtrough; threeeighttwo:=(.618*(trendpeak-trendtrough))+trendtrough; fifty:=(.5*(trendpeak-trendtrough))+trendtrough;
if (close(0)<=(1+percentage)*sixoneeight and close(0)>=(1-percentage)*sixoneeight) then println symbol:-6, "Period: ", period:-4, "Close: ", close(0):6:2, " ", "61.8%: ", sixoneeight:6:2, " ", "50%: ", fifty:6:2, " ", "38.2%: ", threeeighttwo:6:2, " ", "Trough: ", trendtrough:6:2, " ", "Peak: ", trendpeak:6:2; endif;
period:=16; // SET PERIOD FOR PEAK AND TROUGH OF TREND
trendpeak:=max(0,-(period-1),hi); trendtrough:=min(0,-(period-1),lo); sixoneeight:=(.382*(trendpeak-trendtrough))+trendtrough; threeeighttwo:=(.618*(trendpeak-trendtrough))+trendtrough; fifty:=(.5*(trendpeak-trendtrough))+trendtrough;
if (close(0)<=(1+percentage)*sixoneeight and close(0)>=(1-percentage)*sixoneeight) then println symbol:-6, "Period: ", period:-4, "Close: ", close(0):6:2, " ", "61.8%: ", sixoneeight:6:2, " ", "50%: ", fifty:6:2, " ", "38.2%: ", threeeighttwo:6:2, " ", "Trough: ", trendtrough:6:2, " ", "Peak: ", trendpeak:6:2; endif;
period:=32; // SET PERIOD FOR PEAK AND TROUGH OF TREND
trendpeak:=max(0,-(period-1),hi); trendtrough:=min(0,-(period-1),lo); sixoneeight:=(.382*(trendpeak-trendtrough))+trendtrough; threeeighttwo:=(.618*(trendpeak-trendtrough))+trendtrough; fifty:=(.5*(trendpeak-trendtrough))+trendtrough;
if (close(0)<=(1+percentage)*sixoneeight and close(0)>=(1-percentage)*sixoneeight) then println symbol:-6, "Period: ", period:-4, "Close: ", close(0):6:2, " ", "61.8%: ", sixoneeight:6:2, " ", "50%: ", fifty:6:2, " ", "38.2%: ", threeeighttwo:6:2, " ", "Trough: ", trendtrough:6:2, " ", "Peak: ", trendpeak:6:2; endif;
period:=64; // SET PERIOD FOR PEAK AND TROUGH OF TREND
trendpeak:=max(0,-(period-1),hi); trendtrough:=min(0,-(period-1),lo); sixoneeight:=(.382*(trendpeak-trendtrough))+trendtrough; threeeighttwo:=(.618*(trendpeak-trendtrough))+trendtrough; fifty:=(.5*(trendpeak-trendtrough))+trendtrough;
if (close(0)<=(1+percentage)*sixoneeight and close(0)>=(1-percentage)*sixoneeight) then println symbol:-6, "Period: ", period:-4, "Close: ", close(0):6:2, " ", "61.8%: ", sixoneeight:6:2, " ", "50%: ", fifty:6:2, " ", "38.2%: ", threeeighttwo:6:2, " ", "Trough: ", trendtrough:6:2, " ", "Peak: ", trendpeak:6:2; endif;
period:=128; // SET PERIOD FOR PEAK AND TROUGH OF TREND
trendpeak:=max(0,-(period-1),hi); trendtrough:=min(0,-(period-1),lo); sixoneeight:=(.382*(trendpeak-trendtrough))+trendtrough; threeeighttwo:=(.618*(trendpeak-trendtrough))+trendtrough; fifty:=(.5*(trendpeak-trendtrough))+trendtrough;
if (close(0)<=(1+percentage)*sixoneeight and close(0)>=(1-percentage)*sixoneeight) then println symbol:-6, "Period: ", period:-4, "Close: ", close(0):6:2, " ", "61.8%: ", sixoneeight:6:2, " ", "50%: ", fifty:6:2, " ", "38.2%: ", threeeighttwo:6:2, " ", "Trough: ", trendtrough:6:2, " ", "Peak: ", trendpeak:6:2; endif; |