Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (1 invisible), 672 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Number of trades in an asset loop #482623
03/08/21 10:46
03/08/21 10:46
Joined: Mar 2017
Posts: 15
edu Offline OP
Newbie
edu  Offline OP
Newbie

Joined: Mar 2017
Posts: 15
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;
}

}


Re: Number of trades in an asset loop [Re: edu] #482667
03/15/21 11:29
03/15/21 11:29
Joined: Mar 2017
Posts: 15
edu Offline OP
Newbie
edu  Offline OP
Newbie

Joined: Mar 2017
Posts: 15
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?

Re: Number of trades in an asset loop [Re: edu] #482702
03/18/21 15:07
03/18/21 15:07
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
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.

Re: Number of trades in an asset loop [Re: jcl] #482787
03/29/21 07:55
03/29/21 07:55
Joined: Mar 2017
Posts: 15
edu Offline OP
Newbie
edu  Offline OP
Newbie

Joined: Mar 2017
Posts: 15
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;
}

}

Re: Number of trades in an asset loop [Re: edu] #482797
03/30/21 10:02
03/30/21 10:02
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
Look closely at your code. Where do you set the stop?

Re: Number of trades in an asset loop [Re: edu] #482842
04/05/21 10:29
04/05/21 10:29
Joined: Mar 2017
Posts: 15
edu Offline OP
Newbie
edu  Offline OP
Newbie

Joined: Mar 2017
Posts: 15
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.


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1