3 registered members (dr_panther, Ayumi, 1 invisible),
877
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
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
boatman
OP
Senior Member
|
OP
Senior Member
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
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:
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]
#459973
06/13/16 09:52
06/13/16 09:52
|
Joined: Jul 2000
Posts: 27,986 Frankfurt
jcl
Chief Engineer
|
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.
|
|
|
|