Просмотр исходного кода

ticket # 1483

bos and third condition updated
AhtashamShahzad3 лет назад: 2
Родитель
Сommit
5c3d32641c
2 измененных файлов с 226 добавлено и 143 удалено
  1. BIN
      BOS_CHOCH.ex5
  2. 226 143
      BOS_CHOCH.mq5

+ 226 - 143
BOS_CHOCH.mq5

@@ -64,6 +64,8 @@ int index = 0;
64
 
64
 
65
 string signal = "";
65
 string signal = "";
66
 datetime time_of_candle = 0.0;
66
 datetime time_of_candle = 0.0;
67
+
68
+//double close1 = 0.0;
67
 //+------------------------------------------------------------------+
69
 //+------------------------------------------------------------------+
68
 //| Expert initialization function                                   |
70
 //| Expert initialization function                                   |
69
 //+------------------------------------------------------------------+
71
 //+------------------------------------------------------------------+
@@ -76,11 +78,12 @@ void Bos(int i)
76
 
78
 
77
 
79
 
78
       high = iHigh(Symbol(),PERIOD_CURRENT,high_index);
80
       high = iHigh(Symbol(),PERIOD_CURRENT,high_index);
79
-
80
       high1 = iHigh(Symbol(),PERIOD_CURRENT,i);
81
       high1 = iHigh(Symbol(),PERIOD_CURRENT,i);
81
 
82
 
83
+      double close = iClose(Symbol(),PERIOD_CURRENT,i);
84
+
82
 
85
 
83
-      if(high1 > high)
86
+      if(close > high)
84
         {
87
         {
85
 
88
 
86
          if(object_find("high") > 0)
89
          if(object_find("high") > 0)
@@ -91,6 +94,8 @@ void Bos(int i)
91
 
94
 
92
          high = high1;
95
          high = high1;
93
 
96
 
97
+
98
+
94
          ObjectCreate(0,"high",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),high,iTime(Symbol(),PERIOD_CURRENT,0),high);
99
          ObjectCreate(0,"high",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),high,iTime(Symbol(),PERIOD_CURRENT,0),high);
95
          ObjectSetInteger(0,"high",OBJPROP_RAY_RIGHT,true);
100
          ObjectSetInteger(0,"high",OBJPROP_RAY_RIGHT,true);
96
          ObjectSetInteger(0,"high",OBJPROP_COLOR,clrBlue);
101
          ObjectSetInteger(0,"high",OBJPROP_COLOR,clrBlue);
@@ -105,13 +110,17 @@ void Bos(int i)
105
 
110
 
106
          int count = (high_index-1) - i;
111
          int count = (high_index-1) - i;
107
 
112
 
