// 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
Margin= 30;
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);
}