Allocate Margin to asset portfolio

Posted By: Cheulmen

Allocate Margin to asset portfolio - 05/07/18 23:12

Hi, I’m not able to find anywhere how to allocate Capital to different assets while using loop(). I want to allocate the Capital to the first asset that is going to enterLong() according to some TA indicator. Until that trade exits, the other algos won’t have any money to trade. Then, when that first trade exits because a Stop or the exitLong(), the other algos will be able to use the money (as long as their indicator is hit). So, at any time, only one combination algo/asset will use all the money.

So for instance using a combination of 2 assets and 3 algos, how should I do that?
If doing this is not possible, how can I assign a fixed amount to each asset/algo? (so, in my example, how could I assign 100 to each one of the 6 combinations?)

void run()
{
Capital =600;

while(asset(loop(“EUR/USD”, “GBP/USD”)))
while(algo(loop("H1", "H2”, "H3”)))
{
Margin=Capital+ProfitClosed; //<—— How should I modify this??

if(indicator==1) //“indicator” will be filled somewhere
enterLong();
else
if (indicator==2)
exitLong();
}
}

I don't want to use FACTORS or OptimalF, by the way, I want all the assets to have the same importance. The workshop6 talks about capital allocation but it doesn't answer my doubts...
Posted By: Brax

Re: Allocate Margin to asset portfolio - 05/08/18 11:18

Use a static var to lock the entry and exit condition.

static bool tradelock = false;

...

Margin = Capital+(WinTotal-LossTotal) //Total money in account

...

if(!NumOpenLong && indicator==1 && !tradelock)
enterLong();
tradelock = true;
else
if (NumOpenLong && indicator==2 && tradelock)
exitLong();
tradelock = false;
}
Posted By: Cheulmen

Re: Allocate Margin to asset portfolio - 05/08/18 13:34

Oh, shame on me for not realizing before, that's a very easy solution laugh Thanks!
© 2024 lite-C Forums