//+------------------------------------------------------------------+ //| Piptology_Bridge.mq4 | //| Piptology - The Science of Market Precision | //| Real-Time Price & Tick Bridge EA for MetaTrader 4 | //| Menghubungkan harga live XAU/USD MetaTrader 4 ke Piptology | //+------------------------------------------------------------------+ #property copyright "Piptology - The Science of Market Precision" #property link "http://localhost:8000" #property version "1.00" #property strict //--- Input Parameters input string ServerURL = "http://localhost:8000/api/metatrader/feed"; // URL Server Piptology input int UpdateIntervalMillis = 500; // Frekuensi update (milidetik) input bool SendCompletedCandle = true; // Kirim candle M1/M5 selesai //--- Global Variables datetime last_send_time = 0; datetime last_candle_time = 0; ulong last_tick_milli = 0; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { Print("🚀 [Piptology Bridge MT4] Diinisialisasi untuk simbol: ", Symbol(), " di broker: ", AccountCompany()); Print("â„šī¸ [Piptology Bridge MT4] Pastikan URL: http://localhost:8000 telah diizinkan di Tools -> Options -> Expert Advisors -> Allow WebRequest"); EventSetMillisecondTimer(UpdateIntervalMillis); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { EventKillTimer(); Print("🛑 [Piptology Bridge MT4] Dihentikan."); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { SendTickData(); } //+------------------------------------------------------------------+ //| Timer function | //+------------------------------------------------------------------+ void OnTimer() { SendTickData(); } //+------------------------------------------------------------------+ //| Fungsi Mengirim Data Tick & Candle ke Server Web | //+------------------------------------------------------------------+ void SendTickData() { ulong now_milli = GetMicrosecondCount() / 1000; if(now_milli - last_tick_milli < (ulong)UpdateIntervalMillis) return; last_tick_milli = now_milli; double bid = Bid; double ask = Ask; if(bid <= 0 || ask <= 0) return; string broker = AccountCompany(); string account = IntegerToString(AccountNumber()); string sym = Symbol(); int server_time = (int)TimeCurrent(); // Format JSON payload string payload = "{" + "\"broker\":\"" + broker + "\"," + "\"account\":\"" + account + "\"," + "\"symbol\":\"" + sym + "\"," + "\"bid\":" + DoubleToString(bid, 2) + "," + "\"ask\":" + DoubleToString(ask, 2) + "," + "\"time\":" + IntegerToString(server_time) + "," + "\"timeframe\":\"" + EnumToString((ENUM_TIMEFRAMES)Period()) + "\""; // Tambahkan candle terbaru jika diperlukan if(SendCompletedCandle) { double o = iOpen(sym, Period(), 0); double h = iHigh(sym, Period(), 0); double l = iLow(sym, Period(), 0); double c = iClose(sym, Period(), 0); long v = iVolume(sym, Period(), 0); int t = (int)iTime(sym, Period(), 0); payload += ",\"candle\":{" + "\"time\":" + IntegerToString(t) + "," + "\"open\":" + DoubleToString(o, 2) + "," + "\"high\":" + DoubleToString(h, 2) + "," + "\"low\":" + DoubleToString(l, 2) + "," + "\"close\":" + DoubleToString(c, 2) + "," + "\"volume\":" + IntegerToString(v) + "}"; } payload += "}"; // Kirim via WebRequest char post_data[]; char result_data[]; string result_headers; string headers = "Content-Type: application/json\r\n"; StringToCharArray(payload, post_data, 0, StringLen(payload)); int res = WebRequest("POST", ServerURL, headers, 1000, post_data, result_data, result_headers); if(res == -1) { int err = GetLastError(); if(err == 4060) // ERR_WEBREQUEST_URL_NOT_ALLOWED { Print("âš ī¸ [Piptology Bridge MT4 Error] URL belum diizinkan! Buka Tools -> Options -> Expert Advisors, centang 'Allow WebRequest for listed URL' dan tambahkan: http://localhost:8000"); } } } //+------------------------------------------------------------------+