Hi Jcl,
There is only one line of code where I set the Stop equal to a value.
And looks like this is happening only in live trading with IB.
I checked the test log and all stops hit have normal values.

Script is below: Is just the Get Rich slowly modified for trading:

#define LEVERAGE 2 // 1:4 leverage
#define DAYS 252 // 1 year
#define NN 300 // max number of assets

string Names[NN];
vars Returns[NN];
var Means[NN];
var Covariances[NN][NN];
var Weights[NN];

//////////////////////////////////////////////////////

function run()
{
BarPeriod = 1440;
LookBack = DAYS;
NumYears = 5;
Verbose = 30;
set(PRELOAD); // allow extremely long lookback period



var TotalCapital = slider(1,1000,0,10000,"Capital","Total capital to distribute");
var VFactor = slider(2,10,0,100,"Risk","Variance factor");

int N = 0;
assetList("AssetsZ8NasdaqStocks.csv");
while (asset(loop(Assets)))
{
Names[N] =Asset;

Returns[N] = series((priceClose(0)-priceClose(1))/priceClose(1));
if(N++ >= NN) break;
}


int i,j;
for(i=0; i<N; i++)
{
Means[i] = Moment(Returns[i],LookBack,1);
for(j=0; j<N; j++)
Covariances[N*i+j] = Covariance(Returns[i],Returns[j],LookBack);
}

var BestVariance = markowitz(Covariances,Means,N,0.5);
var MinVariance = markowitzReturn(0,0);
markowitzReturn(Weights,MinVariance+VFactor/100.*(BestVariance-MinVariance));

for(i=0; i<N; i++)
{
asset(Names[i]);
Stop=priceClose()-(3*ATR(30));
Trail=ATR(2);
MarginCost = priceClose()/LEVERAGE;
int Position = TotalCapital*Weights[i]/MarginCost;

//printf("n%s: %d Contracts at %.0f$",Names[i],Position,priceClose());

if(tdm() == 1 )
{
if(Position>LotsPool)
{
enterLong(Position-LotsPool);//Position-LotsPool);

}
else if(Position<LotsPool)
{
exitLong(0,0,LotsPool-Position);//0,0,LotsPool-Position);
}
}
}

}



THanks
Vincenzo