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) > ref(l,-1) and L>ref(L,-1) and
ref(l,-1)<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> </DIV>
<DIV><FONT size=2>X=Cum(1);<BR>condP=Ref(H,-1)>Ref(H,-2) AND Ref(H,-1)>H
AND Ref(H,-1)>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>ends, x, 1 ));<BR>startS = LastValue( ValueWhen( P AND H>ends, H,
1 ));<BR>dtS =endt-startt;<BR>aS = (endS-startS)/dtS;bS = endS;<BR>tH = aS
* ( x -endt ) + bS;
tH1=IIf(X>STARTT-3,tH,-1E10);<BR>Plot(tH1,"",5,1);// PEAK TO PEAK
TRENDLINE</FONT></DIV>
<DIV><FONT size=2>condT=Ref(L,-2) > Ref(L,-1) AND L>Ref(L,-1) AND
Ref(L,-1)<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<endsT, x, 1 ));<BR>startST = LastValue( ValueWhen( T AND L<endsT,L,
1 ));<BR>dtST =endtT-starttT;<BR>aST = (endST-startST)/dtST;bST =
endST;<BR>tHT = aST * ( x -endtT ) + bST;
tH1T=IIf(X>STARTTT-3,tHT,-1E10);<BR>Plot(tH1T,"",4,1);// TROUGH TO TROUGH
TRENDLINE<BR>GraphXSpace=2;</FONT></DIV>
<DIV> </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> </DIV>
<DIV><FONT size=2></FONT> </DIV></BODY></HTML>
------=_NextPart_001_0018_01C267BA.1D56C900--
Attachment:
gif00447.gif
Attachment:
Description: "Description: GIF image"
|