Gamestudio Links
Zorro Links
Newest Posts
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
Release 2.68 replacement of the .par format
by Martin_HH. 09/23/25 20:48
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 16,510 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 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: 60
V
vicknick Offline OP
Junior Member
vicknick  Offline OP
Junior Member
V

Joined: Apr 2023
Posts: 60
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