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 ....
phi1.618 - part 1 dt 16-05-2013 for Amibroker (AFL)
Copy & Paste Friendly
Back
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 | //////////begin///////// box1=0; box2=0; SetBarsRequired (10000,10000); procedure fillDarvas(start,end,swap,top, bottom ) { for ( j = start; j < end; j++) { if ( box1[j] == swap) box1[j]= top ; else box1[j]= bottom; if (box2[j] == swap) box2[j]= bottom ; else box2[j]= top; } } BoxArr1 = 0; BoxArr2 = 0; StateArray = 0; DBuy = 0; DSell = 0; TopArray = 0; BotArray = 0; tick=0; BoxTop = High [0]; BoxBot = Low [0]; swap=0; state = 0; BoxStart = 0; for (i=0; i< BarCount ; i++) { if (state==5) { TopArray[i]=BoxTop; BotArray[i]=BoxBot; if ( Low [i]<(BoxBot*(1-tick/100)) || High [i]>(BoxTop*(1+tick/100))) { fillDarvas(BoxStart,i,swap,BoxTop,BoxBot); state = 1; swap = !swap; BoxTop = High [i]; BoxStart = i; } } else { if ( High [i]<BoxTop) { if ((state<3) || ( Low [i]>BoxBot)) { state++; } else { state=3; } if (state==3) BoxBot= Low [i]; } else { state=1; BoxTop= High [i]; } } StateArray[i] = state; } fillDarvas(BoxStart, BarCount ,swap,BoxTop,BoxBot); Buyrule= H > Ref (box1,-1) AND H > Ref (box2,-1) AND Ref (statearray,-1)==5; Sellrule= L < Ref (box1,-1) AND L < Ref (box2,-1) AND Ref (statearray,-1)==5; _SECTION_BEGIN ( "Darvas box" ); Plot ( C , "" ,1,64); Plot ( box2, "" , 1 + statearray , styleLine ); Plot ( box1, " Status = " + WriteVal (statearray,1.0) , 1 + statearray, styleLine ); _SECTION_END (); Buy = Buyrule; statopt = Optimize ( "statopt var" , 3, 1, 5, 1 ); lossopt= Optimize ( "lossopt var" , 5, 3, 10, 1 ); //statopt=5; //lossopt=7; topvalue= IIf (box1>box2,box1,box2); Sellrule2 = (((topvalue- Close )*100/topvalue) > lossopt) AND (statearray == statopt); Sell = Sellrule OR Sellrule2; Short = Sell ; Cover = Buy ; _SECTION_BEGIN ( "PANEL 25 MURREY MATH" ); ParamShowLevel= ParamList ( "Show harmonic levels" , "1/8|1/4|1/2" , 1 ); ParamShowLabel= ParamStyle ( "Show harmonic labels" , styleNoLabel , styleNoLabel ); if ( Status ( "action" ) ==1) //indicator { LastVisibleIndex = LastValue ( Status ( "lastvisiblebarindex" )); if (LastVisibleIndex > BarCount -1) //to avoid errors is case of cursor is behind the last bar LastVisibleIndex = BarCount -1; TotalVisibleBars = LastVisibleIndex - LastValue ( Status ( "firstvisiblebarindex" )) + 1; } else { LastVisibleIndex = BarCount -1; TotalVisibleBars = BarCount ; } HHScreen = HHV ( High , TotalVisibleBars); LLScreen = LLV ( Low , TotalVisibleBars); PRScreen = HHScreen[LastVisibleIndex] - LLScreen[LastVisibleIndex]; //Price range PriceRangeVisible = PRScreen * 1.1; MiddleVisible = (HHScreen[LastVisibleIndex] + LLScreen[LastVisibleIndex]) /2; HighestVisible= MiddleVisible + PriceRangeVisible / 2; LowestVisible = MiddleVisible - PriceRangeVisible / 2; SquareBase = 0.1953125; if (HighestVisible > 0.390625) { SquareBase = 1.5625; } if (HighestVisible > 1.5625) { SquareBase = 3.125; } if (HighestVisible > 3.125) { SquareBase = 6.25; } if (HighestVisible > 6.25) { SquareBase = 12.5; } if (HighestVisible > 25) { SquareBase = 100; } if (HighestVisible > 250) { SquareBase = 1000; } if (HighestVisible > 2500) { SquareBase = 10000; } if (HighestVisible > 25000) { SquareBase = 100000; } ShowLevel = 1; PriceStep = SquareBase / 8; while ( PriceRangeVisible / 4 <= PriceStep AND ShowLevel < 4) { PriceStep = PriceStep / 8; ShowLevel++; } //Lowest,highest harmonic value to show on the panel LowerValue = floor (LowestVisible / PriceStep) * PriceStep; HigherValue = ceil (HighestVisible / PriceStep) * PriceStep; Octave1PriceStep = SquareBase / 8; Octave2PriceStep = SquareBase / 64 ; Octave3PriceStep = SquareBase / 512; Harmonic = LowerValue; //iterate from low to high values while ( Harmonic <= HigherValue ) { style = styleDashed ; // 1/8, 3/8, 5/8, 7/8 lines of any level color = colorBlue ; //1/8, 7/8 if ((Harmonic / PriceStep) % 8 == 1 OR (Harmonic / PriceStep) % 8 == 7) color = colorBlue ; // 3/8, 5/8 if (ParamShowLevel != "1/8" ) style = styleNoLine ; if ((Harmonic / PriceStep) % 2 == 0) // 1/4, 3/4 lines of any level { style = styleLine ; color = colorBlack ; if (ParamShowLevel == "1/2" ) style = styleNoLine ; } if ((Harmonic / PriceStep) % 4 == 0) // 1/2 line of any level { style = styleDots ; color = colorViolet ; } if ((Harmonic / PriceStep) % 8 == 0) // 1/1 line of Baby level { color = colorDarkYellow ; style = styleDots ; if ((Harmonic / Octave3PriceStep) % 64 == 0) // 1/1 line of Minor level { style = styleDots ; // 1/1 /Level Minor } } if (style != styleNoLine ) //if there is a line to plot... (avoid printing unused labels) { style = style + ParamShowLabel; Plot ( Harmonic, "" , color, style); } Harmonic = Harmonic + PriceStep; } _SECTION_END (); _SECTION_BEGIN ( "NICK MA Swing" ); SetBarsRequired (200,0); GraphXSpace = 5; SetChartOptions (0, chartShowArrows | chartShowDates ); k = Optimize ( "K" , Param ( "K" ,1,0.25,5,0.25),0.25,5,0.25); Per= Optimize ( "atr" , Param ( "atr" ,4,3,20,1),3,20,1); HACLOSE=( O + H + L + C )/4; HaOpen = AMA ( Ref ( HaClose, -1 ), 0.5 ); HaHigh = Max ( H , Max ( HaClose, HaOpen ) ); HaLow = Min ( L , Min ( HaClose, HaOpen ) ); j=Haclose; //======================================================================================================================= //=========================Indicator============================================================================================== f= ATR (14); rfsctor = WMA ( H - L , Per); revers = k * rfsctor; Trend = 1; NW[0] = 0; for (i = 1; i < BarCount ; i++) { if (Trend[i-1] == 1) { if (j[i] < NW[i-1]) { Trend[i] = -1; NW[i] = j[i] + Revers[i]; } else { Trend[i] = 1; if ((j[i] - Revers[i]) > NW[i-1]) { NW[i] = j[i] - Revers[i]; } else { NW[i] = NW[i-1]; } } } if (Trend[i-1] == -1) { if (j[i] > NW[i-1]) { Trend[i] = 1; NW[i] = j[i] - Revers[i]; } else { Trend[i] = -1; if ((j[i] + Revers[i]) < NW[i-1]) { NW[i] = j[i] + Revers[i]; } else { NW[i] = NW[i-1]; } } } } //===============system================ Buy = Cover = Cross (j,nw); Sell = Short = Cross (nw,j); SellPrice = ValueWhen ( Sell , C ,1); BuyPrice = ValueWhen ( Buy , C ,1); Long= Flip ( Buy , Sell ); Shrt= Flip ( Sell , Buy ); _SECTION_END (); //=================TITLE================================================================================================ _SECTION_BEGIN ( "Title" ); if ( Status ( "action" ) == actionIndicator ) ( EncodeColor ( colorLime )+ WriteIf ( Buy , " GO LONG / Reverse Signal at " + C + " " , "" )+ WriteIf ( Sell , " EXIT LONG / Reverse Signal at " + C + " " , "" )+ "\n" + EncodeColor ( colorWhite )+ WriteIf ( Sell , "Total Profit/Loss for the Last Trade Rs." +( C - BuyPrice )+ "" , "" )+ WriteIf ( Buy , "Total Profit/Loss for the Last trade Rs." +( SellPrice - C )+ "" , "" )+ WriteIf (Long AND NOT Buy , "Trade : Long - Entry price Rs." +( BuyPrice ), "" )+ WriteIf (shrt AND NOT Sell , "Trade : Short - Entry price Rs." +( SellPrice ), "" )+ "\n" + WriteIf (Long AND NOT Buy , "Current Profit/Loss Rs." +( C - BuyPrice )+ "" , "" )+ WriteIf (shrt AND NOT Sell , "Current Profit/Loss Rs." +( SellPrice - C )+ "" , "" )); PlotShapes ( IIf ( Buy , shapeSquare , shapeNone ), colorGreen , 0, L , Offset=-40); PlotShapes ( IIf ( Buy , shapeSquare , shapeNone ), colorLime , 0, L , Offset=-50); PlotShapes ( IIf ( Buy , shapeUpArrow , shapeNone ), colorWhite , 0, L , Offset=-45); PlotShapes ( IIf ( Sell , shapeSquare , shapeNone ), colorRed , 0, H , Offset=40); PlotShapes ( IIf ( Sell , shapeSquare , shapeNone ), colorOrange , 0, H , Offset=50); PlotShapes ( IIf ( Sell , shapeDownArrow , shapeNone ), colorWhite , 0, H , Offset=-45); _SECTION_END (); _SECTION_BEGIN ( "pivot" ); price = ParamToggle ( "Plot Price" , "Off|On" , 1 ); num = Param ( "trend" , 4, 1, 10, 1 ); dist = 0.5 * ATR ( 10 ); rightfig = Param ( "rightfig " , 7, 1, 10, 1 ); xspace = Param ( "GraphXSpace " , 10, 1, 20, 1 ); mHHV = HHV ( H , num ); mLLV = LLV ( L , num ); FirstVisibleBar = Status ( "FirstVisibleBar" ); Lastvisiblebar = Status ( "LastVisibleBar" ); for ( b = Firstvisiblebar + num; b <= Lastvisiblebar AND b < BarCount - num; b++ ) { i = num; ml = 0; mu = 0; while ( i > 0 ) { if ( L [b] < L [b+i] ) { ml++; } if ( H [b] > H [b+i] ) { mu++; } i--; } if ( ml == num AND L [B] == mLLV[B] ) { PlotText ( "\n *\n" , b, L [b], colorBrightGreen ); if ( price == 1 ) { p = StrRight ( NumToStr ( L [b], 4.1 ), rightfig ); PlotText ( "\n\n" + p, b - 2 , L [b] , colorBrightGreen ); } } if ( mu == num AND H [B] == mHHV[B] ) { PlotText ( " *\n" , b, H [b], colorRed ); if ( price == 1 ) { p = StrRight ( NumToStr ( H [b], 4.1 ), rightfig ); PlotText ( p , b - 2 , H [b] + dist[b] + 1, colorRed ); } } } _SECTION_END (); GraphXSpace = xspace; //ELLIOT Fractals _SECTION_BEGIN ( "Price" ); SetChartOptions (0, chartShowArrows | chartShowDates ); Plot ( C , "Close" , ParamColor ( "Color" , colorBlack ), styleCandle | ParamStyle ( "Style" ) | GetPriceStyle () ); _SECTION_END (); _SECTION_BEGIN ( "ELLIOTT Fractals" ); /* The basic definition of an 'up' fractal is a bar high that is both higher than the two bars immediately preceding it and higher than the two bars immediately following it. The lows of the bars are NOT considered in determining the up fractal progression. If two bars in the progression have equal highs followed by two consecutive bars with lower highs, then a total of six bars rather than the usual five bars will make up the progression. The first High becomes the counting fractal. Reverse for 'down' fractals. The 5 bar formation works best on Daily or longer time frame charts.For intraday data charts we often use 9 bar, 13 bar and 21 bar formations for fractal counting */ Up5BarFractal = Ref ( H ,-2) < H AND Ref ( H ,-1) < H AND Ref ( H ,1) < H AND Ref ( H ,2) < H ; Up6BarFractal = Ref ( H ,-2) < H AND Ref ( H ,-1) < H AND ( H == Ref ( H ,1)) AND Ref ( H ,2) < H AND Ref ( H ,3) < H ; Down5BarFractal = Ref ( L ,-2) > L AND Ref ( L ,-1) > L AND Ref ( L ,1) > L AND Ref ( L ,2) > L ; Down6BarFractal = Ref ( L ,-2) > L AND Ref ( L ,-1) > L AND ( L == Ref ( L ,1)) AND Ref ( L ,2) > L AND Ref ( L ,3) > L ; //TODO: More filtering: Show only troughs that are around atrough in trix(9). Up = (Up5BarFractal OR Up6BarFractal); Down = (Down5BarFractal OR Down6BarFractal); //Removing false fractals: DownSignal = Flip ( Ref (Up,-1), Ref (Down,-1)); UpSignal = Flip ( Ref (Down,-1), Ref (Up,-1)); LastHigh[0] = H [0]; LastLow[0] = L [0]; LastLowIndex = 0; LastHighIndex = 0; Valid = 0; for (i=1; i < BarCount ; i++) { LastHigh[i] = LastHigh[i-1]; LastLow[i] = LastLow[i-1]; if (Up[i]) { Valid[i] = True ; if (DownSignal[i]) { //Sequence of 2 Up Fractals. Validate only the higher one. Valid[i] = H [i] >= H [LastHighIndex]; Valid[LastHighIndex] = H [LastHighIndex] > H [i]; } LastHigh[i] = Max ( H [i], H [LastHighIndex ]); LastHighIndex = i; } if (Down[i]) { Valid[i] = True ; if (UpSignal[i]) { //Sequence of 2 Down Fractals. Validate only the lower one. Valid[i] = L [i] <= L [LastLowIndex]; Valid[LastLowIndex] = L [LastLowIndex] < L [i]; } LastLow[i] = Min ( L [i], L [LastLowIndex]); LastLowIndex = i; } } TrixN = Trix (9); TroughLow = Ref (TrixN, -3) > TrixN AND Ref (TrixN, -2) > TrixN AND Ref (TrixN, -1) > TrixN AND Ref (TrixN, 1) > TrixN AND Ref (TrixN, 2) > TrixN AND Ref (TrixN, 3) > TrixN; TroughHigh = Ref (TrixN, -3) < TrixN AND Ref (TrixN, -2) < TrixN AND Ref (TrixN, -1) < TrixN AND Ref (TrixN, 1) < TrixN AND Ref (TrixN, 2) < TrixN AND Ref (TrixN, 3) < TrixN; //TroughLow = Ref(TrixN, -2) > TrixN AND Ref(TrixN, -1) > TrixN AND Ref(TrixN, 1) > TrixN AND Ref(TrixN, 2) > TrixN; //TroughHigh = Ref(TrixN, -2) < TrixN AND Ref(TrixN, -1) < TrixN AND Ref(TrixN, 1) < TrixN AND Ref(TrixN, 2) < TrixN; ZeroValid = Cross (TrixN, 0) OR Cross (0, TrixN) OR Ref ( Cross (TrixN, 0),1) OR Ref ( Cross (0, TrixN),1); ValidLow = TroughLow OR Ref (TroughLow, 1) OR Ref (TroughLow, 2) OR Ref (TroughLow, 3) OR Ref (TroughLow, 4); // OR Ref(TroughLow, 5)); ValidHigh = TroughHigh OR Ref (TroughHigh, 1) OR Ref (TroughHigh, 2) OR Ref (TroughHigh, 3) OR Ref (TroughHigh, 4); // OR Ref(TroughHigh, 5)); //Plot(LastHigh-10 ,"LastHigh", colorBlue, styleLine); //Plot(LastLow-10 ,"LastLow ", colorRed, styleLine); //Plot(Valid*5 + 10 ,"LastLow ", colorGreen, styleLine | styleThick); //PlotShapes( IIf(Down AND Valid,shapeSmallUpTriangle,0) ,colorGreen, 0, L,-12); //PlotShapes( IIf(Up AND Valid,shapeSmallDownTriangle,0) ,colorRed, 0, H,-12); Maxi = Up AND (ValidHigh OR ZeroValid); Mini = Down AND (ValidLow OR ZeroValid); PlotShapes ( IIf (Down AND (ValidLow OR ZeroValid), shapeSmallUpTriangle ,0) , colorBrightGreen , 0, L ,-12); PlotShapes ( IIf (Up AND (ValidHigh OR ZeroValid), shapeSmallDownTriangle ,0) , colorRed , 0, H ,-12); AlertIf (Down AND (ValidLow OR ZeroValid), "SOUND C:\\Windows\\Media\\Chord.wav" , "Audio alert" , 2); AlertIf (Up AND (ValidHigh OR ZeroValid), "SOUND C:\\Windows\\Media\\Ding.wav" , "Audio alert" , 2); //Plot(UpSignal*3+5,"UpSignal", colorBlue, styleLine| styleThick); //Plot(DownSignal*3 ,"DownSignal", colorRed, styleLine| styleThick); /* LastMaxi = 0; LastMini = 0; ElliotLines = 0; State = 0; for (i=1; i < BarCount; i++) { State[i] = State[i-1]; if (Maxi[i]) { State[i] = 1;//down } if (Mini[i]) { State[i] = 2; } } PlotShapes(IIf(State > 0, shapeSmallCircle, 0), IIf(State == 1, colorRed, colorBlue), 0, IIf(State == 1, H, L), -5); */ //Line = LineArray( x0, y0, x1, y1, 1 ); //Plot( Line, "Trend line", colorBlue ); /* Wave B Usually 50% of Wave A Should not exceed 75% of Wave A Wave C either 1 x Wave A or 1.62 x Wave A or 2.62 x Wave A */ function CorrectiveRatios(StartPrice, A, B, C , RatioDelta, Delta) { ALength = abs (startPrice - A); BLength = abs (A-B); CLength = abs (B- C ); Ratio1 = BLength / CLength ; Cond1 = Ration1 >= 0.5 - RatioDelta AND ratio1 <= 0.75 + RatioDelta; Cond2 = abs (Clength - ALength) < Delta OR abs (Clength - 1.62 * ALength) < Delta OR abs (CLength - 2.62 * ALength) < Delta; return Cond1 AND Cond2; } function ImpulseRules(StartPrice, One, Two, Three, Four, Five) { //Wave 2 should be beneath wave 1 start: Cond1 = Two > StartPrice AND Two < One; //Wave 4 - the same: Cond2 = Four > Two AND Four < Three; //Wave 5 should be <= wave 3 Cond3 = abs (Three-Two) >= abs (Five - Four); //Wave 1 should be smaller than wave five, making wave 3 the biggest: Cond4 = abs (StartPrice - One) < abs (Five - Four); return Cond1 AND Cond2 AND Cond3 AND Cond4; } _SECTION_END (); _SECTION_BEGIN ( "Marva Mid R-Line Signal" ); x = Cum (1); lastx = LastValue ( x ); Daysback = 10; aa = LastValue ( LinRegIntercept ( Close , Daysback) ); bb = LastValue ( LinRegSlope ( Close , Daysback ) ); y = Aa + bb * ( x - (Lastx - DaysBack) ); //Plot( Close, "Close", colorRose, styleCandle ); per1= Param ( "per1" , 0.325,0.1,50,0.10); perc=per1; x1= BarIndex ();xx= SelectedValue (x); t1= SelectedValue ( ValueWhen ( PeakBars ( C ,perc)==0,x)) ; H1= SelectedValue ( ValueWhen ( PeakBars ( C ,perc)==0, C )) ; t11= SelectedValue ( ValueWhen ( TroughBars ( C ,perc)==0, x)); H11= SelectedValue ( ValueWhen ( TroughBars ( C ,perc)==0, C )); g=t1>t11; shape= IIf (g,shapeHollowDownTriangle*(x==t1),shapeHollowUpTriangle*(x ==t11)); Color= IIf (g, colorRed , colorBrightGreen ); PlotShapes (shape,color); _SECTION_END (); _SECTION_BEGIN ( "A24" ); //Shortavg=Param("Short average",13,5,25,2); Longavg= Param ( "Long average" ,13,5,80,2); TrendAvg= Param ( "Trender average" ,21,5,100,3); Dix = Param ( "Directional Index" ,14,5,25,1); Oversold = Param ( "Oversold" , 50, 20, 70, 5 ); Overbot = Param ( "Overbot" , 50, 50, 100, 5 ); ADXThreshold = Param ( "ADXThreshold" ,15,5,25,1); //MACD// FAST = Param ( "FAST" ,12,0,100,1); SLOW = Param ( "SLOW" ,26,0,100,1); SIG = Param ( "SIG" ,5,0,100,1); MACDLine = MACD (FAST,SLOW); MACDSignal = Signal (FAST,SLOW,SIG); //Trendscore// TrendScore = IIf ( C >= Ref ( C ,-13),1,-1)+ IIf ( C >= Ref ( C ,-14),1,-1)+ IIf ( C >= Ref ( C ,-15),1,-1)+ IIf ( C >= Ref ( C ,-16),1,-1)+ IIf ( C >= Ref ( C ,-17),1,-1)+ IIf ( C >= Ref ( C ,-18),1,-1)+ IIf ( C >= Ref ( C ,-19),1,-1)+ IIf ( C >= Ref ( C ,-20),1,-1)+ IIf ( C >= Ref ( C ,-21),1,-1)+ IIf ( C >= Ref ( C ,-22),1,-1); /////////////////AROON//////////////////// Period = 14; LLVBarsSince = LLVBars ( L , Period) + 1; HHVBarsSince = HHVBars ( H , Period) + 1; AroonDn = 100 * (Period - LLVBarsSince) / (Period - 1); AroonUp = 100 * (Period - HHVBarsSince) / (Period - 1); ///Buy and cover// Buy = Cross ( C , EMA ( C ,Longavg)) //AND (C>=EMA(C,TrendAvg)) AND ( ADX (Dix) > ADXThreshold) AND PDI (Dix)> MDI (Dix) //AND MACDLine>MACDSignal; AND ( RSI (14)>Oversold); //AND AroonUp>30; Cover = C > EMA ( C ,Longavg) AND RSI (14)>Oversold; //Short AND Sell// Short = Cross ( EMA ( C ,Longavg), C ) //AND (C<=EMA(C,TrendAvg)) AND ( ADX (Dix) > ADXThreshold) AND PDI (Dix)> MDI (Dix) //AND MACDLine<MACDSignal; AND ( RSI (14)<Overbot); //AND AroonDn>30; Sell = C < EMA ( C ,Longavg) AND RSI (14)<Overbot; Buy = ExRem ( Buy , Sell ); Sell = ExRem ( Sell , Buy ); Cover = ExRem ( Cover , Short ); Short = ExRem ( Short , Cover ); PlotShapes ( Buy * shapeUpArrow , colorLime , 0, L , Offset = -20); PlotShapes ( Sell *shapeHollowDownArrow, colorOrange , 0, H , Offset = -10); PlotShapes ( Short * shapeDownArrow , colorRed , 0, H , Offset = -20); PlotShapes ( Cover * shapeHollowUpArrow , colorGreen , 0, L , Offset = -10); PositionSize = -20; //StopAmount = 10 * ATR( 20 ); //ApplyStop( 0, 2, StopAmount, 1 ); //AND (ADX (Dix) < 50) // trendscore>5; // AND trendscore>5 _SECTION_END (); _SECTION_BEGIN ( "SAR" ); acc = Param ( "Acceleration" , 0.02, 0, 1, 0.001 ); accm = Param ( "Max. acceleration" , 0.2, 0, 1, 0.001 ); Plot ( SAR ( acc, accm ), _DEFAULT_NAME (), ParamColor ( "Color" , colorCycle ), ParamStyle ( "Style" , styleDots | styleNoLine , maskDefault | styleDots | styleNoLine ) ); if ( Status ( "action" ) == actionCommentary ) { printf ( "The Parabolic SAR provides excellent exit points. You should Close long positions when the price falls below the SAR AND Close Short positions when the price rises above the SAR." ); } _SECTION_END (); _SECTION_BEGIN ( "Gartley" ); GBmin = Param ( "Swing B Min." ,0.55,0.3,1,0.01); GBmax = Param ( "Swing B Max." ,0.72,0.4,1,0.01); GCmin = Param ( "Swing C Min." ,0.38,0.3,1.27,0.01); GCmax = Param ( "Swing C Max." ,1.0,0.4,1.27,0.01); GDmin = Param ( "Swing D Min.(XA)" ,0.55,0.3,1,0.01); GDmax = Param ( "Swing D Max.(XA)" ,1.0,0.4,1.0,0.01); _SECTION_END (); _SECTION_BEGIN ( "Bat" ); BatBmin = Param ( "Swing B Min." ,0.38,0.3,1,0.01); BatBmax = Param ( "Swing B Max." ,0.55,0.4,1,0.01); BatCmin = Param ( "Swing C Min." ,0.38,0.3,1.62,0.01); BatCmax = Param ( "Swing C Max." ,1.27,0.4,1.62,0.01); BatDmin = Param ( "Swing D Min.(XA)" ,0.5,0.3,1,0.01); BatDmax = Param ( "Swing D Max.(XA)" ,1.0,0.4,1.0,0.01); _SECTION_END (); _SECTION_BEGIN ( "Butterfly" ); BtBmin = Param ( "Swing B Min." ,0.55,0.3,1,0.01); BtBmax = Param ( "Swing B Max." ,0.9,0.4,1,0.01); BtCmin = Param ( "Swing C Min." ,0.38,0.3,1.62,0.01); BtCmax = Param ( "Swing C Max." ,1.27,0.4,1.62,0.01); BtDmin = Param ( "Swing D Min.(XA)" ,1,1,1.8,0.01); BtDmax = Param ( "Swing D Max.(XA)" ,1.8,1,1.8,0.01); // Max XA of Butterfly = (1.0 - 1.618) _SECTION_END (); _SECTION_BEGIN ( "Crab" ); CBmin = Param ( "Swing B Min." ,0.38,0.3,1,0.01); CBmax = Param ( "Swing B Max." ,0.65,0.4,1,0.01); CCmin = Param ( "Swing C Min." ,0.38,0.3,1.62,0.01); CCmax = Param ( "Swing C Max." ,1.270,0.4,1.62,0.01); CDmin = Param ( "Swing D Min.(XA)" ,1.25,1,1.8,0.01); CDmax = Param ( "Swing D Max.(XA)" ,1.8,1,2,0.01); _SECTION_END (); _SECTION_BEGIN ( "AB=CD" ); abcd_Cmin = Param ( "Swing C Min." ,0.3, 0.3 , 1, 0.01); abcd_Cmax = Param ( "Swing C Max." ,0.8, 0.8 , 1, 0.01); abcd_Dmin = Param ( "Swing D Min." ,1.2, 1, 2.7, 0.01); abcd_Dmax = Param ( "Swing D Max." ,3.7, 1, 4, 0.01); _SECTION_END (); _SECTION_BEGIN ( "Patterns" ); //strength = Param("Strength",5,2,15,1); // Best use: 3, 4, 5 strength = Param ( "BARS of each LINE" ,5,2,15,1); // So luong bar cho moi duong XA, AB, BC, bu = ParamToggle ( "Bullish Pattern" , "Off|On" ,1); // So bar/lines se quyet dinh. mo^ hinh` duoc ve the' nao` be = ParamToggle ( "Bearish Pattern" , "Off|On" ,1); bi = Cum (1)-1; function GetTop(bars) // Lay' gia' tri cao nhat' = di?nh { Top = H == HHV ( H ,2*bars) AND Ref ( HHV ( H ,bars),bars) < H ; Top = Top AND LastValue (bi)- ValueWhen (Top,bi) > bars; return Top; } function GetValley(bars) // La'y gia tri thap' nhat' = day' { Valley = L == LLV ( L ,2*bars) AND Ref ( LLV ( L ,bars),bars) > L ; Valley = Valley AND LastValue (bi)- ValueWhen (Valley,bi) > bars; return Valley; } // Build fractals array P1 = GetTop(strength); // so' bar cho 1 duong` XA, AB, BC, CD V1 = GetValley(Strength); P1 = IIf (P1, IIf ( ValueWhen (P1,bi,2) < ValueWhen (V1,bi),P1, IIf ( ValueWhen (P1, H ,2) > H , False ,P1)),P1); P1 = IIf (P1 AND ValueWhen (P1,bi,0) > bi, IIf ( ValueWhen (P1,bi,0) < ValueWhen (V1,bi,0), IIf ( ValueWhen (P1, H ,0) >= H , False ,P1),P1),P1); V1 = IIf (V1, IIf ( ValueWhen (V1,bi,2) < ValueWhen (P1,bi),V1, IIf ( ValueWhen (V1, L ,2)< L , False ,V1)),V1); V1 = IIf (V1 AND ValueWhen (V1,bi,0) > bi , IIf ( ValueWhen (V1,bi,0) < ValueWhen (P1,bi,0), IIf ( ValueWhen (V1, L ,0) <= L , False ,V1),V1),V1); P1H1 = ValueWhen (P1, H ); P1Bar1 = ValueWhen (P1,bi); P1H2 = ValueWhen (P1, H ,2); P1Bar2 = ValueWhen (P1,bi,2); V1L1 = ValueWhen (V1, L ); V1Bar1 = ValueWhen (V1,bi); V1L2 = ValueWhen (V1, L ,2); V1Bar2 = ValueWhen (V1,bi,2); //============================================ // BULLISH PATTERNS //============================================ /* Mo hinh Bullish: A = P1H2 B = V1L1 C = P1H1 X = V1L2 */ PTvalid = (P1Bar1 > V1Bar1 AND V1Bar1 > P1Bar2 AND P1bar2 > V1Bar2) AND P1; // Peaks and troughs are in order myAX = P1H2-V1L2; myAB = P1H2-V1L1; myBC = P1H1-V1L1; myAB_AX = myAB/ myAX; myBC_AB = myBC/ myAB; BullGartley4 = PTvalid AND ( myAB_AX > GBmin ) AND ( myAB_AX < GBmax ) AND ( myBC_AB > GCMin ) AND ( myBC_AB < GCMax ); BullBat4 = PTvalid AND ( myAB_AX > BatBmin ) AND ( myAB_AX < BatBmax ) AND ( myBC_AB > BatCMin ) AND ( myBC_AB < BatCMax ); BullButterfly4 = PTvalid AND ( myAB_AX > BtBmin ) AND ( myAB_AX < BtBMax ) AND ( myBC_AB > BtCmin ) AND ( myBC_AB < BtCmin ); BullCrab4 = PTvalid AND ( myAB_AX > CBmin ) AND ( myAB_AX < CBmax ) AND ( myBC_AB > CCmin ) AND ( myBC_AB < CCmax ); BullABCD4 = PTvalid AND ( myBC_AB > abcd_Cmin) AND ( myBC_AB < abcd_Cmax ); strPattern = "" ; //================================================== // BULLISH ABCD // Bullish pattern found. D retracement level is not evaluated //================================================== dHigh = HighestSince (BullABCD4, H ); // Tinh' gia' tri min, max cua duong Ad. Duong Ad la duong con cua AD dLow = LowestSince (BullABCD4, L ); myC = ValueWhen (BullABCD4,P1H1); myB = ValueWhen (BullABCD4,V1L1); myA = ValueWhen (BullABCD4,P1H2); myX = ValueWhen (BullABCD4,V1L2); myCB = myC - myB; my_d_min = myCB * abcd_DMin ; // Tinh' gia' tri cua duong Ad con. Khi gia' giam? tu` tre^n xuong' thi` max -> min my_d_max = myCB * abcd_DMax ; my_Cd_min = myC - my_d_min; // Khoang dich chuyen cua duong Ad con. my_Cd_max = myC - my_d_max; BullABCD = IIf ( ( dLow < my_Cd_min ) AND ( dLow > my_Cd_max ) AND ( dHigh <= myC ) AND ( dLow == L ), True , False ); BullABCD = BullABCD AND (dLow < myB); //================================================== // BULLISH GARTLEY //================================================== dHigh = HighestSince (BullGartley4, H ); // Tinh' gia' tri min, max cua duong Ad. Duong Ad la duong con cua AD dLow = LowestSince (BullGartley4, L ); myC = ValueWhen (BullGartley4,P1H1); myB = ValueWhen (BullGartley4,V1L1); myA = ValueWhen (BullGartley4,P1H2); myX = ValueWhen (BullGartley4,V1L2); myAX = myA - myX; my_d_min = myAX * GDmin; // Tinh' gia' tri cua duong Ad con. Khi gia' giam? tu` tre^n xuong' thi` max -> min my_d_max = myAX * GDMax; my_Ad_min = myA - my_d_min; // Khoang dich chuyen cua duong Ad con. my_Ad_max = myA - my_d_max; BullGartley = IIf ( ( dLow < my_Ad_min ) AND ( dLow > my_Ad_max ) AND ( dHigh <= myC ) AND ( dLow == L ), True , False ); BullGartley = BullGartley AND (dLow < myB); // diem D thap' hon B strPattern = WriteIf (BullGartley, "BULLISH GARTLEY" ,strPattern); //================================================== // BULLISH BAT //================================================== dHigh = HighestSince (BullBat4, H ); // Tinh' gia' tri min, max cua duong Ad. Duong Ad la duong con cua AD dLow = LowestSince (BullBat4, L ); myC = ValueWhen (BullBat4,P1H1); myB = ValueWhen (BullBat4,V1L1); myA = ValueWhen (BullBat4,P1H2); myX = ValueWhen (BullBat4,V1L2); myAX = myA - myX; my_d_min = myAX * BatDmin; // Tinh' gia' tri cua duong Ad con. Khi gia' giam? tu` tre^n xuong' thi` max -> min my_d_max = myAX * BatDmax ; my_Ad_min = myA - my_d_min; // Khoang dich chuyen cua duong Ad con. my_Ad_max = myA - my_d_max; BullBat = IIf ( ( dLow < my_Ad_min ) AND ( dLow > my_Ad_max ) AND ( dHigh <= myC ) AND ( dLow == L ), True , False ); BullBat = BullBat AND (dLow < myB); // diem d thap hon diem B strPattern = WriteIf (BullBat, "BULLISH BAT" ,strPattern); //================================================== // BULLISH CRAB - CUA //================================================== dHigh = HighestSince (BullCrab4, H ); // Tinh' gia' tri min, max cua duong Ad. Duong Ad la duong con cua AD dLow = LowestSince (BullCrab4, L ); myC = ValueWhen (BullCrab4,P1H1); myB = ValueWhen (BullCrab4,V1L1); myA = ValueWhen (BullCrab4,P1H2); myX = ValueWhen (BullCrab4,V1L2); myAX = myA - myX; my_d_min = myAX * CDmin ; // Tinh' gia' tri cua duong Ad con. Khi gia' giam? tu` tre^n xuong' thi` max -> min my_d_max = myAX * CDmax ; my_Ad_min = myA - my_d_min; // Khoang dich chuyen cua duong Ad con. my_Ad_max = myA - my_d_max; BullCrab = IIf ( ( dLow < my_Ad_min ) AND ( dLow > my_Ad_max ) AND ( dHigh <= myC ) AND ( dLow == L ), True , False ); BullCrab = BullCrab AND (dLow < myX); // diem D thap' hon X strPattern = WriteIf (BullCrab , "BULLISH CRAB" ,strPattern); //================================================== // BULLISH BUTTTERFLY //================================================== dHigh = HighestSince (BullButterfly4, H ); // Tinh' gia' tri min, max cua duong Ad. Duong Ad la duong con cua AD dLow = LowestSince (BullButterfly4, L ); myC = ValueWhen (BullButterfly4,P1H1); myB = ValueWhen (BullButterfly4,V1L1); myA = ValueWhen (BullButterfly4,P1H2); myX = ValueWhen (BullButterfly4,V1L2); myAX = myA - myX; my_d_min = myAX * BtDmin ; // Tinh' gia' tri cua duong Ad con. Khi gia' giam? tu` tre^n xuong' thi` max -> min my_d_max = myAX * BtDmax ; my_Ad_min = myA - my_d_min; // Khoang dich chuyen cua duong Ad con. my_Ad_max = myA - my_d_max; BullButterfly = IIf ( ( dLow < my_Ad_min ) AND ( dLow > my_Ad_max ) AND ( dHigh <= myC ) AND ( dLow == L ), True , False ); BullButterfly = BullButterfly AND (dLow < myX); // diem D thap' hon X strPattern = WriteIf (BullButterfly , "BULLISH BUTTERFLY" ,strPattern); //========================================================== // VE DUONG CHO MO HINH BULLISH ABCB //========================================================== BullHar4 = BullABCD4; BullHar = BullABCD; Point4 = IIf (BullHar, ValueWhen (BullHar4,bi), Null ); BullHar = IIf (BullHar, IIf (Point4 == ValueWhen (BullHar,point4,0) AND ValueWhen (BullHar,bi,0) > bi , False ,BullHar),BullHar); A = ValueWhen (BullHar4,P1H2); Abar = ValueWhen (BullHar4,P1bar2); B = ValueWhen (BullHar4,V1L1); Bbar = ValueWhen (BullHar4,V1bar1); C1 = ValueWhen (BullHar4,P1H1); C1bar = ValueWhen (BullHar4,P1bar1); D = ValueWhen (BullHar, L ); Dbar = ValueWhen (BullHar,bi); BCdAB = (C1-B)/(A-B); BCdCD = (C1-D)/(C1-B); PlotPattern = Dbar > C1bar; if ( LastValue (PlotPattern) AND bu) { ColorX = colorGreen ; // Ve cac duong AB, BC, CD Plot ( LineArray ( LastValue (Abar), LastValue (A), LastValue (Bbar), LastValue (B)), "" ,ColorX , styleThick ); Plot ( LineArray ( LastValue (Bbar), LastValue (B), LastValue (C1bar), LastValue (C1)), "" ,ColorX , styleThick ); Plot ( LineArray ( LastValue (C1bar), LastValue (C1), LastValue (Dbar), LastValue (D)), "" ,ColorX , styleThick ); Plot ( LineArray ( LastValue (Abar), LastValue (A), LastValue (C1bar), LastValue (C1)), "" ,ColorX , styleDashed ); Plot ( LineArray ( LastValue (Bbar), LastValue (B), LastValue (Dbar), LastValue (D)), "" ,ColorX , styleDashed ); // Ve cac gia tri Fibo PlotText ( NumToStr ( LastValue (BCdAB),1.2),( LastValue (C1bar)+ LastValue (Abar))/2,( LastValue (C1)+ LastValue (A))/2,ColorX ); PlotText ( NumToStr ( LastValue (BCdCD),1.2),( LastValue (Bbar)+ LastValue (Dbar))/2,( LastValue (B)+ LastValue (D))/2,ColorX ); //---------- Viet cac diem X, A, B, C, D: by binhnd--------------------- xlech = 0; ylech = 2; PlotText ( "A" , LastValue (Abar) + xlech, LastValue (A) + ylech, ColorX ); PlotText ( "B" , LastValue (Bbar) + xlech, LastValue (B) - ylech, ColorX ); PlotText ( "C" , LastValue (C1bar) + xlech, LastValue (C1) + ylech, ColorX ); PlotText ( "D" , LastValue (Dbar) + xlech, LastValue (D) - ylech, ColorX ); //--------- Viet thuyet minh mo hinh: by binhnd-------------- if (strPattern!= "" ) { myStr = "Pattern: BULLISH AB=CD" ; toadoX = LastValue (Abar); toadoY = LastValue (D); PlotText (myStr,toadoX,toadoY,ColorX ); } } // end of Ve duong` bullish abcd //========================================================== // VE DUONG CHO MO HINH BULLISH BAT, GARTLEY, BUTTERFLY, CRAB //========================================================== BullHar4 = BullGartley4 OR BullButterfly4 OR BullBat4 OR BullCrab4 ; BullHar = BullGartley OR BullButterfly OR BullBat OR BullCrab; Point4 = IIf (BullHar, ValueWhen (BullHar4,bi), Null ); BullHar = IIf (BullHar, IIf (Point4 == ValueWhen (BullHar,point4,0) AND ValueWhen (BullHar,bi,0) > bi , False ,BullHar),BullHar); X = ValueWhen (BullHar4,V1L2); Xbar = ValueWhen (BullHar4,V1Bar2); A = ValueWhen (BullHar4,P1H2); Abar = ValueWhen (BullHar4,P1bar2); B = ValueWhen (BullHar4,V1L1); Bbar = ValueWhen (BullHar4,V1bar1); C1 = ValueWhen (BullHar4,P1H1); C1bar = ValueWhen (BullHar4,P1bar1); D = ValueWhen (BullHar, L ); Dbar = ValueWhen (BullHar,bi); ABdXA = (A-B)/(A-X); BCdAB = (C1-B)/(A-B); ADdXA = (A-D)/(A-X); BCdCD = (C1-D)/(C1-B); PlotPattern = Dbar > C1bar; if ( LastValue (PlotPattern) AND bu) { ColorX = colorBlue ; // Ve cac duong XA, AB, BC, CD Plot ( LineArray ( LastValue (Xbar), LastValue (X), LastValue (Abar), LastValue (A)), "" ,ColorX, styleThick ); Plot ( LineArray ( LastValue (Abar), LastValue (A), LastValue (Bbar), LastValue (B)), "" ,ColorX, styleThick ); Plot ( LineArray ( LastValue (Bbar), LastValue (B), LastValue (C1bar), LastValue (C1)), "" ,ColorX, styleThick ); Plot ( LineArray ( LastValue (C1bar), LastValue (C1), LastValue (Dbar), LastValue (D)), "" ,ColorX, styleThick ); Plot ( LineArray ( LastValue (Xbar), LastValue (X), LastValue (Bbar), LastValue (B)), "" ,ColorX, styleDashed ); Plot ( LineArray ( LastValue (Xbar), LastValue (X), LastValue (Abar), LastValue (A)), "" ,ColorX, styleThick ); Plot ( LineArray ( LastValue (Abar), LastValue (A), LastValue (C1bar), LastValue (C1)), "" ,ColorX, styleDashed ); Plot ( LineArray ( LastValue (Bbar), LastValue (B), LastValue (Dbar), LastValue (D)), "" ,ColorX, styleDashed ); Plot ( LineArray ( LastValue (Xbar), LastValue (X), LastValue (Dbar), LastValue (D)), "" ,ColorX, styleDashed ); // Ve cac gia tri Fibo PlotText ( NumToStr ( LastValue (ABdXA),1.2),( LastValue (Bbar)+ LastValue (Xbar))/2,( LastValue (B)+ LastValue (X))/2,ColorX); PlotText ( NumToStr ( LastValue (BCdAB),1.2),( LastValue (C1bar)+ LastValue (Abar))/2,( LastValue (C1)+ LastValue (A))/2,ColorX); PlotText ( NumToStr ( LastValue (ADdXA),1.2) ,( LastValue (Dbar)+ LastValue (Xbar))/2,( LastValue (D)+ LastValue (X))/2,ColorX); PlotText ( NumToStr ( LastValue (BCdCD),1.2),( LastValue (Bbar)+ LastValue (Dbar))/2,( LastValue (B)+ LastValue (D))/2,ColorX); //---------- Viet cac diem X, A, B, C, D: by binhnd--------------------- xlech = 0; ylech = 2; PlotText ( "X" , LastValue (Xbar) + xlech, LastValue (X) - ylech, ColorX); PlotText ( "A" , LastValue (Abar) + xlech, LastValue (A) + ylech, ColorX); PlotText ( "B" , LastValue (Bbar) + xlech, LastValue (B) - ylech, ColorX); PlotText ( "C" , LastValue (C1bar) + xlech, LastValue (C1) + ylech, ColorX); PlotText ( "D" , LastValue (Dbar) + xlech, LastValue (D) - ylech, ColorX); //--------- Viet thuyet minh mo hinh: by binhnd-------------- if (strPattern!= "" ) { strPattern = "Pattern: " + strPattern; toadoX = ( LastValue (Dbar)+ LastValue (Xbar))/2; toadoY = ( LastValue (D)+ LastValue (X))/2; PlotText (strPattern,toadoX,toadoY-2,ColorX); } } // end of Ve duong cho cac mo hinh Crab, Butterfly, Bat //============================================================= // BEARISH PATTERNS //============================================================= PTvalid = (V1Bar1 > P1Bar1 AND P1Bar1 > V1Bar2 AND V1Bar2 > P1Bar2) AND V1; /*===================== X = P1H2 Trong mo hinh` bear: Die^m X cao hon diem A. MyAX = X-> A A = V1L2 B = P1H1 C = V1L1 =======================*/ myAX = P1H2-V1L2; myAB = P1H1-V1L2; myBC = P1H1-V1L1; myAB_AX = myAB/ myAX; myBC_AB = myBC/ myAB; BearGartley4 = PTvalid AND ( myAB_AX > GBmin ) AND ( myAB_AX < GBmax ) AND ( myBC_AB > GCMin ) AND ( myBC_AB < GCMax ); BearBat4 = PTvalid AND ( myAB_AX > BatBmin ) AND ( myAB_AX < BatBmax ) AND ( myBC_AB > BatCMin ) AND ( myBC_AB < BatCMax ); BearButterfly4 = PTvalid AND ( myAB_AX > BtBmin ) AND ( myAB_AX < BtBMax ) AND ( myBC_AB > BtCmin ) AND ( myBC_AB < BtCmin ); BearCrab4 = PTvalid AND ( myAB_AX > CBmin ) AND ( myAB_AX < CBmax ) AND ( myBC_AB > CCmin ) AND ( myBC_AB < CCmax ); BearABCD4 = PTvalid AND ( myBC_AB > abcd_Cmin) AND ( myBC_AB < abcd_Cmax ); strPattern = "" ; //========================================================== // BEARISH ABCD // Bearish pattern found. D retracement level is not evaluated //========================================================== dHigh = HighestSince (BearABCD4, H ); // Tinh' gia' tri min, max cua duong Ad. Duong Ad la duong con cua AD dLow = LowestSince (BearABCD4, L ); myA = ValueWhen (BearABCD4,V1L2); myB = ValueWhen (BearABCD4,P1H1); myC = ValueWhen (BearABCD4,V1L1); myCB = myB - myC; my_d_min = myCB * abcd_DMin ; // Tinh' gia' tri cua duong Ad con. Khi gia' giam? tu` tre^n xuong' thi` max -> min my_d_max = myCB * abcd_DMax ; my_Cd_min = myC + my_d_min; // Khoang dich chuyen cua duong Ad con. my_Cd_max = myC + my_d_max; BearABCD = IIf ( ( dHigh > my_Cd_min ) AND ( dHigh < my_Cd_max ) AND ( dLow >= myC ) AND ( dHigh == H ), True , False ); BearABCD = BearABCD AND (dHigh > myB); //============================================================= // BEARISH GARTLEY //============================================================= dHigh = HighestSince (BearGartley4, H ); // Tinh' gia' tri min, max cua duong Ad. Duong Ad la duong con cua AD dLow = LowestSince (BearGartley4, L ); myX = ValueWhen (BearGartley4,P1H2); myA = ValueWhen (BearGartley4,V1L2); myAX = myX - myA; myB = ValueWhen (BearGartley4,P1H1); myC = ValueWhen (BearGartley4,V1L1); my_d_min = myAX * GDmin; // Tinh' gia' tri cua duong Ad con. Khi gia' giam? tu` tre^n xuong' thi` max -> min my_d_max = myAX * GDMax; my_Ad_min = myA + my_d_min; // Khoang dich chuyen cua duong Ad con. my_Ad_max = myA + my_d_max; BearGartley = IIf ( ( dHigh > my_Ad_min ) AND ( dHigh < my_Ad_max ) AND ( dLow >= myC ) AND ( dHigh == H ), True , False ); BearGartley = BearGartley AND (dHigh > myB); // diem D cao hon B strPattern = WriteIf (BearGartley , "BEARISH GARTLEY" ,strPattern); //============================================================= // BEARISH BAT //============================================================= dHigh = HighestSince (BearBat4, H ); // Tinh' gia' tri min, max cua duong Ad. Duong Ad la duong con cua AD dLow = LowestSince (BearBat4, L ); myX = ValueWhen (BearBat4,P1H2); myA = ValueWhen (BearBat4,V1L2); myAX = myX - myA; myB = ValueWhen (BearBat4,P1H1); myC = ValueWhen (BearBat4,V1L1); my_d_min = myAX * BatDmin ; // Tinh' gia' tri cua duong Ad con. Khi gia' giam? tu` tre^n xuong' thi` max -> min my_d_max = myAX * BatDMax ; my_Ad_min = myA + my_d_min; // Khoang dich chuyen cua duong Ad con. my_Ad_max = myA + my_d_max; BearBat = IIf ( ( dHigh > my_Ad_min ) AND ( dHigh < my_Ad_max ) AND ( dLow >= myC ) AND ( dHigh == H ), True , False ); BearBat = BearBat AND (dHigh > myB); // diem D cao hon B strPattern = WriteIf (BearBat , "BEARISH BAT" ,strPattern); //============================================================= // BEARISH BUTTERFLY //============================================================= dHigh = HighestSince (BearButterfly4, H ); // Tinh' gia' tri min, max cua duong Ad. Duong Ad la duong con cua AD dLow = LowestSince (BearButterfly4, L ); myX = ValueWhen (BearButterfly4,P1H2); myA = ValueWhen (BearButterfly4,V1L2); myAX = myX - myA; myB = ValueWhen (BearButterfly4,P1H1); myC = ValueWhen (BearButterfly4,V1L1); my_d_min = myAX * BtDmin ; // Tinh' gia' tri cua duong Ad con. Khi gia' giam? tu` tre^n xuong' thi` max -> min my_d_max = myAX * BtDmax ; my_Ad_min = myA + my_d_min; // Khoang dich chuyen cua duong Ad con. my_Ad_max = myA + my_d_max; BearButterfly = IIf ( ( dHigh > my_Ad_min ) AND ( dHigh < my_Ad_max ) AND ( dLow >= myC ) AND ( dHigh == H ), True , False ); BearButterfly = BearButterfly AND (dHigh > myX); // diem D cao hon X strPattern = WriteIf (BearButterfly , "BEARISH BUTTERFLY" ,strPattern); //============================================================= // BEARISH CRAB //============================================================= dHigh = HighestSince (BearCrab4, H ); // Tinh' gia' tri min, max cua duong Ad. Duong Ad la duong con cua AD dLow = LowestSince (BearCrab4, L ); myX = ValueWhen (BearCrab4,P1H2); myA = ValueWhen (BearCrab4,V1L2); myAX = myX - myA; myB = ValueWhen (BearCrab4,P1H1); myC = ValueWhen (BearCrab4,V1L1); my_d_min = myAX * CDmin ; // Tinh' gia' tri cua duong Ad con. Khi gia' giam? tu` tre^n xuong' thi` max -> min my_d_max = myAX * CDmax ; my_Ad_min = myA + my_d_min; // Khoang dich chuyen cua duong Ad con. my_Ad_max = myA + my_d_max; BearCrab = IIf ( ( dHigh > my_Ad_min ) AND ( dHigh < my_Ad_max ) AND ( dLow >= myC ) AND ( dHigh == H ), True , False ); BearCrab = BearCrab AND (dHigh > myX); // diem D cao hon X strPattern = WriteIf (BearCrab , "BEARISH CRAB" ,strPattern); //========================================================== // VE DUONG CHO MO HINH BEARISH ABCD //========================================================== BearHar4 = BearABCD4; BearHar = BearABCD; Point4 = IIf (BearHar, ValueWhen (BearHar4,bi), Null ); BearHar = IIf (BearHar, IIf (Point4 == ValueWhen (BearHar,point4,0) AND ValueWhen (BearHar,bi,0) > bi , False ,BearHar),BearHar); A = ValueWhen (BearHar4,V1L2); Abar = ValueWhen ( BearHar4,V1bar2); B = ValueWhen (BearHar4,P1H1); Bbar = ValueWhen (BearHar4,P1bar1); C1 = ValueWhen (BearHar4,V1L1); C1bar = ValueWhen (BearHar4,V1bar1); D = ValueWhen (BearHar, H ); Dbar = ValueWhen (BearHar,bi); BCdAB = (B-C1)/(B-A); BCdCD = (D-C1)/(B-C1); PlotPattern = Dbar > C1bar; //--------- Ve duong ------------------ if ( LastValue (Plotpattern) AND be) { ColorX = colorYellow ; // Ve duong AB, BC Plot ( LineArray ( LastValue (Abar), LastValue (A), LastValue (Bbar), LastValue (B)), "" ,ColorX , styleThick ); Plot ( LineArray ( LastValue (Bbar), LastValue (B), LastValue (C1bar), LastValue (C1)), "" ,ColorX , styleThick ); Plot ( LineArray ( LastValue (C1bar), LastValue (C1), LastValue (Dbar), LastValue (D)), "" ,ColorX , styleThick ); Plot ( LineArray ( LastValue (Abar), LastValue (A), LastValue (C1bar), LastValue (C1)), "" ,ColorX , styleDashed ); Plot ( LineArray ( LastValue (Bbar), LastValue (B), LastValue (Dbar), LastValue (D)), "" ,ColorX , styleDashed ); // Viet cac gia tri Fibo tren duong AB, BC PlotText ( NumToStr ( LastValue (BCdAB),1.2),( LastValue (C1bar)+ LastValue (Abar))/2,( LastValue (C1)+ LastValue (A))/2,ColorX ); PlotText ( NumToStr ( LastValue (BCdCD),1.2) ,( LastValue (Dbar)+ LastValue (Bbar))/2,( LastValue (D)+ LastValue (B))/2,ColorX ); //---------- Viet cac diem A, B, C, D: by binhnd--------------------- xlech = -1; ylech = 1; PlotText ( "A" , LastValue (Abar) + xlech, LastValue (A) - ylech, ColorX ); PlotText ( "B" , LastValue (Bbar) + xlech, LastValue (B) + ylech, ColorX ); PlotText ( "C" , LastValue (C1bar) + xlech, LastValue (C1) - ylech, ColorX ); PlotText ( "D" , LastValue (Dbar) + xlech, LastValue (D) + ylech, ColorX ); //--------- Viet thuyet minh mo hinh: by binhnd-------------- if (strPattern!= "" ) { myStr = "Pattern: BEARISH AB=CD" ; toadoaX = LastValue (Abar); toadoY = LastValue (D); PlotText (myStr,toadoaX,toadoY+1,ColorX ); } } // end of VE DUONG CHO MO HINH BEARISH ABCD //========================================================== // VE DUONG CHO MO HINH BEARISH BAT, GARTLEY, BUTTERFLY, CRAB //========================================================== BearHar4 = BearGartley4 OR BearButterfly4 OR BearBat4 OR BearCrab4 ; BearHar = BearGartley OR BearButterfly OR BearBat OR BearCrab ; Point4 = IIf (BearHar, ValueWhen (BearHar4,bi), Null ); BearHar = IIf (BearHar, IIf (Point4 == ValueWhen (BearHar,point4,0) AND ValueWhen (BearHar,bi,0) > bi , False ,BearHar),BearHar); X = ValueWhen (BearHar4,P1H2); Xbar = ValueWhen (BearHar4,P1Bar2); A = ValueWhen (BearHar4,V1L2); Abar = ValueWhen ( BearHar4,V1bar2); B = ValueWhen (BearHar4,P1H1); Bbar = ValueWhen (BearHar4,P1bar1); C1 = ValueWhen (BearHar4,V1L1); C1bar = ValueWhen (BearHar4,V1bar1); D = ValueWhen (BearHar, H ); Dbar = ValueWhen (BearHar,bi); ABdXA = (B-A)/(X-A); BCdAB = (B-C1)/(B-A); ADdXA = (D-A)/(X-A); BCdCD = (D-C1)/(B-C1); PlotPattern = Dbar > C1bar; //--------- Ve duong ------------------ if ( LastValue (Plotpattern) AND be) { ColorX = colorRed ; // Ve duong XA, AB, BC Plot ( LineArray ( LastValue (Xbar), LastValue (X), LastValue (Abar), LastValue (A)), "" ,ColorX , styleThick ); Plot ( LineArray ( LastValue (Abar), LastValue (A), LastValue (Bbar), LastValue (B)), "" ,ColorX , styleThick ); Plot ( LineArray ( LastValue (Bbar), LastValue (B), LastValue (C1bar), LastValue (C1)), "" ,ColorX , styleThick ); Plot ( LineArray ( LastValue (C1bar), LastValue (C1), LastValue (Dbar), LastValue (D)), "" ,ColorX , styleThick ); Plot ( LineArray ( LastValue (Xbar), LastValue (X), LastValue (Bbar), LastValue (B)), "" ,ColorX , styleDashed ); Plot ( LineArray ( LastValue (Xbar), LastValue (X), LastValue (Abar), LastValue (A)), "" ,ColorX , styleThick ); Plot ( LineArray ( LastValue (Abar), LastValue (A), LastValue (C1bar), LastValue (C1)), "" ,ColorX , styleDashed ); Plot ( LineArray ( LastValue (Bbar), LastValue (B), LastValue (Dbar), LastValue (D)), "" ,ColorX , styleDashed ); Plot ( LineArray ( LastValue (Xbar), LastValue (X), LastValue (Dbar), LastValue (D)), "" ,ColorX , styleDashed ); // Viet cac gia tri Fibo tren duong XA, AB, BC PlotText ( NumToStr ( LastValue (ABdXA),1.2),( LastValue (Bbar)+ LastValue (Xbar))/2,( LastValue (B)+ LastValue (X))/2,ColorX ); PlotText ( NumToStr ( LastValue (BCdAB),1.2),( LastValue (C1bar)+ LastValue (Abar))/2,( LastValue (C1)+ LastValue (A))/2,ColorX ); PlotText ( NumToStr ( LastValue (BCdCD),1.2) ,( LastValue (Dbar)+ LastValue (Bbar))/2,( LastValue (D)+ LastValue (B))/2,ColorX ); PlotText ( NumToStr ( LastValue (ADdXA),1.2) ,( LastValue (Dbar)+ LastValue (Xbar))/2,( LastValue (D)+ LastValue (X))/2,ColorX ); //---------- Viet cac diem X, A, B, C, D: by binhnd--------------------- xlech = -1; ylech = 1; PlotText ( "X" , LastValue (Xbar) + xlech, LastValue (X) + ylech, ColorX ); PlotText ( "A" , LastValue (Abar) + xlech, LastValue (A) - ylech, ColorX ); PlotText ( "B" , LastValue (Bbar) + xlech, LastValue (B) + ylech, ColorX ); PlotText ( "C" , LastValue (C1bar) + xlech, LastValue (C1) - ylech, ColorX ); PlotText ( "D" , LastValue (Dbar) + xlech, LastValue (D) + ylech, ColorX ); //--------- Viet thuyet minh mo hinh: by binhnd-------------- if (strPattern!= "" ) { strPattern = "Pattern: " + strPattern; toadoaX = ( LastValue (Dbar)+ LastValue (Xbar))/2; toadoY = ( LastValue (D)+ LastValue (X))/2; PlotText (strPattern,toadoaX,toadoY+1,ColorX ); } } // end of VE DUONG CHO MO HINH BEARISH BAT, GARTLEY, BUTTERFLY, CRAB //================================= // Show diem ho^~ tro. va` khang' cu. ko? //================================= plotFractals = ParamToggle ( "Plot Fractals" , "Off|On" ,1); if (PlotFractals) { PlotShapes ( shapeSmallCircle *P1, colorBlack ,0, H ,10); PlotShapes ( shapeSmallCircle *V1, colorBlue ,0, L ,-10); } //============================================== // DAT DIEU KIEN cho TIM KIEM BULL //============================================== dkBull = False ; ListBull = ParamList ( "Type of Bullish" , "None|AB=CD|Gartley|Butterfly|Bat|Crab|All Patterns" , 6); if ( ListBull == "None" ) dkBull = True ; if ( ListBull == "AB=CD" ) dkBull = BullABCD ; if ( ListBull == "Gartley" ) dkBull = BullGartley ; if ( ListBull == "Butterfly" ) dkBull = BullButterfly ; if ( ListBull == "Bat" ) dkBull = BullBat ; if ( ListBull == "Crab" ) dkBull = BullCrab ; if ( ListBull == "All Patterns" ) dkBull = (BullABCD) OR (BullGartley) OR (BullButterfly ) OR (BullBat ) OR (BullCrab); //============================================== // DAT DIEU KIEN cho TIM KIEM BEAR //============================================== dkBear = False ; ListBear = ParamList ( "Type of Bearish" , "None|AB=CD|Gartley|Butterfly|Bat|Crab|All Patterns" , 0); if ( ListBear == "None" ) dkBear = True ; if ( ListBear == "AB=CD" ) dkBear = BearABCD ; if ( ListBear == "Gartley" ) dkBear = BearGartley ; if ( ListBear == "Butterfly" ) dkBear = BearButterfly ; if ( ListBear == "Bat" ) dkBear = BearBat ; if ( ListBear == "Crab" ) dkBear = BearCrab ; if ( ListBear == "All Patterns" ) dkBear = (BearABCD ) OR (BearGartley ) OR (BearButterfly ) OR (BearBat ) OR (BearCrab ); //=============================== AddColumn ( V , "Volume" ,1.0); Filter = (dkBull) AND (dkBear); _SECTION_BEGIN ( "Kpl System" ); /* my entry is very simple(daily data for trading) kpl system for entry only & exit as follow: 1 st exit at x % from entry price only 1/3 quantity.(ie 1st profit target) 2 nd exit when exit Signal comes from kpl sys remaining 1/3 quantity. 3. scale-in to initial quantity if new kpl Buy Signal comes. re-do above scaling-out & scaling-in till filal exit. 4. final exit all quantity when Close below 21 Day EMA. kpl system code bellow : */ //AFL by Kamalesh Langote. Email:kpl@... no= Param ( "Swing" , 8, 1, 55 ); tsl_col= ParamColor ( "Color" , colorWhite ); res= HHV ( H ,no); sup= LLV ( L ,no); avd= IIf ( C > Ref (res,-1),1, IIf ( C < Ref (sup,-1),-1,0)); avn= ValueWhen (avd!=0,avd,1); tsl= IIf (avn==1,sup,res); Buy = Cover = Cross ( C ,tsl) ; Sell = Short = Cross (tsl, C ) ; Plot (tsl, _DEFAULT_NAME (), tsl_col, styleStaircase ); Buy = ExRem ( Buy , Sell ); Sell = ExRem ( Sell , Buy ); Short = ExRem ( Short , Cover ); Cover = ExRem ( Cover , Short ); PlotShapes ( IIf ( Buy , shapeUpArrow , shapeNone ), colorWhite , 0, Low ,-15); PlotShapes ( IIf ( Sell , shapeDownArrow , shapeNone ), colorYellow , 0, High ,-15); PlotShapes ( IIf ( Cover , shapeHollowCircle , shapeNone ), colorWhite , 0, Close ,0); PlotShapes ( IIf ( Short , shapeHollowCircle , shapeNone ), colorYellow , 0, Close ,0); SetPositionSize (300, spsShares ); ApplyStop (0,1,10,1); //-----------end-------------- Long= Flip ( Buy , Sell ); Shrt= Flip ( Sell , Buy ); BuyPrice = ValueWhen ( Buy , C ); SellPrice = ValueWhen ( Sell , C ); Edc=( WriteIf ( Buy AND Ref (shrt,-1), " BUY @ " + C + " " , "" )+ WriteIf ( Sell AND Ref (Long,-1), " SEll @ " + C + " " , "" )+ WriteIf ( Sell , "Last Trade Profit Rs." +( C - BuyPrice )+ "" , "" )+ WriteIf ( Buy , "Last Trade Profit Rs." +( SellPrice - C )+ "" , "" )); _SECTION_END (); //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx //TRENDING RIBBON // Paste the code below to your price chart somewhere and green ribbon means both // both MACD and ADX trending up so if the red ribbon shows up the MACD and the ADX // are both trending down. _SECTION_BEGIN ( "trending ribbon" ); uptrend= PDI ()> MDI () AND MACD ()> Signal () ; downtrend= MDI ()> PDI () AND Signal ()> MACD () ; Plot ( 2, /* defines the height of the ribbon in percent of pane width */ "" , IIf ( uptrend AND EMA ( C ,50)>= Ref ( EMA ( C ,50),-1), colorLime , IIf ( downtrend OR EMA ( C ,50)< Ref ( EMA ( C ,50),-1), colorRed , colorAqua )), /* choose color */ styleOwnScale | styleArea | styleNoLabel , -0.5, 100 ); _SECTION_END (); //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |