Reputation: 9
I'm trying to print the totalprofit into the output file, but the totalprofit comes out to be nan. The profit variable is fine, and its not turning toward infinity or dividing by 0. I'm simply adding the profit values into a totalprofit. Not sure why its showing me nan.
double profit, totalprofit;
int intsize = 500;
for(int j = 0; j < 372500; j++)
{
infile>>data;
tradethis.push_back(data);
if(j%intsize==0)
{
for(int i=1; i<intsize; i++)
{
profit=0;
profit=eurusd.position(i-1)*((tradethis[i]-tradethis[i-1])); //position returns 1000
totalprofit = totalprofit + profit;
outdata<<totalprofit<<endl;
cout<<totalprofit<<endl;
//pnl.push_back(totalprofit);
if(profit>0)
{
c+=1.0;
t+=1.0;
}
else if(profit<0)
{
w+=1.0;
t+=1.0;
}
}
tradethis.clear();
}
}
outdata.close();
Upvotes: 0
Views: 131
Reputation: 11178
double profit = 0, totalprofit = 0;
A good compiler would warn on that.
profit
does not need an early declaration.Upvotes: 2