Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (degenerate_762, AndrewAMD), 877 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Margin Issues / not working? #464076
01/20/17 09:29
01/20/17 09:29
Joined: Aug 2016
Posts: 95
Wien
T
trenki2 Offline OP
Junior Member
trenki2  Offline OP
Junior Member
T

Joined: Aug 2016
Posts: 95
Wien
In the following script I calculate the Margin value to use and print it to the console. Even though the computed margin value is always different the strategy seems not to use it as in the result log it always sais:

Code:
Max open margin     1000$



I don't understand how the max open margin can be 1000 when I set the Margin variable in the script to much higher values before entering long.

The code to reproduce this is this one here:

Code:
function run()
{
	set(PARAMETERS);
	
	BarPeriod = 1440;
	StartDate = 1993;
	LookBack = 500;
	Capital = 10000;
	var InitialMargin = 1000;
	
	assetList("AssetsFXCMCFD.csv");
	assetHistory("SPY", FROM_YAHOO);
	asset("SPY");
	
	Margin = InitialMargin * (Balance / Capital);
	
	vars price = series(priceClose());
	var ma = SMA(price, optimize(200, 25, 500));
	
	if (NumOpenLong == 0 && price[0] > ma)
	{
		printf("n%f", Margin);
		enterLong();	
	}
		
	if (NumOpenLong > 0 && price[0] < ma)
		exitLong();
}



AssetsFXCMCFD.csv:
Code:
Name,Price,Spread,RollLong,RollShort,PIP,PIPCost,MarginCost,Leverage,LotAmount,Commission,Symbol
SPY,225.91,0.01,0,0,0.01,0.01,0,10,1,0,


Re: Margin Issues / not working? [Re: trenki2] #464080
01/20/17 12:32
01/20/17 12:32
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
It would have been bad for us all if the margin were not working, but I do not understand the problem from your code. If you think something is not working, you can just calculate it yourself and compare it with the statistics. The max open margin is not identical with the "Margin" variable. It is the max open lots multiplied with the margin cost per lot. The margin cost is provided by your broker and must be entered in the asset list. The open lots can be summed up in a trade enumeration loop.

Re: Margin Issues / not working? [Re: jcl] #464089
01/20/17 16:43
01/20/17 16:43
Joined: Aug 2016
Posts: 95
Wien
T
trenki2 Offline OP
Junior Member
trenki2  Offline OP
Junior Member
T

Joined: Aug 2016
Posts: 95
Wien
Ok, so i modified the script to compute the max open margin as you said by computing the max of TradeLots * MarginCost.

Here is the code:

Code:
function run()
{
	BarPeriod = 1440;
	StartDate = 1993;
	LookBack = 200;
	Capital = 10000;
	var InitialMargin = 1000;
	
	assetList("AssetsFXCMCFD.csv");
	assetHistory("SPY", FROM_YAHOO);
	asset("SPY");
	
	Margin = InitialMargin * (Balance / Capital);
	
	// Compute max open margin. 
	// Note: there is only one open trade, so we don't have to sum things up.
	static var MaxOpenMargin = 0;
	for (open_trades)
		MaxOpenMargin = max(MaxOpenMargin, TradeLots * MarginCost);
	
	vars price = series(priceClose());
	var ma = SMA(price, 200);
	
	if (NumOpenLong == 0 && price[0] > ma)
		enterLong();	
		
	if (NumOpenLong > 0 && price[0] < ma)
		exitLong();
		
	if (is(EXITRUN))
		printf("nMax open margin: %f", MaxOpenMargin);
}



In the EXITRUN I print the computed max open margin to the console.
When I run it it prints

Code:
Max open margin: 5134.946152



But When I look into the trade results it says:

Code:
Max open margin     1000$



Am I still doing something wrong here or is this a real issue?

Re: Margin Issues / not working? [Re: trenki2] #464192
01/27/17 14:14
01/27/17 14:14
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
When I run your script, I get a correct max open margin both ways. However I used the IB assets. Maybe something is wrong in your asset list?

Re: Margin Issues / not working? [Re: jcl] #464197
01/27/17 15:04
01/27/17 15:04
Joined: Aug 2016
Posts: 95
Wien
T
trenki2 Offline OP
Junior Member
trenki2  Offline OP
Junior Member
T

Joined: Aug 2016
Posts: 95
Wien
I supplied the full contents of my AssetsList.csv file in the original post! You can try with that and reproduce the results.

What could be wrong in the AssetsList? I just copied a line from the IB list, changed the leverage and added the current price for the asset.

Re: Margin Issues / not working? [Re: trenki2] #464204
01/27/17 16:39
01/27/17 16:39
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
With your asset list I still get similar results. They are not exactly identical since your script sums up the margin one bar later.

I'm using the latest beta version, but I don't think that this affects the margin. Have you changed something else in your installation?

Re: Margin Issues / not working? [Re: jcl] #464209
01/27/17 17:17
01/27/17 17:17
Joined: Aug 2016
Posts: 95
Wien
T
trenki2 Offline OP
Junior Member
trenki2  Offline OP
Junior Member
T

Joined: Aug 2016
Posts: 95
Wien
No, I have not changed anything. I get this result with a fresh installation.

I have now also tested the latest beta. There I get a different margin value! Its not identical to the one that the script calculates but much closer!

Re: Margin Issues / not working? [Re: trenki2] #464232
01/30/17 11:59
01/30/17 11:59
Joined: Apr 2013
Posts: 35
J
Joaquin Offline
Newbie
Joaquin  Offline
Newbie
J

Joined: Apr 2013
Posts: 35
I have also tested your code. In the EXITRUN log I have
Max open margin: 2539.021343
And in the trade log I have
Max open margin 283$
I'm using Zorro 1.50 . Do these results look good to you?

Re: Margin Issues / not working? [Re: Joaquin] #464235
01/30/17 14:30
01/30/17 14:30
Joined: Aug 2016
Posts: 95
Wien
T
trenki2 Offline OP
Junior Member
trenki2  Offline OP
Junior Member
T

Joined: Aug 2016
Posts: 95
Wien
Interesting!

In Zorro 1.50.6 i get the following EXITRUN log:
Max open margin: 5188.282166

While in the results I get:
Max open margin 1000$

This is with the above Assets file.

When I use the current Zorro Beta 1.53.2 i get this in the EXITRUN log:
Max open margin: 5280.110168

And in the test results it shows this:
Max open margin 4854$

Now there seems to be a difference in every version. An this is pretty serious since the Max open margin value is a very important value!

Now there is one thing that I forgot in the script and that is to set the EndDate to a fixed date. But still the differences should never be that big.

Re: Margin Issues / not working? [Re: trenki2] #464238
01/30/17 14:47
01/30/17 14:47
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
This is the same result that I got. There's no margin issue of 1.50.6 mentioned on our bug list. I'll check what the 1.50.6 problem might have been and if someone has maybe fixed it and forgot to put it on the list.


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