Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/20/24 01:28
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (7th_zorro), 793 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Trying to get TradeVar[0] to work correctly #438064
03/06/14 01:08
03/06/14 01:08
Joined: Jul 2013
Posts: 522
D
dusktrader Offline OP
User
dusktrader  Offline OP
User
D

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?
Code:
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: dusktrader] #438066
03/06/14 07:29
03/06/14 07:29
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Originally Posted By: The Mighty Manual
The trade variables listed above can only be used inside TMFs and in trade enumeration loops; they are not actualized outside.

http://manual.zorro-trader.com/trade.htm

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
D
dusktrader Offline OP
User
dusktrader  Offline OP
User
D

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]:
Quote:
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
D
dusktrader Offline OP
User
dusktrader  Offline OP
User
D

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] #438075
03/06/14 12:18
03/06/14 12:18
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
There are no "v0..v7" variables. Between the parentheses in a function definition is the list of arguments that the function takes. "v0..v7" just means that the function takes 8 arguments - their names are up to you.

TradeVar is used for storing a trade-dependent value between TMF calls. It's like a static variable, only difference is that static variables would be the same for all trades, while a TradeVar can have an individual value per trade.

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
D
DdlV Offline
Serious User
DdlV  Offline
Serious User
D

Joined: Jun 2013
Posts: 1,609
Hi dusktrader. Here are my answers so jcl can correct both of us! laugh

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
D
dusktrader Offline OP
User
dusktrader  Offline OP
User
D

Joined: Jul 2013
Posts: 522
Thanks jcl & DdlV,
I'm understanding!

DdlV, on this one piece:
Originally Posted By: DdlV
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.
Re: Trying to get TradeVar[0] to work correctly [Re: dusktrader] #438080
03/06/14 15:11
03/06/14 15:11
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
DdlV is correct.

For passing a changing value, such as an indicator, from the run function to a TMF, simply use a global variable. Global variables are defined outside of functions, and can be accessed by all functions.

http://manual.zorro-trader.com/aarray.htm

Re: Trying to get TradeVar[0] to work correctly [Re: jcl] #438112
03/07/14 11:49
03/07/14 11:49
Joined: Jul 2013
Posts: 522
D
dusktrader Offline OP
User
dusktrader  Offline OP
User
D

Joined: Jul 2013
Posts: 522
I'm having trouble finding or creating a global variable that is accessible within the TMF, that can be kept with its asset.

For example I think AlgoVar[] should work in a while(asset(loop, but it doesn't seem to do what I want. After a few iterations, the values set in AlgoVar[0] do not seem to stay with their current asset, or perhaps they are getting reset when the loop changes

I want to be able to take a series value from run() and then inside the TMF for any trades taken under that asset, be able to access that value. However, the global value needs to stay with its asset, because during the while(asset(loop, different series values would be used for different assets.

Another possibility might be to set ThisTrade.TradeVar once I'm inside the TMF. But so far I don't know how to do this (but believe it should be possible).

Re: Trying to get TradeVar[0] to work correctly [Re: dusktrader] #438117
03/07/14 13:46
03/07/14 13:46
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
For storing values specific to an asset and algo, AlgoVar is the right choice. But for selecting the right AlgoVar set, you need to call algo() with a valid algo name before, in the run function as well as in the TMF.

I do not know what trouble you're having, but if something does not work as expected, you can almost always find the reason by logging the variables with printf() commands.

Otherwise post the code that does not work and I'll look through it.

Page 1 of 2 1 2

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1