Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (dr_panther, Ayumi, 1 invisible), 877 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Using TradeVar to store an indicator value for later evaluation #459839
06/08/16 13:19
06/08/16 13:19
Joined: Apr 2014
Posts: 482
Sydney, Australia
B
boatman Offline OP
Senior Member
boatman  Offline OP
Senior Member
B

Joined: Apr 2014
Posts: 482
Sydney, Australia
What is the correct usage of the TradeVar[] variables for storing an indicator value for later use? I am running into problems using these variables in a portfolio strategy that trades more than one algorithm. In my usage below, I get the expected results if I comment out one of the algo calls in the algo loop. But if I run both algos, the TradeVars for algo1 all return 0, which is not the values assigned to them in the algo1() function.

Wondering if this could be a bug or if I am missing something obvious?

Thanks

Code:
void algo1()
{
...
TradeVar[0] = x
TradeVar[1] = y
...
enterLong();
...
enterShort();
}

void algo2()
{
...
TradeVar[0] = x
TradeVar[1] = y
enterLong();
...
enterShort();

}

function run()
{
...
while(algo(loop("algo1", "algo2")))
	{
		if(Algo == "algo1") algo1();
		if(Algo == "algo2") algo2();

	}	
	
	if(is(EXITRUN))
	{
		for(all_trades)
		{
			printf("\n%s, Value1: %f, Value2: %f", TradeAlgo, TradeVar[0], TradeVar[1]);
		}
	}
}



And an eample of the output - as you can see, the TradeVars for the algo1 trades always return 0:
Code:
algo2, Value1: 37.563797, Value2:: 1.118150
algo2, Value1: 28.984416, Value2:: 1.118747
algo1, Value1: 0.000000, Value2:: 0.000000
algo1, Value1: 0.000000, Value2:: 0.000000
algo2, Value1: 7.145730, Value2:: 1.116183
algo2, Value1: 6.539160, Value2:: 1.116329
algo2, Value1: 6.571875, Value2:: 1.116340
algo1, Value1: 0.000000, Value2:: 0.000000
algo2, Value1: 7.412091, Value2:: 1.116200


Last edited by boatman; 06/09/16 00:10.
Re: Using TradeVar to store an indicator value for later evaluation [Re: boatman] #459962
06/13/16 08:11
06/13/16 08:11
Joined: Apr 2014
Posts: 482
Sydney, Australia
B
boatman Offline OP
Senior Member
boatman  Offline OP
Senior Member
B

Joined: Apr 2014
Posts: 482
Sydney, Australia
Thought I would give this a bump

Re: Using TradeVar to store an indicator value for later evaluation [Re: boatman] #459973
06/13/16 09:52
06/13/16 09:52
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Maybe you wanted to use AlgoVar, not TradeVar. TradeVar is a variable of a trade, but there is no trade accessed in your code, unless the "..." was a trade enumeration loop.

For passing variables to a specific trade, call enterLong(TMF,Var1,Var2,.. etc.). The TMF is then also called with those parameters, and you can then store them in TradeVars. TradeVar without a trade won't crash, but has no meaning either. It is not passed to the next opened trade.

Re: Using TradeVar to store an indicator value for later evaluation [Re: jcl] #459994
06/13/16 11:34
06/13/16 11:34
Joined: Apr 2014
Posts: 482
Sydney, Australia
B
boatman Offline OP
Senior Member
boatman  Offline OP
Senior Member
B

Joined: Apr 2014
Posts: 482
Sydney, Australia
There is a trade enumeration loop called when EXITRUN is true. This is the last few lines of code in my example. Maybe you missed it because you need to scroll down the code to see it?

It seems that the values assigned to the TradeVars prior to entering a trade with enterLong() or enterShort() are associated with each individual trade, because when I call the trade enumeration loop, I get mostly correct values printed for the TradeVars. However, this is only the case when I comment out one of the algos in the algo loop, which seems like it could be a bug? Either that, or my usage is incorrect.

Re: Using TradeVar to store an indicator value for later evaluation [Re: boatman] #459996
06/13/16 11:57
06/13/16 11:57
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
The usage in your trade enumeration loop is correct, only the rest is wrong.

Setting Tradevar in your code would normally crash, since you're writing into an undefined pointer. For preventing such crashes, Zorro keeps valid pointers for all internal variables. So you can in fact write into trade variables even with no trade, although it makes no sense. In your case you're probably getting the variables of the last valid trade pointer. That's why you see the written values at random in some of your trades.

You can manually set a trade pointer, it's ThisTrade, from an entered trade and then access all variables of this trade. That would work, but it's not the 'official' method.

Re: Using TradeVar to store an indicator value for later evaluation [Re: MatPed] #460017
06/13/16 16:33
06/13/16 16:33
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Yes, but please use a new thread for questions unrelated.

You need to request a V1 API fxtrader account from Oanda. The default account is not supported by the API. Details are in the manual.

Re: Using TradeVar to store an indicator value for later evaluation [Re: jcl] #460018
06/13/16 16:36
06/13/16 16:36
Joined: Feb 2015
Posts: 652
Milano, Italy
M
MatPed Offline
User
MatPed  Offline
User
M

Joined: Feb 2015
Posts: 652
Milano, Italy
Sorry, posted in the wrong session not intentionally. Deleted

Re: Using TradeVar to store an indicator value for later evaluation [Re: jcl] #460043
06/14/16 08:20
06/14/16 08:20
Joined: Apr 2014
Posts: 482
Sydney, Australia
B
boatman Offline OP
Senior Member
boatman  Offline OP
Senior Member
B

Joined: Apr 2014
Posts: 482
Sydney, Australia
Thanks for that, jcl. I'll try implementing this using the official approach by using my variables as arguments to the TMF and then storing them in TradeVars. I didn't understand that such parameters had to be passed as arguments to the TMF, but now I can see why that is the case.

Cheers


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1