PureBytes Links
Trading Reference Links
|
I have put together straight afl (no loops) to remove the lower TPs for
consecutive tops/bottoms. Code below and picture to match previous is
attached, once only this time hopefully. This only removes a single
occurrence so would need to have it run ?? Times to be sure all are removed.
My preferred method would be to add in the necessary bots/tops rather than
remove them.
The circles blue and red remain from the original chart to show the
differences.
Plot(C,"",colorBlack,styleBar);
//Assign H & L for zero volatility Bars as = Last Bar with H not= L
H = IIf( V==0 AND GroupID()!= 1, ValueWhen( V > 0, H ), H );
L = IIf( V==0 AND GroupID()!= 1, ValueWhen( V > 0, L ), L );
SetBarsRequired(10000,10000);
//Set the intitial values for looping
MajorTop = Null;
MajorBottom = Null;
LastMajorTop = 0;
MajorResLevel = Null;
MajorSupLevel = Null;
MajorBotBar = Null;
MajorBotBar = Null;
MediumTop = Null;
MediumBottom = Null;
LastMediumTop = 0;
MediumResLevel = Null;
MediumSupLevel = Null;
MediumBotBar = Null;
MediumBotBar = Null;
//look backward & forward bars for trends
MajorM = 10; //Param("M",10,5,20,1);
MajorN = 50; //Param("N",50,30,80,5);
MediumM = Param("M",5,1,20,1);
MediumN = Param("N",5,1,20,1);
//DEFINE THE BACKWARD & FORWARD REQUIREMENTS
MajorHigh =
H == Ref( HHV( H, ( 2 * MajorM ) + 1 ), MajorM ) AND
H > Ref( HHV( H, MajorN ), -MajorM-1 ) AND
H > Ref( HHV( H, MajorN ), MajorM + MajorN );
MajorLow =
L == Ref( LLV( L, ( 2 * MajorM ) + 1 ), MajorM ) AND
L < Ref( LLV( L, MajorN ), - MajorM-1 ) AND
L < Ref( LLV( L, MajorN ), MajorM + MajorN );
MediumHigh =
H == Ref( HHV( H, ( 2 * MediumM ) + 1 ), MediumM ) AND
H > Ref( HHV( H, MediumN ), -MediumM-1 ) AND
H > Ref( HHV( H, MediumN ), MediumM + MediumN );
MediumLow =
L == Ref( LLV( L, ( 2 * MediumM ) + 1 ), MediumM ) AND
L < Ref( LLV( L, MediumN ), - MediumM-1 ) AND
L < Ref( LLV( L, MediumN ), MediumM + MediumN );
//MAJOR TRENDS
//Loop to find MajorTops and MajorBottoms, plus price values of MajorTops &
MajorBottoms
for( i=1; i<BarCount-1; i++ )
{
if( MajorHigh[i] && LastMajorTop[i-1]==0 )
{
MajorTop[i] = 1;
MajorResLevel[i] = H[i];
LastMajorTop[i] = 1;
MajorTopBar[i] = i;
MajorSupLevel[i] = MajorSupLevel[i-1];
}
else
{
if( MajorHigh[i] && LastMajorTop[i-1]==1 && H[i]>MajorResLevel[i-1] )
{
MajorTop[i] = 1;
MajorResLevel[i] = H[i];
LastMajorTop[i] = 1;
MajorTopBar[i] = i;
MajorSupLevel[i] = MajorSupLevel[i-1];
}
else
{
if( MajorLow[i] && LastMajorTop[i-1]==1 )
{
MajorBottom[i] = 1;
MajorSupLevel[i] = L[i];
LastMajorTop[i] = 0;
MajorBotBar[i] = i;
MajorResLevel[i] = MajorResLevel[i-1];
}
else
{
if( MajorLow[i] && LastMajorTop[i-1]==0 && L[i]<MajorSupLevel[i-1] )
{
MajorBottom[i] = 1;
MajorSupLevel[i] = L[i];
LastMajorTop[i] = 0;
MajorBotBar[i] = i;
MajorResLevel[i] = MajorResLevel[i-1];
}
else
{
MajorSupLevel[i] = MajorSupLevel[i-1];
MajorResLevel[i] = MajorResLevel[i-1];
LastMajorTop[i] = LastMajorTop[i-1];
}
}
}
}
}
//Define last and next TP and if consecutive
MajorTopBarFwd = ValueWhen( MajorTop, BarIndex(), -1 );
MajorTopBarBak = ValueWhen( MajorTop, BarIndex(), 1 );
MajorBottomBarFwd = ValueWhen( MajorBottom, BarIndex(), -1 );
MajorBottomBarBak = ValueWhen( MajorBottom, BarIndex(), 1 );
MajorTopLast = Ref( MajorTopBarBak, -1 ) >= Ref( MajorBottomBarBak, -1 );
MajorTopNext = Ref( MajorTopBarFwd, 0 ) <= Ref( MajorBottomBarFwd, 0 );
MajorBottomLast = Ref( MajorTopBarBak, -1 ) <= Ref( MajorBottomBarBak, -1 );
MajorBottomNext = Ref( MajorTopBarFwd, 0 ) >= Ref( MajorBottomBarFwd, 0 );
//Assign values to conditions
MajorRes = ValueWhen( MajorTop, MajorResLevel, 1 );
MajorSup = ValueWhen( MajorBottom, MajorSupLevel, 1 );
MajorResFwd = ValueWhen( MajorTop, MajorResLevel, 0 );
MajorSupFwd = ValueWhen( MajorBottom, MajorSupLevel, 0 );
MajorTop = IIf( MajorTop AND MajorTopNext AND MajorResFwd > MajorRes, Null,
MajorTop );
MajorBottom = IIf( MajorBottom AND MajorBottomNext AND MajorSupFwd <
MajorSup , Null, MajorBottom );
MajorTop = MajorTop;
MajorBottom = MajorBottom;
MajorResLevel = ValueWhen( MajorTop, MajorResLevel, 1 );
MajorSupLevel = ValueWhen( MajorBottom, MajorSupLevel, 1 );
PlotShapes( MajorBottom * shapeStar, colorGreen, 0, L, -20 );
PlotShapes( MajorTop * shapeStar, colorGreen, 0, H, 20 );
Plot( MajorSupLevel, "MajorSupTP Level", colorGreen, styleNoLine|styleDots
);
Plot( MajorResLevel, "MajorResTP Level", colorGreen, styleNoLine|styleDots
);
GraphXSpace = 5;
Cheers,
Graham
http://groups.msn.com/asxsharetrading
http://groups.msn.com/fmsaustralia
-----Original Message-----
From: Graham [mailto:gkavanagh@xxxxxxxxxxxxx]
Sent: Saturday, 20 December 2003 6:41 AM
To: amibroker@xxxxxxxxxxxxxxx
Subject: RE: [amibroker] Finding points between points
I will attach a png file of an example with consecutive top and bottom TPs.
Tops are circle blue and bottoms red
And in case the code is lost somewhere will add it here again
//BASE CALCULATION OF TURN POINTS Plot(C,"",colorBlack,styleBar); //Assign H
& L for zero volatility Bars as = Last Bar with H not= L H = IIf( V==0 AND
GroupID()!= 1, ValueWhen( V > 0, H ), H ); L = IIf( V==0 AND GroupID()!= 1,
ValueWhen( V > 0, L ), L ); SetBarsRequired(10000,10000);
//Set the intitial values for looping
MajorTop = Null;
MajorBottom = Null;
LastMajorTop = 0;
MajorResLevel = Null;
MajorSupLevel = Null;
MajorBotBar = Null;
MajorBotBar = Null;
//look backward & forward bars for trends
MajorM = 10; //Param("M",10,5,20,1);
MajorN = 50; //Param("N",50,30,80,5);
//DEFINE THE BACKWARD & FORWARD REQUIREMENTS
MajorHigh =
H == Ref( HHV( H, ( 2 * MajorM ) + 1 ), MajorM ) AND
H > Ref( HHV( H, MajorN ), -MajorM-1 ) AND
H > Ref( HHV( H, MajorN ), MajorM + MajorN );
MajorLow =
L == Ref( LLV( L, ( 2 * MajorM ) + 1 ), MajorM ) AND
L < Ref( LLV( L, MajorN ), - MajorM-1 ) AND
L < Ref( LLV( L, MajorN ), MajorM + MajorN );
//Loop to find MajorTops and MajorBottoms, plus price values of MajorTops &
MajorBottoms for( i=1; i<BarCount-1; i++ ) { if( MajorHigh[i] &&
LastMajorTop[i-1]==0 ) {
MajorTop[i] = 1;
MajorResLevel[i] = H[i];
LastMajorTop[i] = 1;
MajorTopBar[i] = i;
MajorSupLevel[i] = MajorSupLevel[i-1];
}
else
{
if( MajorHigh[i] && LastMajorTop[i-1]==1 && H[i]>MajorResLevel[i-1] )
{
MajorTop[i] = 1;
MajorResLevel[i] = H[i];
LastMajorTop[i] = 1;
MajorTopBar[i] = i;
MajorSupLevel[i] = MajorSupLevel[i-1];
}
else
{
if( MajorLow[i] && LastMajorTop[i-1]==1 )
{
MajorBottom[i] = 1;
MajorSupLevel[i] = L[i];
LastMajorTop[i] = 0;
MajorBotBar[i] = i;
MajorResLevel[i] = MajorResLevel[i-1];
}
else
{
if( MajorLow[i] && LastMajorTop[i-1]==0 && L[i]<MajorSupLevel[i-1] )
{
MajorBottom[i] = 1;
MajorSupLevel[i] = L[i];
LastMajorTop[i] = 0;
MajorBotBar[i] = i;
MajorResLevel[i] = MajorResLevel[i-1];
}
else
{
MajorSupLevel[i] = MajorSupLevel[i-1];
MajorResLevel[i] = MajorResLevel[i-1];
LastMajorTop[i] = LastMajorTop[i-1];
}
}
}
}
}
PlotShapes( MajorBottom * shapeStar, colorGreen, 0, L, -20 ); PlotShapes(
MajorTop * shapeStar, colorGreen, 0, H, 20 );
Plot( MajorSupLevel, "MajorSupTP Level", colorGreen, styleNoLine|styleDots
); Plot( MajorResLevel, "MajorResTP Level", colorGreen,
styleNoLine|styleDots );
GraphXSpace = 5;
Cheers,
Graham
http://groups.msn.com/asxsharetrading
http://groups.msn.com/fmsaustralia << File: TopsBots.PNG >> << File:
TopsBots.PNG >>
Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Yahoo! Groups Links
To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|