// Downloaded From https://www.WiseStockTrader.com _SECTION_BEGIN("TDST_DeMark_Perl"); /* Set Parameters. */ Plotall=ParamToggle("Plot all lines ", "No|Yes",1); Plotpercent=Param("Plot percentage above/below visible range ",20,0,100,5,0); gapprox=Param("Proximity Gap Multiplier",1,0,5,0.5,0); bluedist=Param("Blue_Multiplier",1.75,0,10,0.25,0); reddist=Param("Red_multiplier",0.25,0,10,0.25,0); /* Initialise variables. */ sup1=sup2=sup3=sup4=sup5=sup6=sup7=sup8=sup9=Null; res1=res2=res3=res4=res5=res6=res7=res8=res9=Null; TDSeqBuy=False; TDSeqbuydigits=0; TDSeqbuyrisk=TDSeqbuyreward=TDSeqbuyrrratio=TDSeqbuystop=0; TDSeqSell=False; TDSeqselldigits=0; TDSeqsellrisk=TDSeqsellreward=TDSeqsellrrratio=TDSeqsellstop=0; supinuse=resinuse=Null; supvio=resvio=0; tfarray=True; distance=ATR(10); BCDplot=False; BSetupind=BCDind=BCDrisk=0; BSmaxr=BSminr=BScnt=BSmaxrc=BSminrc=0; CurBSmaxr=CurBSminr=CurBScnt=CurBSmaxrc=CurBSminrc=0; PreBSmaxr=PreBSminr=PreBScnt=PreBSmaxrc=PreBSminrc=0; CurBCDstart=CurBCD=CurBCD8=CurBCDmaxr=CurBCDminr=CurBCDtext=CurBCDfin=0; PreBCDstart=PreBCD=PreBCD8=PreBCDmaxr=PreBCDminr=PreBCDtext=PreBCDfin=0; SCDplot=False; SSetupind=SCDind=SCDrisk=0; SSmaxr=SSminr=SScnt=SSmaxrc=SSminrc=0; CurSSmaxr=CurSSminr=CurSScnt=CurSSmaxrc=CurSSminrc=0; PreSSmaxr=PreSSminr=PreSScnt=PreSSmaxrc=PreSSminrc=0; CurSCDstart=CurSCD=CurSCD8=CurSCDmaxr=CurSCDminr=CurSCDtext=CurSCDfin=0; PreSCDstart=PreSCD=PreSCD8=PreSCDmaxr=PreSCDminr=PreSCDtext=PreSCDfin=0; /* Identify functions and procedures. */ /* This function checks the TD Sequential Digits for a valid sequence. */ function seqcheck(TDSeqdigits,ival) { Loop=0; if (TDSeqdigits[ival-1]>0 AND TDSeqdigits[ival-1]<9) { Loop=TDSeqdigits[ival-1]; for (jloop=0; jloopRef(Close,-4) AND Ref(Close,-1)Ref(Close,-5),True,False); Bullhold=Flip(Bullflip,Bearflip); Bearhold=Flip(Bearflip,Bullflip); /* Identify TD Setup's - Buy and Sell. */ Buyconsecdays=IIf(Close=9,True,False); BSmaxr=IIf(BSetupind==True,HHV(High,Buy9Bars),0); BSminr=IIf(BSetupind==True,LLV(Low,Buy9Bars),0); BScnt=Sum(BSetupind,BarsSince(BSetupind==False))+8; BSmaxrc=IIf(BSetupind==True,HHV(Close,Buy9Bars),0); BSminrc=IIf(BSetupind==True,LLV(Close,Buy9Bars),0); Sellconsecdays=IIf(Close>Ref(Close,-4),True,False); Sell9Bars=BarsSince(BarsSince(Sellconsecdays)); Sell9Signal=IIf(Sell9Bars==9,True,False); Sell9Req=IIf(Sell9Signal==True AND Ref(Bullflip,-8)==True,True,False); SSetupind=IIf(Bullhold==True AND Sell9Bars>=9,True,False); SSmaxr=IIf(SSetupind==True,HHV(High,Sell9Bars),0); SSminr=IIf(SSetupind==True,LLV(Low,Sell9Bars),0); SScnt=Sum(SSetupind,BarsSince(SSetupind==False))+8; SSmaxrc=IIf(SSetupind==True,HHV(Close,Sell9Bars),0); SSminrc=IIf(SSetupind==True,LLV(Close,Sell9Bars),0); /* Prepare Countdown Arrays for TD Setup's - Buy and Sell. */ Buyconseccloses=IIf(Close<=Ref(Low,-2),True,False); Sellconseccloses=IIf(Close>=Ref(High,-2),True,False); /* Get the highest high's and the lowests low's to have occurred in the last 9 days. */ HHV9=HHV(High,9); LLV9=LLV(Low,9); WhenHHV9=HHVBars(High,9); WhenLLV9=LLVBars(Low,9); /* Begin TD Sequential - Defining the Trend and Identifying Exhaustion Points. */ for (i=0; i0 AND Buy9Bars[i]<10 AND Bearflip[i+1-Buy9Bars[i]]==True) TDSeqbuydigits[i]=Buy9Bars[i]; if (Sell9Bars[i]>0 AND Sell9Bars[i]<10 AND Bullflip[i+1-Sell9Bars[i]]==True) TDSeqselldigits[i]=Sell9Bars[i]; /* Delete numbers that were created if there is a break in the sequence before 9 is reached. */ if (i>0 AND TDSeqbuydigits[i-1]>TDSeqbuydigits[i]) TDSeqbuydigits=seqcheck(TDSeqbuydigits,i); if (i>0 AND TDSeqselldigits[i-1]>TDSeqselldigits[i]) TDSeqselldigits=seqcheck(TDSeqselldigits,i); /* Update current running support and resistance lines */ /* How many the program will need is unknown !! - Limit is 9 for each. */ if (i>0) { if (sup1[i-1]>-1 AND sup1[i-1]-1 AND sup2[i-1]-1 AND sup3[i-1]-1 AND sup4[i-1]-1 AND sup5[i-1]-1 AND sup6[i-1]-1 AND sup7[i-1]-1 AND sup8[i-1]-1 AND sup9[i-1]-1 AND res1[i-1]>Close[i]) res1[i]=res1[i-1]; if (res2[i-1]>-1 AND res2[i-1]>Close[i]) res2[i]=res2[i-1]; if (res3[i-1]>-1 AND res3[i-1]>Close[i]) res3[i]=res3[i-1]; if (res4[i-1]>-1 AND res4[i-1]>Close[i]) res4[i]=res4[i-1]; if (res5[i-1]>-1 AND res5[i-1]>Close[i]) res5[i]=res5[i-1]; if (res6[i-1]>-1 AND res6[i-1]>Close[i]) res6[i]=res6[i-1]; if (res7[i-1]>-1 AND res7[i-1]>Close[i]) res7[i]=res7[i-1]; if (res8[i-1]>-1 AND res8[i-1]>Close[i]) res8[i]=res8[i-1]; if (res9[i-1]>-1 AND res9[i-1]>Close[i]) res9[i]=res9[i-1]; } /* The following code is essentially for the drawing of the TDST support and resistance lines. */ /* Test for a new support level and place in an empty support array */ if (Sell9Req[i]==True) { /* Determine which support array to use */ tfarray[i]=True; if (tfarray[i]==True) sup1= supres(sup1,(i-WhenLLV9[i]),i,LLV9[i]); if (tfarray[i]==True) sup2= supres(sup2,(i-WhenLLV9[i]),i,LLV9[i]); if (tfarray[i]==True) sup3= supres(sup3,(i-WhenLLV9[i]),i,LLV9[i]); if (tfarray[i]==True) sup4= supres(sup4,(i-WhenLLV9[i]),i,LLV9[i]); if (tfarray[i]==True) sup5= supres(sup5,(i-WhenLLV9[i]),i,LLV9[i]); if (tfarray[i]==True) sup6= supres(sup6,(i-WhenLLV9[i]),i,LLV9[i]); if (tfarray[i]==True) sup7= supres(sup7,(i-WhenLLV9[i]),i,LLV9[i]); if (tfarray[i]==True) sup8= supres(sup8,(i-WhenLLV9[i]),i,LLV9[i]); if (tfarray[i]==True) sup9= supres(sup9,(i-WhenLLV9[i]),i,LLV9[i]); /* Check to see if we need to erase the lowest support line (all 9 in-use) to make way for the newest. */ if (tfarray[i]==True) { for (j=0; jres8[i]) { for (j=0; Jres7[i]) { for (j=0; Jres6[i]) { for (j=0; Jres5[i]) { for (j=0; Jres4[i]) { for (j=0; Jres3[i]) { for (j=0; Jres2[i]) { for (j=0; Jres1[i]) { for (j=0; J0 AND (NOT IsEmpty(supinuse[i-1])) AND Close[i]0 AND (NOT IsEmpty(resinuse[i-1])) AND Close[i]>resinuse[i-1]) resvio[i]=True; /* Set flags to indicate completed TD Buy and Sell Countdown sequences. */ if (i>0) { BCDind[i]=BCDind[i-1]; SCDind[i]=SCDind[i-1]; PreBCDfin[i]=PreBCDfin[i-1]; CurBCDfin[i]=CurBCDfin[i-1]; PreSCDfin[i]=PreSCDfin[i-1]; CurSCDfin[i]=CurSCDfin[i-1]; } /* Check Perl's Rules for Trading TD Buy Setups Objectively. */ if (Buy9Req[i]==True) { /* Perl's Rule 1: Check for perfected TD Buy Setup. */ if (Low[i]2) { BCDind[i]=BCDind[i]-1; kval=PreBCDstart[i]; ResetBSpre(kval,i+1); PreBCDfin[i]=False; } /* Filters That Cancel a Developing TD Buy Countdown. */ /* 1. If the price action rallies and generates a TD Sell Setup, or */ /* 2. If the market trades higher and posts a true low above the true high of the prior TD Buy Setup - that is, TDST Resistance. */ /* The second condition is dealt with later in the program. */ if (SCDind[i]>0) { if (SCDind[i]>1) { SCDind[i]=SCDind[i]-1; kval=PreSCDstart[i]; ResetSSpre(kval,i+1); } SCDind[i]=SCDind[i]-1; kval=CurSCDstart[i]; ResetSScur(kval,i+1); } PreSCDfin[i]=False; CurSCDfin[i]=False; /* Determine if another Buy TD Sequential Setup has been initiated before the completion of the previous TD Buy Countdown. */ if (BCDind[i]==2) { /* Record details of the previous Buy TD Sequential Setup and Countdown. */ for (j=CurBCDstart[i-1]; jHigh[i-1]) tmpval[i]=High[i]; else tmpval[i]=High[i-1]; if (tmpval[i]>=High[i-2] AND tmpval[i]>=High[i-3]) { /* Perl's Rule 2: Check for TDST resistance violation. */ tmpval[i]=0; for (j=i-8; j2) { SCDind[i]=SCDind[i]-1; kval=PreSCDstart[i]; ResetSSpre(kval,i+1); PreSCDfin[i]=False; } /* Filters That Cancel a Developing TD Sell Countdown. */ /* 1. If the price action declines and generates a TD Buy Setup, or */ /* 2. If the market trades lower and posts a true high below the true low of the prior TD Sell Setup - that is, TDST support. */ /* The second condition is dealt with later in the program. */ if (BCDind[i]>0) { if (BCDind[i]>1) { BCDind[i]=BCDind[i]-1; kval=PreBCDstart[i]; ResetBSpre(kval,i+1); } BCDind[i]=BCDind[i]-1; kval=CurBCDstart[i]; ResetBScur(kval,i+1); } PreBCDfin[i]=False; CurBCDfin[i]=False; /* Determine if another Sell TD Sequential Setup has been initiated before the completion of the previous TD Sell Countdown. */ if (SCDind[i]==2) { /* Record details of the previous Sell TD Sequential Setup and Countdown. */ for (j=CurSCDstart[i-1]; j0) { if (BCDind[i]>1) { /* Record details of the ongoing (previous) Buy TD Sequential Setup. */ PreBSmaxr[i]=PreBSmaxr[i-1]; PreBSminr[i]=PreBSminr[i-1]; PreBScnt[i]=PreBScnt[i-1]; PreBSmaxrc[i]=PreBSmaxrc[i-1]; PreBSminrc[i]=preBSminrc[i-1]; /* Check to see if the ongoing (previous) TD Buy Countdown is still in progress and record details. */ PreBCDstart[i]=PreBCDstart[i-1]; PreBCD[i]=PreBCD[i-1]+Buyconseccloses[i]; PreBCDmaxr[i]=PreBCDmaxr[i-1]; PreBCDminr[i]=PreBCDminr[i-1]; if (PreBCDminr[i]>Low[i] AND PreBCD[i]>0) { PreBCDmaxr[i]=High[i]; PreBCDminr[i]=Low[i]; } PreBCD8[i]=PreBCD8[i-1]; if (PreBCD[i]==8 AND PreBCD[i-1]!=8) PreBCD8[i]=Close[i]; /* Perl's Rules to Complete a TD Buy Countdown. */ /* 1. The Low of TD Buy Countdown bar 13 must be less than, or equal to, the close of TD Buy Countdown bar 8. */ /* 2. The close of TD Buy Countdown bar 13 must be less than, or equal to, the low two bars earlier. */ if (Buyconseccloses[i]==True) { if (PreBCD[i]<13) { PreBCDtext[i]=PreBCD[i]; } else { if (PreBCD[i]>12 AND Low[i]<=PreBCD8[i]) { PreBCDtext[i]=13; BCDplot[i]=PreBCDtext[i]; /* Perl's Risk Management for a TD Buy Countdown. */ BCDrisk[i]=PreBCDminr[i]-(PreBCDmaxr[i]-PreBCDminr[i]); kval=PreBCDstart[i]; ResetBSpre(kval,i+1); BCDind[i]=BCDind[i]-1; PreBCDfin[i]=i; } else { PreBCDtext[i]=43; // Deferred Countdown print "+". } } } } /* Record details of the current Buy TD Sequential Setup. */ if (CurBCDmaxr[i]<0) { CurBSmaxr[i]=BSmaxr[i]; CurBSminr[i]=BSminr[i]; CurBScnt[i]=BScnt[i]; CurBSmaxrc[i]=BSmaxrc[i]; CurBSminrc[i]=BSminrc[i]; /* Record details of the current TD Buy Countdown. */ CurBCD[i]=CurBCD[i]+Buyconseccloses[i]; if (Buyconseccloses[i]==False) { CurBCDmaxr[i]=0; } else { CurBCDmaxr[i]=High[i]; CurBCDminr[i]=Low[i]; } } else { /* Record details of the current Buy TD Sequential Setup. */ if (BSetupind[i]==True) { CurBSmaxr[i]=BSmaxr[i]; CurBSminr[i]=BSminr[i]; CurBScnt[i]=BScnt[i]; CurBSmaxrc[i]=BSmaxrc[i]; CurBSminrc[i]=BSminrc[i]; } else { CurBSmaxr[i]=CurBSmaxr[i-1]; CurBSminr[i]=CurBSminr[i-1]; CurBScnt[i]=CurBScnt[i-1]; CurBSmaxrc[i]=CurBSmaxrc[i-1]; CurBSminrc[i]=CurBSminrc[i-1]; } /* Record details of the current TD Buy Countdown. */ CurBCDstart[i]=CurBCDstart[i-1]; CurBCD[i]=CurBCD[i-1]+Buyconseccloses[i]; CurBCDmaxr[i]=CurBCDmaxr[i-1]; CurBCDminr[i]=CurBCDminr[i-1]; if (CurBCDminr[i]>Low[i] AND CurBCD[i]>0) { CurBCDmaxr[i]=High[i]; CurBCDminr[i]=Low[i]; } CurBCD8[i]=CurBCD8[i-1]; if (CurBCD[i]==8 AND CurBCD[i-1]!=8) CurBCD8[i]=Close[i]; } /* Perl's Rules to Complete a TD Buy Countdown. */ /* 1. The Low of TD Buy Countdown bar 13 must be less than, or equal to, the close of TD Buy Countdown bar 8. */ /* 2. The close of TD Buy Countdown bar 13 must be less than, or equal to, the low two bars earlier. */ if (Buyconseccloses[i]==True) { if (CurBCD[i]<13) { CurBCDtext[i]=CurBCD[i]; } else { if (CurBCD[i]>12 AND Low[i]<=CurBCD8[i]) { CurBCDtext[i]=13; BCDplot[i]=CurBCDtext[i]; /* Perl's Risk Management for a TD Buy Countdown. */ BCDrisk[i]=CurBCDminr[i]-(CurBCDmaxr[i]-CurBCDminr[i]); BCDrisk[i-1]=CurBCDminr[i]; kval=CurBCDstart[i]; ResetBScur(kval,i+1); BCDind[i]=BCDind[i]-1; CurBCDfin[i]=i; } else { CurBCDtext[i]=43; // Deferred Countdown use "+" sign. } } } /* Filters That Cancel a Developing TD Buy Countdown. */ /* 1. If the price action rallies and generates a TD Sell Setup, or */ /* 2. If the market trades higher and posts a true low above the true high of the prior TD Buy Setup - that is, TDST Resistance. */ /* The first condition is dealt with earlier in the program. */ if (Low[i]>HHV9[CurBCDstart[i]] AND CurBCDstart[i]>0) { BCDind[i]=BCDind[i]-1; kval=CurBCDstart[i]; ResetBScur(kval,i+1); /* If we have an ongoing (previous) TD Buy Countdown then, make it current. */ if (BCDind[i]>0) { kval=PreBCDstart[i]; CopyBSpre(kval,i+1); ResetBSpre(kval,i+1); } } /* TD Buy Countdown Cancellation and Recycle Qualifiers. */ if (BCDind[i]>1 AND BSetupind[i]==False AND BSetupind[i-1]==True) { /* TD Buy Countdown Cancellation Qualifier 1. */ /* If the size of the true range of the most recently completed TD Buy Setup is equal to, or greater than, */ /* the size of the previous TD Buy Setup, but less than 1.618 times it's size then, */ /* a TD Setup Recycle will occcur; that is, whichever TD Buy Setup has the larger true range will become */ /* the active TD Buy Setup. */ TRcur=CurBSmaxr[i]-CurBSminr[i]; TRpre=PreBSmaxr[i]-PreBSminr[i]; if (TRcur>=TRpre AND TRcur<1.618*TRpre) { if (TRcur>TRpre) { /* Reset the TD Buy Setup previous arrays. */ BCDind[i]=BCDind[i]-1; kval=PreBCDstart[i]; ResetBSpre(kval,i+1); } else { BCDind[i]=BCDind[i]-1; kval=CurBCDstart[i]; ResetBSCur(kval,i+1); kval=PreBCDstart[i]; CopyBSpre(kval,i+1); ResetBSpre(kval,i+1); } } /* TD Buy Countdown Cancellation Qualifier 2 (a TD Buy Setup Within a TD Buy Setup). */ /* If the market has completed a TD Buy Setup that has a closing range within the true range */ /* of the prior TD Buy Setup, without recording a TD Sell Setup between the two, and if */ /* the current TD buy Setup has a price extreme within the true range of the prior TD Buy Setup, then */ /* the prior TD BUY Setup is the active TD Setup, and the TD Buy Countdown relating to it remains intact. */ if (BCDind[i]>1 AND CurBSmaxrc[i]PreBSminr[i] AND (CurBSmaxr[i]PreBSminr[i])) { BCDind[i]=BCDind[i]-1; kval=CurBCDstart[i]; ResetBSCur(kval,i+1); kval=PreBCDstart[i]; CopyBSpre(kval,i+1); ResetBSpre(kval,I+1); } } /* TD Buy Countdown Recycle Qualifier. */ /* An 'R' will appear when a TD Buy Setup that began before, on, or after the completion of a developing TD Buy Countdown, */ /* but prior to a bullish TD Price Flip, extends to eighteen bars - that is, eighteen closes, with each one less than than */ /* the close four price bars earlier. */ if (CurBScnt[i]==18 AND CurBScnt[i-1]!=18) { BCDplot[i]=82; // Recycle Qualifier use the letter "R". } /* Requirements for Validation of a TD Sequential 9-13-9 Buy Count. */ /* 1. The TD Buy Setup must not begin before or on the same price bar as the completed TD Buy Countdown. */ /* 2. The ensuing bullish TD Buy Setup must be preceded by a TD price flip, and */ /* 3. No complted TD Sell Setup should occur prior to the appearence of the TD Buy Setup. */ if (CurBCDfin[i]>0 AND TDSeqbuydigits[i]==9) { if (CurBCDfin[i]<(i-8)) { BCDplot[i]=9139; /* Risk Management for the TD Sequential 9-13-9 */ /* Subtract the true range of the price bar with the lowest true low in the TD Buy Countdown */ /* and ensuing TD Buy Setup from the true low of that bar. */ if (BCDrisk[CurBCDfin[i]-1]0) { if (SCDind[i]>1) { /* Record details of the ongoing (previous) Sell TD Sequential Setup. */ PreSSmaxr[i]=PreSSmaxr[i-1]; PreSSminr[i]=PreSSminr[i-1]; PreSScnt[i]=PreSScnt[i-1]; PreSSmaxrc[i]=PreSSmaxrc[i-1]; PreSSminrc[i]=preSSminrc[i-1]; /* Check to see if the ongoing (previous) TD Sell Countdown is still in progress and record details. */ PreSCDstart[i]=PreSCDstart[i-1]; PreSCD[i]=PreSCD[i-1]+Sellconseccloses[i]; PreSCDmaxr[i]=PreSCDmaxr[i-1]; PreSCDminr[i]=PreSCDminr[i-1]; if (PreSCDmaxr[i]0) { PreSCDmaxr[i]=High[i]; PreSCDminr[i]=Low[i]; } PreSCD8[i]=PreSCD8[i-1]; if (PreSCD[i]==8 AND PreSCD[i-1]!=8) PreSCD8[i]=Close[i]; /* Perl's Rules to Complete a TD Sell Countdown. */ /* 1. The High of TD Sell Countdown bar 13 must be greater than, or equal to, the close of TD Sell Countdown bar 8. */ /* 2. The close of TD Sell Countdown bar 13 must be greater than, or equal to, the high two bars earlier. */ if (Sellconseccloses[i]==True) { if (PreSCD[i]<13) { PreSCDtext[i]=PreSCD[i]; } else { if (PreSCD[i]>12 AND High[i]>=PreSCD8[i]) { PreSCDtext[i]=13; SCDplot[i]=PreSCDtext[i]; /* Perl's Risk Management for a TD Buy Countdown. */ SCDrisk[i]=PreSCDmaxr[i]+(PreSCDmaxr[i]-PreSCDminr[i]); kval=PreSCDstart[i]; ResetSSpre(kval,i+1); SCDind[i]=SCDind[i]-1; PreSCDfin[i]=i; } else { PreSCDtext[i]=43; } } } } /* Record details of the current Sell TD Sequential Setup. */ if (CurSCDmaxr[i]<0) { CurSSmaxr[i]=SSmaxr[i]; CurSSminr[i]=SSminr[i]; CurSScnt[i]=SScnt[i]; CurSSmaxrc[i]=SSmaxrc[i]; CurSSminrc[i]=SSminrc[i]; /* Record details of the current TD Sell Countdown. */ CurSCD[i]=CurSCD[i]+Sellconseccloses[i]; if (Sellconseccloses[i]==False) { CurSCDmaxr[i]=0; } else { CurSCDmaxr[i]=High[i]; CurSCDminr[i]=Low[i]; } } else { /* Record details of the current Sell TD Sequential Setup. */ if (SSetupind[i]==True) { CurSSmaxr[i]=SSmaxr[i]; CurSSminr[i]=SSminr[i]; CurSScnt[i]=SScnt[i]; CurSSmaxrc[i]=SSmaxrc[i]; CurSSminrc[i]=SSminrc[i]; } else { CurSSmaxr[i]=CurSSmaxr[i-1]; CurSSminr[i]=CurSSminr[i-1]; CurSScnt[i]=CurSScnt[i-1]; CurSSmaxrc[i]=CurSSmaxrc[i-1]; CurSSminrc[i]=CurSSminrc[i-1]; } /* Record details of the current TD Sell Countdown. */ CurSCDstart[i]=CurSCDstart[i-1]; CurSCD[i]=CurSCD[i-1]+Sellconseccloses[i]; CurSCDmaxr[i]=CurSCDmaxr[i-1]; CurSCDminr[i]=CurSCDminr[i-1]; if (CurSCDmaxr[i]0) { CurSCDmaxr[i]=High[i]; CurSCDminr[i]=Low[i]; } CurSCD8[i]=CurSCD8[i-1]; if (CurSCD[i]==8 AND CurSCD[i-1]!=8) CurSCD8[i]=Close[i]; } /* Perl's Rules to Complete a TD Sell Countdown. */ /* 1. The high of TD Sell Countdown bar 13 must be greater than, or equal to, the close of TD Sell Countdown bar 8. */ /* 2. The close of TD Sell Countdown bar 13 must be greater than, or equal to, the high two bars earlier. */ if (Sellconseccloses[i]==True) { if (CurSCD[i]<13) { CurSCDtext[i]=CurSCD[i]; } else { if (CurSCD[i]>12 AND High[i]>=CurSCD8[i]) { CurSCDtext[i]=13; SCDplot[i]=CurSCDtext[i]; /* Perl's Risk Management for a TD Buy Countdown. */ SCDrisk[i]=CurSCDmaxr[i]+(CurSCDmaxr[i]-CurSCDminr[i]); SCDrisk[i-1]=CurSCDmaxr[i]; kval=CurSCDstart[i]; ResetSScur(kval,i+1); SCDind[i]=SCDind[i]-1; CurSCDfin[i]=i; } else { CurSCDtext[i]=43; // Deferred Countdown use "+" sign. } } } /* Filters That Cancel a Developing TD Sell Countdown. */ /* 1. If the price action declines and generates a TD Buy Setup, or */ /* 2. If the market trades lower and posts a true high below the true low of the prior TD Sell Setup - that is, TDST support. */ /* The first condition is dealt with earlier in the program. */ if (High[i]0) { SCDind[i]=SCDind[i]-1; kval=CurSCDstart[i]; ResetSScur(kval,i+1); /* If we have an ongoing (previous) TD Sell Countdown then, make it current. */ if (SCDind[i]>0) { kval=PreSCDstart[i]; CopySSpre(kval,i+1); ResetSSpre(kval,i+1); } } /* TD Sell Countdown Cancellation and Recycle Qualifiers. */ if (SCDind[i]>1 AND SSetupind[i]==False AND SSetupind[i-1]==True) { /* TD Sell Countdown Cancellation Qualifier 1. */ /* If the size of the true range of the most recently completed TD Sell Setup is equal to, or greater than, */ /* the size of the previous TD Sell Setup, but less than 1.618 times it's size then, */ /* a TD Setup Recycle will occcur; that is, whichever TD Sell Setup has the larger true range will become */ /* the active TD Sell Setup. */ TRcur=CurSSmaxr[i]-CurSSminr[i]; TRpre=PreSSmaxr[i]-PreSSminr[i]; if (TRcur>=TRpre AND TRcur<1.618*TRpre) { if (TRcur>TRpre) { /* Reset the TD Sell Setup previous arrays. */ SCDind[i]=SCDind[i]-1; kval=PreSCDstart[i]; ResetSSpre(kval,i+1); } else { SCDind[i]=SCDind[i]-1; kval=CurSCDstart[i]; ResetSSCur(kval,i+1); kval=PreSCDstart[i]; CopySSpre(kval,i+1); ResetSSpre(kval,i+1); } } /* TD Sell Countdown Cancellation Qualifier 2 (a TD Sell Setup Within a TD Sell Setup). */ /* If the market has completed a TD Sell Setup that has a closing range within the true range */ /* of the prior TD Sell Setup, without recording a TD Buy Setup between the two, and if */ /* the current TD Sell Setup has a price extreme within the true range of the prior TD Buy Setup, then */ /* the prior TD Sell Setup is the active TD Setup, and the TD Sell Countdown relating to it remains intact. */ if (SCDind[i]>1 AND CurSSmaxrc[i]PreSSminr[i] AND (CurSSmaxr[i]PreSSminr[i])) { SCDind[i]=SCDind[i]-1; kval=CurSCDstart[i]; ResetSSCur(kval,i+1); kval=PreSCDstart[i]; CopySSpre(kval,i+1); ResetSSpre(kval,i+1); } } /* TD Buy Countdown Recycle Qualifier. */ /* An 'R' will appear when a TD Sell Setup that began before, on, or after the completion of a developing TD Sell Countdown, */ /* but prior to a bearish TD Price Flip, extends to eighteen bars - that is, eighteen closes, with each one greater than than */ /* the close four price bars earlier. */ if (CurSScnt[i]==18 AND CurSScnt[i-1]!=18) { SCDplot[i]=82; // Recycle Qualifier use the letter "R". } /* Requirements for Validation of a TD Sequential 9-13-9 Sell Count. */ /* 1. The TD Sell Setup must not begin before or on the same price bar as the completed TD Sell Countdown. */ /* 2. The ensuing bullish TD Sell Setup must be preceded by a TD price flip, and */ /* 3. No completed TD Buy Setup should occur prior to the appearence of the TD Sell Setup. */ if (CurSCDfin[i]>0 AND TDSeqselldigits[i]==9) { if (CurSCDfin[i]<(i-8)) { SCDplot[i]=9139; /* Risk Management for the TD Sequential 9-13-9 */ /* Add the true range of the price bar with the highest true high in the TD Sell Countdown */ /* and ensuing TD Sell Setup to the true high of that bar. */ if (SCDrisk[CurSCDfin[i]-1]>HHV9[i]) { SCDrisk[i]=SCDrisk[CurSCDfin[i]]; } else { SCDrisk[i]=HHV9[i]+(HHV9[i]-Low[i-WhenHHV9[i]]); } } CurSCDfin[i]=False; } } } /* Sort plot area */ Lowestlow=LowestVisibleValue(Low); Highesthigh=HighestVisibleValue(High); Plotrange=Highesthigh-Lowestlow; Plotlow=IIf(Plotall==False,(Lowestlow-(Plotpercent/100*Plotrange)),0); Plothigh=IIf(Plotall==False,(Highesthigh+(Plotpercent/100*Plotrange)),999999); /* perform plot routines. */ Plot(C, "", -1, styleCandle); /* Plot red buy digits and pink Countdown digits. */ PlotShapes( IIf( BCDplot==13, shapeUpArrow, IIf(BCDplot==9139, shapeHollowUpArrow, shapeNone)), colorDarkRed,0,IIf(BCDplot>0,Low,High)); for (i=0; i0) PlotText( " " + NumToStr(TDSeqbuydigits[ i ],1.0), i, H[ i ]+dist1[i], colorRed ); if (BCDplot[i]==82) PlotText("R",i,IIf(TDSeqbuydigits[i]>0,H[i]+2*dist1[i],H[i]+dist1[i]), colorDarkRed); if (BCDind[i]>1) { if (PreBCDtext[i]>0 AND PreBCDtext[i]<13) PlotText(" " + NumToStr(PreBCDtext[ i ],1.0),IIf(PreBCDtext[i]>9,i-0.5,i),IIf(TDSeqbuydigits[i]>0,H[i]+2*dist1[i],H[i]+dist1[i]), colorPink); if (PreBCDtext[i]==43) PlotText("+",i+0.25,IIf(TDSeqbuydigits[i]>0,H[i]+2*dist1[i],H[i]+dist1[i]), colorPink); } if (BCDind[i]==1) { if (CurBCDtext[i]>0 AND CurBCDtext[i]<13) PlotText(" " + NumToStr(CurBCDtext[ i ],1.0),IIf(CurBCDtext[i]>9,i-0.5,i),IIf(TDSeqbuydigits[i]>0,H[i]+2*dist1[i],H[i]+dist1[i]), colorDarkRed); if (CurBCDtext[i]==43) PlotText("+",i+0.25,IIf(TDSeqbuydigits[i]>0,H[i]+2*dist1[i],H[i]+dist1[i]), colorDarkRed); } } /* plot blue sell digits. */ PlotShapes( IIf( SCDplot==13, shapeDownArrow, IIf(SCDplot==9139, shapeHollowDownArrow, shapeNone)), colorIndigo,0,IIf(SCDplot>0,High,Low)); for (i=0; i0) PlotText( " " + NumToStr(TDSeqselldigits[ i ],1.0), i, L[ i ]-dist1[i], colorBlue ); if (SCDplot[i]==82) PlotText("R",i,IIf(TDSeqselldigits[i]>0,L[i]-2*dist1[i],L[i]-dist1[i]), colorIndigo); if (SCDind[i]>1) { if (PreSCDtext[i]>0 AND PreSCDtext[i]<13) PlotText(" " + NumToStr(PreSCDtext[ i ],1.0),IIf(PreSCDtext[i]>9,i-0.5,i),IIf(TDSeqselldigits[i]>0,L[i]-2*dist1[i],L[i]-dist1[i]), colorTurquoise); if (PreSCDtext[i]==43) PlotText("+",i+0.25,IIf(TDSeqselldigits[i]>0,L[i]-2*dist1[i],L[i]-dist1[i]), colorTurquoise); } if (SCDind[i]==1) { if (CurSCDtext[i]>0 AND CurSCDtext[i]<13) PlotText(" " + NumToStr(CurSCDtext[ i ],1.0),IIf(CurSCDtext[i]>9,i-0.5,i),IIf(TDSeqselldigits[i]>0,L[i]-2*dist1[i],L[i]-dist1[i]), colorIndigo); if (CurSCDtext[i]==43) PlotText("+",i+0.25,IIf(TDSeqselldigits[i]>0,L[i]-2*dist1[i],L[i]-dist1[i]), colorIndigo); } } PlotShapes( IIf( TDSeqBuy, shapeUpArrow, shapeNone ), colorYellow,0,IIf(TDSeqbuy,Low,High)); PlotShapes( IIf( TDSeqsell, shapeDownArrow, shapeNone ), colorYellow,0,IIf(TDSeqsell,High,Low)); //PlotShapes( IIf( supvio, IIf(supvio, shapeHollowDownTriangle, shapeUpTriangle), shapeNone ), colorYellow,0,IIf(supvio,High,Low)); //PlotShapes( IIf( resvio, IIf(resvio, shapeHollowUpTriangle, shapeDownTriangle), shapeNone ), colorYellow,0,IIf(resvio,Low,High)); Plot(IIf(res1PlotLow,sup1,Null),"sup1",colorOrange,styleLine); Plot(IIf(sup2>PlotLow,sup2,Null),"sup2",colorYellow,styleLine); Plot(IIf(sup3>PlotLow,sup3,Null),"sup3",colorBlue,styleLine); Plot(IIf(sup4>PlotLow,sup4,Null),"sup4",colorGreen,styleLine); Plot(IIf(sup5>PlotLow,sup5,Null),"sup5",colorRed,styleLine); Plot(IIf(sup6>PlotLow,sup6,Null),"sup6",colorWhite,styleLine); Plot(IIf(sup7>PlotLow,sup7,Null),"sup7",colorBrown,styleLine); Plot(IIf(sup8>PlotLow,sup8,Null),"sup8",colorIndigo,styleLine); Plot(IIf(sup9>PlotLow,sup9,Null),"sup9",colorDarkGreen,styleLine); /* Automatic Analysis Explore Routines. */ /* Setup Column Information. */ NumColumns=8; Column0=IIf(TDSeqBuy==True,True,False); Column1=IIf(BCDplot==13,True,False); Column2=IIf(BCDplot==9139,True,False); Column3=IIf(BCDplot==82,True,False); Column4=IIf(TDSeqSell==True,True,False); Column5=IIf(SCDplot==13,True,False); Column6=IIf(SCDplot==9139,True,False); Column7=IIf(SCDplot==82,True,False); Column0Name = "TDSeq Buy "; Column1Name = "BCD 13 "; Column2Name = "BCD 9-13-9 "; Column3Name = "TDST Buy 'R' "; Column4Name = "TDSeq Sell "; Column5Name = "SCD 13 "; Column6Name = "SCD 9-13-9 "; Column7Name = "TDST Sell 'R' "; Filter= IIf(TDSeqBuy==True OR BCDplot==13 OR BCDplot==9139 OR BCDplot==82,True,False) OR IIf(TDSeqSell==True OR SCDplot==13 OR SCDplot==9139 OR SCDplot==82,True,False); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Title = "{{DATE}} - "+Name()+" ("+ FullName()+ ") - "+" Open="+O+", High="+H+", Low="+L+", Close="+C+StrFormat(" (%.2f %.1f%%) ",IIf(ROC(C,1)==0,0,C-Ref(C,-1)),SelectedValue( ROC( C, 1 )))+ "\n"+EncodeColor(colorBlue) + WriteIf(TDSeqBuy==True, "\nPotential TDST Buy : Risk= " + WriteVal(TDSeqbuyrisk,8.2) + " Reward= " + WriteVal(TDSeqbuyreward,8.2) + " Reward Risk Ratio= " + WriteVal(TDSeqbuyrrratio,8.2) + " Stop @ " + WriteVal(TDSeqbuystop,8.2),"") + ""+EncodeColor(colorRed) + WriteIf(TDSeqsell==True, "\nPotential TDST Short : Risk= " + WriteVal(TDSeqsellrisk,8.2) + " Reward= " + WriteVal(TDSeqsellreward,8.2) + " Reward Risk Ratio= " + WriteVal(TDSeqsellrrratio,8.2) + " Stop @ " + WriteVal(TDSeqsellstop,8.2),"") + "\n"+EncodeColor(colorBlue) + WriteIf(BCDplot==13, "\nBuy CD 13 trade : Stop loss at " + WriteVal(BCDRisk,8.2) + " Risk is " + WriteVal(Close-BCDRisk,8.2),"") + ""+EncodeColor(colorBlue) + WriteIf(BCDplot==9139, "\nBuy CD 9-13-9 trade : Stop loss at " + WriteVal(BCDRisk,8.2) + " Risk is " + WriteVal(Close-BCDRisk,8.2),"") + "\n"+EncodeColor(colorRed) + WriteIf(SCDplot==13, "\nSell CD 13 trade : Stop loss at " + WriteVal(SCDRisk,8.2) + " Risk is " + WriteVal(SCDRisk-Close,8.2),"") + ""+EncodeColor(colorRed) + WriteIf(SCDplot==9139, "\nSell CD 9-13-9 trade : Stop loss at " + WriteVal(SCDRisk,8.2) + " Risk is " + WriteVal(SCDRisk-Close,8.2),"") + "\n"+EncodeColor(colorGold)+" "+WriteVal(BarCount)+" =BarCount" + " bar Number = " + WriteVal(Cum(1)-1,8.0); _SECTION_END() ;