Number of trades in an asset loop

Posted By: edu

Number of trades in an asset loop - 03/08/21 10:46

Hi everyone

I dont understand why the number of trades that I get when I run a script with an asset loop is not equal to the sum of trades that I get when I run the same script on each asset individually.

Shouldn’t they be the same?

For example:

Script run for each pair individually
Number of trades:
EURUSD: 281
GBPUSD: 298
USDCAD: 271
AUDUSD: 304
----------------------------
Sum: 1154

Script run using an asset loop
Number of trades: 964

Here's the code I used
Thanks in advance

Code
function run() 
{
StartDate = 2010;
EndDate = 2020;
BarMode = BR_FLAT;
set(PARAMETERS+TESTNOW);

BarPeriod=60;
NumWFOCycles=3;
LookBack = 500;

Capital = 1000000;
while(asset(loop("EUR/USD","GBP/USD","USD/CAD","AUD/USD")))
	
{
vars Price = series(price());

int MMP = optimize(300,200,400,40);
vars MM1 = series(LowPass(Price, MMP));
int MMIP = 300;
vars MMI_Raw = series(MMI(Price,MMIP));
vars MSmooth = series(LowPass(MMI_Raw,300));

if(
NumOpenLong < 1 
and valley(MM1)
and falling(MSmooth) 
) enterLong();

if(
NumOpenShort < 1 
and peak(MM1) 
and falling(MSmooth) 
) enterShort();

Stop = ATR(25)*3;
Trail = ATR(25)*3;
}

}

Posted By: edu

Re: Number of trades in an asset loop - 03/15/21 11:29

It seems that the problem is the WFO

When I comment this part out, the number of trades match.
Code
NumWFOCycles=3;



Why are the WFO results different when I optimize the whole portfolio with an asset loop and when I optimize for each asset independently?
Posted By: jcl

Re: Number of trades in an asset loop - 03/18/21 15:07

This is probably not what you intended:

BarMode = BR_FLAT;

BR_WEEKEND is missing, so you're getting flat candles all weekend, which will affect your indicators. I don't know if that's the reason of the different trades, but it does not look right. You can see the reason of the different trades when you look in the logs and compare a few trades with all assets vs. a single asset.
Posted By: edu

Re: Number of trades in an asset loop - 03/29/21 07:55

Thank you jcl, it gets better with BR_WEEKEND, now I get the same number of trades, but I still get different results.
When I compare the logs with a single asset vs all assets, I see that all trades have the same entries, but in some of them the exit is different. Same thing happens when I change the order of the assets inside the loop. Any idea why this could happen?

I simplified the script, here's the version I'm using:

Code
function run() 

{

BarMode = BR_WEEKEND+BR_FLAT;

set(LOGFILE);

BarPeriod=60;
LookBack = 500;
StartDate = 2016;
EndDate = 2017;

while(asset(loop("EUR/USD","GBP/USD")))
	
{	
vars Price = series(price());

vars MM1 = series(LowPass(Price, 100));

if(NumOpenLong < 1 and valley(MM1)) 
	enterLong();

if(NumOpenShort < 1 and peak(MM1) ) 
	enterShort();

Stop = ATR(25)*3;
Trail = ATR(25)*3;
}

}
Posted By: jcl

Re: Number of trades in an asset loop - 03/30/21 10:02

Look closely at your code. Where do you set the stop?
Posted By: edu

Re: Number of trades in an asset loop - 04/05/21 10:29

Thank you for the hint jcl, I set the stop before the entry logic and it works fine. I don't know why this happens.
© 2024 lite-C Forums