mirror of
https://github.com/A6-9V/MQL5-Google-Onedrive.git
synced 2026-04-11 10:30:58 +00:00
- Create `mt5/MQL5/Include/AiAssistant.mqh` for shared AI logic. - Modularize Gemini API calls, prompt construction, and response parsing. - Update `SMC_TrendBreakout_MTF_EA.mq5` to use `AiAssistant.mqh`. - Enhance AI prompt with RSI and ATR context for better decision making. - Add `RSIPeriod` input parameter. - Add include guards to `AiAssistant.mqh` and `ZoloBridge.mqh`.
54 lines
1.9 KiB
MQL5
54 lines
1.9 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| ZoloBridge.mqh |
|
|
//| Copyright 2024, GenX Solutions |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "Copyright 2024, GenX Solutions"
|
|
#property strict
|
|
|
|
#ifndef ZOLO_BRIDGE_MQH
|
|
#define ZOLO_BRIDGE_MQH
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Helper: Sanitize JSON String |
|
|
//+------------------------------------------------------------------+
|
|
string Zolo_SanitizeJSON(string text)
|
|
{
|
|
string res = text;
|
|
// Replace backslash first to avoid double escaping
|
|
StringReplace(res, "\\", "\\\\");
|
|
StringReplace(res, "\"", "\\\"");
|
|
StringReplace(res, "\n", " ");
|
|
StringReplace(res, "\r", " ");
|
|
StringReplace(res, "\t", " ");
|
|
return res;
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| ZOLO Bridge Function |
|
|
//+------------------------------------------------------------------+
|
|
void SendSignalToBridge(string msg, bool enable, string url)
|
|
{
|
|
if (!enable || url == "") return;
|
|
|
|
string sanitized_msg = Zolo_SanitizeJSON(msg);
|
|
string body = "{\"event\":\"signal\",\"message\":\"" + sanitized_msg + "\"}";
|
|
|
|
char data[];
|
|
int len = StringToCharArray(body, data, 0, WHOLE_ARRAY, CP_UTF8);
|
|
if (len > 0) ArrayResize(data, len - 1); // Remove null terminator
|
|
|
|
char result[];
|
|
string result_headers;
|
|
string headers = "Content-Type: application/json";
|
|
|
|
int res = WebRequest("POST", url, headers, 5000, data, result, result_headers);
|
|
|
|
if (res != 200)
|
|
{
|
|
// Only print on failure to reduce log noise
|
|
PrintFormat("ZOLO WebRequest failed. Code: %d. URL: %s", res, url);
|
|
if(res == -1) Print("Error: ", GetLastError());
|
|
}
|
|
}
|
|
|
|
#endif // ZOLO_BRIDGE_MQH
|