Setup guide
- Use a webhook receiver (PineConnector, or your own relay that queues orders).
- In MetaTrader: Tools → Options → Expert Advisors → allow WebRequest for your relay URL.
- Paste the EA below into MetaEditor, compile, and attach to any chart with the same secret & magic number.
- Switch the header to "Live MT4/MT5 Bridge". Always test on a demo account first.
//+------------------------------------------------------------------+
//| FXSentinelBridge.mq5 — polls your relay and executes JSON orders |
//| Tools > Options > Expert Advisors > Allow WebRequest for RELAY_URL|
//+------------------------------------------------------------------+
#property strict
#include <Trade/Trade.mqh>
input string RELAY_URL = "https://your-relay.example.com/orders";
input string SECRET = "change-me";
input long MAGIC = 240611;
input int POLL_SEC = 2;
CTrade trade;
int OnInit(){ trade.SetExpertMagicNumber(MAGIC); EventSetTimer(POLL_SEC); return INIT_SUCCEEDED; }
void OnDeinit(const int r){ EventKillTimer(); }
string J(string js,string key){
int p=StringFind(js,"\""+key+"\""); if(p<0) return "";
p=StringFind(js,":",p)+1;
while(StringGetCharacter(js,p)==' '||StringGetCharacter(js,p)=='"') p++;
int e=p; while(e<StringLen(js)){ ushort c=StringGetCharacter(js,e); if(c==','||c=='}'||c=='"') break; e++; }
return StringSubstr(js,p,e-p);
}
void OnTimer(){
char post[],res[]; string hdr="X-Secret: "+SECRET+"\r\n", rh;
int code=WebRequest("GET",RELAY_URL,hdr,3000,post,res,rh);
if(code!=200) return;
string js=CharArrayToString(res); if(StringLen(js)<5) return;
if(J(js,"secret")!=SECRET) return;
string act=J(js,"action"), sym=J(js,"symbol");
double lots=StringToDouble(J(js,"lots")), sl=StringToDouble(J(js,"sl")), tp=StringToDouble(J(js,"tp1"));
int dev=(int)StringToInteger(J(js,"slippage")); trade.SetDeviationInPoints(dev);
if(act=="BUY") trade.Buy(lots,sym,0,sl,tp,J(js,"comment"));
if(act=="SELL") trade.Sell(lots,sym,0,sl,tp,J(js,"comment"));
if(act=="CLOSE_ALL"){ for(int i=PositionsTotal()-1;i>=0;i--){ ulong t=PositionGetTicket(i);
if(PositionGetInteger(POSITION_MAGIC)==MAGIC) trade.PositionClose(t);} }
}