Currency strength functions

ccySet(var Strength)

Stores the strength of the current Forex asset separately for currency and counter currency. The Strength value can be any indicator or other price function that depends on "strength" or "weakness" of a currrency. It is decomposed into separate strength values for the currency and the counter currency.

ccyReset()

Resets the stored strengths of all currencies. Usually called at the begin of every bar before the strengths are summed up by ccySet.

ccyStrength(string Currency): var

Returns the accumulated average strength of the given Currency (3 letters, f.i. "USD") or the strength difference of the given currency pair (7 letters, f.i. "EUR/USD").

ccyMax(): string

Returns the currency pair with the strongest currency and the weakest counter currency.

ccyMin(): string

Returns the currency pair with the weakest currency and the strongest counter currency.

Parameters:

Strength Strength value, for instance the price rate of change. Must be in the same range for all currency pairs.
Currency Either a single currency ("USD") or a currency pair ("EUR/USD").

Remarks:

Example:

// Currency Strength Strategy /////////////////////
// Exploits price shocks f.i. by CHF cap and Brexit

function run()
{
  BarPeriod = 60;
  ccyReset();	// reset strengths at begin of any bar
  string Name;
  while(Name = (loop(Assets)))
  {
    if(assetType(Name) != FOREX) 
      continue; // Currency pairs only
    asset(Name);
    vars Prices = series(priceClose());
    ccySet(ROC(Prices,1)); // store price change as strength
  }
  
// get currency pairs with highest and lowest strength difference
  string Best = ccyMax(), Worst = ccyMin();
  var Threshold = 1.0;

  static char OldBest[8], OldWorst[8];	// static for keeping contents between runs
  if(*OldBest && !strstr(Best,OldBest)) { // new strongest asset?
    asset(OldBest);
    exitLong();
    if(ccyStrength(Best) > Threshold) {
      asset(Best);
      enterLong();
    }
  } 
  if(*OldWorst && !strstr(Worst,OldWorst)) { // new weakest asset?
    asset(OldWorst);
    exitShort();
    if(ccyStrength(Worst) < -Threshold) {
      asset(Worst);
      enterShort();
    }
  }

// store previous strongest and weakest asset names  
  strcpy(OldBest,Best);
  strcpy(OldWorst,Worst);
}

See also:

asset, ROC

► latest version online