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

Re: Fw: Help with pattern detection code?



PureBytes Links

Trading Reference Links

Eugene,
1. the lines
tH1=IIf(X>STARTT-3,tH,-1E10);
tH1T=IIf(X>STARTTT-3,tHT,-1E10);
calibrate the left extension 3 bars before the starting candle.
If you write
tH1=IIf(X>STARTT-30,tH,-1E10);
tH1T=IIf(X>STARTTT-30,tHT,-1E10);
you will extend the lines 30 bars before the start and, finaly with
tH1=tH;
tH1T=tHT;
you will have the whole line [although it is not convenient...]

2. 
The

X=Cum(1);
D=1;// CHANGE 1 WITH 2, 3 etc
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));
endt= LastValue(ValueWhen( P, x, D ));
endS = LastValue(ValueWhen( P, H, D ) );
startt=LastValue(ValueWhen( P AND H>ends AND X<ENDT, x, 1 ));
startS = LastValue( ValueWhen( P AND H>ends AND X<ENDT, 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);
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));
Plot(C,"",4*P+3*T+1,64);
endtT= LastValue(ValueWhen( T, x, D ));
endST = LastValue(ValueWhen( T, L, D ) );
starttT=LastValue(ValueWhen( T AND L<endsT AND X<ENDTT, x, 1 ));
startST = LastValue( ValueWhen( T AND L<endsT AND X<ENDTT, 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);
GraphXSpace=2;

for D=1, D=2, D=3 will end the trendlines to the 1st, 2nd, 3rd 
peak/trough.
DT
--- In amibroker@xxxx, "Eugene" <johngalt1234@xxxx> wrote:
> 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