Stock Portfolio Organizer
The ultimate porfolio management solution.
Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
WiseTrader Toolbox
#1 Selling Amibroker Plugin featuring:
Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
TD Sequential Perl for Amibroker (AFL)
Rating:
5 / 5 (Votes 2)
Tags:
amibroker
Based on the book of Jason perl
Similar Indicators / Formulas
Kavach Of Karna v2
Submitted
by hbkwarez over 10 years ago
Advanced Elliott Waves
Submitted
by MarcosEn over 13 years ago
3_6Day GuaiLiLv
Submitted
by motorfly over 13 years ago
Williams Alligator System
Submitted
by durgesh1712 over 13 years ago
*Level Breakout system*
Submitted
by Tinych over 13 years ago
Horizontal Live Priceline Tool
Submitted
by northstar over 13 years ago
Indicator / Formula
Copy & Paste Friendly
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 | _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; jloop<Loop; jloop++) { TDSeqdigits[ival-1-jloop]=0; } } return TDSeqdigits; } /* Fuction to set up support and resistance arrays */ function supres(supresarray,jval,ival,supresValue) { global tfarray; if ( IsEmpty (supresarray[jval])) { tfarray[ival]= False ; for (jcount=jval; jcount<(ival+1); jcount++) { supresarray[jcount]=supresvalue; } } return supresarray; } /* Prodedures to reset TD Sequential Buy arrays. */ procedure ResetBScur(Loop,Ival) { for (j=Loop; j<Ival; j++) { CurBSmaxr[j]=0; CurBSminr[j]=0; CurBScnt[j]=0; CurBSmaxrc[j]=0; CurBSminrc[j]=0; CurBCDstart[j]=0; CurBCD[j]=0; CurBCDmaxr[j]=0; CurBCDminr[j]=0; CurBCD8[j]=0; // CurBCDfin[j]=0; CurBCDtext[j]=0; } return ; } procedure ResetBSpre(Loop,Ival) { for (j=Loop; j<Ival; j++) { PreBSmaxr[j]=0; PreBSminr[j]=0; PreBScnt[j]=0; PreBSmaxrc[j]=0; PreBSminrc[j]=0; PreBCDstart[j]=0; PreBCD[j]=0; PreBCDmaxr[j]=0; PreBCDminr[j]=0; PreBCD8[j]=0; // PreBCDfin[j]=0; PreBCDtext[j]=0; } return ; } /* Procedure to copy the TD Setup Buy arrays (previous) into the TD Setup Buy arrays (current). */ procedure CopyBSpre(Loop,Ival) { for (j=Loop; j<Ival; j++) { CurBSmaxr[j]=PreBSmaxr[j]; CurBSminr[j]=PreBSminr[j]; CurBScnt[j]=PreBScnt[j]; CurBSmaxrc[j]=PreBSmaxrc[j]; CurBSminrc[j]=PreBSminrc[j]; CurBCDstart[j]=PreBCDstart[j]; CurBCD[j]=PreBCD[j]; CurBCDmaxr[j]=PreBCDmaxr[j]; CurBCDminr[j]=PreBCDminr[j]; CurBCD8[j]=PreBCD8[j]; CurBCDfin[j]=PreBCDfin[j]; CurBCDtext[j]=PreBCDtext[j]; } return ; } /* Prodedures to reset TD Sequential Sell arrays. */ procedure ResetSScur(Loop,Ival) { for (j=Loop; j<Ival; j++) { CurSSmaxr[j]=0; CurSSminr[j]=0; CurSScnt[j]=0; CurSSmaxrc[j]=0; CurSSminrc[j]=0; CurSCDstart[j]=0; CurSCD[j]=0; CurSCDmaxr[j]=0; CurSCDminr[j]=0; CurSCD8[j]=0; // CurSCDfin[j]=0; CurSCDtext[j]=0; } return ; } procedure ResetSSpre(Loop,Ival) { for (j=Loop; j<Ival; j++) { PreSSmaxr[j]=0; PreSSminr[j]=0; PreSScnt[j]=0; PreSSmaxrc[j]=0; PreSSminrc[j]=0; PreSCDstart[j]=0; PreSCD[j]=0; PreSCDmaxr[j]=0; PreSCDminr[j]=0; PreSCD8[j]=0; // PreSCDfin[j]=0; PreSCDtext[j]=0; } return ; } /* Procedure to copy the TD Setup Sell arrays (previous) into the TD Setup Sell arrays (current). */ procedure CopySSpre(Loop,Ival) { for (j=Loop; j<Ival; j++) { CurSSmaxr[j]=PreSSmaxr[j]; CurSSminr[j]=PreSSminr[j]; CurSScnt[j]=PreSScnt[j]; CurSSmaxrc[j]=PreSSmaxrc[j]; CurSSminrc[j]=PreSSminrc[j]; CurSCDstart[j]=PreSCDstart[j]; CurSCD[j]=PreSCD[j]; CurSCDmaxr[j]=PreSCDmaxr[j]; CurSCDminr[j]=PreSCDminr[j]; CurSCD8[j]=PreSCD8[j]; CurSCDfin[j]=PreSCDfin[j]; CurSCDtext[j]=PreSCDtext[j]; } return ; } /* Begin Assignments. */ SetBarsRequired ( sbrAll ); /* Identify Bullish and Bearish Price Flips. Then, latch these values. */ Bullflip= IIf ( Close > Ref ( Close ,-4) AND Ref ( Close ,-1)< Ref ( Close ,-5), True , False ); Bearflip= IIf ( Close < Ref ( 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 < Ref ( Close ,-4), True , False ); Buy9Bars= BarsSince ( BarsSince (Buyconsecdays)); Buy9Signal= IIf (Buy9Bars==9, True , False ); Buy9Req= IIf (Buy9Signal== True AND Ref (Bearflip,-8)== True , True , False ); BSetupind= IIf (Bearhold== True AND Buy9Bars>=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; i< BarCount ; i++) { /* Obtain TD Sequential Digits to be plotted. */ if (Buy9Bars[i]>0 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]< Close [i]) sup1[i]=sup1[i-1]; if (sup2[i-1]>-1 AND sup2[i-1]< Close [i]) sup2[i]=sup2[i-1]; if (sup3[i-1]>-1 AND sup3[i-1]< Close [i]) sup3[i]=sup3[i-1]; if (sup4[i-1]>-1 AND sup4[i-1]< Close [i]) sup4[i]=sup4[i-1]; if (sup5[i-1]>-1 AND sup5[i-1]< Close [i]) sup5[i]=sup5[i-1]; if (sup6[i-1]>-1 AND sup6[i-1]< Close [i]) sup6[i]=sup6[i-1]; if (sup7[i-1]>-1 AND sup7[i-1]< Close [i]) sup7[i]=sup7[i-1]; if (sup8[i-1]>-1 AND sup8[i-1]< Close [i]) sup8[i]=sup8[i-1]; if (sup9[i-1]>-1 AND sup9[i-1]< Close [i]) sup9[i]=sup9[i-1]; if (res1[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; j< BarCount ; j++) { sup1[j]=sup2[j]; sup2[j]=sup3[j]; sup3[j]=sup4[j]; sup4[j]=sup5[j]; sup5[j]=sup6[j]; sup6[j]=sup7[j]; sup7[j]=sup8[j]; sup8[j]=sup9[j]; sup9[j]= Null ; } sup9= supres(sup9,(i-WhenLLV9[i]),i,LLV9[i]); } /* Check to ensure the latest addition is in the correct 'sup' array. */ if (( NOT ( IsEmpty (sup9[i]) OR IsEmpty (sup8[i]))) AND sup9[i]<sup8[i]) { for (j=0; J< BarCount ; j++) { swap[j]=sup9[j]; sup9[j]=sup8[j]; sup8[j]=swap[j]; } } if (( NOT ( IsEmpty (sup8[i]) OR IsEmpty (sup7[i]))) AND sup8[i]<sup7[i]) { for (j=0; J< BarCount ; j++) { swap[j]=sup8[j]; sup8[j]=sup7[j]; sup7[j]=swap[j]; } } if (( NOT ( IsEmpty (sup7[i]) OR IsEmpty (sup6[i]))) AND sup7[i]<sup6[i]) { for (j=0; J< BarCount ; j++) { swap[j]=sup7[j]; sup7[j]=sup6[j]; sup6[j]=swap[j]; } } if (( NOT ( IsEmpty (sup6[i]) OR IsEmpty (sup5[i]))) AND sup6[i]<sup5[i]) { for (j=0; J< BarCount ; j++) { swap[j]=sup6[j]; sup6[j]=sup5[j]; sup5[j]=swap[j]; } } if (( NOT ( IsEmpty (sup5[i]) OR IsEmpty (sup4[i]))) AND sup5[i]<sup4[i]) { for (j=0; J< BarCount ; j++) { swap[j]=sup5[j]; sup5[j]=sup4[j]; sup4[j]=swap[j]; } } if (( NOT ( IsEmpty (sup4[i]) OR IsEmpty (sup3[i]))) AND sup4[i]<sup3[i]) { for (j=0; J< BarCount ; j++) { swap[j]=sup4[j]; sup4[j]=sup3[j]; sup3[j]=swap[j]; } } if (( NOT ( IsEmpty (sup3[i]) OR IsEmpty (sup2[i]))) AND sup3[i]<sup2[i]) { for (j=0; J< BarCount ; j++) { swap[j]=sup3[j]; sup3[j]=sup2[j]; sup2[j]=swap[j]; } } if (( NOT ( IsEmpty (sup2[i]) OR IsEmpty (sup1[i]))) AND sup2[i]<sup1[i]) { for (j=0; J< BarCount ; j++) { swap[j]=sup2[j]; sup2[j]=sup1[j]; sup1[j]=swap[j]; } } } /* Test for a new resistance level and place in empty resistance array */ if (Buy9Req[i]== True ) { /* Determine which resistance array to use */ tfarray[i]= True ; if (tfarray[i]== True ) res1= supres(res1,(i-WhenHHV9[i]),i,HHV9[i]); if (tfarray[i]== True ) res2= supres(res2,(i-WhenHHV9[i]),i,HHV9[i]); if (tfarray[i]== True ) res3= supres(res3,(i-WhenHHV9[i]),i,HHV9[i]); if (tfarray[i]== True ) res4= supres(res4,(i-WhenHHV9[i]),i,HHV9[i]); if (tfarray[i]== True ) res5= supres(res5,(i-WhenHHV9[i]),i,HHV9[i]); if (tfarray[i]== True ) res6= supres(res6,(i-WhenHHV9[i]),i,HHV9[i]); if (tfarray[i]== True ) res7= supres(res7,(i-WhenHHV9[i]),i,HHV9[i]); if (tfarray[i]== True ) res8= supres(res8,(i-WhenHHV9[i]),i,HHV9[i]); if (tfarray[i]== True ) res9= supres(res9,(i-WhenHHV9[i]),i,HHV9[i]); /* Check to see if we need to erase the highest resistance line (all 9 in-use) to make way for the newest. */ if (tfarray[i]== True ) { for (j=0; j< BarCount ; j++) { res1[j]=res2[j]; res2[j]=res3[j]; res3[j]=res4[j]; res4[j]=res5[j]; res5[j]=res6[j]; res6[j]=res7[j]; res7[j]=res8[j]; res8[j]=res9[j]; res9[j]= Null ; } res9= supres(res9,(i-WhenHHV9[i]),i,HHV9[i]); } /* Check to ensure the latest addition is in the correct 'res' array. */ if (( NOT ( IsEmpty (res9[i]) OR IsEmpty (res8[i]))) AND res9[i]>res8[i]) { for (j=0; J< BarCount ; j++) { swap[j]=res9[j]; res9[j]=res8[j]; res8[j]=swap[j]; } } if (( NOT ( IsEmpty (res8[i]) OR IsEmpty (res7[i]))) AND res8[i]>res7[i]) { for (j=0; J< BarCount ; j++) { swap[j]=res8[j]; res8[j]=res7[j]; res7[j]=swap[j]; } } if (( NOT ( IsEmpty (res7[i]) OR IsEmpty (res6[i]))) AND res7[i]>res6[i]) { for (j=0; J< BarCount ; j++) { swap[j]=res7[j]; res7[j]=res6[j]; res6[j]=swap[j]; } } if (( NOT ( IsEmpty (res6[i]) OR IsEmpty (res5[i]))) AND res6[i]>res5[i]) { for (j=0; J< BarCount ; j++) { swap[j]=res6[j]; res6[j]=res5[j]; res5[j]=swap[j]; } } if (( NOT ( IsEmpty (res5[i]) OR IsEmpty (res4[i]))) AND res5[i]>res4[i]) { for (j=0; J< BarCount ; j++) { swap[j]=res5[j]; res5[j]=res4[j]; res4[j]=swap[j]; } } if (( NOT ( IsEmpty (res4[i]) OR IsEmpty (res3[i]))) AND res4[i]>res3[i]) { for (j=0; J< BarCount ; j++) { swap[j]=res4[j]; res4[j]=res3[j]; res3[j]=swap[j]; } } if (( NOT ( IsEmpty (res3[i]) OR IsEmpty (res2[i]))) AND res3[i]>res2[i]) { for (j=0; J< BarCount ; j++) { swap[j]=res3[j]; res3[j]=res2[j]; res2[j]=swap[j]; } } if (( NOT ( IsEmpty (res2[i]) OR IsEmpty (res1[i]))) AND res2[i]>res1[i]) { for (j=0; J< BarCount ; j++) { swap[j]=res2[j]; res2[j]=res1[j]; res1[j]=swap[j]; } } } /* Support and resistance arrays ready for plotting. */ /* Determine which TDST lines are currently being used. */ supval[0]=sup1[i]; supval[1]=sup2[i]; supval[2]=sup3[i]; supval[3]=sup4[i]; supval[4]=sup5[i]; supval[5]=sup6[i]; supval[6]=sup7[i]; supval[7]=sup8[i]; supval[8]=sup9[i]; resval[0]=res1[i]; resval[1]=res2[i]; resval[2]=res3[i]; resval[3]=res4[i]; resval[4]=res5[i]; resval[5]=res6[i]; resval[6]=res7[i]; resval[7]=res8[i]; resval[8]=res9[i]; /* Hopefully, get a valid support value into the top location. */ Count=0; while ( IsEmpty (supval[8]) AND Count<8) { for (j=0; j<8; j++) { supval[8-j]=supval[7-j]; } Count=Count+1; } /* Hopefully, get a valid resistance value into the top location. */ Count=0; while ( IsEmpty (resval[8]) AND Count<8) { for (j=0; j<8; j++) { resval[8-j]=resval[7-j]; } Count=Count+1; } /* Record support and resistance values. */ supinuse[i]=supval[8]; resinuse[i]=resval[8]; /* Determine if the current close halts a current support or resistance line. */ if (TDSeqbuydigits[i]>0 AND ( NOT IsEmpty (supinuse[i-1])) AND Close [i]<supinuse[i-1]) supvio[i]= True ; if (TDSeqselldigits[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]< Low [i-1]) tmpval[i]= Low [i]; else tmpval[i]= Low [i-1]; if (tmpval[i]<= Low [i-2] AND tmpval[i]<= Low [i-3]) { /* Perl's Rule 2: Check for TDST support violation. */ tmpval[i]=0; for (j=i-8; j<i+1; j++) { tmpval[i]=tmpval[i]+supvio[j]; } if (tmpval[i]==0) { /* Perl's Rule 3: Check the close of TD Buy Setup bar 9 is in close proximity to TDST support. */ /* This rule is highly subjective. I have chosen the low of bar 9 to be within one ATR distance of the TDST support. */ if ( NOT IsEmpty (supinuse[i])) { if (( Low [i]-supinuse[i])<distance[i]*gapprox) { /* Perl's Risk Management: Calculating the TD Risk Level for Trading a TD Buy Setup. */ TDSeqBuy[i]= True ; TDSeqbuystop[i]=LLV9[i]-( High [i-WhenLLV9[i]]-LLV9[i]); TDSeqbuyrisk[i]= Close [i]-TDSeqbuystop[i]; TDSeqbuyreward[i]=resinuse[i]- Close [i]; TDSeqbuyrrratio[i]=TDSeqbuyreward[i]/TDSeqbuyrisk[i]; } } } } /* Initiate setup for TD Buy Countdown. */ BCDind[i]=BCDind[i]+ True ; /* Check to ensure only two TD Sequential Buy patterns are being considered. */ if (BCDind[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]; j<i; j++) { PreBSmaxr[j]=CurBSmaxr[j]; PreBSminr[j]=CurBSminr[j]; PreBScnt[j]=CurBScnt[j]; PreBSmaxrc[j]=CurBSmaxrc[j]; PreBSminrc[j]=CurBSminrc[j]; PreBCD[j]=CurBCD[j]; PreBCDmaxr[j]=CurBCDmaxr[j]; PreBCDminr[j]=CurBCDminr[j]; PreBCD8[j]=CurBCD8[j]; PreBCDtext[j]=CurBCDtext[j]; PreBCDstart[j]=CurBCDstart[j]; PreBCDfin[j]=CurBCDfin[j]; } ResetBScur(CurBCDstart[i-1],i); } /* Record details of the new Buy TD Sequential Setup. */ CurBCD[i]=0; CurBCDmaxr[i]=-999999; CurBCDminr[i]=999999; CurBCDtext[i]=0; CurBCDstart[i]=i; } /* Check Perl's Rules for Trading TD Sell Setups Objectively. */ if (Sell9Req[i]== True ) { /* Perl's Rule 1: Check for perfected TD Sell Setup. */ if ( High [i]> High [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; j<i+1; j++) { tmpval[i]=tmpval[i]+resvio[j]; } if (tmpval[i]==0) { /* Perl's Rule 3: Check the close of TD Sell Setup bar 9 is in close proximity to TDST resistance. */ /* This rule is highly subjective. I have chosen the high of bar 9 to be within one ATR distance of the TDST resistance. */ if ( NOT IsEmpty (resinuse[i])) { if ((resinuse[i]- High [i])<distance[i]*gapprox) { /* Perl's Risk Management: Calculating the TD Risk Level for Trading a TD Sell Setup. */ TDSeqSell[i]= True ; TDSeqsellstop[i]=HHV9[i]+(HHV9[i]- Low [i-WhenHHV9[i]]); TDSeqsellrisk[i]=TDSeqsellstop[i]- Close [i]; TDSeqsellreward[i]= Close [i]-supinuse[i]; TDSeqsellrrratio[i]=TDSeqsellreward[i]/TDSeqsellrisk[i]; } } } } /* Initiate setup for TD Sell Countdown. */ SCDind[i]=SCDind[i]+ True ; /* Check to ensure only two TD Sequential Buy patterns are being considered. */ if (SCDind[i]>2) { 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]; j<i; j++) { PreSSmaxr[j]=CurSSmaxr[j]; PreSSminr[j]=CurSSminr[j]; PreSScnt[j]=CurSScnt[j]; PreSSmaxrc[j]=CurSSmaxrc[j]; PreSSminrc[j]=CurSSminrc[j]; PreSCD[j]=CurSCD[j]; PreSCDmaxr[j]=CurSCDmaxr[j]; PreSCDminr[j]=CurSCDminr[j]; PreSCD8[j]=CurSCD8[j]; PreSCDtext[j]=CurSCDtext[j]; PreSCDstart[j]=CurSCDstart[j]; PreSCDfin[j]=CurSCDfin[j]; } ResetSScur(CurSCDstart[i-1],i); } /* Record details of the new Sell TD Sequential Setup. */ CurSCD[i]=0; CurSCDmaxr[i]=-999999; CurSCDminr[i]=999999; CurSCDtext[i]=0; CurSCDstart[i]=i; } /* Perl's Rules for trading TD Countdowns. */ /* Check to see if a TD Buy Countdown is being processed. */ if (BCDind[i]>0) { 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]<PreBSmaxr[i] AND CurBSminrc[i]>PreBSminr[i] AND (CurBSmaxr[i]<PreBSmaxr[i] OR CurBSminr[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]<LLV9[i]) { BCDrisk[i]=BCDrisk[CurBCDfin[i]]; } else { BCDrisk[i]=LLV9[i]-( High [i-whenLLV9[i]]-LLV9[i]); } } CurBCDfin[i]= False ; } } /* Check to see if a TD Sell Countdown is being processed. */ if (SCDind[i]>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]< High [i] AND PreSCD[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]< High [i] AND CurSCD[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]<LLV9[CurSCDstart[i]] AND CurSCDstart[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]<PreSSmaxr[i] AND CurSSminrc[i]>PreSSminr[i] AND (CurSSmaxr[i]<PreSSmaxr[i] OR CurSSminr[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; i< BarCount ; i++) { dist1[i] = reddist[i]*distance[i]; if (TDSeqbuydigits[i]>0) 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; i< BarCount ; i++) { dist1[i] = bluedist[i]*distance[i]; if (TDSeqselldigits[i]>0) 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 (res1<Plothigh,res1, Null ), "res1" , colorOrange , styleLine ); Plot ( IIf (res2<Plothigh,res2, Null ), "res2" , colorYellow , styleLine ); Plot ( IIf (res3<Plothigh,res3, Null ), "res3" , colorBlue , styleLine ); Plot ( IIf (res4<Plothigh,res4, Null ), "res4" , colorGreen , styleLine ); Plot ( IIf (res5<Plothigh,res5, Null ), "res5" , colorRed , styleLine ); Plot ( IIf (res6<Plothigh,res6, Null ), "res6" , colorWhite , styleLine ); Plot ( IIf (res7<Plothigh,res7, Null ), "res7" , colorBrown , styleLine ); Plot ( IIf (res8<Plothigh,res8, Null ), "res8" , colorIndigo , styleLine ); Plot ( IIf (res9<Plothigh,res9, Null ), "res9" , colorDarkGreen , styleLine ); Plot ( IIf (sup1>PlotLow,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 () ; |
3 comments
Leave Comment
Please login here to leave a comment.
Back
good bt too slow …plz do the needfull.
I found the code on the web So >> If anyone can improve the speed please post the relevant changes Thanks in advance.
The Combo would be a great addition to the code. Here are the rules.
Differences in Buy countdown: TD combo vs. TD Sequential
Once the TD Combo Buy Setup is complete, the differences between
TD Combo and TD Sequential become apparent:
• TD Sequential waits for the completion of a TD Buy Setup and
then begins looking for the conditions necessary to satisfy the requirements
for a TD Buy Countdown, but
• TD Combo waits for a TD Buy Setup to finish, and then begins the
TD Buy Countdown, from bar one of the preceding TD Buy Setup
onward.
Requirements for a TD Combo Buy Countdown Version II
(Less-Strict Version)
The first four requirements are the same as for Version I:
1. The close must be less than, or equal to, the low two price bars earlier, up to and
including bar ten of the TD Buy Countdown phase;
2. Each TD Combo Buy Countdown low must be less than, or equal to, the low of
the prior price bar;
3. Each TD Combo Buy Countdown close must be less than the previous TD Combo
Buy Countdown close; and
4. Each TD Combo Buy Countdown close must be less than the close of the prior
price bar.
However, for TD Combo Buy Countdown bars eleven, twelve, and thirteen only,
5. The closes need only be successively lower, and it is not necessary to apply the
more-stringent conditions listed earlier.