1 registered members (AndrewAMD),
1,203
guests, and 9
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Margin Issues / not working?
#464076
01/20/17 09:29
01/20/17 09:29
|
Joined: Aug 2016
Posts: 95 Wien
trenki2
OP
Junior Member
|
OP
Junior Member
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: 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:
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:
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: jcl]
#464089
01/20/17 16:43
01/20/17 16:43
|
Joined: Aug 2016
Posts: 95 Wien
trenki2
OP
Junior Member
|
OP
Junior Member
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:
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
Max open margin: 5134.946152
But When I look into the trade results it says: Am I still doing something wrong here or is this a real issue?
|
|
|
|