|
|
@@ -7,10 +7,35 @@
|
|
7
|
7
|
#property link "https://www.mql5.com"
|
|
8
|
8
|
#property version "1.00"
|
|
9
|
9
|
|
|
|
10
|
+#define orderNum 200
|
|
|
11
|
+
|
|
|
12
|
+struct tradeOrder
|
|
|
13
|
+ {
|
|
|
14
|
+
|
|
|
15
|
+
|
|
|
16
|
+ int choch_index;
|
|
|
17
|
+ int reversal_index;
|
|
|
18
|
+ string Signal;
|
|
|
19
|
+ datetime Time_OF_Candle;
|
|
|
20
|
+ datetime Time_of_candle_For_trade;
|
|
|
21
|
+
|
|
|
22
|
+ tradeOrder()
|
|
|
23
|
+ {
|
|
|
24
|
+ choch_index = -1;
|
|
|
25
|
+ Signal = "";
|
|
|
26
|
+ reversal_index = 0;
|
|
|
27
|
+ Time_OF_Candle = 0.0;
|
|
|
28
|
+ Time_of_candle_For_trade = 0.0;
|
|
|
29
|
+ }
|
|
|
30
|
+
|
|
|
31
|
+ };
|
|
|
32
|
+tradeOrder od_1[orderNum];
|
|
|
33
|
+
|
|
|
34
|
+
|
|
10
|
35
|
sinput string str = "<><><><><><> Object Name <><><><><><>";
|
|
11
|
36
|
input string object_name = "line";
|
|
12
|
37
|
|
|
13
|
|
-
|
|
|
38
|
+int reversal_candle_index = 0;
|
|
14
|
39
|
int ind = 0;
|
|
15
|
40
|
string trend;
|
|
16
|
41
|
|
|
|
@@ -36,6 +61,9 @@ int Store_bos_last_index = 0;
|
|
36
|
61
|
|
|
37
|
62
|
bool choch = false;
|
|
38
|
63
|
int index = 0;
|
|
|
64
|
+
|
|
|
65
|
+string signal = "";
|
|
|
66
|
+datetime time_of_candle = 0.0;
|
|
39
|
67
|
//+------------------------------------------------------------------+
|
|
40
|
68
|
//| Expert initialization function |
|
|
41
|
69
|
//+------------------------------------------------------------------+
|
|
|
@@ -256,6 +284,8 @@ void Entry_Action_1_down(int Store_bos_last_index, int i,int diff)
|
|
256
|
284
|
{
|
|
257
|
285
|
if(iOpen(Symbol(),PERIOD_CURRENT,ind) > iOpen(Symbol(),PERIOD_CURRENT,i) && iClose(Symbol(),PERIOD_CURRENT,ind) < iClose(Symbol(),PERIOD_CURRENT,i))
|
|
258
|
286
|
{
|
|
|
287
|
+ signal = "buy";
|
|
|
288
|
+ time_of_candle = iTime(Symbol(),PERIOD_CURRENT,i);
|
|
259
|
289
|
Print("Place buy order -----------------------------------------------------------------------: ");
|
|
260
|
290
|
}
|
|
261
|
291
|
|
|
|
@@ -297,12 +327,13 @@ void Entry_Action_1_up(int Store_bos_last_index, int i,int diff)
|
|
297
|
327
|
if(checkCandle(j) == "Bearish")
|
|
298
|
328
|
{
|
|
299
|
329
|
ind = j; // reversal candle index
|
|
|
330
|
+
|
|
300
|
331
|
bearish_found = true;
|
|
301
|
332
|
break;
|
|
302
|
333
|
}
|
|
303
|
334
|
|
|
304
|
335
|
}
|
|
305
|
|
- Print("diff is ", diff);
|
|
|
336
|
+//Print("diff is ", diff);
|
|
306
|
337
|
|
|
307
|
338
|
Print("condition satisfied : ",check_values_less_than_choch_low(diff,i));
|
|
308
|
339
|
|
|
|
@@ -313,6 +344,8 @@ void Entry_Action_1_up(int Store_bos_last_index, int i,int diff)
|
|
313
|
344
|
{
|
|
314
|
345
|
if(iOpen(Symbol(),PERIOD_CURRENT,ind) < iOpen(Symbol(),PERIOD_CURRENT,i) && iClose(Symbol(),PERIOD_CURRENT,ind) > iClose(Symbol(),PERIOD_CURRENT,i))
|
|
315
|
346
|
{
|
|
|
347
|
+ signal = "sell";
|
|
|
348
|
+ time_of_candle = iTime(Symbol(),PERIOD_CURRENT,i);
|
|
316
|
349
|
Print("Place sell order -----------------------------------------------------------------------: ");
|
|
317
|
350
|
}
|
|
318
|
351
|
|
|
|
@@ -378,7 +411,7 @@ bool check_values_less_than_choch_low(int diff,int i) // uptrend
|
|
378
|
411
|
{
|
|
379
|
412
|
bool found = false;
|
|
380
|
413
|
int value = (diff + i) - 1; // from which it start to check value is less in index
|
|
381
|
|
- Print("value to be start is ",value);
|
|
|
414
|
+//Print("value to be start is ",value);
|
|
382
|
415
|
for(int k=value; k>i; k--)
|
|
383
|
416
|
{
|
|
384
|
417
|
|
|
|
@@ -416,10 +449,10 @@ void choch(int i)
|
|
416
|
449
|
ObjectCreate(0,"line8"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_ARROW_DOWN,0,iTime(Symbol(),PERIOD_CURRENT,i),iHigh(Symbol(),PERIOD_CURRENT,i)+100*Point());
|
|
417
|
450
|
ObjectSetInteger(0,"line8"+iTime(Symbol(),PERIOD_CURRENT,i),OBJPROP_COLOR,clrRed);
|
|
418
|
451
|
|
|
419
|
|
- Print("last bos index is ",Store_bos_last_index);
|
|
|
452
|
+ //Print("last bos index is ",Store_bos_last_index);
|
|
420
|
453
|
|
|
421
|
454
|
int diff1 = Store_bos_last_index - (i);
|
|
422
|
|
- Print("diff between bos and last choch is ",diff1);
|
|
|
455
|
+ // Print("diff between bos and last choch is ",diff1);
|
|
423
|
456
|
|
|
424
|
457
|
Entry_Action_1_up(Store_bos_last_index,i,diff1);
|
|
425
|
458
|
|
|
|
@@ -504,10 +537,9 @@ void third_Condition(int i)
|
|
504
|
537
|
ObjectCreate(0,"line5"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),iLow(Symbol(),PERIOD_CURRENT,i));
|
|
505
|
538
|
ObjectSetString(0,"line5"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"3_C");
|
|
506
|
539
|
low = low2;
|
|
507
|
|
- //low_index = i;
|
|
|
540
|
+ low_index = i; // addtion to be minus
|
|
508
|
541
|
if(object_find("low") > 0)
|
|
509
|
542
|
{
|
|
510
|
|
- Print("object deleted ");
|
|
511
|
543
|
ObjectDelete(0,"low");
|
|
512
|
544
|
|
|
513
|
545
|
}
|
|
|
@@ -531,7 +563,7 @@ void third_Condition(int i)
|
|
531
|
563
|
ObjectSetString(0,"line6"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"3_C");
|
|
532
|
564
|
|
|
533
|
565
|
high = high2;
|
|
534
|
|
- //high_index = i;
|
|
|
566
|
+ high_index = i; // addtion to be minus
|
|
535
|
567
|
if(object_find("high") > 0)
|
|
536
|
568
|
{
|
|
537
|
569
|
ObjectDelete(0,"high");
|
|
|
@@ -547,7 +579,30 @@ void third_Condition(int i)
|
|
547
|
579
|
}
|
|
548
|
580
|
|
|
549
|
581
|
|
|
|
582
|
+//+------------------------------------------------------------------+
|
|
|
583
|
+//| |
|
|
|
584
|
+//+------------------------------------------------------------------+
|
|
|
585
|
+void store_value_in_structure(int i,int ind,string signal,datetime time_of_candle,datetime time_to_place_trade)
|
|
|
586
|
+ {
|
|
|
587
|
+
|
|
|
588
|
+ for(int l=0; l<200; l++)
|
|
|
589
|
+ {
|
|
|
590
|
+ if(od_1[l].choch_index == -1)
|
|
|
591
|
+ {
|
|
|
592
|
+ od_1[l].choch_index = i;
|
|
|
593
|
+ od_1[l].reversal_index = ind;
|
|
|
594
|
+ od_1[l].Signal = signal;
|
|
|
595
|
+ od_1[l].Time_OF_Candle = time_of_candle;
|
|
|
596
|
+ Print("saved time in the structure ",time_of_candle);
|
|
|
597
|
+ od_1[l].Time_of_candle_For_trade = time_to_place_trade;
|
|
|
598
|
+ Print("saved time in the structure ",time_to_place_trade);
|
|
|
599
|
+ break;
|
|
|
600
|
+
|
|
|
601
|
+ }
|
|
|
602
|
+
|
|
550
|
603
|
|
|
|
604
|
+ }
|
|
|
605
|
+ }
|
|
551
|
606
|
//+------------------------------------------------------------------+
|
|
552
|
607
|
//| |
|
|
553
|
608
|
//+------------------------------------------------------------------+
|
|
|
@@ -566,10 +621,133 @@ void foo(int value)
|
|
566
|
621
|
third_Condition(i);
|
|
567
|
622
|
|
|
568
|
623
|
|
|
569
|
|
- l++;
|
|
|
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
|
+ }
|
|
|
748
|
+
|
|
570
|
749
|
|
|
571
|
750
|
}
|
|
572
|
|
- //Bos(i);
|
|
573
|
751
|
|
|
574
|
752
|
|
|
575
|
753
|
|
|
|
@@ -637,7 +815,39 @@ void OnDeinit(const int reason)
|
|
637
|
815
|
//+------------------------------------------------------------------+
|
|
638
|
816
|
void OnTick()
|
|
639
|
817
|
{
|
|
640
|
|
-
|
|
|
818
|
+
|
|
|
819
|
+// for(int m=0; m < orderNum; m++)
|
|
|
820
|
+// {
|
|
|
821
|
+// if(od_1[m].choch_index != -1)
|
|
|
822
|
+// {
|
|
|
823
|
+// Print(" time to match the condition : ",TimeCurrent());
|
|
|
824
|
+//
|
|
|
825
|
+// if(TimeCurrent() > od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "buy")
|
|
|
826
|
+// {
|
|
|
827
|
+// Print("time to match the condition : ",TimeCurrent());
|
|
|
828
|
+//
|
|
|
829
|
+// //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))
|
|
|
830
|
+// {
|
|
|
831
|
+// ObjectCreate(0,"buy trade"+TimeCurrent(),OBJ_ARROW_BUY,0,TimeCurrent(),iHigh(Symbol(),PERIOD_CURRENT,0));
|
|
|
832
|
+// Print("trade placed buy at index ",0);
|
|
|
833
|
+// od_1[m].choch_index = -1;
|
|
|
834
|
+//
|
|
|
835
|
+// }
|
|
|
836
|
+// Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade);
|
|
|
837
|
+//
|
|
|
838
|
+//
|
|
|
839
|
+// }
|
|
|
840
|
+//
|
|
|
841
|
+// if(TimeCurrent() >= od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "sell")
|
|
|
842
|
+// {
|
|
|
843
|
+// Print(TimeCurrent());
|
|
|
844
|
+// //
|
|
|
845
|
+// // Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade);
|
|
|
846
|
+// od_1[m].choch_index = -1;
|
|
|
847
|
+//
|
|
|
848
|
+// }
|
|
|
849
|
+// }
|
|
|
850
|
+// }
|
|
641
|
851
|
|
|
642
|
852
|
}
|
|
643
|
853
|
|