MQL5

اکسپوژر خالص به تفکیک ارز

هر پوزیشن فارکس رو به اکسپوژر خرید/فروش برای هر ارز تجزیه می‌کنه (پایه خریده‌شده، متقابل فروخته‌شده) تا تمرکز پنهان رو لو بده — سه معامله‌ی «متفاوت» می‌تونن در واقع یک شرط واحد روی USD باشن.

کاربرد

کنترل ریسک پرتفوی: سقف گذاشتن روی اکسپوژر خالص به یک ارز.

پیش‌نیازها

MetaTrader 5, MQL5, symboles Forex standard

MQL5
void PrintCurrencyExposure()
{
   string curr[]; double expo[];

   for(int i = PositionsTotal() - 1; i >= 0; i--)
   {
      if(PositionGetTicket(i) == 0) continue;
      string sym  = PositionGetString(POSITION_SYMBOL);
      string base = SymbolInfoString(sym, SYMBOL_CURRENCY_BASE);
      string quot = SymbolInfoString(sym, SYMBOL_CURRENCY_PROFIT);
      double lots = PositionGetDouble(POSITION_VOLUME);
      if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
         lots = -lots;

      AddExposure(curr, expo, base,  lots);  // acheter EURUSD = long EUR
      AddExposure(curr, expo, quot, -lots);  //                = short USD
   }
   for(int i = 0; i < ArraySize(curr); i++)
      PrintFormat("%s : %+.2f lots nets", curr[i], expo[i]);
}

void AddExposure(string &curr[], double &expo[], string c, double lots)
{
   for(int i = 0; i < ArraySize(curr); i++)
      if(curr[i] == c) { expo[i] += lots; return; }
   int n = ArraySize(curr);
   ArrayResize(curr, n + 1); ArrayResize(expo, n + 1);
   curr[n] = c; expo[n] = lots;
}

نتیجه

2026.06.10 11:45:00.330  ExpoMap (EURUSD,M15)  Positions : BUY 0.50 EURUSD | BUY 0.30 GBPUSD | SELL 0.20 USDJPY
2026.06.10 11:45:00.331  ExpoMap (EURUSD,M15)  EUR : +0.50 lots nets
2026.06.10 11:45:00.331  ExpoMap (EURUSD,M15)  USD : -1.00 lots nets
2026.06.10 11:45:00.332  ExpoMap (EURUSD,M15)  GBP : +0.30 lots nets
2026.06.10 11:45:00.332  ExpoMap (EURUSD,M15)  JPY : +0.20 lots nets
2026.06.10 11:45:00.333  ExpoMap (EURUSD,M15)  Concentration : 3 trades "différents" = 1 seul pari anti-USD
ExpositionDevisesPortefeuilleRisk Management

اسنیپت‌های مرتبط

بازگشت به آزمایشگاه داده