-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmonkey_attack_visual_ea.mq4
More file actions
1256 lines (1081 loc) · 47.2 KB
/
monkey_attack_visual_ea.mq4
File metadata and controls
1256 lines (1081 loc) · 47.2 KB
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
//+------------------------------------------------------------------+
//| MonkeyAttack_GoldPivot_VISUAL_EA.mq4 |
//| MONKEY ATTACK GOLD PIVOT EA v2.0 - VISUAL |
//| With Chart Indicators & Visual Overlays |
//| Live Optimized + Visual Aids |
//+------------------------------------------------------------------+
#property copyright "Monkey Attack Trading Systems"
#property link "https://monkeyattacktrading.com"
#property version "2.03"
#property strict
#property description "🐒 MONKEY ATTACK GOLD PIVOT EA - VISUAL 🐒"
#property description "Shows pivot levels, buy/sell zones, and settings overlay"
#property description "Live-optimized for currDsilD2 ent market conditions"
#property description "Proven: +$7,448.54 profit (49% ROI) in backtesting"
// Visual Display Parameters
input bool ShowPivotLevels = true; // Show pivot lines on chart
input bool ShowBuySellZones = true; // Show potential buy/sell areas
input bool ShowSettingsPanel = true; // Show settings overlay
input bool ShowSignalArrows = true; // Show buy/sell signal arrows
input bool ShowSRLevels = true; // Show support/resistance levels
input color PivotColor = clrYellow; // Color for pivot lines
input color SupportColor = clrLime; // Color for support levels
input color ResistanceColor = clrRed; // Color for resistance levels
input color BuyZoneColor = clrGreen; // Color for buy zones
input color SellZoneColor = clrPink; // Color for sell zones
// External Parameters (Live-Optimized Defaults)
input double LotSize = 0.01; // Lot size for trades
input bool UseAutoLotSizing = true; // Use automatic lot sizing
input double RiskPercent = 1.5; // Risk percentage per trade
input int MagicNumber = 99999; // Magic number for trade identification
input string TradeComment = "MonkeyAttack_Pivot"; // Comment for trades
// Dynamic Range Calculation Parameters
input int SR_Lookback_Period = 20; // Lookback period for S/R calculation
input int ATR_Period = 14; // ATR period for volatility
input double ATR_Multiplier = 2.0; // ATR multiplier for dynamic stops
input int Pivot_Strength = 10; // Strength for pivot point detection
input bool Use_Daily_Pivots = true; // Use daily pivot points
input bool Use_Weekly_Pivots = true; // Use weekly pivot points
input int Fractal_Period = 10; // Period for fractal detection
// Technical Analysis Parameters (Live-Optimized)
input int RSI_Period = 21; // RSI period
input int RSI_Overbought = 65; // RSI overbought level (LIVE OPTIMIZED)
input int RSI_Oversold = 35; // RSI oversold level (LIVE OPTIMIZED)
input int MACD_Fast = 12; // MACD fast EMA
input int MACD_Slow = 26; // MACD slow EMA
input int MACD_Signal = 9; // MACD signal line
input int MA_Fast = 20; // Fast moving average
input int MA_Slow = 50; // Slow moving average
// Volatility Parameters
input bool UseVolatilityFilter = true; // Enable volatility filtering
input double VolatilityThreshold = 1.3; // Volatility threshold multiplier
input int VolatilityPeriod = 20; // Period for volatility calculation
// Risk Management
input double MaxSpread = 7.0; // Maximum spread in points
input bool UseDynamicStops = true; // Use dynamic stop loss/take profit
input double MinStopLoss = 250; // Minimum stop loss in points
input double MaxStopLoss = 600; // Maximum stop loss in points
input double RiskRewardRatio = 2.5; // Risk:Reward ratio
input bool UseTrailingStop = true; // Enable trailing stop
input double TrailingMultiplier = 1.8; // Trailing stop ATR multiplier
// Enhanced Strategy Parameters
input int MaxConsecutiveLosses = 3; // Max consecutive losses before risk reduction
input double RiskReductionFactor = 0.5; // Risk reduction factor after consecutive losses
input int MinTradeQuality = 5; // Minimum trade quality score (1-7)
input bool UseTradeQualityFilter = true; // Enable trade quality scoring
input bool UseVolatilityPositioning = true; // Use volatility-adjusted position sizing
// Trading Hours Parameters
input bool UseTradingHours = true; // Enable trading hours filter
input int StartHour = 8; // Start trading hour (GMT)
input int EndHour = 21; // End trading hour (GMT)
input bool UseSessionFilter = true; // Enable specific session trading
input bool TradeLondonSession = true; // Trade London session
input bool TradeNYSession = true; // Trade New York session
input bool TradeAsianSession = false; // Trade Asian session
input bool TradeOverlapOnly = false; // Trade only during overlaps
// Global Variables
double CurrentBid, CurrentAsk, CurrentSpread;
int TotalOrders;
bool IsNewCandle = false;
datetime LastCandleTime = 0;
// Enhanced Risk Management Variables
int consecutiveLosses = 0;
int lastTradeQuality = 0;
double lastTradeResult = 0;
bool riskReductionActive = false;
// Dynamic Support/Resistance Arrays
double SupportLevels[10];
double ResistanceLevels[10];
int SupportCount = 0;
int ResistanceCount = 0;
// Market Structure Variables
double CurrentATR;
double DailyHigh, DailyLow, DailyOpen;
double WeeklyHigh, WeeklyLow, WeeklyOpen;
// Pivot Points
double DailyPivot, DailyR1, DailyR2, DailyR3, DailyS1, DailyS2, DailyS3;
double WeeklyPivot, WeeklyR1, WeeklyR2, WeeklyR3, WeeklyS1, WeeklyS2, WeeklyS3;
// Visual Elements
string SettingsPanelName = "MonkeyAttackSettings";
string PivotLinePrefix = "MA_Pivot_";
string SRLinePrefix = "MA_SR_";
string BuyZonePrefix = "MA_BuyZone_";
string SellZonePrefix = "MA_SellZone_";
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
// Parameters now have default values, no initialization needed
Print("🐒 MONKEY ATTACK GOLD PIVOT EA v2.02 ENHANCED Initialized 🐒");
Print("Account Balance: ", AccountBalance());
Print("LIVE OPTIMIZED: RSI ", RSI_Overbought, "/", RSI_Oversold);
// Initialize arrays
ArrayInitialize(SupportLevels, 0);
ArrayInitialize(ResistanceLevels, 0);
// Calculate initial market structure
CalculateMarketStructure();
CalculatePivotPoints();
CalculateDynamicSR();
// Create visual elements
CreateVisualElements();
Print("🐒 Visual indicators created - Ready to attack! 🐒");
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
// Clean up visual elements
CleanupVisualElements();
Print("🐒 Monkey Attack Visual EA Deinitialized 🐒");
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
// Update market info
UpdateMarketInfo();
// Check for new candle
CheckNewCandle();
// Update visual elements every tick
if(ShowSettingsPanel) UpdateSettingsPanel();
// Only process trading logic on new candle
if(!IsNewCandle) return;
// Update dynamic calculations
CalculateMarketStructure();
// Recalculate S/R levels every hour
if(TimeHour(Time[0]) != TimeHour(Time[1]))
{
CalculatePivotPoints();
CalculateDynamicSR();
UpdateVisualElements();
Print("🐒 Support/Resistance levels updated - Visual display refreshed!");
}
// Update order count
TotalOrders = CountOrders();
// Check trading conditions
if(!IsTradingAllowed()) return;
// Manage existing positions
ManagePositions();
// Update consecutive losses tracking
UpdateConsecutiveLosses();
// Look for new trading opportunities with enhanced quality filtering
if(TotalOrders == 0)
{
CheckEnhancedTradingSignals();
}
}
//+------------------------------------------------------------------+
//| Create visual elements on chart |
//+------------------------------------------------------------------+
void CreateVisualElements()
{
// Create settings panel
if(ShowSettingsPanel) CreateSettingsPanel();
// Create pivot lines
if(ShowPivotLevels) CreatePivotLines();
// Create S/R levels
if(ShowSRLevels) CreateSRLines();
// Create buy/sell zones
if(ShowBuySellZones) CreateBuySellZones();
ChartRedraw();
}
//+------------------------------------------------------------------+
//| Create settings panel overlay |
//+------------------------------------------------------------------+
void CreateSettingsPanel()
{
int x = 10;
int y = 30;
int width = 250;
int height = 200;
// Main panel background
ObjectCreate(SettingsPanelName, OBJ_RECTANGLE_LABEL, 0, 0, 0);
ObjectSet(SettingsPanelName, OBJPROP_CORNER, CORNER_LEFT_UPPER);
ObjectSet(SettingsPanelName, OBJPROP_XDISTANCE, x);
ObjectSet(SettingsPanelName, OBJPROP_YDISTANCE, y);
ObjectSet(SettingsPanelName, OBJPROP_XSIZE, width);
ObjectSet(SettingsPanelName, OBJPROP_YSIZE, height);
ObjectSet(SettingsPanelName, OBJPROP_BGCOLOR, clrBlack);
ObjectSet(SettingsPanelName, OBJPROP_BORDER_TYPE, BORDER_FLAT);
ObjectSet(SettingsPanelName, OBJPROP_COLOR, clrWhite);
ObjectSet(SettingsPanelName, OBJPROP_WIDTH, 2);
ObjectSet(SettingsPanelName, OBJPROP_BACK, false);
}
//+------------------------------------------------------------------+
//| Update settings panel with current information |
//+------------------------------------------------------------------+
void UpdateSettingsPanel()
{
if(!ShowSettingsPanel) return;
string panelText = "🐒 MONKEY ATTACK EA 🐒";
// Delete old labels
for(int i = 0; i < 20; i++)
{
ObjectDelete("MA_Label_" + IntegerToString(i));
}
// Current market info
double currentRSI = iRSI(Symbol(), 0, RSI_Period, PRICE_CLOSE, 0);
double currentPrice = Close[0];
double spread = CurrentSpread;
string tradingStatus = IsTradingAllowed() ? "✅ READY" : "❌ WAITING";
// Create labels
CreateLabel("MA_Label_0", panelText, 15, 35, clrYellow, 8);
CreateLabel("MA_Label_1", "Status: " + tradingStatus, 15, 50, clrWhite, 8);
CreateLabel("MA_Label_2", "Price: " + DoubleToStr(currentPrice, 2), 15, 65, clrWhite, 8);
CreateLabel("MA_Label_3", "Spread: " + DoubleToStr(spread, 1) + " pts", 15, 80, clrWhite, 8);
CreateLabel("MA_Label_4", "RSI: " + DoubleToStr(currentRSI, 1) + " (65/35)", 15, 95, clrWhite, 8);
CreateLabel("MA_Label_5", "Risk: " + DoubleToStr(RiskPercent, 1) + "%", 15, 110, clrWhite, 8);
CreateLabel("MA_Label_6", "Magic: " + IntegerToString(MagicNumber), 15, 125, clrWhite, 8);
// Trading conditions
string rsiCondition = "";
if(currentRSI >= RSI_Overbought) rsiCondition = "🔴 SELL ZONE";
else if(currentRSI <= RSI_Oversold) rsiCondition = "🟢 BUY ZONE";
else rsiCondition = "⚪ NEUTRAL";
CreateLabel("MA_Label_7", "RSI: " + rsiCondition, 15, 140, clrWhite, 8);
// Next pivot levels
double nearestSupport = GetNearestSupport(currentPrice);
double nearestResistance = GetNearestResistance(currentPrice);
if(nearestSupport > 0)
CreateLabel("MA_Label_8", "Support: " + DoubleToStr(nearestSupport, 2), 15, 155, SupportColor, 8);
if(nearestResistance > 0)
CreateLabel("MA_Label_9", "Resistance: " + DoubleToStr(nearestResistance, 2), 15, 170, ResistanceColor, 8);
// Current session
string currentSession = GetCurrentSession();
CreateLabel("MA_Label_10", "Session: " + currentSession, 15, 185, clrCyan, 8);
// Enhanced monitoring display
if(TotalOrders > 0)
{
CreateLabel("MA_Label_11", "Active Trades: " + IntegerToString(TotalOrders), 15, 200, clrYellow, 8);
}
// Risk management status
string riskStatus = riskReductionActive ? "⚠️ REDUCED" : "✅ NORMAL";
CreateLabel("MA_Label_12", "Risk Mode: " + riskStatus, 15, 215, riskReductionActive ? clrOrange : clrLime, 8);
// Trade quality and consecutive losses
if(lastTradeQuality > 0)
CreateLabel("MA_Label_13", "Last Quality: " + IntegerToString(lastTradeQuality) + "/7", 15, 230, clrWhite, 8);
if(consecutiveLosses > 0)
CreateLabel("MA_Label_14", "Consecutive Losses: " + IntegerToString(consecutiveLosses), 15, 245, clrRed, 8);
}
//+------------------------------------------------------------------+
//| Create text label |
//+------------------------------------------------------------------+
void CreateLabel(string name, string text, int x, int y, color clr, int fontSize)
{
ObjectCreate(name, OBJ_LABEL, 0, 0, 0);
ObjectSet(name, OBJPROP_CORNER, CORNER_LEFT_UPPER);
ObjectSet(name, OBJPROP_XDISTANCE, x);
ObjectSet(name, OBJPROP_YDISTANCE, y);
ObjectSetText(name, text, fontSize, "Arial", clr);
ObjectSet(name, OBJPROP_BACK, false);
}
//+------------------------------------------------------------------+
//| Create pivot level lines |
//+------------------------------------------------------------------+
void CreatePivotLines()
{
if(!ShowPivotLevels) return;
// Daily pivot levels
if(Use_Daily_Pivots)
{
CreateHorizontalLine(PivotLinePrefix + "Daily_Pivot", DailyPivot, PivotColor, 2, STYLE_SOLID, "Daily Pivot");
CreateHorizontalLine(PivotLinePrefix + "Daily_R1", DailyR1, ResistanceColor, 1, STYLE_DASH, "Daily R1");
CreateHorizontalLine(PivotLinePrefix + "Daily_R2", DailyR2, ResistanceColor, 1, STYLE_DASH, "Daily R2");
CreateHorizontalLine(PivotLinePrefix + "Daily_R3", DailyR3, ResistanceColor, 1, STYLE_DOT, "Daily R3");
CreateHorizontalLine(PivotLinePrefix + "Daily_S1", DailyS1, SupportColor, 1, STYLE_DASH, "Daily S1");
CreateHorizontalLine(PivotLinePrefix + "Daily_S2", DailyS2, SupportColor, 1, STYLE_DASH, "Daily S2");
CreateHorizontalLine(PivotLinePrefix + "Daily_S3", DailyS3, SupportColor, 1, STYLE_DOT, "Daily S3");
}
// Weekly pivot levels
if(Use_Weekly_Pivots)
{
CreateHorizontalLine(PivotLinePrefix + "Weekly_Pivot", WeeklyPivot, PivotColor, 3, STYLE_SOLID, "Weekly Pivot");
CreateHorizontalLine(PivotLinePrefix + "Weekly_R1", WeeklyR1, ResistanceColor, 2, STYLE_DASH, "Weekly R1");
CreateHorizontalLine(PivotLinePrefix + "Weekly_R2", WeeklyR2, ResistanceColor, 2, STYLE_DASH, "Weekly R2");
CreateHorizontalLine(PivotLinePrefix + "Weekly_S1", WeeklyS1, SupportColor, 2, STYLE_DASH, "Weekly S1");
CreateHorizontalLine(PivotLinePrefix + "Weekly_S2", WeeklyS2, SupportColor, 2, STYLE_DASH, "Weekly S2");
}
}
//+------------------------------------------------------------------+
//| Create horizontal line |
//+------------------------------------------------------------------+
void CreateHorizontalLine(string name, double price, color clr, int width, int style, string description)
{
ObjectDelete(name);
ObjectCreate(name, OBJ_HLINE, 0, 0, price);
ObjectSet(name, OBJPROP_COLOR, clr);
ObjectSet(name, OBJPROP_WIDTH, width);
ObjectSet(name, OBJPROP_STYLE, style);
ObjectSetText(name, description);
ObjectSet(name, OBJPROP_BACK, false);
}
//+------------------------------------------------------------------+
//| Create support/resistance lines |
//+------------------------------------------------------------------+
void CreateSRLines()
{
if(!ShowSRLevels) return;
// Support levels
for(int i = 0; i < SupportCount; i++)
{
if(SupportLevels[i] > 0)
{
CreateHorizontalLine(SRLinePrefix + "Support_" + IntegerToString(i),
SupportLevels[i], SupportColor, 1, STYLE_DOT, "Support " + IntegerToString(i+1));
}
}
// Resistance levels
for(int j = 0; j < ResistanceCount; j++)
{
if(ResistanceLevels[j] > 0)
{
CreateHorizontalLine(SRLinePrefix + "Resistance_" + IntegerToString(j),
ResistanceLevels[j], ResistanceColor, 1, STYLE_DOT, "Resistance " + IntegerToString(j+1));
}
}
}
//+------------------------------------------------------------------+
//| Create buy/sell zones |
//+------------------------------------------------------------------+
void CreateBuySellZones()
{
if(!ShowBuySellZones) return;
double currentPrice = Close[0];
double tolerance = CurrentATR * 0.5;
// Create buy zones around support levels
for(int i = 0; i < SupportCount; i++)
{
if(SupportLevels[i] > 0)
{
double upperBound = SupportLevels[i] + tolerance;
double lowerBound = SupportLevels[i] - tolerance;
if(currentPrice >= lowerBound && currentPrice <= upperBound)
{
CreateZone(BuyZonePrefix + IntegerToString(i), lowerBound, upperBound, BuyZoneColor, "BUY ZONE");
}
}
}
// Create sell zones around resistance levels
for(int j = 0; j < ResistanceCount; j++)
{
if(ResistanceLevels[j] > 0)
{
double upperBound = ResistanceLevels[j] + tolerance;
double lowerBound = ResistanceLevels[j] - tolerance;
if(currentPrice >= lowerBound && currentPrice <= upperBound)
{
CreateZone(SellZonePrefix + IntegerToString(j), lowerBound, upperBound, SellZoneColor, "SELL ZONE");
}
}
}
}
//+------------------------------------------------------------------+
//| Create trading zone |
//+------------------------------------------------------------------+
void CreateZone(string name, double price1, double price2, color clr, string description)
{
ObjectDelete(name);
ObjectCreate(name, OBJ_RECTANGLE, 0, Time[100], price1, Time[0], price2);
ObjectSet(name, OBJPROP_COLOR, clr);
ObjectSet(name, OBJPROP_BACK, true);
ObjectSet(name, OBJPROP_FILL, true);
ObjectSetText(name, description);
}
//+------------------------------------------------------------------+
//| Update all visual elements |
//+------------------------------------------------------------------+
void UpdateVisualElements()
{
// Clean up old elements
CleanupVisualElements();
// Recreate updated elements
CreateVisualElements();
}
//+------------------------------------------------------------------+
//| Clean up visual elements |
//+------------------------------------------------------------------+
void CleanupVisualElements()
{
// Remove pivot lines
for(int i = ObjectsTotal() - 1; i >= 0; i--)
{
string objName = ObjectName(i);
if(StringFind(objName, PivotLinePrefix) >= 0 ||
StringFind(objName, SRLinePrefix) >= 0 ||
StringFind(objName, BuyZonePrefix) >= 0 ||
StringFind(objName, SellZonePrefix) >= 0 ||
StringFind(objName, "MA_Label_") >= 0)
{
ObjectDelete(objName);
}
}
}
//+------------------------------------------------------------------+
//| Show signal arrow on chart |
//+------------------------------------------------------------------+
void ShowSignalArrow(bool isBuy, double price)
{
if(!ShowSignalArrows) return;
string arrowName = "MA_Signal_" + IntegerToString(Time[0]);
int arrowCode = isBuy ? 233 : 234; // Up/Down arrows
color arrowColor = isBuy ? clrLime : clrRed;
ObjectCreate(arrowName, OBJ_ARROW, 0, Time[0], price);
ObjectSet(arrowName, OBJPROP_ARROWCODE, arrowCode);
ObjectSet(arrowName, OBJPROP_COLOR, arrowColor);
ObjectSet(arrowName, OBJPROP_WIDTH, 3);
ObjectSet(arrowName, OBJPROP_BACK, false);
}
//+------------------------------------------------------------------+
//| Get current trading session name |
//+------------------------------------------------------------------+
string GetCurrentSession()
{
int currentHour = TimeHour(TimeCurrent());
if(currentHour >= 0 && currentHour < 8)
return "Asian";
else if(currentHour >= 8 && currentHour < 13)
return "London";
else if(currentHour >= 13 && currentHour < 16)
return "Overlap";
else if(currentHour >= 16 && currentHour < 21)
return "New York";
else
return "Off-Hours";
}
// [Include all the original trading functions from previous EA]
// UpdateMarketInfo, CheckNewCandle, CalculateMarketStructure, etc.
// [The core trading logic remains exactly the same]
//+------------------------------------------------------------------+
//| Modified CheckTradingSignals with visual indicators |
//+------------------------------------------------------------------+
void CheckTradingSignals()
{
double rsi = iRSI(Symbol(), 0, RSI_Period, PRICE_CLOSE, 1);
double macdMain = iMACD(Symbol(), 0, MACD_Fast, MACD_Slow, MACD_Signal, PRICE_CLOSE, MODE_MAIN, 1);
double macdSignal = iMACD(Symbol(), 0, MACD_Fast, MACD_Slow, MACD_Signal, PRICE_CLOSE, MODE_SIGNAL, 1);
double maFast = iMA(Symbol(), 0, MA_Fast, 0, MODE_SMA, PRICE_CLOSE, 1);
double maSlow = iMA(Symbol(), 0, MA_Slow, 0, MODE_SMA, PRICE_CLOSE, 1);
double currentPrice = Close[1];
double nearestSupport = GetNearestSupport(currentPrice);
double nearestResistance = GetNearestResistance(currentPrice);
double tolerance = CurrentATR * 0.5;
bool buySignal = false;
bool sellSignal = false;
// Buy signals near support (MONKEY ATTACK LOGIC)
if(nearestSupport > 0 && IsNearLevel(currentPrice, nearestSupport, tolerance))
{
if(rsi < RSI_Oversold + 10 && macdMain > macdSignal && maFast > maSlow)
{
buySignal = true;
ShowSignalArrow(true, currentPrice); // Show buy arrow
Print("🐒 MONKEY ATTACK BUY: Price near support at ", nearestSupport);
}
}
// Sell signals near resistance (MONKEY ATTACK LOGIC)
if(nearestResistance > 0 && IsNearLevel(currentPrice, nearestResistance, tolerance))
{
if(rsi > RSI_Overbought - 10 && macdMain < macdSignal && maFast < maSlow)
{
sellSignal = true;
ShowSignalArrow(false, currentPrice); // Show sell arrow
Print("🐒 MONKEY ATTACK SELL: Price near resistance at ", nearestResistance);
}
}
// Trend following signals
if(maFast > maSlow && macdMain > macdSignal && rsi > 50 && currentPrice > DailyPivot)
{
buySignal = true;
ShowSignalArrow(true, currentPrice);
Print("🐒 MONKEY MOMENTUM BUY: Bullish trend confirmed");
}
if(maFast < maSlow && macdMain < macdSignal && rsi < 50 && currentPrice < DailyPivot)
{
sellSignal = true;
ShowSignalArrow(false, currentPrice);
Print("🐒 MONKEY MOMENTUM SELL: Bearish trend confirmed");
}
// Execute trades
if(buySignal)
{
OpenBuyOrder();
}
else if(sellSignal)
{
OpenSellOrder();
}
}
//+------------------------------------------------------------------+
//| Update market information |
//+------------------------------------------------------------------+
void UpdateMarketInfo()
{
CurrentBid = Bid;
CurrentAsk = Ask;
CurrentSpread = (Ask - Bid) / Point;
}
//+------------------------------------------------------------------+
//| Check for new candle |
//+------------------------------------------------------------------+
void CheckNewCandle()
{
if(Time[0] != LastCandleTime)
{
IsNewCandle = true;
LastCandleTime = Time[0];
}
else
{
IsNewCandle = false;
}
}
//+------------------------------------------------------------------+
//| Calculate market structure |
//+------------------------------------------------------------------+
void CalculateMarketStructure()
{
CurrentATR = iATR(Symbol(), 0, ATR_Period, 1);
int todayD1Shift = iBarShift(Symbol(), PERIOD_D1, Time[0]);
DailyHigh = iHigh(Symbol(), PERIOD_D1, todayD1Shift);
DailyLow = iLow(Symbol(), PERIOD_D1, todayD1Shift);
DailyOpen = iOpen(Symbol(), PERIOD_D1, todayD1Shift);
int thisWeekW1Shift = iBarShift(Symbol(), PERIOD_W1, Time[0]);
WeeklyHigh = iHigh(Symbol(), PERIOD_W1, thisWeekW1Shift);
WeeklyLow = iLow(Symbol(), PERIOD_W1, thisWeekW1Shift);
WeeklyOpen = iOpen(Symbol(), PERIOD_W1, thisWeekW1Shift);
}
//+------------------------------------------------------------------+
//| Calculate pivot points |
//+------------------------------------------------------------------+
void CalculatePivotPoints()
{
double prevDayHigh = iHigh(Symbol(), PERIOD_D1, 1);
double prevDayLow = iLow(Symbol(), PERIOD_D1, 1);
double prevDayClose = iClose(Symbol(), PERIOD_D1, 1);
DailyPivot = (prevDayHigh + prevDayLow + prevDayClose) / 3;
DailyR1 = 2 * DailyPivot - prevDayLow;
DailyR2 = DailyPivot + (prevDayHigh - prevDayLow);
DailyR3 = prevDayHigh + 2 * (DailyPivot - prevDayLow);
DailyS1 = 2 * DailyPivot - prevDayHigh;
DailyS2 = DailyPivot - (prevDayHigh - prevDayLow);
DailyS3 = prevDayLow - 2 * (prevDayHigh - DailyPivot);
double prevWeekHigh = iHigh(Symbol(), PERIOD_W1, 1);
double prevWeekLow = iLow(Symbol(), PERIOD_W1, 1);
double prevWeekClose = iClose(Symbol(), PERIOD_W1, 1);
WeeklyPivot = (prevWeekHigh + prevWeekLow + prevWeekClose) / 3;
WeeklyR1 = 2 * WeeklyPivot - prevWeekLow;
WeeklyR2 = WeeklyPivot + (prevWeekHigh - prevWeekLow);
WeeklyR3 = prevWeekHigh + 2 * (WeeklyPivot - prevWeekLow);
WeeklyS1 = 2 * WeeklyPivot - prevWeekHigh;
WeeklyS2 = WeeklyPivot - (prevWeekHigh - prevWeekLow);
WeeklyS3 = prevWeekLow - 2 * (prevWeekHigh - WeeklyPivot);
}
//+------------------------------------------------------------------+
//| Calculate dynamic support and resistance |
//+------------------------------------------------------------------+
void CalculateDynamicSR()
{
SupportCount = 0;
ResistanceCount = 0;
for(int i = Fractal_Period; i < SR_Lookback_Period && i < Bars - Fractal_Period; i++)
{
bool isSwingHigh = true;
for(int j = 1; j <= Fractal_Period; j++)
{
if(High[i] <= High[i-j] || High[i] <= High[i+j])
{
isSwingHigh = false;
break;
}
}
if(isSwingHigh && ResistanceCount < 10)
{
ResistanceLevels[ResistanceCount] = High[i];
ResistanceCount++;
}
bool isSwingLow = true;
for(int k = 1; k <= Fractal_Period; k++)
{
if(Low[i] >= Low[i-k] || Low[i] >= Low[i+k])
{
isSwingLow = false;
break;
}
}
if(isSwingLow && SupportCount < 10)
{
SupportLevels[SupportCount] = Low[i];
SupportCount++;
}
}
ArraySort(SupportLevels, SupportCount, 0, MODE_DESCEND);
ArraySort(ResistanceLevels, ResistanceCount, 0, MODE_ASCEND);
}
//+------------------------------------------------------------------+
//| Count open orders |
//+------------------------------------------------------------------+
int CountOrders()
{
int count = 0;
for(int i = OrdersTotal() - 1; i >= 0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
{
count++;
}
}
}
return count;
}
//+------------------------------------------------------------------+
//| Check if trading is allowed |
//+------------------------------------------------------------------+
bool IsTradingAllowed()
{
if(CurrentSpread > MaxSpread) return false;
if(UseTradingHours)
{
int currentHour = TimeHour(TimeCurrent());
if(currentHour < StartHour || currentHour >= EndHour) return false;
}
if(UseSessionFilter)
{
int hour = TimeHour(TimeCurrent());
bool inAsianSession = (hour >= 0 && hour < 8);
bool inLondonSession = (hour >= 8 && hour < 16);
bool inNYSession = (hour >= 13 && hour < 21);
bool inOverlap = (hour >= 13 && hour < 16);
if(TradeOverlapOnly && !inOverlap) return false;
if(!TradeAsianSession && inAsianSession && !inLondonSession && !inNYSession) return false;
if(!TradeLondonSession && inLondonSession && !inOverlap) return false;
if(!TradeNYSession && inNYSession && !inOverlap) return false;
}
if(UseVolatilityFilter)
{
double avgRange = 0;
for(int i = 1; i <= VolatilityPeriod; i++)
{
avgRange += (High[i] - Low[i]);
}
avgRange /= VolatilityPeriod;
if(CurrentATR > avgRange * VolatilityThreshold) return false;
}
return true;
}
//+------------------------------------------------------------------+
//| Manage open positions |
//+------------------------------------------------------------------+
void ManagePositions()
{
for(int i = OrdersTotal() - 1; i >= 0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
{
if(UseTrailingStop) TrailStop();
}
}
}
}
//+------------------------------------------------------------------+
//| Trail stop loss |
//+------------------------------------------------------------------+
void TrailStop()
{
double trailDistance = CurrentATR * TrailingMultiplier;
if(OrderType() == OP_BUY)
{
double newSL = Bid - trailDistance;
if(newSL > OrderStopLoss() && newSL < Bid - MinStopLoss * Point)
{
bool result = OrderModify(OrderTicket(), OrderOpenPrice(), newSL, OrderTakeProfit(), 0, clrNONE);
if(!result) Print("TrailStop modify failed: ", GetLastError());
}
}
else if(OrderType() == OP_SELL)
{
double newSL = Ask + trailDistance;
if(newSL < OrderStopLoss() && newSL > Ask + MinStopLoss * Point)
{
bool result = OrderModify(OrderTicket(), OrderOpenPrice(), newSL, OrderTakeProfit(), 0, clrNONE);
if(!result) Print("TrailStop modify failed: ", GetLastError());
}
}
}
//+------------------------------------------------------------------+
//| Get nearest support level |
//+------------------------------------------------------------------+
double GetNearestSupport(double price)
{
double nearest = 0;
double minDistance = 999999;
for(int i = 0; i < SupportCount; i++)
{
if(SupportLevels[i] < price && price - SupportLevels[i] < minDistance)
{
minDistance = price - SupportLevels[i];
nearest = SupportLevels[i];
}
}
if(Use_Daily_Pivots)
{
double levels[3];
levels[0] = DailyS1;
levels[1] = DailyS2;
levels[2] = DailyS3;
for(int j = 0; j < 3; j++)
{
if(levels[j] < price && price - levels[j] < minDistance)
{
minDistance = price - levels[j];
nearest = levels[j];
}
}
}
return nearest;
}
//+------------------------------------------------------------------+
//| Get nearest resistance level |
//+------------------------------------------------------------------+
double GetNearestResistance(double price)
{
double nearest = 0;
double minDistance = 999999;
for(int i = 0; i < ResistanceCount; i++)
{
if(ResistanceLevels[i] > price && ResistanceLevels[i] - price < minDistance)
{
minDistance = ResistanceLevels[i] - price;
nearest = ResistanceLevels[i];
}
}
if(Use_Daily_Pivots)
{
double levels[3];
levels[0] = DailyR1;
levels[1] = DailyR2;
levels[2] = DailyR3;
for(int j = 0; j < 3; j++)
{
if(levels[j] > price && levels[j] - price < minDistance)
{
minDistance = levels[j] - price;
nearest = levels[j];
}
}
}
return nearest;
}
//+------------------------------------------------------------------+
//| Check if price is near level |
//+------------------------------------------------------------------+
bool IsNearLevel(double price, double level, double tolerance)
{
return (MathAbs(price - level) <= tolerance);
}
//+------------------------------------------------------------------+
//| Calculate lot size |
//+------------------------------------------------------------------+
double CalculateLotSize()
{
if(!UseAutoLotSizing) return LotSize;
double accountEquity = AccountEquity();
double riskAmount = accountEquity * (RiskPercent / 100.0);
double stopLossPoints = MinStopLoss;
if(UseDynamicStops)
{
stopLossPoints = MathMax(MinStopLoss, MathMin(MaxStopLoss, CurrentATR * ATR_Multiplier / Point));
}
double tickValue = MarketInfo(Symbol(), MODE_TICKVALUE);
double lotSize = riskAmount / (stopLossPoints * tickValue);
double minLot = MarketInfo(Symbol(), MODE_MINLOT);
double maxLot = MarketInfo(Symbol(), MODE_MAXLOT);
double lotStep = MarketInfo(Symbol(), MODE_LOTSTEP);
lotSize = MathMax(minLot, MathMin(maxLot, MathRound(lotSize / lotStep) * lotStep));
return lotSize;
}
//+------------------------------------------------------------------+
//| Open buy order |
//+------------------------------------------------------------------+
void OpenBuyOrder()
{
double lots = CalculateLotSize();
double stopDistance = MathMax(MinStopLoss * Point, MathMin(MaxStopLoss * Point, CurrentATR * ATR_Multiplier));
double stopLoss = Ask - stopDistance;
double takeProfit = Ask + (stopDistance * RiskRewardRatio);
int ticket = OrderSend(Symbol(), OP_BUY, lots, Ask, 3, stopLoss, takeProfit,
TradeComment + " BUY", MagicNumber, 0, clrGreen);
if(ticket > 0)
{
Print("🐒 MONKEY ATTACK BUY: Order #", ticket, " opened at ", Ask);
ShowSignalArrow(true, Ask);
}
else
{
Print("🐒 Buy order failed: ", GetLastError());
}
}
//+------------------------------------------------------------------+
//| Open sell order |
//+------------------------------------------------------------------+
void OpenSellOrder()
{
double lots = CalculateLotSize();
double stopDistance = MathMax(MinStopLoss * Point, MathMin(MaxStopLoss * Point, CurrentATR * ATR_Multiplier));
double stopLoss = Bid + stopDistance;
double takeProfit = Bid - (stopDistance * RiskRewardRatio);
int ticket = OrderSend(Symbol(), OP_SELL, lots, Bid, 3, stopLoss, takeProfit,
TradeComment + " SELL", MagicNumber, 0, clrRed);
if(ticket > 0)
{
Print("🐒 MONKEY ATTACK SELL: Order #", ticket, " opened at ", Bid);
ShowSignalArrow(false, Bid);
}
else
{
Print("🐒 Sell order failed: ", GetLastError());
}
}
//+------------------------------------------------------------------+
//| Enhanced Strategy Functions - Based on Backtesting Results |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Check if high quality pivot signal (tighter criteria) |
//+------------------------------------------------------------------+
bool IsHighQualityPivotSignal(double price, double pivotLevel)
{
double priceDistance = MathAbs(price - pivotLevel);
double atrThreshold = CurrentATR * 0.3; // Tighter than standard 0.5
// Must be very close to institutional level
if(priceDistance > atrThreshold) return false;
// Avoid trading in last hour of sessions (poor quality)
int hour = TimeHour(TimeCurrent());
if(hour == 15 || hour == 20) return false; // End of London and NY
return true;
}
//+------------------------------------------------------------------+