Gamestudio Links
Zorro Links
Newest Posts
EntryDelay Clarification
by Ger1
Yesterday at 22:11
strf length-limitation
by Grant
Yesterday at 18:49
Deformers struct in MDL7 abspeichern.
by tagimbul
Yesterday at 17:41
Compiling Trading Strategies with C++
by pascalx
Yesterday at 12:18
global breakeven of a portfolio inside tmf function
by kmerlo
08/19/17 12:21
AUM Magazine
Latest Screens
AckCon'17: Lotter vs The World
Triton Wing
ZeaL
Computer Repair Simulator
Collider (working title)
Who's Online
11 registered (3dgamelight, Grant, alibaba, Iglarion, jrath, JoFo, jyd, tagimbul, mk_1, 1 invisible), 447 Guests and 4 Spiders online.
Key: Admin, Global Mod, Mod
Newest Members
mqo, Aimak, Grant, Marce, pascalx
17719 Registered Users
Topic Options
Rate This Topic
#467463 - 08/04/17 04:25 global breakeven of a portfolio inside tmf function
Nanitek Offline
Senior Member

Registered: 03/25/15
Posts: 310
Loc: 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?

Top
#467465 - 08/04/17 13:52 Re: global breakeven of a portfolio inside tmf function [Re: Nanitek]
jcl Offline

Chief Engineer

Registered: 07/22/00
Posts: 25661
Loc: 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.

Top
#467475 - 08/04/17 16:28 Re: global breakeven of a portfolio inside tmf function [Re: jcl]
Nanitek Offline
Senior Member

Registered: 03/25/15
Posts: 310
Loc: 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?

Top
#467482 - 08/05/17 12:12 Re: global breakeven of a portfolio inside tmf function [Re: Nanitek]
jcl Offline

Chief Engineer

Registered: 07/22/00
Posts: 25661
Loc: 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.

Top
#467512 - 08/08/17 11:34 Re: global breakeven of a portfolio inside tmf function [Re: jcl]
Ger1 Offline
Newbie

Registered: 03/28/17
Posts: 22
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

Top
#467519 - 08/08/17 16:50 Re: global breakeven of a portfolio inside tmf function [Re: Ger1]
jcl Offline

Chief Engineer

Registered: 07/22/00
Posts: 25661
Loc: 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.

Top
#467552 - 08/11/17 22:57 Re: global breakeven of a portfolio inside tmf function [Re: jcl]
Ger1 Offline
Newbie

Registered: 03/28/17
Posts: 22
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")))
....
}


Edited by Ger1 (08/11/17 23:18)

Top
#467653 - 08/19/17 07:11 Re: global breakeven of a portfolio inside tmf function [Re: Ger1]
Ger1 Offline
Newbie

Registered: 03/28/17
Posts: 22
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);
}

}
}

Top
#467656 - 08/19/17 12:21 Re: global breakeven of a portfolio inside tmf function [Re: Ger1]
kmerlo Offline
Newbie

Registered: 03/08/17
Posts: 41
Loc: Bologna
Thanks, very nice solution :-)

Top



Gamestudio download | chip programmers | Zorro platform | shop | resources | magazine | manual | support faq | bugs | beta features

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) 3dgamestudio.net