Code: Select all
// convert to units
coef[i] = coef[i] * 1/ConvertCurrency(1,symb[i],"USD",iOpen(symb[i],0,0),s);
here is the function
// convert the coefficients to usable hege ratios by multiplying
// xxx/usd pairs with their quote. The results can then be
// conveniently interpreted as multiples of needed Lots or Units.
// also take care of the special case when fitting a spread
// instead a trend
string s;
for (i=0; i<pairs; i++){
// if we fit a spread then all pairs except this one are on the other
// side (negative) and this one (the regressand) is 1 by definition
if (!trend){
if (i == this){
coef[i] = 1;
}else{
coef[i] = -coef[i];
}
}
// convert to units
coef[i] = coef[i] * 1/ConvertCurrency(1,symb[i],"USD",iOpen(symb[i],0,0),s);
// The following makes sure that if the first pair is an USD/XXX pair
// it is normalized to 1 again and the lot sizes of the other ones
// instead made smaller by the same factor.
if (!trend){
coef[i] = coef[i] /ConvertCurrency(1,symb[i],"USD",iOpen(symb[i],0,0),s);
}
}