2 registered members (Akow, tomaslolo),
1,536
guests, and 12
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
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
Ger1
Junior Member
|
Junior Member
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
Ger1
Junior Member
|
Junior Member
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); } } }
|
|
|
|