I use separate databases for each exchange, only takes 2 clicks to load each database and keeps everything simple. Others may have different experiences with organising data into different markets using the same database but for the sake of simplicity I've found maintaining data in individual databases works for me.
I’m trying to set up fixed fractional position sizing in Amibroker and am unsure how to set a maximum limit on the calculated position size. Can Anyone help?
This is what I’ve got so far:
PositionSize = -1 / (BuyStop - StopLoss) * BuyStop;
BuyStop and StopLoss are obviously defined elsewhere in the code. This sets the maximum risk per trade to 1%. This seems to work, but I also want to limit the position size to a maximum of 20% of the portfolio equity (some trades in the report appear to be putting the entire equity on a single trade!). ie. Position size should be the MINIMUM of the above calculation OR 20% of portfolio equity. How would I do that?
thanks
I’m trying to set up fixed fractional position sizing in Amibroker and am unsure how to set a maximum limit on the calculated position size. Can Anyone help?
This is what I’ve got so far:
PositionSize = -1 / (BuyStop - StopLoss) * BuyStop;
BuyStop and StopLoss are obviously defined elsewhere in the code. This sets the maximum risk per trade to 1%. This seems to work, but I also want to limit the position size to a maximum of 20% of the portfolio equity (some trades in the report appear to be putting the entire equity on a single trade!). ie. Position size should be the MINIMUM of the above calculation OR 20% of portfolio equity. How would I do that?
thanks
PositionSize = max( -20 , -1 / (BuyStop - StopLoss) * BuyStop);
Does this work?
Hi Cap. Does PositionSize not take the lowest of two choices for an OR situation?
Does this work?
Max returns the largest number, so if your stop loss calcs return a number less than -20 (ie. position size greater than 20% of equity) then the position size defaults to 20% of equity. Position sizing uses negative numbers so max should give the correct solution as you want the number to be greater than -20.Code:PositionSize = max( -20 , -1 / (BuyStop - StopLoss) * BuyStop);
No, it will take the first number, whether it's higher or lower. Try these two in a backtest formula.
PositionSize = -50 OR -20;
PositionSize = -20 OR -50;
The first one will open 2 postions at a time. The second will open 5. Position score formula needs to return a single negative number, using OR doesn't return a single number.
Index = ParamList("Index","^AORD | ^GSPC | ^GSPTSE | ^FTAS",0) ;
X = Foreign("Index","Close",1);
X1 = DEMA(X, 250);
X2 = X > X1;
Okay thanks. Here is one that baffles me. I would like to switch index via Parameters for backtesting/scan/exploration rather than manually changing the code. Is this possible Captain (or anyone)?
I thought this would work because the Index can be changed in Parameters but the Foreign Function does not read the change.
Code:Index = ParamList("Index","^AORD | ^GSPC | ^GSPTSE | ^FTAS",0) ; X = Foreign("Index","Close",1); X1 = DEMA(X, 250); X2 = X > X1;
You need to create a condition for each "constituent" of index.
Example...
If (Index == "^AORD")
{
...some condition....
}
Else.... etc.
Index = ParamList("Index","^AORD | ^GSPC | ^GSPTSE | ^FTAS" );
if (Index == "^AORD")
{
X = Foreign("^AORD", "Close");
X1 = DEMA(X, 250);
X2 = X > X1;
Buy = X2;
}
else
{
X = Foreign("^GSPC", "Close");
X1 = DEMA(X, 250);
X2 = X > X1;
Buy = X2;
}
if (Index == "^GSPTSE")
{
X = Foreign("^GSPTSE", "Close");
X1 = DEMA(X, 250);
X2 = X > X1;
Buy = X2;
}
else
{
X = Foreign("^FTAS", "Close");
X1 = DEMA(X, 250);
X2 = X > X1;
Buy = X2
}
Index = ParamList("Index","^AORD | ^GSPC | ^GSPTSE | ^FTAS",0) ;
X = Foreign("^AORD", "Close");
That's okay. I simply want to change the foreign function in Parameters instead of having to change the foreign function in the code every time.
In AA Parameters with this statement ...
Index = ParamList("Index","^AORD | ^GSPC | ^GSPTSE | ^FTAS",0) ;
I can change the "Index".
But what then needs to happen is the foreign function needs to read the change.
So the change in AA Parameters here.
creates a change in foreign function here.PHP:Index = ParamList("Index","^AORD | ^GSPC | ^GSPTSE | ^FTAS",0) ;
I can manually change from "^AORD" to "^FTAS" etc. but would like to simply switch through AA Parameters.PHP:X = Foreign("^AORD", "Close");
X = Foreign(ParamList("Index","^AORD | ^GSPC | ^GSPTSE | ^FTAS",0) , "Close");
This should work but it doesn't. This works exactly as statedI think I get what you're trying to do now.
Does this work?
Click on the Parameters button in AA and the Index constituents are listed.Code:X = Foreign(ParamList("Index","^AORD | ^GSPC | ^GSPTSE | ^FTAS",0) , "Close");
X = Foreign("^AORD", "Close");
SetForeign( ParamList("Index","XAO|ANZ"), True, True );
Buyfilter = Close >MA( C, 40 );
Sellfilter = Close < MA( C, 40 );
RestorePriceArrays( True );
X = SetForeign( ParamList("Index","^AORD | ^GSPC | ^GSPTSE | ^FTAS"), True, True );
X1 = DEMA(C, 250);
X2 = X > X1; //Open long stock positions
X3 = X < X1; //Open short stock positions
Buy = X2 && Close >MA( C, 40 );
Sell = Close < MA( C, 40 );
Short = X3 && Cross(0, MACD());
Cover = Cross(MACD(), 0);
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short = ExRem(Short,Cover);
Cover = ExRem(Cover,Short);
RestorePriceArrays( True );
SetForeign( ParamList("Index","XAO|ANZ"), True, True );
X1 = DEMA(C, 250);
X2 = C > X1; //Open long stock positions
X3 = C < X1; //Open short stock positions
RestorePriceArrays( True );
Buy = X2 && Close >MA( C, 40 );
Sell = Close < MA( C, 40 );
Short = X3 && Cross(0, MACD());
Cover = Cross(MACD(), 0);
SetFormulaName( "wysiwyg_test" );
SetOption( "PriceBoundChecking", 1 );
SetOption( "CommissionMode", 2 );
SetOption( "CommissionAmount", 6 );
SetOption( "UsePrevBarEquityForPosSizing", 1 );
pq = 10;
PosQty = pq;
PositionSize = -100 / posqty;
SetOption( "MaxOpenPositions", PosQty );
PositionScore = 100/ Close;
SetTradeDelays( 1, 1, 1, 1 );
BuyPrice = Coverprice = Open;
SellPrice = Shortprice = Open;
Had a quick play around and here's something to try. I'm using XAO and ANZ again as I've got my ASX database loaded atm but change it to suit what you're after.
I haven't run through the trade list but I'm getting different results using XAO and ANZ as filters.
Using close price in relation to DEMA 250 this way references close price of stock and not foreign index.
SetForeign( ParamList("Index","^AORD | ^GSPC"), True, True );
X1 = DEMA(C, 250);
X2 = C > X1; //Open long stock positions
X3 = C < X1; //Open short stock positions
You see the short taken when the stock price is below the DEMA 250 while the Index price is above the DEMA 250.
example WOW stock price chart top, AORD below...
Hello and welcome to Aussie Stock Forums!
To gain full access you must register. Registration is free and takes only a few seconds to complete.
Already a member? Log in here.