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

Fw: Help with pattern detection code?



PureBytes Links

Trading Reference Links

X=Cum(1);
condP=Ref(H,-1)>Ref(H,-2) AND Ref(H,-1)>H AND Ref(H,-1)>Ref(C,-2);
P=Ref(CONDP,1)*(X!=LastValue(X));// PEAK CONDITION
endt= LastValue(ValueWhen( P, x, 1 ));
endS = LastValue(ValueWhen( P, H, 1 ) );
startt=LastValue(ValueWhen( P AND H>ends, x, 1 ));
startS = LastValue( ValueWhen( P AND H>ends, H, 1 ));
dtS =endt-startt;
aS = (endS-startS)/dtS;bS = endS;
tH = aS * ( x -endt ) + bS; tH1=IIf(X>STARTT-3,tH,-1E10);
Plot(tH1,"",5,1);// PEAK TO PEAK TRENDLINE
condT=Ref(L,-2) > Ref(L,-1) AND L>Ref(L,-1) AND Ref(L,-1)<Ref(Close,-3);
T=Ref(CondT,1)*(X!=LastValue(X));// TROUGH CONDITION
Plot(C,"",4*P+3*T+1,64);
endtT= LastValue(ValueWhen( T, x, 1 ));
endST = LastValue(ValueWhen( T, L, 1 ) );
starttT=LastValue(ValueWhen( T AND L<endsT, x, 1 ));
startST = LastValue( ValueWhen( T AND L<endsT, L, 1 ));
dtST =endtT-starttT;
aST = (endST-startST)/dtST;bST = endST;
tHT = aST * ( x -endtT ) + bST; tH1T=IIf(X>STARTTT-3,tHT,-1E10);
Plot(tH1T,"",4,1);// TROUGH TO TROUGH TRENDLINE
GraphXSpace=2;

Notes:
1. If you do not want to paint the peak/trough candles, replace Plot(C,"",4*P+3*T+1,64); with Plot(C,"",1,64);
2. In many cases the last trough is the lowest trough and the trough trendline goes back to the first bar.
3. Some candles, like X in the att. gif, are simultaneously "peaks" and "troughs", according to your definitions.
3. The formula looks into the future. To be more specific it looks into +1 bar.
4. In the att. gif you see for AMZN we go back 12 peaks until we find a higher one. 
For QQQ, the last [09/24] trough is the lowest since Jan 2000 [when my databegin] and the trough trendline goes to 0.
5. The same logic may be used for trendlines linking any "conditional" points.
I hope you have a clear picture now and try your AFL research better.
Dimitris Tsokakis



------=_NextPart_001_0018_01C267BA.1D56C900
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>Eugene,<BR>Let me suppose that you also need the trough 
trendline.<BR>According to your <BR>"A trough is determined to be as 
follows<BR>ref(l,-2) &gt; ref(l,-1) and L&gt;ref(L,-1) and 
ref(l,-1)&lt;ref(close,-3) "<BR>and similar to the<BR>"I want a trendline 
between the nearest peak to the previous peak that is higher than it",<BR>you 
should ask<BR>"a trendline between the nearest trough to the previous trough 
that is lower than it".<BR>These requirements are expressed in the following 
code for ind. builder</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=2>X=Cum(1);<BR>condP=Ref(H,-1)&gt;Ref(H,-2) AND Ref(H,-1)&gt;H 
AND Ref(H,-1)&gt;Ref(C,-2);<BR>P=Ref(CONDP,1)*(X!=LastValue(X));// PEAK 
CONDITION</FONT></DIV>
<DIV><FONT size=2>endt= LastValue(ValueWhen( P, x, 1 ));<BR>endS = 
LastValue(ValueWhen( P, H, 1 ) );<BR>startt=LastValue(ValueWhen( P AND 
H&gt;ends, x, 1 ));<BR>startS = LastValue( ValueWhen( P AND H&gt;ends, H, 
1&nbsp; ));<BR>dtS =endt-startt;<BR>aS = (endS-startS)/dtS;bS = endS;<BR>tH = aS 
* ( x&nbsp; -endt ) + bS; 
tH1=IIf(X&gt;STARTT-3,tH,-1E10);<BR>Plot(tH1,"",5,1);// PEAK TO PEAK 
TRENDLINE</FONT></DIV>
<DIV><FONT size=2>condT=Ref(L,-2) &gt; Ref(L,-1) AND L&gt;Ref(L,-1) AND 
Ref(L,-1)&lt;Ref(Close,-3);<BR>T=Ref(CondT,1)*(X!=LastValue(X));// TROUGH 
CONDITION<BR>Plot(C,"",4*P+3*T+1,64);</FONT></DIV>
<DIV><FONT size=2>endtT= LastValue(ValueWhen( T, x, 1 ));<BR>endST = 
LastValue(ValueWhen( T, L, 1 ) );<BR>starttT=LastValue(ValueWhen( T AND 
L&lt;endsT, x, 1 ));<BR>startST = LastValue( ValueWhen( T AND L&lt;endsT,L, 
1&nbsp; ));<BR>dtST =endtT-starttT;<BR>aST = (endST-startST)/dtST;bST = 
endST;<BR>tHT = aST * ( x&nbsp; -endtT ) + bST; 
tH1T=IIf(X&gt;STARTTT-3,tHT,-1E10);<BR>Plot(tH1T,"",4,1);// TROUGH TO TROUGH 
TRENDLINE<BR>GraphXSpace=2;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=2>Notes:<BR>1. If you do not want to paint the peak/trough 
candles, replace Plot(C,"",4*P+3*T+1,64); with Plot(C,"",1,64);<BR>2. In many 
cases the last trough is the lowest trough and the trough trendline goes back to 
the first bar.<BR>3. Some candles, like X in the att. gif, are simultaneously 
"peaks" and "troughs", according to your definitions.<BR></FONT><FONT size=2>3. 
The formula looks into the future. To be more specific it looks into +1 
bar.</FONT></DIV>
<DIV><FONT size=2>4. In the att. gif you see for AMZN we go back 12 peaksuntil 
we find a higher one. <BR>For QQQ, the last [09/24] trough is the lowest since 
Jan 2000 [when my data begin] and the trough trendline goes to 0.</FONT></DIV>
<DIV><FONT size=2>5. The same logic may be used for trendlines linking any 
"conditional" points.</FONT></DIV>
<DIV><FONT size=2>I hope you have a clear picture now and try your AFL research 
better.</FONT></DIV>
<DIV><FONT size=2>Dimitris Tsokakis</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_001_0018_01C267BA.1D56C900--

Attachment:
gif00447.gif

Attachment: Description: "Description: GIF image"