fork download
  1. //+------------------------------------------------------------------+
  2. //| MoneyCatcher-Ai.mq4 |
  3. //| Copyright 2024, MoneyCatcher AI Systems |
  4. //| https://w...content-available-to-author-only...r.ai |
  5. //+------------------------------------------------------------------+
  6. #property copyright "Copyright 2024, MoneyCatcher AI Systems"
  7. #property link "https://w...content-available-to-author-only...r.ai"
  8. #property version "3.1"
  9. #property strict
  10. #property description "MoneyCatcher AI - نظام تداول ذكي متقدم"
  11. #property description "باستخدام تقنيات الذكاء الاصطناعي للتداول"
  12. #property description "الدعم: support@moneycatcher.ai"
  13.  
  14. //+------------------------------------------------------------------+
  15. //| إعدادات النظام الأساسية |
  16. //+------------------------------------------------------------------+
  17. input group "══════════════════ إعدادات النظام ═══════════════════"
  18. input string AuthorizedID = ""; // ID الترخيص (اختياري)
  19. input bool EnableAI = true; // تفعيل نظام الذكاء الاصطناعي
  20. input ENUM_TIMEFRAMES TradingTF = PERIOD_H1; // إطار التداول الرئيسي
  21.  
  22. input group "═══════════════ إدارة رأس المال ═════════════════"
  23. input double FixedLotSize = 0.1; // حجم اللوت الثابت
  24. input bool UseMoneyManagement = true; // استخدام إدارة رأس المال
  25. input double RiskPercent = 1.5; // نسبة المخاطرة (٪)
  26. input double MaxLotSize = 5.0; // الحد الأقصى للوت
  27.  
  28. input group "══════════════ إعدادات الوقف ═══════════════════"
  29. input bool UseAutoStopLoss = true; // وقف الخسارة التلقائي
  30. input int StopLossPips = 40; // وقف الخسارة (نقاط)
  31. input bool UseAutoTakeProfit = true; // جني الأرباح التلقائي
  32. input int TakeProfitPips = 80; // جني الأرباح (نقاط)
  33. input bool UseBreakEven = true; // تفعيل نقطة التعادل
  34. input int BreakEvenAt = 20; // تفعيل عند (نقاط)
  35.  
  36. input group "═══════════════ أوقات التداول ══════════════════"
  37. input bool UseTradingHours = true; // تقييد أوقات التداول
  38. input int TradingStartHour = 2; // ساعة البدء (توقيت السيرفر)
  39. input int TradingEndHour = 22; // ساعة الانتهاء
  40. input bool AvoidNews = true; // تجنب أخبار السوق
  41. input int NewsBufferMinutes = 30; // دقائق قبل/بعد الخبر
  42.  
  43. input group "═══════════ إعدادات الذكاء الاصطناعي ════════════"
  44. input int AILookbackPeriod = 100; // فترة تحليل الذكاء الاصطناعي
  45. input double AIConfidenceLevel = 0.65; // مستوى ثقة الذكاء الاصطناعي
  46. input bool UseMarketFilter = true; // فلتر حالة السوق
  47.  
  48. input group "══════════════ إعدادات متقدمة ═════════════════"
  49. input int MagicNumber = 2024001; // الرقم السحري
  50. input int MaxOpenTrades = 3; // الحد الأقصى للصفقات
  51. input int Slippage = 3; // الانزلاق المسموح
  52. input bool EnableHedging = false; // السماح بالتحوط
  53.  
  54. //+------------------------------------------------------------------+
  55. //| المتغيرات العالمية |
  56. //+------------------------------------------------------------------+
  57. enum MARKET_CONDITION
  58. {
  59. MARKET_TREND_UP, // اتجاه صاعد
  60. MARKET_TREND_DOWN, // اتجاه هابط
  61. MARKET_RANGE, // سوق جانبي
  62. MARKET_VOLATILE // سوق متقلب
  63. };
  64.  
  65. struct TradeSignal
  66. {
  67. int direction; // 1 للشراء، -1 للبيع، 0 لا إشارة
  68. double confidence; // ثقة الإشارة (0-1)
  69. double entryPrice; // سعر الدخول المقترح
  70. double stopLoss; // وقف الخسارة المقترح
  71. double takeProfit; // جني الأرباح المقترح
  72. string signalName; // اسم الإشارة
  73. };
  74.  
  75. // المتغيرات
  76. double gPoint;
  77. datetime gLastBarTime;
  78. int gTotalTradesToday;
  79. double gDailyProfit;
  80. double gAccountRisk;
  81. bool gIsNewsTime;
  82. MqlDateTime gCurrentTime;
  83.  
  84. //+------------------------------------------------------------------+
  85. //| دالة التهيئة |
  86. //+------------------------------------------------------------------+
  87. int OnInit()
  88. {
  89. // ضبط القيم الأساسية
  90. gPoint = _Point;
  91. gLastBarTime = 0;
  92. gTotalTradesToday = 0;
  93. gDailyProfit = 0;
  94. gIsNewsTime = false;
  95.  
  96. // التحقق من صحة الإعدادات
  97. if(!ValidateSettings())
  98. {
  99. Print("خطأ: إعدادات غير صالحة!");
  100. return INIT_PARAMETERS_INCORRECT;
  101. }
  102.  
  103. // حساب مخاطرة الحساب
  104. CalculateAccountRisk();
  105.  
  106. // عرض معلومات النظام
  107. DisplayStartupInfo();
  108.  
  109. // إنشاء كائنات الرسم (للنسخ المميزة)
  110. if(MQLInfoInteger(MQL_DLLS_ALLOWED))
  111. CreateDashboard();
  112.  
  113. Print("====== MoneyCatcher AI ======");
  114. Print("الإصدار: ", _Version);
  115. Print("الرمز: ", Symbol());
  116. Print("الرسم البياني: ", EnumToString(Period()));
  117. Print("تم التهيئة بنجاح!");
  118.  
  119. return INIT_SUCCEEDED;
  120. }
  121.  
  122. //+------------------------------------------------------------------+
  123. //| التحقق من صحة الإعدادات |
  124. //+------------------------------------------------------------------+
  125. bool ValidateSettings()
  126. {
  127. if(RiskPercent <= 0 || RiskPercent > 10)
  128. {
  129. Alert("نسبة المخاطرة يجب أن تكون بين 0.1 و 10");
  130. return false;
  131. }
  132.  
  133. if(FixedLotSize <= 0)
  134. {
  135. Alert("حجم اللوت يجب أن يكون أكبر من الصفر");
  136. return false;
  137. }
  138.  
  139. if(MaxOpenTrades <= 0)
  140. {
  141. Alert("يجب السماح بفتح صفقة واحدة على الأقل");
  142. return false;
  143. }
  144.  
  145. return true;
  146. }
  147.  
  148. //+------------------------------------------------------------------+
  149. //| حساب مخاطرة الحساب |
  150. //+------------------------------------------------------------------+
  151. void CalculateAccountRisk()
  152. {
  153. double balance = AccountInfoDouble(ACCOUNT_BALANCE);
  154. double equity = AccountInfoDouble(ACCOUNT_EQUITY);
  155.  
  156. gAccountRisk = (equity / balance - 1) * 100;
  157.  
  158. if(gAccountRisk < -20)
  159. {
  160. Print("تحذير: مخاطرة الحساب مرتفعة: ", DoubleToString(gAccountRisk, 2), "%");
  161. }
  162. }
  163.  
  164. //+------------------------------------------------------------------+
  165. //| عرض معلومات البدء |
  166. //+------------------------------------------------------------------+
  167. void DisplayStartupInfo()
  168. {
  169. Comment("\n",
  170. "════════════════════════════════════════════════════\n",
  171. " MoneyCatcher AI v3.1 \n",
  172. "════════════════════════════════════════════════════\n",
  173. "الحساب: ", AccountInfoString(ACCOUNT_NAME), "\n",
  174. "الرصيد: $", DoubleToString(AccountInfoDouble(ACCOUNT_BALANCE), 2), "\n",
  175. "الرمز: ", Symbol(), " | ", EnumToString(Period()), "\n",
  176. "════════════════════════════════════════════════════\n",
  177. "الصفقات النشطة: ", CountActiveTrades(), "\n",
  178. "مخاطرة الحساب: ", DoubleToString(gAccountRisk, 2), "%\n",
  179. "════════════════════════════════════════════════════\n",
  180. "حالة النظام: ", (EnableAI ? "✓ الذكاء الاصطناعي مفعل" : "النظام التقليدي"), "\n",
  181. "════════════════════════════════════════════════════"
  182. );
  183. }
  184.  
  185. //+------------------------------------------------------------------+
  186. //| الدالة الرئيسية |
  187. //+------------------------------------------------------------------+
  188. void OnTick()
  189. {
  190. // تحديث الوقت الحالي
  191. TimeCurrent(gCurrentTime);
  192.  
  193. // التحقق من الشمعة الجديدة
  194. if(!IsNewBar())
  195. return;
  196.  
  197. // تحديث بيانات اليوم
  198. UpdateDailyStats();
  199.  
  200. // التحقق من وقت الأخبار
  201. if(AvoidNews)
  202. CheckNewsTime();
  203.  
  204. // التحليل الفني
  205. TradeSignal signal = AnalyzeMarket();
  206.  
  207. // إدارة الصفقات المفتوحة
  208. ManageOpenTrades();
  209.  
  210. // فتح صفقات جديدة إذا كان هناك إشارة
  211. if(signal.direction != 0 && signal.confidence >= AIConfidenceLevel)
  212. {
  213. if(CheckTradingConditions())
  214. {
  215. OpenTrade(signal);
  216. }
  217. }
  218.  
  219. // تحديث لوحة المعلومات
  220. UpdateDashboard();
  221. }
  222.  
  223. //+------------------------------------------------------------------+
  224. //| تحليل السوق باستخدام الذكاء الاصطناعي |
  225. //+------------------------------------------------------------------+
  226. TradeSignal AnalyzeMarket()
  227. {
  228. TradeSignal signal;
  229. ZeroMemory(signal);
  230.  
  231. // إذا كان الذكاء الاصطناعي معطل، استخدام النظام التقليدي
  232. if(!EnableAI)
  233. {
  234. signal = TraditionalAnalysis();
  235. }
  236. else
  237. {
  238. // نظام الذكاء الاصطناعي المتقدم
  239. signal = AIAnalysis();
  240. }
  241.  
  242. // تطبيق فلتر حالة السوق
  243. if(UseMarketFilter)
  244. {
  245. MARKET_CONDITION condition = DetermineMarketCondition();
  246. if(!IsConditionSuitable(signal.direction, condition))
  247. {
  248. signal.direction = 0;
  249. signal.confidence = 0;
  250. }
  251. }
  252.  
  253. return signal;
  254. }
  255.  
  256. //+------------------------------------------------------------------+
  257. //| التحليل التقليدي |
  258. //+------------------------------------------------------------------+
  259. TradeSignal TraditionalAnalysis()
  260. {
  261. TradeSignal signal;
  262. ZeroMemory(signal);
  263.  
  264. // مؤشرات متعددة للتحليل
  265. double rsi = iRSI(Symbol(), TradingTF, 14, PRICE_CLOSE, 0);
  266. double macd_main, macd_signal;
  267. GetMACD(macd_main, macd_signal);
  268. double ma_fast = iMA(Symbol(), TradingTF, 20, 0, MODE_EMA, PRICE_CLOSE, 0);
  269. double ma_slow = iMA(Symbol(), TradingTF, 50, 0, MODE_EMA, PRICE_CLOSE, 0);
  270.  
  271. bool buyCondition = (rsi < 30 && macd_main > macd_signal && Close[0] > ma_fast);
  272. bool sellCondition = (rsi > 70 && macd_main < macd_signal && Close[0] < ma_fast);
  273.  
  274. if(buyCondition)
  275. {
  276. signal.direction = 1;
  277. signal.confidence = 0.7;
  278. signal.entryPrice = Ask;
  279. signal.signalName = "Trend_Reversal_Buy";
  280. }
  281. else if(sellCondition)
  282. {
  283. signal.direction = -1;
  284. signal.confidence = 0.7;
  285. signal.entryPrice = Bid;
  286. signal.signalName = "Trend_Reversal_Sell";
  287. }
  288.  
  289. return signal;
  290. }
  291.  
  292. //+------------------------------------------------------------------+
  293. //| تحليل الذكاء الاصطناعي |
  294. //+------------------------------------------------------------------+
  295. TradeSignal AIAnalysis()
  296. {
  297. TradeSignal signal;
  298. ZeroMemory(signal);
  299.  
  300. // جمع بيانات السوق
  301. double features[];
  302. CollectMarketFeatures(features);
  303.  
  304. // محاكاة نظام ذكاء اصطناعي (يمكن استبدالها بشبكة عصبية حقيقية)
  305. double aiScore = CalculateAIScore(features);
  306.  
  307. if(aiScore > AIConfidenceLevel)
  308. {
  309. signal.direction = 1;
  310. signal.confidence = aiScore;
  311. signal.entryPrice = Ask;
  312. signal.signalName = "AI_Buy_Signal";
  313. }
  314. else if(aiScore < -AIConfidenceLevel)
  315. {
  316. signal.direction = -1;
  317. signal.confidence = MathAbs(aiScore);
  318. signal.entryPrice = Bid;
  319. signal.signalName = "AI_Sell_Signal";
  320. }
  321.  
  322. // حساب وقف الخسارة وجني الأرباح
  323. if(signal.direction != 0)
  324. {
  325. CalculateStopLevels(signal);
  326. }
  327.  
  328. return signal;
  329. }
  330.  
  331. //+------------------------------------------------------------------+
  332. //| جمع ميزات السوق للذكاء الاصطناعي |
  333. //+------------------------------------------------------------------+
  334. void CollectMarketFeatures(double &features[])
  335. {
  336. ArrayResize(features, 10);
  337.  
  338. // 1. قوة الاتجاه
  339. features[0] = CalculateTrendStrength();
  340.  
  341. // 2. التقلب
  342. features[1] = CalculateVolatility();
  343.  
  344. // 3. زخم السوق
  345. features[2] = CalculateMomentum();
  346.  
  347. // 4. حجم التداول
  348. features[3] = CalculateVolumeRatio();
  349.  
  350. // 5. مؤشر RSI
  351. features[4] = iRSI(Symbol(), TradingTF, 14, PRICE_CLOSE, 0) / 100;
  352.  
  353. // 6. Stochastic
  354. double stochK, stochD;
  355. GetStochastic(stochK, stochD);
  356. features[5] = stochK / 100;
  357.  
  358. // 7. فرق المتوسطات
  359. features[6] = (iMA(Symbol(), TradingTF, 20, 0, MODE_SMA, PRICE_CLOSE, 0) -
  360. iMA(Symbol(), TradingTF, 50, 0, MODE_SMA, PRICE_CLOSE, 0)) / Point;
  361.  
  362. // 8. سعر الإغلاق النسبي
  363. features[7] = (Close[0] - iMA(Symbol(), TradingTF, 20, 0, MODE_SMA, PRICE_CLOSE, 0)) / Point;
  364.  
  365. // 9. عرض النطاق
  366. features[8] = (iATR(Symbol(), TradingTF, 14, 0) / Point) / 100;
  367.  
  368. // 10. نسبة المخاطرة/المكافأة
  369. features[9] = CalculateRiskRewardRatio();
  370. }
  371.  
  372. //+------------------------------------------------------------------+
  373. //| حساب نتيجة الذكاء الاصطناعي |
  374. //+------------------------------------------------------------------+
  375. double CalculateAIScore(double &features[])
  376. {
  377. // أوزان النموذج (محاكاة لشبكة عصبية)
  378. double weights[] = {0.15, 0.12, 0.18, 0.10, 0.08, 0.07, 0.12, 0.09, 0.05, 0.04};
  379. double bias = -0.3;
  380.  
  381. double score = bias;
  382. for(int i = 0; i < ArraySize(features); i++)
  383. {
  384. score += features[i] * weights[i];
  385. }
  386.  
  387. // تطبيق دالة sigmoid
  388. score = 2.0 / (1.0 + MathExp(-2.0 * score)) - 1.0;
  389.  
  390. return score;
  391. }
  392.  
  393. //+------------------------------------------------------------------+
  394. //| تحديد حالة السوق |
  395. //+------------------------------------------------------------------+
  396. MARKET_CONDITION DetermineMarketCondition()
  397. {
  398. double atr = iATR(Symbol(), TradingTF, 14, 0);
  399. double maDiff = MathAbs(iMA(Symbol(), TradingTF, 20, 0, MODE_EMA, PRICE_CLOSE, 0) -
  400. iMA(Symbol(), TradingTF, 50, 0, MODE_EMA, PRICE_CLOSE, 0));
  401.  
  402. if(maDiff > atr * 2)
  403. {
  404. if(iMA(Symbol(), TradingTF, 20, 0, MODE_EMA, PRICE_CLOSE, 0) >
  405. iMA(Symbol(), TradingTF, 50, 0, MODE_EMA, PRICE_CLOSE, 0))
  406. return MARKET_TREND_UP;
  407. else
  408. return MARKET_TREND_DOWN;
  409. }
  410. else if(atr > iATR(Symbol(), TradingTF, 14, 20))
  411. {
  412. return MARKET_VOLATILE;
  413. }
  414.  
  415. return MARKET_RANGE;
  416. }
  417.  
  418. //+------------------------------------------------------------------+
  419. //| التحقق من ملائمة حالة السوق |
  420. //+------------------------------------------------------------------+
  421. bool IsConditionSuitable(int direction, MARKET_CONDITION condition)
  422. {
  423. if(direction == 1) // شراء
  424. {
  425. if(condition == MARKET_TREND_DOWN)
  426. return false;
  427. }
  428. else if(direction == -1) // بيع
  429. {
  430. if(condition == MARKET_TREND_UP)
  431. return false;
  432. }
  433.  
  434. if(condition == MARKET_VOLATILE && AvoidNews)
  435. return false;
  436.  
  437. return true;
  438. }
  439.  
  440. //+------------------------------------------------------------------+
  441. //| حساب مستويات الوقف |
  442. //+------------------------------------------------------------------+
  443. void CalculateStopLevels(TradeSignal &signal)
  444. {
  445. double atr = iATR(Symbol(), TradingTF, 14, 0);
  446.  
  447. if(UseAutoStopLoss)
  448. {
  449. if(signal.direction == 1)
  450. signal.stopLoss = signal.entryPrice - (StopLossPips * Point);
  451. else
  452. signal.stopLoss = signal.entryPrice + (StopLossPips * Point);
  453. }
  454.  
  455. if(UseAutoTakeProfit)
  456. {
  457. if(signal.direction == 1)
  458. signal.takeProfit = signal.entryPrice + (TakeProfitPips * Point);
  459. else
  460. signal.takeProfit = signal.entryPrice - (TakeProfitPips * Point);
  461. }
  462. }
  463.  
  464. //+------------------------------------------------------------------+
  465. //| التحقق من ظروف التداول |
  466. //+------------------------------------------------------------------+
  467. bool CheckTradingConditions()
  468. {
  469. // التحقق من وقت التداول
  470. if(UseTradingHours)
  471. {
  472. if(gCurrentTime.hour < TradingStartHour || gCurrentTime.hour >= TradingEndHour)
  473. return false;
  474. }
  475.  
  476. // التحقق من الأخبار
  477. if(gIsNewsTime && AvoidNews)
  478. return false;
  479.  
  480. // التحقق من الحد الأقصى للصفقات
  481. if(CountActiveTrades() >= MaxOpenTrades)
  482. return false;
  483.  
  484. // التحقق من رصيد الحساب
  485. if(AccountInfoDouble(ACCOUNT_BALANCE) < 100)
  486. {
  487. Print("رصيد الحساب منخفض جدًا");
  488. return false;
  489. }
  490.  
  491. // التحقق من انتشار السوق
  492. double spread = (Ask - Bid) / Point;
  493. if(spread > 20)
  494. {
  495. Print("الانتشار مرتفع جدًا: ", spread);
  496. return false;
  497. }
  498.  
  499. return true;
  500. }
  501.  
  502. //+------------------------------------------------------------------+
  503. //| فتح صفقة جديدة |
  504. //+------------------------------------------------------------------+
  505. void OpenTrade(TradeSignal &signal)
  506. {
  507. // حساب حجم اللوت
  508. double lotSize = CalculateLotSize();
  509.  
  510. // إعداد أمر التداول
  511. MqlTradeRequest request;
  512. MqlTradeResult result;
  513. ZeroMemory(request);
  514. ZeroMemory(result);
  515.  
  516. request.action = TRADE_ACTION_DEAL;
  517. request.symbol = Symbol();
  518. request.volume = lotSize;
  519. request.type = (signal.direction == 1) ? ORDER_TYPE_BUY : ORDER_TYPE_SELL;
  520. request.price = (signal.direction == 1) ? Ask : Bid;
  521. request.sl = signal.stopLoss;
  522. request.tp = signal.takeProfit;
  523. request.deviation = Slippage;
  524. request.magic = MagicNumber;
  525. request.comment = signal.signalName;
  526. request.type_filling = ORDER_FILLING_IOC;
  527.  
  528. // إرسال الأمر
  529. if(OrderSend(request, result))
  530. {
  531. Print("تم فتح صفقة #", result.order, " ", signal.signalName,
  532. " حجم: ", lotSize, " ثقة: ", DoubleToString(signal.confidence * 100, 1), "%");
  533.  
  534. gTotalTradesToday++;
  535. }
  536. else
  537. {
  538. Print("فشل فتح الصفقة: ", GetLastError());
  539. }
  540. }
  541.  
  542. //+------------------------------------------------------------------+
  543. //| إدارة الصفقات المفتوحة |
  544. //+------------------------------------------------------------------+
  545. void ManageOpenTrades()
  546. {
  547. for(int i = OrdersTotal() - 1; i >= 0; i--)
  548. {
  549. if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
  550. {
  551. if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
  552. {
  553. // تطبيق نقطة التعادل
  554. if(UseBreakEven)
  555. ApplyBreakEven(OrderTicket());
  556.  
  557. // إغلاق الصفقات بناءً على شروط الذكاء الاصطناعي
  558. CheckForEarlyClose(OrderTicket());
  559. }
  560. }
  561. }
  562. }
  563.  
  564. //+------------------------------------------------------------------+
  565. //| تطبيق نقطة التعادل |
  566. //+------------------------------------------------------------------+
  567. void ApplyBreakEven(int ticket)
  568. {
  569. if(OrderSelect(ticket, SELECT_BY_TICKET))
  570. {
  571. double currentProfit = OrderProfit();
  572. double pointsInProfit = 0;
  573.  
  574. if(OrderType() == OP_BUY)
  575. pointsInProfit = (Bid - OrderOpenPrice()) / Point;
  576. else if(OrderType() == OP_SELL)
  577. pointsInProfit = (OrderOpenPrice() - Ask) / Point;
  578.  
  579. if(pointsInProfit >= BreakEvenAt && OrderStopLoss() == 0)
  580. {
  581. double newStopLoss = OrderOpenPrice();
  582. ModifyOrder(ticket, OrderOpenPrice(), OrderTakeProfit());
  583. Print("تم تفعيل نقطة التعادل للصفقة #", ticket);
  584. }
  585. }
  586. }
  587.  
  588. //+------------------------------------------------------------------+
  589. //| حساب حجم اللوت |
  590. //+------------------------------------------------------------------+
  591. double CalculateLotSize()
  592. {
  593. double lotSize = FixedLotSize;
  594.  
  595. if(UseMoneyManagement)
  596. {
  597. double riskAmount = AccountInfoDouble(ACCOUNT_BALANCE) * (RiskPercent / 100);
  598. double tickValue = MarketInfo(Symbol(), MODE_TICKVALUE);
  599. double stopLossPoints = StopLossPips * 10; // تحويل للنقاط
  600.  
  601. if(stopLossPoints > 0 && tickValue > 0)
  602. {
  603. lotSize = riskAmount / (stopLossPoints * tickValue);
  604. }
  605.  
  606. // التطبيع
  607. double minLot = MarketInfo(Symbol(), MODE_MINLOT);
  608. double maxLot = MarketInfo(Symbol(), MODE_MAXLOT);
  609. double lotStep = MarketInfo(Symbol(), MODE_LOTSTEP);
  610.  
  611. lotSize = MathMax(lotSize, minLot);
  612. lotSize = MathMin(lotSize, MaxLotSize);
  613. lotSize = NormalizeDouble(lotSize, 2);
  614. }
  615.  
  616. return lotSize;
  617. }
  618.  
  619. //+------------------------------------------------------------------+
  620. //| التحقق من وقت الأخبار |
  621. //+------------------------------------------------------------------+
  622. void CheckNewsTime()
  623. {
  624. // هذه وظيفة تجميلية - في النسخة الحقيقية يمكن ربطها بمصدر أخبار
  625. // محاكاة فترات الأخبار (8:30, 13:30, 15:00 توقيت السيرفر)
  626. int newsHours[] = {8, 13, 15};
  627. int newsMinutes[] = {30, 30, 0};
  628.  
  629. gIsNewsTime = false;
  630.  
  631. for(int i = 0; i < ArraySize(newsHours); i++)
  632. {
  633. if(gCurrentTime.hour == newsHours[i] &&
  634. gCurrentTime.min >= (newsMinutes[i] - NewsBufferMinutes) &&
  635. gCurrentTime.min <= (newsMinutes[i] + NewsBufferMinutes))
  636. {
  637. gIsNewsTime = true;
  638. break;
  639. }
  640. }
  641. }
  642.  
  643. //+------------------------------------------------------------------+
  644. //| تحديث إحصائيات اليوم |
  645. //+------------------------------------------------------------------+
  646. void UpdateDailyStats()
  647. {
  648. static datetime lastDayCheck = 0;
  649. MqlDateTime today;
  650. TimeCurrent(today);
  651.  
  652. if(lastDayCheck == 0 || today.day != TimeDay(lastDayCheck))
  653. {
  654. gTotalTradesToday = 0;
  655. gDailyProfit = 0;
  656. lastDayCheck = TimeCurrent();
  657. }
  658. }
  659.  
  660. //+------------------------------------------------------------------+
  661. //| تحديث لوحة المعلومات |
  662. //+------------------------------------------------------------------+
  663. void UpdateDashboard()
  664. {
  665. if(!MQLInfoInteger(MQL_VISUAL_MODE)) return;
  666.  
  667. string dashboard =
  668. "\n" +
  669. "════════════════════════════════════════════════════\n" +
  670. " MoneyCatcher AI - لوحة التحكم \n" +
  671. "════════════════════════════════════════════════════\n" +
  672. "الوقت: " + TimeToString(TimeCurrent()) + "\n" +
  673. "السعر: " + DoubleToString(Ask, _Digits) + "\n" +
  674. "════════════════════════════════════════════════════\n" +
  675. "الصفقات النشطة: " + IntegerToString(CountActiveTrades()) + "\n" +
  676. "صفقات اليوم: " + IntegerToString(gTotalTradesToday) + "\n" +
  677. "ربح اليوم: $" + DoubleToString(GetDailyProfit(), 2) + "\n" +
  678. "════════════════════════════════════════════════════\n" +
  679. "حالة السوق: " + GetMarketConditionText() + "\n" +
  680. "الانتشار: " + DoubleToString((Ask-Bid)/Point, 0) + " نقطة\n" +
  681. "════════════════════════════════════════════════════\n" +
  682. (gIsNewsTime ? "⚠️ وقت الأخبار - التداول محدود\n" : "✓ وقت تداول عادي\n") +
  683. "════════════════════════════════════════════════════";
  684.  
  685. Comment(dashboard);
  686. }
  687.  
  688. //+------------------------------------------------------------------+
  689. //| الدوال المساعدة |
  690. //+------------------------------------------------------------------+
  691. bool IsNewBar()
  692. {
  693. datetime currentBarTime = iTime(Symbol(), Period(), 0);
  694. if(currentBarTime != gLastBarTime)
  695. {
  696. gLastBarTime = currentBarTime;
  697. return true;
  698. }
  699. return false;
  700. }
  701.  
  702. int CountActiveTrades()
  703. {
  704. int count = 0;
  705. for(int i = OrdersTotal() - 1; i >= 0; i--)
  706. {
  707. if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
  708. {
  709. if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
  710. count++;
  711. }
  712. }
  713. return count;
  714. }
  715.  
  716. double GetDailyProfit()
  717. {
  718. double profit = 0;
  719. for(int i = OrdersTotal() - 1; i >= 0; i--)
  720. {
  721. if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
  722. {
  723. if(OrderSymbol() == Symbol() &&
  724. OrderMagicNumber() == MagicNumber &&
  725. TimeDay(OrderOpenTime()) == TimeDay(TimeCurrent()))
  726. {
  727. profit += OrderProfit() + OrderSwap() + OrderCommission();
  728. }
  729. }
  730. }
  731. return profit;
  732. }
  733.  
  734. string GetMarketConditionText()
  735. {
  736. MARKET_CONDITION condition = DetermineMarketCondition();
  737. switch(condition)
  738. {
  739. case MARKET_TREND_UP: return "📈 اتجاه صاعد";
  740. case MARKET_TREND_DOWN: return "📉 اتجاه هابط";
  741. case MARKET_RANGE: return "↔️ سوق جانبي";
  742. case MARKET_VOLATILE: return "⚡ سوق متقلب";
  743. }
  744. return "غير معروف";
  745. }
  746.  
  747. void GetMACD(double &main, double &signal)
  748. {
  749. main = iMACD(Symbol(), TradingTF, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, 0);
  750. signal = iMACD(Symbol(), TradingTF, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 0);
  751. }
  752.  
  753. void GetStochastic(double &K, double &D)
  754. {
  755. K = iStochastic(Symbol(), TradingTF, 14, 3, 3, MODE_SMA, 0, MODE_MAIN, 0);
  756. D = iStochastic(Symbol(), TradingTF, 14, 3, 3, MODE_SMA, 0, MODE_SIGNAL, 0);
  757. }
  758.  
  759. double CalculateTrendStrength()
  760. {
  761. double adx = iADX(Symbol(), TradingTF, 14, PRICE_CLOSE, MODE_MAIN, 0);
  762. return adx / 100;
  763. }
  764.  
  765. double CalculateVolatility()
  766. {
  767. double atr = iATR(Symbol(), TradingTF, 14, 0);
  768. double avgAtr = iATR(Symbol(), TradingTF, 14, 20);
  769. return atr / avgAtr - 1;
  770. }
  771.  
  772. double CalculateMomentum()
  773. {
  774. double momentum = (Close[0] - Close[20]) / Point;
  775. return momentum / 1000;
  776. }
  777.  
  778. double CalculateVolumeRatio()
  779. {
  780. double volume = iVolume(Symbol(), TradingTF, 0);
  781. double avgVolume = 0;
  782. for(int i = 1; i <= 20; i++)
  783. avgVolume += iVolume(Symbol(), TradingTF, i);
  784. avgVolume /= 20;
  785. return volume / avgVolume;
  786. }
  787.  
  788. double CalculateRiskRewardRatio()
  789. {
  790. if(StopLossPips > 0 && TakeProfitPips > 0)
  791. return (double)TakeProfitPips / StopLossPips;
  792. return 1.0;
  793. }
  794.  
  795. void CreateDashboard()
  796. {
  797. // إنشاء كائنات رسم للنسخة المميزة
  798. // (يمكن إضافة رسوم بيانية ومؤشرات متقدمة هنا)
  799. }
  800.  
  801. void CheckForEarlyClose(int ticket)
  802. {
  803. // منطق الإغلاق المبكر بناءً على تحليل الذكاء الاصطناعي
  804. if(OrderSelect(ticket, SELECT_BY_TICKET))
  805. {
  806. double currentProfit = OrderProfit();
  807. double openPrice = OrderOpenPrice();
  808. double currentPrice = (OrderType() == OP_BUY) ? Bid : Ask;
  809.  
  810. // مثال: إغلاق إذا انعكس السوق بقوة
  811. double priceMove = MathAbs(currentPrice - openPrice) / Point;
  812. if(priceMove > TakeProfitPips * 0.5 && currentProfit > 0)
  813. {
  814. // يمكن إضافة منطق إغلاق ذكي هنا
  815. }
  816. }
  817. }
  818.  
  819. void ModifyOrder(int ticket, double sl, double tp)
  820. {
  821. MqlTradeRequest request;
  822. MqlTradeResult result;
  823. ZeroMemory(request);
  824. ZeroMemory(result);
  825.  
  826. if(OrderSelect(ticket, SELECT_BY_TICKET))
  827. {
  828. request.action = TRADE_ACTION_SLTP;
  829. request.order = ticket;
  830. request.symbol = OrderSymbol();
  831. request.sl = sl;
  832. request.tp = tp;
  833.  
  834. OrderSend(request, result);
  835. }
  836. }
  837.  
  838. //+------------------------------------------------------------------+
  839. //| دالة إلغاء التهيئة |
  840. //+------------------------------------------------------------------+
  841. void OnDeinit(const int reason)
  842. {
  843. // تنظيف الذاكرة والمؤشرات
  844. ObjectsDeleteAll(0, -1);
  845.  
  846. // حفظ سجل التداول
  847. SaveTradingLog();
  848.  
  849. // عرض رسالة الخروج
  850. Print("====== MoneyCatcher AI - إنهاء ======");
  851. Print("السبب: ", GetDeinitReasonText(reason));
  852. Print("صفقات اليوم: ", gTotalTradesToday);
  853. Print("ربح اليوم: $", DoubleToString(GetDailyProfit(), 2));
  854. Print("====================================");
  855.  
  856. Comment("");
  857. }
  858.  
  859. //+------------------------------------------------------------------+
  860. //| الحصول على نص سبب الإنهاء |
  861. //+------------------------------------------------------------------+
  862. string GetDeinitReasonText(int reason)
  863. {
  864. switch(reason)
  865. {
  866. case REASON_ACCOUNT: return "تغيير الحساب";
  867. case REASON_CHARTCHANGE: return "تغيير الرسم البياني";
  868. case REASON_CHARTCLOSE: return "إغلاق الرسم البياني";
  869. case REASON_PARAMETERS: return "تغيير المعلمات";
  870. case REASON_RECOMPILE: return "إعادة الترجمة";
  871. case REASON_REMOVE: return "إزالة الخبير";
  872. case REASON_TEMPLATE: return "تغيير القالب";
  873. default: return "سبب غير معروف";
  874. }
  875. }
  876.  
  877. //+------------------------------------------------------------------+
  878. //| حفظ سجل التداول |
  879. //+------------------------------------------------------------------+
  880. void SaveTradingLog()
  881. {
  882. // في النسخة الكاملة، يمكن حفظ البيانات في ملف أو قاعدة بيانات
  883. string logEntry = StringFormat("%s,%s,%.2f,%d,%.2f",
  884. TimeToString(TimeCurrent()),
  885. Symbol(),
  886. AccountInfoDouble(ACCOUNT_EQUITY),
  887. gTotalTradesToday,
  888. GetDailyProfit()
  889. );
  890.  
  891. // مثال لحفظ في ملف (يمكن تفعيله في النسخة المدفوعة)
  892. // int handle = FileOpen("MoneyCatcher_Log.csv", FILE_READ|FILE_WRITE|FILE_CSV);
  893. // if(handle != INVALID_HANDLE)
  894. // {
  895. // FileSeek(handle, 0, SEEK_END);
  896. // FileWrite(handle, logEntry);
  897. // FileClose(handle);
  898. // }
  899. }
  900. //+------------------------------------------------------------------+
