//+------------------------------------------------------------------+ //| Piptology_Bridge.mq5 | //| Piptology - The Science of Market Precision | //| Real-Time Price & Tick Bridge EA for MetaTrader 5 | //| Menghubungkan harga live XAU/USD MetaTrader 5 ke Piptology | //+------------------------------------------------------------------+ #property copyright "Piptology - The Science of Market Precision" #property link "http://localhost:8000" #property version "1.00" //--- 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 ulong last_tick_milli = 0; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { Print("🚀 [Piptology Bridge MT5] Diinisialisasi untuk simbol: ", _Symbol, " di broker: ", AccountInfoString(ACCOUNT_COMPANY)); Print("â„šī¸ [Piptology Bridge MT5] 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 MT5] 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; MqlTick last_tick; if(!SymbolInfoTick(_Symbol, last_tick)) return; double bid = last_tick.bid; double ask = last_tick.ask; if(bid <= 0 || ask <= 0) return; string broker = AccountInfoString(ACCOUNT_COMPANY); string account = IntegerToString(AccountInfoInteger(ACCOUNT_LOGIN)); 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 if(SendCompletedCandle) { MqlRates rates[]; ArraySetAsSeries(rates, true); if(CopyRates(_Symbol, _Period, 0, 1, rates) > 0) { payload += ",\"candle\":{" + "\"time\":" + IntegerToString((int)rates[0].time) + "," + "\"open\":" + DoubleToString(rates[0].open, 2) + "," + "\"high\":" + DoubleToString(rates[0].high, 2) + "," + "\"low\":" + DoubleToString(rates[0].low, 2) + "," + "\"close\":" + DoubleToString(rates[0].close, 2) + "," + "\"volume\":" + IntegerToString(rates[0].tick_volume) + "}"; } } 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 == 4014 || err == 5203) // ERR_WEBREQUEST_NOT_ALLOWED { Print("âš ī¸ [Piptology Bridge MT5 Error] URL belum diizinkan! Buka Tools -> Options -> Expert Advisors, centang 'Allow WebRequest for listed URL' dan tambahkan: http://localhost:8000"); } } } //+------------------------------------------------------------------+