1 registered members (7th_zorro),
793
guests, and 1
spider. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Trying to get TradeVar[0] to work correctly
#438064
03/06/14 01:08
03/06/14 01:08
|
Joined: Jul 2013
Posts: 522
dusktrader
OP
User
|
OP
User
Joined: Jul 2013
Posts: 522
|
I'm having trouble getting TradeVar's to work. Can you please look at this code and tell me what I'm doing wrong?
int tmf(var v0)
{
printf("\n\nTradePriceClose = %f",(var)TradePriceClose);
printf("\nv0=%f",v0);
printf("\nTradeVar[0] in tmf() = %f",TradeVar[0]);
return 0;
}
function run()
{
StartDate = 20140204;
EndDate = 20140214;
BarPeriod = 5;
static int iteration;
if (is(INITRUN)) iteration=0;
enterLong(tmf,5.124);
printf("\nTradeVar[0] in run() = %f",TradeVar[0]);
if(iteration++ > 100) quit();
}
THANKS
|
|
|
Re: Trying to get TradeVar[0] to work correctly
[Re: jcl]
#438069
03/06/14 10:53
03/06/14 10:53
|
Joined: Jul 2013
Posts: 522
dusktrader
OP
User
|
OP
User
Joined: Jul 2013
Posts: 522
|
Yes I did read that. But perhaps I'm misunderstanding something here: my understanding is that the 8 general purpose variables are referred to as both v0...v7 and also TradeVar[0]...TradeVar[7] But they don't seem to be the same, so maybe that is where I'm wrong? I also forgot to give you this script output, which shows that v0 is not the same value as TradeVar[0]: TradePriceClose = 81.592003 v0=5.124000 TradeVar[0] in tmf() = 0.000000 TradeVar[0] in run() = 0.000000 Cancelled
I understand that TradeVar[0]...TradeVar[7] are stored in the TRADE struct, so they are available on each successive tmf call. What I don't understand is the enterLong man page, which (to me) suggests that v0...v7 may be the same. If they are indeed the same, then why can't I use them interchangeably?
|
|
|
Re: Trying to get TradeVar[0] to work correctly
[Re: dusktrader]
#438074
03/06/14 11:42
03/06/14 11:42
|
Joined: Jul 2013
Posts: 522
dusktrader
OP
User
|
OP
User
Joined: Jul 2013
Posts: 522
|
Ok I may be answering my own question here, but please correct me if I'm wrong:
based on some more testing, I think I've figured out that v0...v7 are arguments that can be sent to a TMF (as in the above example). However, once a trade is triggered, it seems like this value cannot be changed for the same trade (for example, on successive iterations of the run() function, presumably since the tmf is called only at the time of trade entry).
However, if I set a changing value (such as a series output that I want to evaluate with each run() iteration) in TradeVar[0], then that is like a global static that can then be evaluated inside the TMF.
So if I wanted to create a series in the run() function and then from bar-to-bar evaluate that series' current value inside my active TMF, I would need to use a TradeVar[]
I think the confusion for me is that v0...v7 sounds similar to TradeVar[0]...TradeVar[7] in the description, but they are really not the same at all.
Please correct if any of this is wrong, thank you
|
|
|
Re: Trying to get TradeVar[0] to work correctly
[Re: dusktrader]
#438076
03/06/14 12:26
03/06/14 12:26
|
Joined: Jun 2013
Posts: 1,609
DdlV
Serious User
|
Serious User
Joined: Jun 2013
Posts: 1,609
|
Hi dusktrader. Here are my answers so jcl can correct both of us! Yes, v0..v7 are arguments that are passed to the tmf. No, per the manual, the tmf is called every tick, not only at the time of trade entry. Also per the manual, these parameters are passed again with each call, so each call will use their current values. Yes, they are not the same as the TradeVar's. FYI, I've used #DEFINE to code with meaningful names rather than TradeVar[x] or vx. HTH.
|
|
|
Re: Trying to get TradeVar[0] to work correctly
[Re: DdlV]
#438079
03/06/14 13:55
03/06/14 13:55
|
Joined: Jul 2013
Posts: 522
dusktrader
OP
User
|
OP
User
Joined: Jul 2013
Posts: 522
|
Thanks jcl & DdlV, I'm understanding! DdlV, on this one piece: No, per the manual, the tmf is called every tick, not only at the time of trade entry.
Also per the manual, these parameters are passed again with each call, so each call will use their current values. ...my findings are different. What I meant in my above statement was that the TMF is only triggered upon trade entry. My finding is that a changing value cannot be re-sent as an argument to the tmf() via enterLong(). For example, if you wanted to send the current value of a custom series you built within the run() function (which is different on each iteration of run() ) (Sidenote: for lack of better terminology, the way I envision Zorro working is that a tmf() is essentially "spawned" from the run() loop. Whereas run() loops once per BarPeriod, tmf() loops once per tick. Therefore, the loops run independently and simultaneously. As such, once the tmf() is spawned, it would not be re-spawned again for that trade, which explains why no further arguments can be sent via the initiation.) Instead, you can set TradeVar[0] in the run() function with your changing series value, and it will be accessible within the tmf() that is already active. That would allow one-per-BarPeriod current value to be accessible within the tmf() Those are my findings at least. If this is not correct in any way please clarify. Thanks
Last edited by dusktrader; 03/06/14 14:02.
|
|
|
|