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

Re: Fw: Help with pattern detection code?



PureBytes Links

Trading Reference Links

Dimitris, 
I am amazed at the stuff you can do..Thanks very much for the trough
code as well

Just a couple of quick questions 

1. Is there any way to right and left extend the trend lines to infinity.
2. Your code is really complex for me to figure out. What changes
would I need to make to effect a trend line from the second most
recent peak. 

Thanks once again for being the wonderful resource you are.

Eugene


--- In amibroker@xxxx, "Dimitris Tsokakis" <TSOKAKIS@xxxx> wrote:
> Eugene,
> Let me suppose that you also need the trough trendline.
> According to your 
> "A trough is determined to be as follows
> ref(l,-2) > ref(l,-1) and L>ref(L,-1) and ref(l,-1)<ref(close,-3) "
> and similar to the
> "I want a trendline between the nearest peak to the previous peak
that is higher than it",
> you should ask
> "a trendline between the nearest trough to the previous trough that
is lower than it".
> These requirements are expressed in the following code for ind. builder
> 
> 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 data begin] 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