Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, Nymphodora, Quad), 919 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Wrong commission calculation in FXPortfolio?? #482909
04/15/21 18:19
04/15/21 18:19
Joined: Apr 2021
Posts: 19
S
simonkrebs Offline OP
Newbie
simonkrebs  Offline OP
Newbie
S

Joined: Apr 2021
Posts: 19
Hi,

when I'm running the following script on "EUR/USD" only, the total commission is: 1468$
when I'm running the following script on "XAU/USD" only, the total commission is: 2143$
when I'm looping "EUR/USD" and "XAU/USD", the total commission is: 5997$

(I set commission 0.8 in the AssetsList file)

Is this a bug??

Would be glad if someone can help me find out what the problem is.

Here is the code:

Code
#include <profile.c>
#include <custom.c>

#define INITCAPITAL 10000
#define ASSETLIST "AssetsGP-org"
#define RISK 0.5

static int tradeCount; 
static int tradeLots;
static var tradeComm;
static var tradeRoll;
static var tradeSpread;

function tradeCounterTrend()
{
	TimeFrame = frameSync(4);
	vars Prices = series(price());
	vars Cycles = series(BandPass(Prices,30,2));
	vars Signals = series(FisherN(Cycles,500));
	var Threshold = optimize(1,0.8,1.2,0.1);

	LifeTime = 4*optimize(100,50,150,10);
	Trail = Stop = optimize(10,4,20,2)*ATR(100);
	MaxLong = MaxShort = -1;
	
	var Regime = FractalDimension(Prices,100);
	var RegimeThreshold = optimize(1.5,1.3,1.7,0.1);
	if(Regime > RegimeThreshold)
	{
		if(crossUnder(Signals,-Threshold))
			enterLong(); 
		else if(crossOver(Signals,Threshold))
			enterShort();
	} 
}

function tradeTrend()
{
	TimeFrame = 1;
	vars Prices = series(price());
	vars Trends = series(Laguerre(Prices,optimize(0.05,0.02,0.15,0.01)));
	
	Stop = optimize(10,4,20,2)*ATR(100);
	Trail = 0;
	LifeTime = 0;
	MaxLong = MaxShort = -1;
	
	var MMI_Period = optimize(300,100,400,100);
	vars MMI_Raws = series(MMI(Prices,MMI_Period));
	vars MMI_Avgs = series(SMA(MMI_Raws,MMI_Period));
	
	if(falling(MMI_Avgs)) {
		if(valley(Trends))
			enterLong();
		else if(peak(Trends))
			enterShort();
	}
}

function run()
{
	set(PARAMETERS); //From Training
	set(FACTORS); //For OptimalF
	set(TESTNOW+PLOTNOW);
	set(PRELOAD); //reduce load for fetching data from MT4 server
	set(NOLOCK); //speed up API access
	
   StartDate = ymd(wdate(NOW) - 356*10); //Instead calculate StartDate -> 356*10 = 10 years
   EndDate = Now; 

	BarPeriod = 60;	// 1 hour bars
	LookBack = 4*500;	// needed for FisherN()
	
	//Set capital - either from tsv file or from slider
	SaveMode = SV_ALGOVARS+SV_ALGOVARS2+SV_TRADES+SV_BACKUP+SV_HTML; //Not save slider -> reset via tsv

	if(INITCAPITAL)
		Capital = slider(1,INITCAPITAL,0,20000,"Capital",""); //Set capital from tsv file
	else
		Capital = slider(1,10000,0,20000,"Capital",""); //If not set or test/train mode
	
	if(Train) Detrend = TRADES;
	NumWFOCycles = 12; // activate WFO
	if(Train) NumCores = -2;		// multicore training (Zorro S only)
	//ReTrainDays = 1; //From WFO test cycles -> 44 weeks * 7 days = 308 days
	
	if(ReTrain) {
		UpdateDays = -1;	// update price data from the server 
		SelectWFO = -1;	// select the last cycle for re-optimization
		reset(FACTORS);
		NumCores = -4; 
	}
	
// portfolio loop
	assetList(ASSETLIST);
	//for(listed_assets) {
	while(asset(loop("EUR/USD","XAU/USD"))) {
		asset(Asset);
		
		//To fix problems with rollover values (far too high!!) 
		//So set Roll to zero & instead defined Interest variable
		RollLong = RollShort = 0;
		Interest = 0.015 * 356; //calculated in percent per 10K -> 1%
		//RollLong = priceClose()*(1-1/100)*0.03;
		//Commission = RollLong = RollShort = Spread = 0;
		
		if(is(FIRSTINITRUN) && !Test)
			assetHistory(Asset,1);

		while(algo(loop("TRND","CNTR")))
		{
			Margin = RISK * OptimalF * Capital * sqrt(1 + ProfitTotal/Capital);

			if(Algo == "TRND") 
				tradeTrend();
			else if(Algo == "CNTR") 
				tradeCounterTrend();
		}	
	}	
	if(is(EXITRUN)){
		for(closed_trades) {
			tradeCount++;
			tradeLots += TradeLots;
			tradeComm += abs(TradeCommission)*TradeLots;
			tradeRoll += abs(TradeRoll);
			tradeSpread += abs(TradeSpread);
			
		}
		printf("\nNumber=%d,Lots=%d\nSpread=%.2f,Comm=%.2f,Roll=%.2f",tradeCount,tradeLots/100,tradeSpread,tradeComm/10,tradeRoll);
	}
}


Thanks,

Simon

Re: Wrong commission calculation in FXPortfolio?? [Re: simonkrebs] #483059
04/29/21 06:19
04/29/21 06:19
Joined: Apr 2008
Posts: 585
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 585
Austria
The commission is different because your trade volume is different. And your Interest setting is also probably wrong, for forex you use no interest but rollover.


Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1