TD sell seq countDn

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
bill
Posts: 9
Joined: 20 Nov 2006

TD sell seq countDn

Postby bill » 18 May 2009

this is a indicator call TD sell seq countDn

Code: Select all

[LegacyColorValue = true];



Inputs:
{*******SETUP PARAMETERS****}
Setup(9), {Number of Bars needed for Setup}
Lookback(4), {Reference bar of Setup}
Su_Price(Close), {Price used for comparison during Setup}
SetUp_EQ(False), {If true, comparison above during Setup uses <= and >=
If false, comparrison uses < and >.}
SS_Pric1(Low), {"Price" used to collect Sell Setup Low "Price", will be compared
to during countdown for possible recycle}
SS_Pric2(High), {"Price" used during Countdown to compare to Low Price
formed during SetUp for recycle}

{*******INTERSECTION PARAMETERS****}
Int_On(false), {If true, requires intersection
if false, no intersection required}
I_Signal(8), {First Bar of Setup to look for intersection}
I_Flag(True), {If true, looks for intersection during and after the setup is complete
If false, then looks for intersection only during SetUp,
starting with "I_Signal" bar}

{*******COUNTDOWN PARAMETERS****}
ContDown(13), {Number of Bars needed for Countdown}
C_Look(2), {Reference bar of CountDown}
CS_Price(Close), {"Price" used to compare to High of "2" bars ago during
a "Sell" CountDown}
Count_EQ(True); {If true, comparrison of prior bar uses <= and >=
If false, comparrison of prior bar uses < and >.}

Inputs:
{*******RECYCLE PARAMETERS****}
{***Note - A "Recycle" causes all of the CountDown Numbers to be
removed from the Chart***}
Before(True), {If true and you get a 9 setup in the same direction before the
completion of countdown, you "RECYCLE" - Restart Countdown}
On13(True), {If true and you get a 9 setup in the same direction ON the
completion of countdown, you "RECYCLE" - Restart Countdown}
After(True), {If true and you get a 9 setup in the same direction after the
completion of countdown, AND there has not been an intervening
"1" Setup counter in the opposite direction since the
completion of CountDown, you "RECYCLE" - Restart
Countdown}
Ignre1st(False), {If true, the first occurance of a "Recycle" will be ignored. In this
case, it will Recycle the 1st time there is a subsequent new 9 count.
If false, it will Recycle on the first occurance of a new 9 count}
IgnreSml(True), {If true, a subsequent new 9 count will be ignored if it has a
smaller true range from high to low}
SmlFactr(1), {Used to determine a smaller true range.
1.00 = Any smaller true range
.50 = Any true range that is half the size of the initial}
IgnreLrg(True), {If true, a subsequent new 9 count will be ignored if it has a
larger true range from high to low}
LrgFactr(1.618), {Used to determine a larger true range.
1.618 = Any true range that is more than 1.618 times the initial
1.00 = Any larger true range}

