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,