Success #stdin #stdout #stderr 0.01s 5316KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: near line 1: near "/": syntax error
Error: near line 65: near "struct": syntax error
Error: near line 75: near "/": syntax error
Error: near line 77: near "datetime": syntax error
Error: near line 78: near "int": syntax error
Error: near line 79: near "double": syntax error
Error: near line 80: near "double": syntax error
Error: near line 81: near "bool": syntax error
Error: near line 82: near "MqlDateTime": syntax error
Error: near line 84: near "/": syntax error
Error: near line 91: near "gLastBarTime": syntax error
Error: near line 92: near "gTotalTradesToday": syntax error
Error: near line 93: near "gDailyProfit": syntax error
Error: near line 94: near "gIsNewsTime": syntax error
Error: near line 96: near "/": syntax error
Error: near line 100: near "return": syntax error
Error: near line 101: unrecognized token: "}"
Error: near line 106: near "/": syntax error
Error: near line 109: near "/": syntax error
Error: near line 113: near "Print": syntax error
Error: near line 114: near "Print": syntax error
Error: near line 115: near "Print": syntax error
Error: near line 116: near "Print": syntax error
Error: near line 117: near "Print": syntax error
Error: near line 119: near "return": syntax error
Error: near line 120: unrecognized token: "}"
Error: near line 130: near "return": syntax error
Error: near line 131: unrecognized token: "}"
Error: near line 136: near "return": syntax error
Error: near line 137: unrecognized token: "}"
Error: near line 142: near "return": syntax error
Error: near line 143: unrecognized token: "}"
Error: near line 146: unrecognized token: "}"
Error: near line 154: near "double": syntax error
Error: near line 156: near "gAccountRisk": syntax error
Error: near line 158: near "if": syntax error
Error: near line 161: unrecognized token: "}"
Error: near line 183: unrecognized token: "}"
Error: near line 193: near "/": syntax error
Error: near line 197: near "/": syntax error
Error: near line 200: near "/": syntax error
Error: near line 204: near "/": syntax error
Error: near line 207: near "/": syntax error
Error: near line 210: near "/": syntax error
Error: near line 216: unrecognized token: "}"
Error: near line 221: unrecognized token: "}"
Error: near line 229: near "ZeroMemory": syntax error
Error: near line 231: near "/": syntax error
Error: near line 235: unrecognized token: "}"
Error: near line 240: unrecognized token: "}"
Error: near line 246: near "if": syntax error
Error: near line 249: near "signal": syntax error
Error: near line 250: unrecognized token: "}"
Error: near line 254: unrecognized token: "}"
Error: near line 262: near "ZeroMemory": syntax error
Error: near line 264: near "/": syntax error
Error: near line 266: near "double": syntax error
Error: near line 267: near "GetMACD": syntax error
Error: near line 268: near "double": syntax error
Error: near line 269: near "double": syntax error
Error: near line 271: near "bool": syntax error
Error: near line 272: near "bool": syntax error
Error: near line 274: near "if": syntax error
Error: near line 277: near "signal": syntax error
Error: near line 278: near "signal": syntax error
Error: near line 279: near "signal": syntax error
Error: near line 280: unrecognized token: "}"
Error: near line 284: near "signal": syntax error
Error: near line 285: near "signal": syntax error
Error: near line 286: near "signal": syntax error
Error: near line 287: unrecognized token: "}"
Error: near line 290: unrecognized token: "}"
Error: near line 298: near "ZeroMemory": syntax error
Error: near line 300: near "/": syntax error
Error: near line 302: near "CollectMarketFeatures": syntax error
Error: near line 304: near "/": syntax error
Error: near line 307: near "if": syntax error
Error: near line 310: near "signal": syntax error
Error: near line 311: near "signal": syntax error
Error: near line 312: near "signal": syntax error
Error: near line 313: unrecognized token: "}"
Error: near line 317: near "signal": syntax error
Error: near line 318: near "signal": syntax error
Error: near line 319: near "signal": syntax error
Error: near line 320: unrecognized token: "}"
Error: near line 326: unrecognized token: "}"
Error: near line 329: unrecognized token: "}"
Error: near line 338: near "/": syntax error
Error: near line 341: near "/": syntax error
Error: near line 344: near "/": syntax error
Error: near line 347: near "/": syntax error
Error: near line 350: near "/": syntax error
Error: near line 353: near "/": syntax error
Error: near line 355: near "GetStochastic": syntax error
Error: near line 356: near "features": syntax error
Error: near line 358: near "/": syntax error
Error: near line 362: near "/": syntax error
Error: near line 365: near "/": syntax error
Error: near line 368: near "/": syntax error
Error: near line 370: unrecognized token: "}"
Error: near line 379: near "double": syntax error
Error: near line 381: near "double": syntax error
Error: near line 382: near "for": syntax error
Error: near line 385: unrecognized token: "}"
Error: near line 390: near "return": syntax error
Error: near line 391: unrecognized token: "}"
Error: near line 399: near "double": syntax error
Error: near line 402: near "if": syntax error
Error: near line 407: near "else": syntax error
Error: near line 409: unrecognized token: "}"
Error: near line 413: unrecognized token: "}"
Error: near line 416: unrecognized token: "}"
Error: near line 427: unrecognized token: "}"
Error: near line 432: unrecognized token: "}"
Error: near line 437: near "return": syntax error
Error: near line 438: unrecognized token: "}"
Error: near line 447: near "if": syntax error
Error: near line 451: near "else": syntax error
Error: near line 453: unrecognized token: "}"
Error: near line 459: near "else": syntax error
Error: near line 461: unrecognized token: "}"
Error: near line 474: unrecognized token: "}"
Error: near line 480: near "/": syntax error
Error: near line 484: near "/": syntax error
Error: near line 488: near "return": syntax error
Error: near line 489: unrecognized token: "}"
Error: near line 493: near "if": syntax error
Error: near line 496: near "return": syntax error
Error: near line 497: unrecognized token: "}"
Error: near line 500: unrecognized token: "}"
Error: near line 510: near "/": syntax error
Error: near line 512: near "MqlTradeResult": syntax error
Error: near line 513: near "ZeroMemory": syntax error
Error: near line 514: near "ZeroMemory": syntax error
Error: near line 516: near "request": syntax error
Error: near line 517: near "request": syntax error
Error: near line 518: near "request": syntax error
Error: near line 519: near "request": syntax error
Error: near line 520: near "request": syntax error
Error: near line 521: near "request": syntax error
Error: near line 522: near "request": syntax error
Error: near line 523: near "request": syntax error
Error: near line 524: near "request": syntax error
Error: near line 525: near "request": syntax error
Error: near line 526: near "request": syntax error
Error: near line 528: near "/": syntax error
Error: near line 534: near "gTotalTradesToday": syntax error
Error: near line 535: unrecognized token: "}"
Error: near line 539: unrecognized token: "}"
Error: near line 557: near "/": syntax error
Error: near line 559: unrecognized token: "}"
Error: near line 572: near "double": syntax error
Error: near line 574: near "if": syntax error
Error: near line 576: near "else": syntax error
Error: near line 579: near "if": syntax error
Error: near line 582: near "ModifyOrder": syntax error
Error: near line 583: near "Print": syntax error
Error: near line 584: unrecognized token: "}"
Error: near line 595: near "if": syntax error
Error: near line 598: near "double": syntax error
Error: near line 599: near "double": syntax error
Error: near line 604: unrecognized token: "}"
Error: near line 608: near "double": syntax error
Error: near line 609: near "double": syntax error
Error: near line 611: near "lotSize": syntax error
Error: near line 612: near "lotSize": syntax error
Error: near line 613: near "lotSize": syntax error
Error: near line 614: unrecognized token: "}"
Error: near line 617: unrecognized token: "}"
Error: near line 627: near "int": syntax error
Error: near line 629: near "gIsNewsTime": syntax error
Error: near line 631: near "for": syntax error
Error: near line 638: near "break": syntax error
Error: near line 639: unrecognized token: "}"
Error: near line 649: near "MqlDateTime": syntax error
Error: near line 650: near "TimeCurrent": syntax error
Error: near line 652: near "if": syntax error
Error: near line 655: near "gDailyProfit": syntax error
Error: near line 656: near "lastDayCheck": syntax error
Error: near line 657: unrecognized token: "}"
Error: near line 667: near "string": syntax error
Error: near line 685: near "Comment": syntax error
Error: near line 686: unrecognized token: "}"
Error: near line 694: near "if": syntax error
Error: near line 697: near "return": syntax error
Error: near line 698: unrecognized token: "}"
Error: near line 700: unrecognized token: "}"
Error: near line 705: near "for": syntax error
Error: near line 711: unrecognized token: "}"
Error: near line 714: unrecognized token: "}"
Error: near line 719: near "for": syntax error
Error: near line 728: unrecognized token: "}"
Error: near line 732: unrecognized token: "}"
Error: near line 737: near "switch": syntax error
Error: near line 740: near "case": syntax error
Error: near line 741: near "case": syntax error
Error: near line 742: near "case": syntax error
Error: near line 743: unrecognized token: "}"
Error: near line 745: unrecognized token: "}"
Error: near line 750: near "signal": syntax error
Error: near line 751: unrecognized token: "}"
Error: near line 756: near "D": syntax error
Error: near line 757: unrecognized token: "}"
Error: near line 762: near "return": syntax error
Error: near line 763: unrecognized token: "}"
Error: near line 768: near "double": syntax error
Error: near line 769: near "return": syntax error
Error: near line 770: unrecognized token: "}"
Error: near line 775: near "return": syntax error
Error: near line 776: unrecognized token: "}"
Error: near line 781: near "double": syntax error
Error: near line 782: near "for": syntax error
Error: near line 784: near "avgVolume": syntax error
Error: near line 785: near "return": syntax error
Error: near line 786: unrecognized token: "}"
Error: near line 792: near "return": syntax error
Error: near line 793: unrecognized token: "}"
Error: near line 807: near "double": syntax error
Error: near line 808: near "double": syntax error
Error: near line 810: near "/": syntax error
Error: near line 812: near "if": syntax error
Error: near line 822: near "MqlTradeResult": syntax error
Error: near line 823: near "ZeroMemory": syntax error
Error: near line 824: near "ZeroMemory": syntax error
Error: near line 826: near "if": syntax error
Error: near line 829: near "request": syntax error
Error: near line 830: near "request": syntax error
Error: near line 831: near "request": syntax error
Error: near line 832: near "request": syntax error
Error: near line 834: near "OrderSend": syntax error
Error: near line 835: unrecognized token: "}"
Error: near line 846: near "/": syntax error
Error: near line 849: near "/": syntax error
Error: near line 851: near "Print": syntax error
Error: near line 852: near "Print": syntax error
Error: near line 853: near "Print": syntax error
Error: near line 854: near "Print": syntax error
Error: near line 856: near "Comment": syntax error
Error: near line 857: unrecognized token: "}"
Error: near line 867: near "case": syntax error
Error: near line 868: near "case": syntax error
Error: near line 869: near "case": syntax error
Error: near line 870: near "case": syntax error
Error: near line 871: near "case": syntax error
Error: near line 872: near "case": syntax error
Error: near line 873: near "default": syntax error
Error: near line 874: unrecognized token: "}"
Error: near line 891: near "/": syntax error
Error: near line 893: near "/": syntax error
Error: near line 896: near "/": syntax error
Error: near line 897: near "/": syntax error
Error: near line 898: near "/": syntax error