108
-         for(int j=1; j <= count; j++)
113
+         //Print("count is ",count);
114
+
115
+         for(int j=0; j <= count; j++)
109
            {
116
            {
110
 
117
 
111
             if(checkCandle(high_index-j) == "Bearish")
118
             if(checkCandle(high_index-j) == "Bearish")
112
               {
119
               {
120
+               //Print("bearish candle found and its low is ",low);
113
 
121
 
114
                low =  iLow(Symbol(),PERIOD_CURRENT,high_index-j);
122
                low =  iLow(Symbol(),PERIOD_CURRENT,high_index-j);
123
+               //Print("bearish candle found and its low is ",low);
115
                bearish_found = true;
124
                bearish_found = true;
116
 
125
 
117
 
126
 
@@ -122,7 +131,7 @@ void Bos(int i)
122
          if(bearish_found == true)
131
          if(bearish_found == true)
123
            {
132
            {
124
 
133
 
125
-            for(int k=1; k < count; k++)
134
+            for(int k=0; k <= count; k++)
126
               {
135
               {
127
 
136
 
128
                low1 = iLow(Symbol(),PERIOD_CURRENT,high_index - k);
137
                low1 = iLow(Symbol(),PERIOD_CURRENT,high_index - k);
@@ -130,23 +139,52 @@ void Bos(int i)
130
                  {
139
                  {
131
 
140
 
132
                   low = low1;
141
                   low = low1;
133
-                  index_of_low =high_index- k;
142
+                  index_of_low = high_index- k;
143
+                  bearish_found = false;
144
+
145
+
134
 
146
 
135
                  }
147
                  }
136
               }
148
               }
137
-            if(object_find("low") > 0)
138
-              {
139
-               ObjectDelete(0,"low");
140
 
149
 
150
+
151
+
152
+           }
153
+         if(object_find("low") > 0)
154
+           {
155
+
156
+            if(ObjectDelete(0,"low"))
157
+              {
158
+               Print("object deleted :");
159
+              }
160
+            else
161
+              {
162
+               Print("object deleted error: ",GetLastError());
141
               }
163
               }
142
-            ObjectCreate(0,"low",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,index_of_low),low,iTime(Symbol(),PERIOD_CURRENT,0),low);
143
-            ObjectSetInteger(0,"low",OBJPROP_RAY_RIGHT,true);
144
 
164
 
145
-            ObjectSetInteger(0,"low",OBJPROP_COLOR,clrRed);
146
-            bearish_found = false;
147
 
165
 
148
            }
166
            }
167
+         Print("low value is ", low);
168
+         Print("index of low ",index_of_low);
169
+         Print("time is ", iTime(Symbol(),PERIOD_CURRENT,index_of_low));
170
+         Print("time is ", iTime(Symbol(),PERIOD_CURRENT,0));
171
+
172
+         if(!ObjectCreate(0,"low",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),low,iTime(Symbol(),PERIOD_CURRENT,0),low))
173
+           {
174
+            Print("object created error:",GetLastError());
175
+           }
176
+         //else
177
+           {
178
+            Print("object created ");
179
+           }
180
+         ObjectSetInteger(0,"low",OBJPROP_RAY_RIGHT,true);
181
+
182
+         ObjectSetInteger(0,"low",OBJPROP_COLOR,clrRed);
183
+
184
+
149
 
185
 
186
+         Print("high of uptrend is ", high);
187
+         Print("low of uptrend is ", low);
150
 
188
 
151
 
189
 
152
          high_index = i;
190
          high_index = i;
@@ -162,10 +200,12 @@ void Bos(int i)
162
 
200
 
163
 
201
 
164
       low = iLow(Symbol(),PERIOD_CURRENT,low_index);
202
       low = iLow(Symbol(),PERIOD_CURRENT,low_index);
165
-
166
       low1 = iLow(Symbol(),PERIOD_CURRENT,i);
203
       low1 = iLow(Symbol(),PERIOD_CURRENT,i);
167
 
204
 
168
-      if(low1 < low)
205
+
206
+      double close1 = iClose(Symbol(),PERIOD_CURRENT,i);
207
+
208
+      if(close1 < low)
169
         {
209
         {
170
 
210
 
171
          if(object_find("low") > 0)
211
          if(object_find("low") > 0)
@@ -212,7 +252,7 @@ void Bos(int i)
212
             for(int k=1; k < count; k++)
252
             for(int k=1; k < count; k++)
213
               {
253
               {
214
 
254
 
215
-               high1 = iHigh(Symbol(),PERIOD_CURRENT,low_index - k);
255
+               double high1 = iHigh(Symbol(),PERIOD_CURRENT,low_index - k);
216
                if(high1 >= high)
256
                if(high1 >= high)
217
                  {
257
                  {
218
 
258
 
@@ -236,7 +276,8 @@ void Bos(int i)
236
 
276
 
237
 
277
 
238
 
278
 
239
-
279
+         Print("high is ", high);
280
+         Print("low is ", low);
240
          low_index = i;
281
          low_index = i;
241
 
282
 
242
 
283
 
@@ -531,6 +572,7 @@ void third_Condition(int i)
531
    if(trend == "uptrend")
572
    if(trend == "uptrend")
532
      {
573
      {
533
       low2 = iLow(Symbol(),PERIOD_CURRENT,i);
574
       low2 = iLow(Symbol(),PERIOD_CURRENT,i);
575
+      high2 = iHigh(Symbol(),PERIOD_CURRENT,i);
534
 
576
 
535
       if(low2 < low)
577
       if(low2 < low)
536
         {
578
         {
@@ -551,11 +593,34 @@ void third_Condition(int i)
551
 
593
 
552
          Print("low update due to third condition",low," time of the candle is ",iTime(Symbol(),PERIOD_CURRENT,i));
594
          Print("low update due to third condition",low," time of the candle is ",iTime(Symbol(),PERIOD_CURRENT,i));
553
         }
595
         }
596
+
597
+      if(high2 > high)
598
+        {
599
+         ObjectCreate(0,"line51"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),iHigh(Symbol(),PERIOD_CURRENT,i));
600
+         ObjectSetString(0,"line51"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"3_C");
601
+         high = high2;
602
+         high_index = i;        // addtion to be minus
603
+         if(object_find("high") > 0)
604
+           {
605
+            ObjectDelete(0,"high");
606
+
607
+           }
608
+
609
+         ObjectCreate(0,"high",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),high,iTime(Symbol(),PERIOD_CURRENT,0),high);
610
+         ObjectSetInteger(0,"high",OBJPROP_RAY_RIGHT,true);
611
+
612
+         ObjectSetInteger(0,"high",OBJPROP_COLOR,clrBlue);
613
+
614
+         Print("high update due to third condition",high," time of the candle is ",iTime(Symbol(),PERIOD_CURRENT,i));
615
+        }
616
+
617
+
554
      }
618
      }
555
 
619
 
556
    if(trend == "downtrend")
620
    if(trend == "downtrend")
557
      {
621
      {
558
       high2 = iHigh(Symbol(),PERIOD_CURRENT,i);
622
       high2 = iHigh(Symbol(),PERIOD_CURRENT,i);
623
+      low2 = iLow(Symbol(),PERIOD_CURRENT,i);
559
 
624
 
560
       if(high2 > high)
625
       if(high2 > high)
561
         {
626
         {
@@ -574,6 +639,24 @@ void third_Condition(int i)
574
          ObjectSetInteger(0,"high",OBJPROP_COLOR,clrBlue);
639
          ObjectSetInteger(0,"high",OBJPROP_COLOR,clrBlue);
575
          Print("high update due to third condition",high);
640
          Print("high update due to third condition",high);
576
         }
641
         }
642
+
643
+      if(low2 < low)
644
+        {
645
+         ObjectCreate(0,"line61"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),iLow(Symbol(),PERIOD_CURRENT,i));
646
+         ObjectSetString(0,"line61"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"3_C");
647
+
648
+         low = low2;
649
+         low_index = i;      // addtion to be minus
650
+         if(object_find("low") > 0)
651
+           {
652
+            ObjectDelete(0,"low");
653
+
654
+           }
655
+         ObjectCreate(0,"low",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),low,iTime(Symbol(),PERIOD_CURRENT,0),low);
656
+         ObjectSetInteger(0,"low",OBJPROP_RAY_RIGHT,true);
657
+         ObjectSetInteger(0,"low",OBJPROP_COLOR,clrBlue);
658
+         Print("low update due to third condition",low);
659
+        }
577
      }
660
      }
578
 
661
 
579
   }
662
   }
@@ -608,9 +691,9 @@ void store_value_in_structure(int i,int ind,string signal,datetime time_of_candl
608
 //+------------------------------------------------------------------+
691
 //+------------------------------------------------------------------+
609
 void foo(int value)
692
 void foo(int value)
610
   {
693
   {
611
-   int l = 0;
612
 
694
 
613
-   for(int i=value-1; i > 0; i--)
695
+
696
+   for(int i=value; i > 0; i--)
614
      {
697
      {
615
       //Print("hi");
698
       //Print("hi");
616
       //if(l < 2)
699
       //if(l < 2)
@@ -621,130 +704,130 @@ void foo(int value)
621
          third_Condition(i);
704
          third_Condition(i);
622
 
705
 
623
 
706
 
624
-         if(signal == "buy" || signal == "sell")
625
-           {
626
-            MqlDateTime  sdate,edate;
627
-            datetime time_to_place_trade = 0.0;
628
-
629
-            //Print("time of the candle ", time_of_candle);
630
-
631
-            int current_time_frame = Period();
632
-
633
-            string current_time_frame_String;
634
-
635
-            switch(current_time_frame)
636
-              {
637
-
638
-               case PERIOD_M1:
639
-                  current_time_frame_String = "1 Minute";
640
-                  break;
641
-               case PERIOD_M5:
642
-                  current_time_frame_String = "5 Minutes";
643
-                  break;
644
-               case PERIOD_M15:
645
-                  current_time_frame_String = "15 Minutes";
646
-                  break;
647
-               case PERIOD_M30:
648
-                  current_time_frame_String = "30 Minutes";
649
-                  break;
650
-               case PERIOD_H1:
651
-                  current_time_frame_String = "1 Hour";
652
-
653
-
654
-                  if(TimeToStruct(time_of_candle,edate))
655
-                    {
656
-                     edate.hour = edate.hour + 2;
657
-                     edate.min  = 0;
658
-                     edate.sec  = 0;
659
-                    }
660
-
661
-
662
-                  // Print("hour of the candle is ",StructToTime(edate));
663
-                  time_to_place_trade = StructToTime(edate);
664
-
665
-                  store_value_in_structure(i,ind,signal,time_of_candle,time_to_place_trade);
666
-
667
-                  //                  for(int m=0; m < orderNum; m++)
668
-                  //                    {
669
-                  //                     if(od_1[m].choch_index != -1)
670
-                  //                       {
671
-                  //                       Print("     time to match the condition : ",TimeCurrent());
672
-                  //
673
-                  //                        if(TimeCurrent() > od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "buy")
674
-                  //                          {
675
-                  //                          Print("time to match the condition : ",TimeCurrent());
676
-                  //
677
-                  //                           //if(iHigh(Symbol(),PERIOD_CURRENT,od_1[m].reversal_index) > iLow(Symbol(),PERIOD_CURRENT,0) && iClose(Symbol(),PERIOD_CURRENT,od_1[m].choch_index) < iClose(Symbol(),PERIOD_CURRENT,0))
678
-                  //                             {
679
-                  //                              ObjectCreate(0,"buy trade"+time_to_place_trade,OBJ_ARROW_BUY,0,time_to_place_trade,iHigh(Symbol(),PERIOD_CURRENT,0));
680
-                  //                              Print("trade placed buy at index ",0);
681
-                  //                              od_1[m].choch_index = -1;
682
-                  //
683
-                  //                             }
684
-                  //                           Print("   time to take trade is ",od_1[m].Time_of_candle_For_trade);
685
-                  //
686
-                  //
687
-                  //                          }
688
-                  //
689
-                  //                        if(TimeCurrent() >= od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "sell")
690
-                  //                          {
691
-                  //                          Print(TimeCurrent());
692
-                  //                           //
693
-                  //                           Print("  time to take trade is ",od_1[m].Time_of_candle_For_trade);
694
-                  //                           od_1[m].choch_index = -1;
695
-                  //
696
-                  //                          }
697
-                  //                       }
698
-                  //                    }
699
-
700
-
701
-
702
-                  //                  if(TimeCurrent() >= time_to_place_trade)
703
-                  //                    {
704
-                  //                     Print("hi");
705
-                  //                     if(signal == "buy")
706
-                  //                       {
707
-                  //                        int index = iBarShift(Symbol(), PERIOD_CURRENT, time_of_candle, false);
708
-                  //                        Print("index of the 2 hour plus index is ",index);
709
-                  //
710
-                  //                        Print("choch index ", i);
711
-                  //                        Print("reversal index ",ind);
712
-                  //                        Print("value to be check index ",i-3);
713
-                  //
714
-                  //                        //if(iHigh(Symbol(),PERIOD_CURRENT,ind) > iLow(Symbol(),PERIOD_CURRENT,i-2) && iClose(Symbol(),PERIOD_CURRENT,i) < iClose(Symbol(),PERIOD_CURRENT,i-2))
715
-                  //                        //  {
716
-                  //                        //   ObjectCreate(0,"buy trade"+time_to_place_trade,OBJ_ARROW_BUY,0,time_to_place_trade,iHigh(Symbol(),PERIOD_CURRENT,i-3));
717
-                  //                        //   Print("trade placed buy at index ",i-3);
718
-                  //                        //  }
719
-                  //                        Print(time_to_place_trade);
720
-                  //
721
-                  //                       }
722
-                  //                     if(signal == "sell")
723
-                  //                       {
724
-                  //                        Print("trade placed ");
725
-                  //                        ObjectCreate(0,"sell trade"+time_to_place_trade,OBJ_ARROW_SELL,0,time_to_place_trade,iLow(Symbol(),PERIOD_CURRENT,i-3));
726
-                  //
727
-                  //                        Print(ind);
728
-                  //                        Print(time_to_place_trade);
729
-                  //                       }
730
-                  //                    }
731
-                  //                  else
732
-                  //                    {
733
-                  //                     time_of_candle = iTime(Symbol(),PERIOD_CURRENT,i);
734
-                  //                    }
735
-
736
-                  break;
737
-
738
-               default:
739
-                  current_time_frame_String = "Unknown";
740
-                  break;
741
-              }
742
-
743
-            //Print("Current Timeframe: ", current_time_frame_String);
744
-
745
-
746
-            signal = "";
747
-           }
707
+         //         if(signal == "buy" || signal == "sell")
708
+         //           {
709
+         //            MqlDateTime  sdate,edate;
710
+         //            datetime time_to_place_trade = 0.0;
711
+         //
712
+         //            //Print("time of the candle ", time_of_candle);
713
+         //
714
+         //            int current_time_frame = Period();
715
+         //
716
+         //            string current_time_frame_String;
717
+         //
718
+         //            switch(current_time_frame)
719
+         //              {
720
+         //
721
+         //               case PERIOD_M1:
722
+         //                  current_time_frame_String = "1 Minute";
723
+         //                  break;
724
+         //               case PERIOD_M5:
725
+         //                  current_time_frame_String = "5 Minutes";
726
+         //                  break;
727
+         //               case PERIOD_M15:
728
+         //                  current_time_frame_String = "15 Minutes";
729
+         //                  break;
730
+         //               case PERIOD_M30:
731
+         //                  current_time_frame_String = "30 Minutes";
732
+         //                  break;
733
+         //               case PERIOD_H1:
734
+         //                  current_time_frame_String = "1 Hour";
735
+         //
736
+         //
737
+         //                  if(TimeToStruct(time_of_candle,edate))
738
+         //                    {
739
+         //                     edate.hour = edate.hour + 2;
740
+         //                     edate.min  = 0;
741
+         //                     edate.sec  = 0;
742
+         //                    }
743
+         //
744
+         //
745
+         //                  // Print("hour of the candle is ",StructToTime(edate));
746
+         //                  time_to_place_trade = StructToTime(edate);
747
+         //
748
+         //                  store_value_in_structure(i,ind,signal,time_of_candle,time_to_place_trade);
749
+         //
750
+         //                  //                  for(int m=0; m < orderNum; m++)
751
+         //                  //                    {
752
+         //                  //                     if(od_1[m].choch_index != -1)
753
+         //                  //                       {
754
+         //                  //                       Print("     time to match the condition : ",TimeCurrent());
755
+         //                  //
756
+         //                  //                        if(TimeCurrent() > od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "buy")
757
+         //                  //                          {
758
+         //                  //                          Print("time to match the condition : ",TimeCurrent());
759
+         //                  //
760
+         //                  //                           //if(iHigh(Symbol(),PERIOD_CURRENT,od_1[m].reversal_index) > iLow(Symbol(),PERIOD_CURRENT,0) && iClose(Symbol(),PERIOD_CURRENT,od_1[m].choch_index) < iClose(Symbol(),PERIOD_CURRENT,0))
761
+         //                  //                             {
762
+         //                  //                              ObjectCreate(0,"buy trade"+time_to_place_trade,OBJ_ARROW_BUY,0,time_to_place_trade,iHigh(Symbol(),PERIOD_CURRENT,0));
763
+         //                  //                              Print("trade placed buy at index ",0);
764
+         //                  //                              od_1[m].choch_index = -1;
765
+         //                  //
766
+         //                  //                             }
767
+         //                  //                           Print("   time to take trade is ",od_1[m].Time_of_candle_For_trade);
768
+         //                  //
769
+         //                  //
770
+         //                  //                          }
771
+         //                  //
772
+         //                  //                        if(TimeCurrent() >= od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "sell")
773
+         //                  //                          {
774
+         //                  //                          Print(TimeCurrent());
775
+         //                  //                           //
776
+         //                  //                           Print("  time to take trade is ",od_1[m].Time_of_candle_For_trade);
777
+         //                  //                           od_1[m].choch_index = -1;
778
+         //                  //
779
+         //                  //                          }
780
+         //                  //                       }
781
+         //                  //                    }
782
+         //
783
+         //
784
+         //
785
+         //                  //                  if(TimeCurrent() >= time_to_place_trade)
786
+         //                  //                    {
787
+         //                  //                     Print("hi");
788
+         //                  //                     if(signal == "buy")
789
+         //                  //                       {
790
+         //                  //                        int index = iBarShift(Symbol(), PERIOD_CURRENT, time_of_candle, false);
791
+         //                  //                        Print("index of the 2 hour plus index is ",index);
792
+         //                  //
793
+         //                  //                        Print("choch index ", i);
794
+         //                  //                        Print("reversal index ",ind);
795
+         //                  //                        Print("value to be check index ",i-3);
796
+         //                  //
797
+         //                  //                        //if(iHigh(Symbol(),PERIOD_CURRENT,ind) > iLow(Symbol(),PERIOD_CURRENT,i-2) && iClose(Symbol(),PERIOD_CURRENT,i) < iClose(Symbol(),PERIOD_CURRENT,i-2))
798
+         //                  //                        //  {
799
+         //                  //                        //   ObjectCreate(0,"buy trade"+time_to_place_trade,OBJ_ARROW_BUY,0,time_to_place_trade,iHigh(Symbol(),PERIOD_CURRENT,i-3));
800
+         //                  //                        //   Print("trade placed buy at index ",i-3);
801
+         //                  //                        //  }
802
+         //                  //                        Print(time_to_place_trade);
803
+         //                  //
804
+         //                  //                       }
805
+         //                  //                     if(signal == "sell")
806
+         //                  //                       {
807
+         //                  //                        Print("trade placed ");
808
+         //                  //                        ObjectCreate(0,"sell trade"+time_to_place_trade,OBJ_ARROW_SELL,0,time_to_place_trade,iLow(Symbol(),PERIOD_CURRENT,i-3));
809
+         //                  //
810
+         //                  //                        Print(ind);
811
+         //                  //                        Print(time_to_place_trade);
812
+         //                  //                       }
813
+         //                  //                    }
814
+         //                  //                  else
815
+         //                  //                    {
816
+         //                  //                     time_of_candle = iTime(Symbol(),PERIOD_CURRENT,i);
817
+         //                  //                    }
818
+         //
819
+         //                  break;
820
+         //
821
+         //               default:
822
+         //                  current_time_frame_String = "Unknown";
823
+         //                  break;
824
+         //              }
825
+         //
826
+         //            //Print("Current Timeframe: ", current_time_frame_String);
827
+         //
828
+         //
829
+         //            signal = "";
830
+         //           }
748
 
831
 
749
 
832
 
750
         }
833
         }
@@ -815,7 +898,7 @@ void OnDeinit(const int reason)
815
 //+------------------------------------------------------------------+
898
 //+------------------------------------------------------------------+
816
 void OnTick()
899
 void OnTick()
817
   {
900
   {
818
-  
901
+
819
 //   for(int m=0; m < orderNum; m++)
902
 //   for(int m=0; m < orderNum; m++)
820
 //     {
903
 //     {
821
 //      if(od_1[m].choch_index != -1)
904
 //      if(od_1[m].choch_index != -1)