1 registered members (sequi),
648
guests, and 4
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Bug in trade management function int input
#488414
10/21/24 15:38
10/21/24 15:38
|
Joined: Jan 2022
Posts: 63 Budapest
NorbertSz
OP
Junior Member
|
OP
Junior Member
Joined: Jan 2022
Posts: 63
Budapest
|
Hello, I have a TMF, here is how I define it, and the way I open the trade:
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:
...
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:
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:
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
Serious User
|
Serious User
Joined: Feb 2017
Posts: 1,753
Chicago
|
This is wrong: 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.htmNote 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
NorbertSz
OP
Junior Member
|
OP
Junior Member
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.
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
Serious User
|
Serious User
Joined: Feb 2017
Posts: 1,753
Chicago
|
That sounds like something I might’ve complained about before 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]
#488423
10/23/24 18:11
10/23/24 18:11
|
Joined: Feb 2017
Posts: 1,753 Chicago
AndrewAMD
Serious User
|
Serious User
Joined: Feb 2017
Posts: 1,753
Chicago
|
jcl, When I look at the TRADE struct, I see this: 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.
|
|
|
|