{*******Qualifier Parameters********}
{**This section allows us to to compare any 2 prices for additional confirmation.
You can compare a Setup bar to another Setup bar, a SetUp bar to a CountDown
bar or a CountDownBar to another CountDown Bar. The comparrison is in the
format of :
if Price of Qual1 is < Price of Qual2 then the Sequential is qualified
(For a Buy Setup). It would be ">" for a Sell Setup. An optional "=" sign
is available for <= (>=)**}
Qualify(True), {If true, perform this additional qualification}
Q_Price1(Close), {Price of first Qualifier}
Q_Price2(Close), {Price of Second Qualifier}
Q_Type1(2), {A "1" represents a bar in the SetUp phase of Sequential}
{A "2" represents a bar in the CountDown Phase of Sequential}
Q_Type2(2),
Q_Bar1(13), {This represents the Number of the bar in that phase}
Q_Bar2(8),
Q_UseEq(True), {If true, uses <= or >= for comparrison}
{***For example: If you want to say that for a Buy Sequential, the close of the 6
CountDown bar has to be < the close of the 8 Setup bar, you would
set the following parameters.
Q_Price1(close) USE CLOSE
Q_Price2(close) USE CLOSE
Q_Type1(2) CountDown Phase
Q_Type2(1) SetUp Phase
Q_Bar1(6) Bar # 6
Q_Bar2(10) Bar # 10
Q_UseEq(false) Don't use = sign in comparrison}

Color(Tool_Red),
Pt_Ofset(0),
AlrtBars(5); {If an alert is used, the Alert will be active this number of bars
after the initial alert}

Vars:pPt_Ofset(0);
if PT_Ofset = 0
then pPT_Ofset = Average(Range,maxbarsback) * .6
else pPt_Ofset = Pt_Ofset Points;

vars:MySwitch(0),SetUpCount(0),Intersection(false),SetupFlag(false),x(0),
CountDown(0),OK2CountDown(false),Direction(0),AutoMaticRecycle(false),
NineBarNumber(0),SetUpLow(0),CountPrice(0),Halt(false),Qual1(0),Qual2(0),
OK2Plot(false),Recycle(false),FirstRecycle(true),_13Bar(0),LastCountDown(0),
Stringg(""),AlertBarNum(-1000),StarCount(0),Smaller(false),Larger(false),
SetUpRange(0),PrevSetUpRange(0);

Arrays:RefNum[100](0),StarRefNum[150](0);

if barnumber = 1 then
begin
if Setup < 2 or Setup > 99 or
Lookback < 1 or Lookback >= Setup or
ContDown < 1 or Contdown > 99 or
C_Look < 1 or C_Look >= ContDown
then Halt = true;
plot1(l,"l");
end;

if Halt = false then BEGIN

Recycle = false;
AutoMaticRecycle = false;

if SetUp_EQ = false then
begin
if Su_Price = Su_Price[Lookback] then MySwitch = 0;
if Su_Price > Su_Price[Lookback] then MySwitch = 1; {***Looking for a Sell Set Up*****}
if Su_Price < Su_Price[Lookback] then MySwitch = -1; {***Looking for a Buy Set Up*****}
end
ELSE
begin
if Su_Price = Su_Price[Lookback] then MySwitch = MySwitch[1]; {= so use last MySwitch}
if Su_Price > Su_Price[Lookback] then MySwitch = 1; {***Looking for a Sell Set Up*****}
if Su_Price < Su_Price[Lookback] then MySwitch = -1; {***Looking for a Buy Set Up*****}
end;

if OK2CountDown then
begin {***Continue CountDown***}
if Direction = 1 then
begin {***Looking for a Sell setup***}

{***Have we gone below the Low "Price of the Setup? If condition1 is true,
it is OK to proceed. If not, we must recycle***}
condition1 = (SS_Pric2>SetUpLow and SetUp_EQ) or
(SS_Pric2>=SetUpLow and SetUp_EQ=false);
if Condition1 = false then
begin {***Exceeded low, must recycle***}
OK2CountDown = false;
AutoMaticRecycle = true;
end;
{***Check "Price" of current Bar with high of "2" bars ago***}
CountPrice = CS_Price;
if Condition1 then
condition2 = (Count_EQ and CountPrice >= high[C_Look]) or
(Count_EQ = false and CountPrice > high[C_Look]);
if Condition1 and Condition2 then
begin
CountDown = CountDown + 1;
{***Added a new bar to countdown, see if we need to save it for a Qualification***}
if Qualify then
begin
if Q_Type1 = 2 and Q_Bar1 = CountDown then Qual1 = Q_Price1;
if Q_Type2 = 2 and Q_Bar2 = CountDown then Qual2 = Q_Price2;
end;
end;

if CountDown > CountDown[1] then
begin
Stringg = NumToStr(CountDown,0);
OK2Plot = true;
if CountDown = Contdown then
begin
{**At last bar of countdown, check for Additional Qualification, if we don't qualify
Print and * and postpone countdown**}
if Qualify and
((Q_Type1 = 2 and Q_Bar1 = CountDown) or
(Q_Type2 = 2 and Q_Bar2 = CountDown)) then
begin
if Q_UseEQ then if Qual1< Qual2 then OK2Plot = false;
if Q_UseEQ = false then if Qual1 <= Qual2 then OK2Plot = false;
end;
if OK2Plot = false then
begin
CountDown = CountDown-1;
Ok2Plot = true;
Stringg = "*";
StarCount = StarCount+1;
end
ELSE
begin
_13Bar = barnumber;
{**Save this CountDown Value for Later possible Recycle use***}
LastCountDown = CountDown;
end;
end;
if OK2PLot then
begin
{*****Put CountDown # on Chart*****}
if Stringg = "*" then
begin
StarRefNum[StarCount]=Text_New(date,time,high+pPt_Ofset,Stringg);
value1 = StarRefNum[StarCount];
end
ELSE
begin
RefNum[CountDown]=Text_New(date,time,high+pPt_Ofset,Stringg);
value1 = RefNum[CountDown];
end;
value2 = Text_SetStyle(value1{RefNum[CountDown]},2,2);
value2 = Text_SetColor(value1{RefNum[CountDown]},Color);
end;
if CountDown = ContDown then
begin
OK2CountDown = false;
AlertBarNum = barnumber;
Alert = true;

end;
end;
end;
end;

if MySwitch = MySwitch[1] then
begin
if SetUpCount < Setup then
begin
SetUpCount = SetUpCount + 1;
{***Added a new bar to SetUP, see if we need to save it for a Qualification***}
if Qualify then
begin
if Q_Type1 = 1 and Q_Bar1 = SetUpCount then Qual1 = Q_Price1;
if Q_Type2 = 1 and Q_Bar2 = SetUpCount then Qual2 = Q_Price2;
end;
end;
if SetUpCount = Setup and SetUpCount[1] = Setup - 1 then
begin {***New "9-count", recycle and paint bars ***}

{***Decide if we need to RECYCLE and remove CountDown #'s from bars***}

{*If we get a Nine count in opposite direction, automatically Recycle*}
if MySwitch = 1 then SetUpRange = 0;
if MySwitch = -1 and OK2CountDown then
begin
AutoMaticRecycle = true;
OK2CountDown = false;
end;

{*If we get a 9 count in the same direction, we may or may not Recycle*}

if MySwitch = 1 and LastCountDown = ContDown and LastCountDown[1] = ContDown
and After and MRO(MySwitch=-1,Barnumber-_13Bar,1) = -1
then Recycle = true;
if MySwitch = 1 and (OK2Countdown or CountDown = ContDown) then
begin
if CountDown < ContDown and Before and CountDown <> 0
then Recycle = true;
if CountDown = ContDown and CountDown[1] <> ContDown
and ON13 then Recycle = true;

end;

NineBarnumber = barnumber;

{***Save the highest(for a sell) or lowest(for a buy) "Price" during Setup.
Need to to use it during countdown for possible "Recycle".***}
if MySwitch = 1 then
begin {**Sell Setup, save Lowest "Price"***}
SetUpLow = Lowest(TrueLow,Setup);
PrevSetUpRange = SetUpRange;
SetUpRange = Highest(TrueHigh,Setup) - Lowest(TrueLow,Setup);
Smaller = SetUpRange < (PrevSetUpRange * SmlFactr);
Larger = False;
If PrevSetUpRange <> 0 Then Larger = SetUpRange > (PrevSetUpRange * LrgFactr);
{If we have a smaller Setup and we ARE NOT ignoring a smaller Setup,
then cancel Countdown}
if Smaller and (IgnreSml = false) then AutoMaticRecycle = True;

{If we have a larger Setup and we ARE NOT ignoring a larger Setup,
then cancel Countdown}
if Larger and IgnreLrg = false then AutoMaticRecycle = True;
end;
end;
if SetUpCount >= I_Signal and Intersection = false then
begin {*****Check for intersection*****}
{***If we do not require intersection (Int_On = false), set Intersection
flag to true***}
if Int_On = false then Intersection = true;
{***Are we allowed to check for intersection yet?***}
if I_Flag = true or (I_Flag = false and SetUpCount[1] <= SetUP-1) then
begin {**OK to look for intersection**}
x = 3;
while x <= (SetUpCount -1) and Intersection = false
begin
if MySwitch = 1 and low < high[x]
then Intersection = true;
{ if MySwitch = -1 and high > low[x]
then Intersection = true;}
x = x+1;
end;
end;
end;
end
else
begin
SetUpCount = 1;
Intersection = false;
end;

if CountDown = ContDown and MySwitch = 1 then CountDown = 0;

if Recycle or (AutoMaticRecycle and CountDown <> 0) then
begin {**May be OK2 Recycle***}
{If we ARE NOT ignoring the 1st Recycle, then cancel Countdown
If AutoMaticRecycle is true, then cancel Countdown
If this IS NOT the 1st Recycle, cancel Countdown}
if ((Ignre1st = false) or AutoMaticRecycle or
(Ignre1st and FirstRecycle = false)) then
begin {****Remove Numbers****}
{***Turn off Alert***}
AlertBarNum = -1000;
if CountDown = 0 then Value86 = LastCountDown else value86 = CountDown;
for x = 1 to Value86
begin
value2 = Text_Delete(RefNum[x]);
end;

{****Delete Stars if necessary*****}
for x = 1 to StarCount
begin
value2 = Text_Delete(StarRefNum[x]);
end;
StarCount = 0;
CountDown = 0;
LastCountDown = 0;
end;
if Ignre1st and FirstRecycle then FirstRecycle = false;
Recycle = false;
end;

if (Intersection and Intersection[1] = false and SetUpCount = Setup) OR
(Intersection and SetUpCount[1] = Setup - 1) then

{*******************************************}
begin {***Just had intersection on this bar, it may be bar 9 or subsequent bar***}
if Recycle or CountDown = 0 then
begin
CountDown = 0;
if MySwitch = 1 then Ok2CountDown = true;
end;
{****************************}
if MySwitch = 1
then Direction = 1
else Direction = -1;

if Direction = -1 or OK2CountDown[1] = false then FirstRecycle = true;
if SetUpCount = SetUp and Direction = 1 and CountDown = 0 then
begin {**We are at the last SetUpBar, Countdown may begin now**}
condition1 = (SS_Pric2>SetUpLow and SetUp_EQ) or
(SS_Pric2>=SetUpLow and SetUp_EQ=false);
if Condition1 = false then
begin {***Exceeded low, must recycle***}
OK2CountDown = false;
Recycle = true;
end;

{***Check "Price" of current Bar with high of "2" bars ago***}
CountPrice = CS_Price;
if Condition1 then
condition2 = (Count_EQ and CountPrice >= high[C_Look]) or
(Count_EQ = false and CountPrice > high[C_Look]);
if Condition1 and Condition2 then
begin
CountDown = 1;
{***Added a new bar to countdown, see if we need to save it for a
Qualification***}
Stringg = NumToStr(CountDown,0);
if Qualify then
begin
if Q_Type1 = 2 and Q_Bar1 = CountDown then Qual1 = Q_Price1;
if Q_Type2 = 2 and Q_Bar2 = CountDown then Qual2 = Q_Price2;
{***Code added 2/24/97 if we do not qualify, postpone countDown, put an * on
chart and continue CountDown. ***}

if ((Q_Type1=2 and Q_Type2=2) and CountDown=MaxList(Q_Bar1,Q_Bar2))
or ((Q_Type1=1 and Q_Type2=2) and CountDown=Q_Bar2)
or ((Q_Type1=2 and Q_Type2=1) and CountDown=Q_Bar1) then
begin {**We at the last qualifier? Check for qualification***}
if Q_UseEQ then if Qual1 < Qual2 then OK2Plot = false;
if Q_UseEQ = false then if Qual1 <= Qual2 then OK2Plot = false;
end;
if OK2Plot = false then
begin
CountDown = CountDown-1;
Ok2Plot = true;
Stringg = "*";
StarCount = StarCount +1;
end;
end;
OK2Plot = true;
{*****Put CountDown # or * on Chart*****}
if Stringg = "*" then
begin StarRefNum[StarCount]=Text_New(date,time,high+pPt_Ofset,Stringg);
value1 = StarRefNum[StarCount];
end
ELSE
begin
RefNum[CountDown]=Text_New(date,time,high+pPt_Ofset,Stringg);
value1 = RefNum[CountDown];
end;

value2 = Text_SetStyle(value1{RefNum[CountDown]},2,2);
value2 = Text_SetColor(value1{RefNum[CountDown]},Color);
end;
end;
end;

if CountDown = 1 then StarCount = 0;
end;



if barnumber <= AlertBarNum + AlrtBars then Alert = true;

Return to “User Contributed Studies and Indicator Library”