Gamestudio Links
Zorro Links
Newest Posts
Zorro version 3.0 prerelease!
by jcl. 02/12/26 14:05
MarginCost discrepancy?
by jcl. 02/12/26 14:02
Hedge on FXCM, 4 or 5?
by qin. 02/11/26 14:12
CMC MT4 CFD vs FX Active - what's better?
by mayarik. 02/11/26 11:00
print a "still alive" log
by qin. 02/10/26 12:16
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
1 registered members (TipmyPip), 7,786 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
ApprenticeInMuc, PatrickH90, USER0328, Sfrdragon, mayarik
19198 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Possible Bug When Multiplying Two Variable #488439
11/24/24 08:31
11/24/24 08:31
Joined: Apr 2023
Posts: 61
V
vicknick Offline OP
Junior Member
vicknick  Offline OP
Junior Member
V

Joined: Apr 2023
Posts: 61
I have a function that returns the var "AlgoForecast", which is then used to multiply with 0.65 to get a final var "Forecast" in the main run().

However, the multiplication seems to be wrong when doing so. The code is as follow:

Code
function tradeAlgo()
{
	var AlgoForecast = -12.34;
	printf("#\nAlgoForecast: %.2f", AlgoForecast);
	return AlgoForecast;
}

function run() 
{
	//Backtest configurations
	set(LOGFILE);
	TickTime = 500;
	StartDate = 1985;
	LookBack = 260;
	Capital = -1000000;
	BarPeriod = 1440;
	Fill = 3;
	Spread = Commission = 0;
	RollLong = RollShort = Slippage = Penalty = 0;
	
	var Forecast;
	Forecast = 0.65*tradeAlgo();
	
	printf("#\nForecast: %.2f", Forecast);
	
}


The log:
Code
[9: Tue 85-01-15 15:40] (170.81)
AlgoForecast: -12.34
Forecast: -7.80


From the code, the AlgoFunction returns -12.34, which is multiplied with 0.65, which should give -12.34*0.65 = -8.021. However, the log shows the final result is -7.80.

Last edited by vicknick; 11/24/24 08:32.
Re: Possible Bug When Multiplying Two Variable [Re: vicknick] #488441
11/24/24 19:28
11/24/24 19:28
Joined: Aug 2017
Posts: 311
Netherlands
G
Grant Offline
Senior Member
Grant  Offline
Senior Member
G

Joined: Aug 2017
Posts: 311
Netherlands
Use 'var tradeAlgo()...' (so not 'function') and and optionally 'printf("\nForecast: %.3f", Forecast);' for better precision.

Last edited by Grant; 11/24/24 19:29.

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1