Aucune description

CribMarketEA.mq5 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. //+------------------------------------------------------------------+
  2. //| CribMarketEA.mq5 |
  3. //| Copyright 2025, MQL Development |
  4. //| https://www.mqldevelopment.com/ |
  5. //+------------------------------------------------------------------+
  6. #property copyright "Copyright 2025, MQL Development"
  7. #property link "https://www.mqldevelopment.com/"
  8. #property version "1.00"
  9. #include <Trade\Trade.mqh>
  10. CTrade trade;
  11. input string Settings = " ------------- General Settings ------------- "; //_
  12. input int magicNo = 333; // Magic no
  13. input double lotSize = 0.1; // Lot Size
  14. string goldPairs[];
  15. int totalGoldPairs = 0;
  16. //+------------------------------------------------------------------+
  17. //| Expert initialization function |
  18. //+------------------------------------------------------------------+
  19. int OnInit()
  20. {
  21. //---
  22. trade.SetExpertMagicNumber(magicNo);
  23. trade.SetDeviationInPoints(10);
  24. trade.SetTypeFilling(ORDER_FILLING_IOC);
  25. trade.LogLevel(LOG_LEVEL_ALL);
  26. trade.SetAsyncMode(false);
  27. getGoldPairsFromMarketWatch();
  28. //---
  29. return(INIT_SUCCEEDED);
  30. }
  31. //+------------------------------------------------------------------+
  32. //| Expert deinitialization function |
  33. //+------------------------------------------------------------------+
  34. void OnDeinit(const int reason)
  35. {
  36. //---
  37. }
  38. //+------------------------------------------------------------------+
  39. //| Expert tick function |
  40. //+------------------------------------------------------------------+
  41. void OnTick()
  42. {
  43. //---
  44. }
  45. //+------------------------------------------------------------------+
  46. //| |
  47. //+------------------------------------------------------------------+
  48. bool newBar()
  49. {
  50. static datetime lastbar;
  51. datetime curbar = iTime(Symbol(), PERIOD_CURRENT, 0);
  52. if(lastbar != curbar)
  53. {
  54. lastbar = curbar;
  55. Print(" ---------------------- New Bar :: ---------------------- ",lastbar);
  56. return (true);
  57. }
  58. else
  59. {
  60. return (false);
  61. }
  62. }
  63. //+------------------------------------------------------------------+
  64. //| |
  65. //+------------------------------------------------------------------+
  66. void placeBuyTrade(string symbol)
  67. {
  68. double ask = SymbolInfoDouble(symbol, SYMBOL_ASK);
  69. double buySL = 0, buyTP = 0;
  70. if(trade.PositionOpen(symbol, ORDER_TYPE_BUY, lotSize, ask, buySL, buyTP, "Buy Trade Placed"))
  71. {
  72. Print("Buy Trade Placed on ", symbol, trade.ResultOrder());
  73. }
  74. else
  75. {
  76. Print("Buy Failed on ", symbol, " Error: ", GetLastError());
  77. }
  78. }
  79. //+------------------------------------------------------------------+
  80. //| |
  81. //+------------------------------------------------------------------+
  82. void placeSellTrade(string symbol)
  83. {
  84. double bid = SymbolInfoDouble(symbol, SYMBOL_BID);
  85. double sellSL = 0, sellTP = 0;
  86. if(trade.PositionOpen(symbol, ORDER_TYPE_SELL, lotSize, bid, sellSL, sellTP, "Sell Trade Placed"))
  87. {
  88. Print("Sell Trade Placed on ", symbol, trade.ResultOrder());
  89. }
  90. else
  91. {
  92. Print("Sell Failed on ", symbol, " Error: ", GetLastError());
  93. }
  94. }
  95. //+------------------------------------------------------------------+
  96. //| |
  97. //+------------------------------------------------------------------+
  98. void getGoldPairsFromMarketWatch()
  99. {
  100. int totalSymbols = SymbolsTotal(true);
  101. ArrayResize(goldPairs, totalSymbols);
  102. for(int i = 0; i < totalSymbols; i++)
  103. {
  104. string symbolName = SymbolName(i, true);
  105. if(StringFind(symbolName, "GOLD") != -1 || StringFind(symbolName, "XAU") != -1)
  106. {
  107. goldPairs[totalGoldPairs] = symbolName;
  108. totalGoldPairs++;
  109. }
  110. }
  111. ArrayResize(goldPairs, totalGoldPairs);
  112. Print("Found ", totalGoldPairs, " gold pairs in Market Watch");
  113. }
  114. //+------------------------------------------------------------------+
  115. //| |
  116. //+------------------------------------------------------------------+
  117. string getSymbolWithLowestAsk()
  118. {
  119. if(totalGoldPairs == 0)
  120. return NULL;
  121. string lowestSymbol = goldPairs[0];
  122. double lowestAsk = SymbolInfoDouble(lowestSymbol, SYMBOL_ASK);
  123. for(int i = 1; i < totalGoldPairs; i++)
  124. {
  125. double currentAsk = SymbolInfoDouble(goldPairs[i], SYMBOL_ASK);
  126. if(currentAsk < lowestAsk)
  127. {
  128. lowestAsk = currentAsk;
  129. lowestSymbol = goldPairs[i];
  130. }
  131. }
  132. return lowestSymbol;
  133. }
  134. //+------------------------------------------------------------------+
  135. //| |
  136. //+------------------------------------------------------------------+
  137. string getSymbolWithHighestBid()
  138. {
  139. if(totalGoldPairs == 0)
  140. return NULL;
  141. string highestSymbol = goldPairs[0];
  142. double highestBid = SymbolInfoDouble(highestSymbol, SYMBOL_BID);
  143. for(int i = 1; i < totalGoldPairs; i++)
  144. {
  145. double currentBid = SymbolInfoDouble(goldPairs[i], SYMBOL_BID);
  146. if(currentBid > highestBid)
  147. {
  148. highestBid = currentBid;
  149. highestSymbol = goldPairs[i];
  150. }
  151. }
  152. return highestSymbol;
  153. }
  154. //+------------------------------------------------------------------+