Gamestudio Links
Zorro Links
Newest Posts
Issue with converted data
by steventrading15. 12/12/24 21:30
MT4 Bridge connectivity issue
by FXSurgeon. 12/11/24 14:40
Zorro Gives Wrong Calculation During Backtest
by vicknick. 12/11/24 06:31
Price is not shifted with PriceOffset
by vicknick. 12/10/24 13:30
Zorro Gives Price that Doesn't Exist
by jcl. 12/10/24 08:55
Multicore Optimize
by jcl. 12/10/24 08:48
Get timestamp as a var
by Mac81. 12/08/24 01:50
Multicore Optimizations
by Cristoig2001. 12/05/24 14:14
AUM Magazine
Latest Screens
Galactic Strike X
Zeal-X2
The Bible Game
A psychological thriller game
Who's Online Now
1 registered members (sequi), 648 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sequi, MikeHe, Algospider, jordi, FXSurgeon
19090 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Bug in trade management function int input #488414
10/21/24 15:38
10/21/24 15:38
Joined: Jan 2022
Posts: 63
Budapest
N
NorbertSz Offline OP
Junior Member
NorbertSz  Offline OP
Junior Member
N

Joined: Jan 2022
Posts: 63
Budapest
Hello,

I have a TMF, here is how I define it, and the way I open the trade:

Code
int tmf(int startBar, int endBar){
    printf("\ntmf startbar endbar %d %d", startBar, endBar);
    printf("\ntmf2 int int %d %d", TradeInt[0], TradeInt[1]);
    return 0;
}

...

TRADE* asd = enterLong(tmf, innerImpulseStartBar, innerImpulseEndBar);
if (asd){
    ThisTrade = asd;
    TradeInt[0] = innerImpulseStartBar;
    TradeInt[1] = innerImpulseEndBar;
}


innerImpulseStartBar and innerImpulseEndBar are both integers, there are no conversations in this case.
At the output window I see the following:

Code
...
tmf startbar endbar -1645196208 -104
tmf2 int int 4 1
...


It seems like a memory garbage, like the startBar and endBar in the tmf is never setted up.
However, if I use vars and floats like this:

Code
int tmf(var startBar, var endBar){
    printf("\ntmf startbar endbar %.5f %.5f", startBar, endBar);
    printf("\ntmf2 float float %.5f %.5f", TradeVar[0], TradeVar[1]);
    return 0;
}

...

TRADE* asd = enterLong(tmf, (float)innerImpulseStartBar, (float)innerImpulseEndBar);
if (asd){
    ThisTrade = asd;
    TradeVar[0] = (float)innerImpulseStartBar;
    TradeVar[1] = (float)innerImpulseEndBar;
}


I get the following result:

Code
tmf startbar endbar 4.00000 1.00000
tmf2 float float 4.00000 1.00000


Am I wrong, or is it a bug in the tmf input handling?

Last edited by NorbertSz; 10/21/24 15:45.
Re: Bug in trade management function int input [Re: NorbertSz] #488418
10/21/24 18:38
10/21/24 18:38
Joined: Feb 2017
Posts: 1,753
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,753
Chicago
This is wrong:
Code
int tmf(int startBar, int endBar)
Reason:
"If the TMF is passed to an enter command, it can receive up to 8 additional var parameters following the function name: enterLong(MyTMF, parameter1, parameter2...). They must also appear in the function's parameter list and keep their values during the lifetime of the trade. The alternative global manage function has no parameters."
https://zorro-project.com/manual/en/trade.htm

Note that is says var and not int.

Re: Bug in trade management function int input [Re: AndrewAMD] #488419
10/22/24 07:11
10/22/24 07:11
Joined: Jan 2022
Posts: 63
Budapest
N
NorbertSz Offline OP
Junior Member
NorbertSz  Offline OP
Junior Member
N

Joined: Jan 2022
Posts: 63
Budapest
Right, thank you.

In this case, there is no way to pass an integer or string to TMF, just var. Because the TMF function runs once immediately after the enter, before we have a chance to set up TradeInt or TradeStr. So in the first iteration of TMF, you have only var inputs.

It would be nice in the future if we could use any type of input in the trade management function. Not just int, but string or even any custom stuff. Now the workaround is to make a global variable of an unordered map or something, use the pointer of the trade as an ID, and store the trade data in a custom-defined struct.
Code
trade_function_data[CUSTOM_GENERATED_TRADE_ID].startBar = 8;
...
enterLong(tmf, CUSTOM_GENERATED_TRADE_ID);


...and of course we need to cleanup aftert the closed trades.

Last edited by NorbertSz; 10/22/24 07:30.
Re: Bug in trade management function int input [Re: NorbertSz] #488420
10/22/24 10:38
10/22/24 10:38
Joined: Feb 2017
Posts: 1,753
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,753
Chicago
That sounds like something I might’ve complained about before grin

Another possibility is to call an “initializer TMF” which will set up TradeInt and change the TMF to the “real TMF” by changing the function pointer in the ThisTrade TRADE struct. You can even call the real TMF from the initializer TMF and return that value.

Last edited by AndrewAMD; 10/22/24 13:55. Reason: fixed an error
Re: Bug in trade management function int input [Re: NorbertSz] #488422
10/23/24 15:13
10/23/24 15:13
Joined: Jul 2000
Posts: 28,003
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,003
Frankfurt
Why so complicated? A var is just a 64-bit value. What's in these 64 bits, whether ints or strings, is up to you.

int tmf(var Parameter1) {
string MyString = (string)&Parameter1;
...
}

string String1 = "Zorro";
enterLong(tmf,*((var*)String1));

Re: Bug in trade management function int input [Re: NorbertSz] #488423
10/23/24 18:11
10/23/24 18:11
Joined: Feb 2017
Posts: 1,753
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,753
Chicago
jcl,

When I look at the TRADE struct, I see this:
Code
typedef struct TRADE
{
	//...
	float	fArg[8];		// TMF arguments
	//...
} TRADE;
Correct me if I'm wrong, but up to eight doubles are cast to float storage, which are then cast to double for the TMF arguments. I would assume this would compromise the integrity of the given 64-bit data.

Re: Bug in trade management function int input [Re: NorbertSz] #488424
10/25/24 14:56
10/25/24 14:56
Joined: Jul 2000
Posts: 28,003
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,003
Frankfurt
You're right. I confused that with the TradeVars. So it's only 32 bit per parameter, and in the example, var must be replaced with float and "Zorro" with "Zor".

Re: Bug in trade management function int input [Re: NorbertSz] #488425
10/25/24 15:58
10/25/24 15:58
Joined: Feb 2017
Posts: 1,753
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,753
Chicago
Oh that's interesting, I assumed the casting would mangle the float bytes. I guess not. The below works:
Code
int main(){
	float f = 0;
	int* pN = &f;
	*pN = 12345;
	double d = f;
	f = 0;
	printf("\n*pN: %d",*pN);
	f = d;
	printf("\n*pN: %d",*pN);
	char* pS = &f;
	strcpy(pS,"abc");
	d = f;
	f = 0;
	printf("\npS: %s",pS);
	f = d;
	printf("\npS: %s",pS);
}

/* output:

*pN: 0
*pN: 12345
pS: 
pS: abc

*/


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1