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.