Edit: See this post of this thread for a more clearer and shorter problem example.
-----------
I get the following output when formatting numbers with the ‘NumToStr(numeric variable, decimals)’ output. For some reason, NumToStr() does not display the last 4 variables it needs to print, but reuses the first four variables – I’ve highlighted these errors in yellow.
I’ve printed the same variables without NumToStr and once with the ‘:0:3’ formatting added to the variable. These do get printed correctly – underlined with blue.
Screenshot of problem.
I assume that, if there was an error in calculation of the variables, the other Print versions would also return some erroneous output. I’ve checked the calculated values with the Performance Report, and they are correct. I don't understand why NumToStr prints the first values correctly, but then reuses the first variables. As you can see in the two printouts following the NumToStr line, the variables do get printed when using something different than NumToStr.
What am I missing?
This NumToStr() behaviour has happened before, and since I've been able to replicate it using the newly written default code below, it might be a error worth further investigation (or I keep making the same errors. ).
Complete code:
Code: Select all
Variables:
accountSize(InitialCapital), winLossRatio(0), winPercentage(0),
profit(0), loss(0), profitFactor(0), pessResult(0), prom(0), stdAfwTrades(0),
numOfTrades(0), nettoProfit(0), avgTrade(0),
numOfWins(0), numOfLosses(0), avgWin(0), avgLoss(0),
outputString(""), headerString(""), ws(";")
;
numOfTrades = TotalTrades;
nettoProfit = NetProfit;
profit = GrossProfit;
loss = GrossLoss;
numOfWins = NumWinTrades;
numOfLosses = NumLosTrades;
// Calculations
avgTrade = nettoProfit / numOfTrades;
avgWin = profit / numOfWins;
avgLoss = loss / numOfLosses;
winLossRatio = avgWin / absvalue(avgLoss);
profitFactor = profit / absvalue(loss);
pessResult = 0;
stdAfwTrades = 0;
prom = accountSize;
winPercentage = (numOfWins / numOfTrades) * 100;
{tmp}
ws = Spaces(4);
// Create string with strategy data
outputString = Text(
NumToStr(profit, 2), ws,
NumToStr(loss, 2), ws,
NumToStr(nettoProfit, 2), ws,
NumToStr(profitFactor, 4), ws,
NumToStr(pessResult, 2), ws,
NumToStr(prom, 3), ws,
NumToStr(avgWin, 3), ws,
NumToStr(avgLoss, 3), ws,
NumToStr(avgTrade, 3), ws,
NumToStr(stdAfwTrades, 4), ws,
NumToStr(winLossRatio, 4), ws,
NumToStr(numOfWins, 0), ws,
NumToStr(numOfLosses, 0), ws,
NumToStr(winPercentage, 3), ws
);
// Create header string
headerString = Text(
"GrossProfit", ws,
"GrossLoss", ws,
"NetProfit", ws,
"ProfitFactor", ws,
"PessimisticResult", ws,
"PROM", ws,
"AvgWin", ws,
"AvgLoss", ws,
"AvgTrade", ws,
"StdAvgTrade", ws,
"WinLossRatio", ws,
"WinningTrades", ws,
"LosingTrades", ws,
"WinPercentage", ws
);
Print(headerString, NewLine, outputString);
// Removing the NumToStr from the output string variable
// Create string with strategy data
outputString = Text(
profit, ws,
loss, ws,
nettoProfit, ws,
profitFactor, ws,
pessResult, ws,
prom, ws,
avgWin, ws,
avgLoss, ws,
avgTrade, ws,
stdAfwTrades, ws,
winLossRatio, ws,
numOfWins, ws,
numOfLosses, ws,
winPercentage, ws
);
Print(NewLine, " Now without NumToStr:");
Print(headerString, NewLine, outputString);
// Now with rounding through :0:3 etc.
outputString = Text(
profit:0:2, ws,
loss:0:2, ws,
nettoProfit:0:2, ws,
profitFactor:0:4, ws,
pessResult:0:2, ws,
prom:0:4, ws,
avgWin:0:4, ws,
avgLoss:0:4, ws,
avgTrade:0:4, ws,
stdAfwTrades:0:4, ws,
winLossRatio:0:4, ws,
numOfWins:0:0, ws,
numOfLosses:0:0, ws,
winPercentage:0:0, ws
);
Print(NewLine, " Now with formatting through :0:3 etc.");
Print(headerString, NewLine, outputString);
Code: Select all
if LastBarOnChart_s = true then begin
MyTestFunction1();
end;