|
|
@@ -0,0 +1,179 @@
|
|
|
+//+------------------------------------------------------------------+
|
|
|
+//| CribMarketEA.mq5 |
|
|
|
+//| Copyright 2025, MQL Development |
|
|
|
+//| https://www.mqldevelopment.com/ |
|
|
|
+//+------------------------------------------------------------------+
|
|
|
+#property copyright "Copyright 2025, MQL Development"
|
|
|
+#property link "https://www.mqldevelopment.com/"
|
|
|
+#property version "1.00"
|
|
|
+
|
|
|
+#include <Trade\Trade.mqh>
|
|
|
+CTrade trade;
|
|
|
+
|
|
|
+
|
|
|
+input string Settings = " ------------- General Settings ------------- "; //_
|
|
|
+input int magicNo = 333; // Magic no
|
|
|
+input double lotSize = 0.1; // Lot Size
|
|
|
+
|
|
|
+
|
|
|
+string goldPairs[];
|
|
|
+int totalGoldPairs = 0;
|
|
|
+
|
|
|
+//+------------------------------------------------------------------+
|
|
|
+//| Expert initialization function |
|
|
|
+//+------------------------------------------------------------------+
|
|
|
+int OnInit()
|
|
|
+ {
|
|
|
+//---
|
|
|
+
|
|
|
+ trade.SetExpertMagicNumber(magicNo);
|
|
|
+ trade.SetDeviationInPoints(10);
|
|
|
+ trade.SetTypeFilling(ORDER_FILLING_IOC);
|
|
|
+ trade.LogLevel(LOG_LEVEL_ALL);
|
|
|
+ trade.SetAsyncMode(false);
|
|
|
+
|
|
|
+ getGoldPairsFromMarketWatch();
|
|
|
+
|
|
|
+
|
|
|
+//---
|
|
|
+ return(INIT_SUCCEEDED);
|
|
|
+ }
|
|
|
+//+------------------------------------------------------------------+
|
|
|
+//| Expert deinitialization function |
|
|
|
+//+------------------------------------------------------------------+
|
|
|
+void OnDeinit(const int reason)
|
|
|
+ {
|
|
|
+//---
|
|
|
+
|
|
|
+ }
|
|
|
+//+------------------------------------------------------------------+
|
|
|
+//| Expert tick function |
|
|
|
+//+------------------------------------------------------------------+
|
|
|
+void OnTick()
|
|
|
+ {
|
|
|
+//---
|
|
|
+
|
|
|
+ }
|
|
|
+//+------------------------------------------------------------------+
|
|
|
+//| |
|
|
|
+//+------------------------------------------------------------------+
|
|
|
+bool newBar()
|
|
|
+ {
|
|
|
+ static datetime lastbar;
|
|
|
+ datetime curbar = iTime(Symbol(), PERIOD_CURRENT, 0);
|
|
|
+ if(lastbar != curbar)
|
|
|
+ {
|
|
|
+ lastbar = curbar;
|
|
|
+ Print(" ---------------------- New Bar :: ---------------------- ",lastbar);
|
|
|
+ return (true);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return (false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+//+------------------------------------------------------------------+
|
|
|
+//| |
|
|
|
+//+------------------------------------------------------------------+
|
|
|
+void placeBuyTrade(string symbol)
|
|
|
+ {
|
|
|
+ double ask = SymbolInfoDouble(symbol, SYMBOL_ASK);
|
|
|
+ double buySL = 0, buyTP = 0;
|
|
|
+
|
|
|
+ if(trade.PositionOpen(symbol, ORDER_TYPE_BUY, lotSize, ask, buySL, buyTP, "Buy Trade Placed"))
|
|
|
+ {
|
|
|
+ Print("Buy Trade Placed on ", symbol, trade.ResultOrder());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Print("Buy Failed on ", symbol, " Error: ", GetLastError());
|
|
|
+ }
|
|
|
+ }
|
|
|
+//+------------------------------------------------------------------+
|
|
|
+//| |
|
|
|
+//+------------------------------------------------------------------+
|
|
|
+void placeSellTrade(string symbol)
|
|
|
+ {
|
|
|
+ double bid = SymbolInfoDouble(symbol, SYMBOL_BID);
|
|
|
+ double sellSL = 0, sellTP = 0;
|
|
|
+
|
|
|
+ if(trade.PositionOpen(symbol, ORDER_TYPE_SELL, lotSize, bid, sellSL, sellTP, "Sell Trade Placed"))
|
|
|
+ {
|
|
|
+ Print("Sell Trade Placed on ", symbol, trade.ResultOrder());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Print("Sell Failed on ", symbol, " Error: ", GetLastError());
|
|
|
+ }
|
|
|
+ }
|
|
|
+//+------------------------------------------------------------------+
|
|
|
+//| |
|
|
|
+//+------------------------------------------------------------------+
|
|
|
+void getGoldPairsFromMarketWatch()
|
|
|
+ {
|
|
|
+ int totalSymbols = SymbolsTotal(true);
|
|
|
+ ArrayResize(goldPairs, totalSymbols);
|
|
|
+
|
|
|
+ for(int i = 0; i < totalSymbols; i++)
|
|
|
+ {
|
|
|
+ string symbolName = SymbolName(i, true);
|
|
|
+ if(StringFind(symbolName, "GOLD") != -1 || StringFind(symbolName, "XAU") != -1)
|
|
|
+ {
|
|
|
+ goldPairs[totalGoldPairs] = symbolName;
|
|
|
+ totalGoldPairs++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ArrayResize(goldPairs, totalGoldPairs);
|
|
|
+ Print("Found ", totalGoldPairs, " gold pairs in Market Watch");
|
|
|
+ }
|
|
|
+//+------------------------------------------------------------------+
|
|
|
+//| |
|
|
|
+//+------------------------------------------------------------------+
|
|
|
+string getSymbolWithLowestAsk()
|
|
|
+ {
|
|
|
+
|
|
|
+ if(totalGoldPairs == 0)
|
|
|
+ return NULL;
|
|
|
+
|
|
|
+ string lowestSymbol = goldPairs[0];
|
|
|
+ double lowestAsk = SymbolInfoDouble(lowestSymbol, SYMBOL_ASK);
|
|
|
+
|
|
|
+ for(int i = 1; i < totalGoldPairs; i++)
|
|
|
+ {
|
|
|
+ double currentAsk = SymbolInfoDouble(goldPairs[i], SYMBOL_ASK);
|
|
|
+ if(currentAsk < lowestAsk)
|
|
|
+ {
|
|
|
+ lowestAsk = currentAsk;
|
|
|
+ lowestSymbol = goldPairs[i];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return lowestSymbol;
|
|
|
+ }
|
|
|
+
|
|
|
+//+------------------------------------------------------------------+
|
|
|
+//| |
|
|
|
+//+------------------------------------------------------------------+
|
|
|
+string getSymbolWithHighestBid()
|
|
|
+ {
|
|
|
+
|
|
|
+ if(totalGoldPairs == 0)
|
|
|
+ return NULL;
|
|
|
+
|
|
|
+ string highestSymbol = goldPairs[0];
|
|
|
+ double highestBid = SymbolInfoDouble(highestSymbol, SYMBOL_BID);
|
|
|
+
|
|
|
+ for(int i = 1; i < totalGoldPairs; i++)
|
|
|
+ {
|
|
|
+ double currentBid = SymbolInfoDouble(goldPairs[i], SYMBOL_BID);
|
|
|
+ if(currentBid > highestBid)
|
|
|
+ {
|
|
|
+ highestBid = currentBid;
|
|
|
+ highestSymbol = goldPairs[i];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return highestSymbol;
|
|
|
+ }
|
|
|
+//+------------------------------------------------------------------+
|