Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (VoroneTZ, monk12, Quad), 829 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
global breakeven of a portfolio inside tmf function #467463
08/04/17 02:25
08/04/17 02:25
Joined: Mar 2015
Posts: 336
Rogaland
N
nanotir Offline OP
Senior Member
nanotir  Offline OP
Senior Member
N

Joined: Mar 2015
Posts: 336
Rogaland
Hi

I am trying to get a breakeven (or close all trades when all_open_trades_profit>x) of a multiasset strategy inside the tmf function but I cannot make it to work.
Any ideas?

Re: global breakeven of a portfolio inside tmf function [Re: nanotir] #467465
08/04/17 11:52
08/04/17 11:52
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
Inside a TMF you have only information about the current trade, but not about the other trades. For summing up all profits I'd use a simple for() loop, no TMF.

Re: global breakeven of a portfolio inside tmf function [Re: jcl] #467475
08/04/17 14:28
08/04/17 14:28
Joined: Mar 2015
Posts: 336
Rogaland
N
nanotir Offline OP
Senior Member
nanotir  Offline OP
Senior Member
N

Joined: Mar 2015
Posts: 336
Rogaland

Thanks for the clarification. I thought I could sum all the profits inside the tmf function.

If I need to use a for loop in the run function, then I will lost the global breakeven if it happens inside the barperiod, thats why I'd like to catch it on a tick level, or should I then use 1 minute candles so that the for loop in the run function does the work?

Re: global breakeven of a portfolio inside tmf function [Re: nanotir] #467482
08/05/17 10:12
08/05/17 10:12
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
No, use a loop in the tick function, not the run function. The tick function runs at every price quote and has access to all trades.

Re: global breakeven of a portfolio inside tmf function [Re: jcl] #467512
08/08/17 09:34
08/08/17 09:34
Joined: Mar 2017
Posts: 65
G
Ger1 Offline
Junior Member
Ger1  Offline
Junior Member
G

Joined: Mar 2017
Posts: 65
I got a similar question to this.

I got a portfolio that trades on a daily timeframe.

Lets say I got 5 algos trading on EUR/USD and all 5 will enter. Is it possible to get the number of trades that are to be opened?

This would help to adjust money to be invested on each trade based on the number of trades at the same time

Re: global breakeven of a portfolio inside tmf function [Re: Ger1] #467519
08/08/17 14:50
08/08/17 14:50
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
When you get a trade signal, do not trade immediately, but store the signal somewhere, f.i. in an AlgoVar or AssetVar. When all signals are processed, count them and then calculate the invested amounts and enter the trades.

Re: global breakeven of a portfolio inside tmf function [Re: jcl] #467552
08/11/17 20:57
08/11/17 20:57
Joined: Mar 2017
Posts: 65
G
Ger1 Offline
Junior Member
Ger1  Offline
Junior Member
G

Joined: Mar 2017
Posts: 65
thanks for your advice jcl.
I tried to set up very high entry conditions and then enterLong controlled by a tmf.

Within the tmf I ran two loops - the first loop counts all the pending trades for each algo (int n used) and after being finished with counting I enter the trade in the second loop, however, I divided TradeLots by n. I used the AlgoVar count to find out whether it is the first loop(to count pending trades) or the second to finally enter the trades adjusted by TradeLots.

However, something seems to be wrong as in certain instances the tmf crashes --> that's when: TradeLots=TradeLots/n; (n is equal 0)
I don't really understand why that happens.

Could you advise please?

Below my code:

#define count as_int(AlgoVar[0])

int n;
int tmf(var sys)
{
if(TradeIsNewBar)
{
n=0;
return 0;
}
if(sys==0)
{
algo("systemA");
}
else if(sys==1)
{
algo("systemB");
}

else if(sys==2)
{
algo("systemC");
}

if(count==1)
{
count=0;
// if(n==0) printf("n %i",date()); --> should never happen
// printf("n %i %s",n,Algo);
TradeLots=TradeLots/n;
// printf("nl %i ",TradeLots);
return 2;
}

if(TradeIsPending)
{
n=n+1;
// printf("n %i ",NumPendingTotal);
count=1;
return 4;
}
return 0;
}

function systemA()
{
...
if(entry_condition == true)
{
Entry = 99999;
enterLong(tmf,0)
}
}

function systemB()
{ ...
}

function systemC()
{ ...
}


function run()
{
BarPeriod = 1440;
...
while(asset(loop("SPX500","NAS100","US30")))
while(algo(loop("sytemA","sytemB","sytemC")))
....
}

Last edited by Ger1; 08/11/17 21:18.
Re: global breakeven of a portfolio inside tmf function [Re: Ger1] #467653
08/19/17 05:11
08/19/17 05:11
Joined: Mar 2017
Posts: 65
G
Ger1 Offline
Junior Member
Ger1  Offline
Junior Member
G

Joined: Mar 2017
Posts: 65
Finally decided to to write 2 for-loops to loop through all assets and algos before actually entering trades and increasing a counter in case of an enter signal in any one of them.

After that I looped through again and set Lots = lot_number/count.

This seems to work as intended.

Below a simple strategy to illustrate:




int count;
int lot;

function tradeB(bool trade)
{

Stop = 2*ATR(30);

vars Price = series(priceClose());

LifeTime=1;
if(Price[0]>Price[1]) //simple entry condition
{
if(trade==false) count++; //increase the counter in case of an entry signal

else if(trade==true) //actual entry
{
printf("n %i %i %s %s",lot,count,Algo,Asset);
Lots=lot/count;
enterLong();
}
}
}


function tradeA(bool trade)
{

Stop = 2*ATR(30);

vars Price = series(priceClose());

LifeTime=1;
if(Price[0]>Price[1])
{
if(trade==false) count++;

else if(trade==true)
{
printf("n %i %i %s %s",lot,count,Algo,Asset);
Lots=lot/count;
enterLong();
}
}

}


function run()
{
StartDate = 20150110;
EndDate = 20150120;
BarPeriod = 1440;

set(TICKS);

lot = 100;



count=0;

string assets[2];
assets[0] = "EUR/USD";
assets[1] = "USD/JPY";

int i;
for(i=0;i!=2;i++) //loop to count entry signals
{
asset(assets[i]);
tradeA(false);
tradeB(false);
}

//actual trade entry loop
while(algo(loop("A","B")))
while(asset(loop("EUR/USD","USD/JPY")))
{
// printf("n %i",count);
if(Algo == "A")
{
tradeA(true);
}

if(Algo == "B")
{
tradeB(true);
}

}
}

Re: global breakeven of a portfolio inside tmf function [Re: Ger1] #467656
08/19/17 10:21
08/19/17 10:21
Joined: Mar 2017
Posts: 48
Bologna
K
kmerlo Offline
Newbie
kmerlo  Offline
Newbie
K

Joined: Mar 2017
Posts: 48
Bologna
Thanks, very nice solution :-)


Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1