|
5 | 5 | //+------------------------------------------------------------------+ |
6 | 6 | #property copyright "Copyright © 2024, EarnForex" |
7 | 7 | #property link "https://www.earnforex.com/metatrader-expert-advisors/ChartPatternHelper/" |
8 | | -#property version "1.14" |
| 8 | +#property version "1.15" |
9 | 9 | #property strict |
10 | 10 |
|
11 | 11 | #include <stdlib.mqh> |
@@ -648,67 +648,83 @@ void AdjustObjects() |
648 | 648 | { |
649 | 649 | if (((HaveBuy) && (!HaveBuyPending))) |
650 | 650 | { |
651 | | - RenameObject(UpperBorderLine); |
652 | | - RenameObject(UpperEntryLine); |
653 | | - RenameObject(EntryChannel); |
| 651 | + if ((ObjectFind(0, UpperBorderLine) >= 0) || (ObjectFind(0, EntryChannel) >= 0)) |
| 652 | + { |
| 653 | + Print("Buy position found, renaming chart objects..."); |
| 654 | + RenameObject(UpperBorderLine); |
| 655 | + RenameObject(UpperEntryLine); |
| 656 | + RenameObject(EntryChannel); |
| 657 | + } |
654 | 658 | if (OneCancelsOther) |
655 | 659 | { |
656 | | - RenameObject(LowerBorderLine); |
657 | | - RenameObject(LowerEntryLine); |
658 | | - RenameObject(BorderChannel); |
| 660 | + if ((ObjectFind(0, LowerBorderLine) >= 0) || (ObjectFind(0, BorderChannel) >= 0)) |
| 661 | + { |
| 662 | + Print("OCO is on, renaming opposite chart objects..."); |
| 663 | + RenameObject(LowerBorderLine); |
| 664 | + RenameObject(LowerEntryLine); |
| 665 | + RenameObject(BorderChannel); |
| 666 | + } |
659 | 667 | } |
660 | 668 | } |
661 | 669 | if (((HaveSell) && (!HaveSellPending))) |
662 | 670 | { |
663 | | - RenameObject(LowerBorderLine); |
664 | | - RenameObject(LowerEntryLine); |
665 | | - RenameObject(EntryChannel); |
| 671 | + if ((ObjectFind(0, LowerEntryLine) >= 0) || (ObjectFind(0, EntryChannel) >= 0)) |
| 672 | + { |
| 673 | + Print("Sell position found, renaming chart objects..."); |
| 674 | + RenameObject(LowerBorderLine); |
| 675 | + RenameObject(LowerEntryLine); |
| 676 | + RenameObject(EntryChannel); |
| 677 | + } |
666 | 678 | if (OneCancelsOther) |
667 | 679 | { |
668 | | - RenameObject(UpperBorderLine); |
669 | | - RenameObject(UpperEntryLine); |
670 | | - RenameObject(BorderChannel); |
| 680 | + if ((ObjectFind(0, UpperBorderLine) >= 0) || (ObjectFind(0, BorderChannel) >= 0)) |
| 681 | + { |
| 682 | + Print("OCO is on, renaming opposite chart objects..."); |
| 683 | + RenameObject(UpperBorderLine); |
| 684 | + RenameObject(UpperEntryLine); |
| 685 | + RenameObject(BorderChannel); |
| 686 | + } |
671 | 687 | } |
672 | 688 | } |
673 | 689 | } |
674 | 690 |
|
675 | 691 | void RenameObject(string Object) |
676 | 692 | { |
677 | | - if (ObjectFind(Object) > -1) // If exists |
| 693 | + if (ObjectFind(0, Object) > -1) // If exists |
678 | 694 | { |
679 | 695 | Print("Renaming ", Object, "."); |
680 | 696 | // Get object's type, price/time coordinates, style properties. |
681 | | - int OT = ObjectType(Object); |
682 | | - double Price1 = ObjectGet(Object, OBJPROP_PRICE1); |
| 697 | + ENUM_OBJECT OT = (ENUM_OBJECT)ObjectGetInteger(0, Object, OBJPROP_TYPE); |
| 698 | + double Price1 = ObjectGetDouble(0, Object, OBJPROP_PRICE, 0); |
683 | 699 | datetime Time1 = 0; |
684 | 700 | double Price2 = 0; |
685 | 701 | datetime Time2 = 0; |
686 | 702 | double Price3 = 0; |
687 | 703 | datetime Time3 = 0; |
688 | 704 | if ((OT == OBJ_TREND) || (OT == OBJ_CHANNEL)) |
689 | 705 | { |
690 | | - Time1 = (datetime)ObjectGet(Object, OBJPROP_TIME1); |
691 | | - Price2 = ObjectGet(Object, OBJPROP_PRICE2); |
692 | | - Time2 = (datetime)ObjectGet(Object, OBJPROP_TIME2); |
| 706 | + Time1 = (datetime)ObjectGetInteger(0, Object, OBJPROP_TIME, 0); |
| 707 | + Price2 = ObjectGetDouble(0, Object, OBJPROP_PRICE, 1); |
| 708 | + Time2 = (datetime)ObjectGetInteger(0, Object, OBJPROP_TIME, 1); |
693 | 709 | if (OT == OBJ_CHANNEL) |
694 | 710 | { |
695 | | - Price3 = ObjectGet(Object, OBJPROP_PRICE3); |
696 | | - Time3 = (datetime)ObjectGet(Object, OBJPROP_TIME3); |
| 711 | + Price3 = ObjectGetDouble(0, Object, OBJPROP_PRICE, 2); |
| 712 | + Time3 = (datetime)ObjectGetInteger(0, Object, OBJPROP_TIME, 2); |
697 | 713 | } |
698 | 714 | } |
699 | | - color Color = (color)ObjectGet(Object, OBJPROP_COLOR); |
700 | | - int Style = (int)ObjectGet(Object, OBJPROP_STYLE); |
701 | | - int Width = (int)ObjectGet(Object, OBJPROP_WIDTH); |
| 715 | + color Color = (color)ObjectGetInteger(0, Object, OBJPROP_COLOR); |
| 716 | + ENUM_LINE_STYLE Style = (ENUM_LINE_STYLE)ObjectGetInteger(0, Object, OBJPROP_STYLE); |
| 717 | + int Width = (int)ObjectGetInteger(0, Object, OBJPROP_WIDTH); |
702 | 718 |
|
703 | 719 | // Delete object. |
704 | | - ObjectDelete(Object); |
705 | | - |
| 720 | + ObjectDelete(0, Object); |
| 721 | + string NewObject = Object + IntegerToString(Magic); |
706 | 722 | // Create the same object with new name and set the old style properties. |
707 | | - ObjectCreate(Object + IntegerToString(Magic), OT, 0, Time1, Price1, Time2, Price2, Time3, Price3); |
708 | | - ObjectSet(Object + IntegerToString(Magic), OBJPROP_COLOR, Color); |
709 | | - ObjectSet(Object + IntegerToString(Magic), OBJPROP_STYLE, Style); |
710 | | - ObjectSet(Object + IntegerToString(Magic), OBJPROP_WIDTH, Width); |
711 | | - ObjectSet(Object + IntegerToString(Magic), OBJPROP_RAY, true); |
| 723 | + ObjectCreate(0, NewObject, OT, 0, Time1, Price1, Time2, Price2, Time3, Price3); |
| 724 | + ObjectSetInteger(0, NewObject, OBJPROP_COLOR, Color); |
| 725 | + ObjectSetInteger(0, NewObject, OBJPROP_STYLE, Style); |
| 726 | + ObjectSetInteger(0, NewObject, OBJPROP_WIDTH, Width); |
| 727 | + ObjectSetInteger(0, NewObject, OBJPROP_RAY, true); |
712 | 728 | } |
713 | 729 | } |
714 | 730 |
|
|
0 commit comments