[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] Re: Questions about the Equity() function



PureBytes Links

Trading Reference Links

danielwardadams wrote:

Al,
Glad to see you're still interested. I tried several variations on
the following few statements but I'm still not any getting results
that make much sense. I won't be able to work on this for the next
several hours but will after that.

VB_Based_PosSize = NumberOfShares*Open ;
Risk = .10 ;
PositionScore = ATR(5)/C * VB_Based_PosSize * IIf(VB_Based_PosSize
> .20*Equity(), 0, VB_Based_PosSize) ; //Note still has Equity in it.
PositionSize  = -Risk*Open/1.1*ATR(5)  ;
//PositionSize = -20 ;

Dan
Dan:

I see a couple of things wrong with what you are doing:

First, be aware of looking into the future. You are multiplying ATR/C (the C being the current close) by the VB term, which is using the open of the same day. Is that what you want? If you are buying on 1-day delays at the open tomorrow, Positionscore should be based on the bar just before the open (i.e., the closing bar of the previous day). So, if your SetTradeDelays is set to 0,0,0,0 (no delays), then your positionscore statement should be ref'd back a day. If you are using delays of 1,1,1,1, then your positionscore needs no reffing back. And make sure you really meant the open in your VB statement to be the same bar as the close in the ATR/C part of the positionscore statement.

I was in error when I told you to "AND" the qualifier in the PositionScore statement. This would mix a Boolean with a non-Boolean and would not work in terms of ranking of the candidate stocks to trade. Booleans get set to 0 when false or 1 when true. So, if the statement is set to 0 (size > 0.2*Equity), then the entire positionscore becomes 0, and the ranking will be determined alphabetically. You don't want this. Now, keeping in mind that I am not a whiz at AFL, I think perhaps one could code this in the following way:

PositionScore = VB_Based_PosSize <= 0.20 * E; // gives a listing of all stocks giving a true condition ranked first and all stocks giveing a false condition ranked below those
PositionScore = PositionScore > 0; //selects all stocks giving only a true condition from the 1st line
PositionScore =  PositionScore * ATR(5)/C * VB_Based_PosSize; // 1 * your actual ranking

I hope someone who knows AFL better than I will correct this if I'm wrong. I'm totally guessing here.

Third, your positionsize statement is using a no-delay Open upon which to base the size of the trade. In real life, you won't know how many shares to order until after the open. Therefore, you should use the previous bar's close to determine your positionsize.

Putting all this together, your code might look something like the following:

SetTradeDelays(1,1,1,1);
Buy = BuyCond1 AND BuyCond2;
Sell = SellCond;
E = Equity(1);
VB_Based_PosSize = NumberOfShares*C;
Risk = 0.10; // Are you sure you want to risk 10% per trade? That's HUGE!! I think you meant 0.01, didn't you?
PositionScore = VB_Based_PosSize <= 0.20 * E;
PositionScore = PositionScore > 0;
PositionScore =  PositionScore* ATR(5)/C * VB_Based_PosSize;

The only other thing is that I'm not sure you can use the Equity function as above.

Let me know if this works.

Al Venosa



Check AmiBroker web page at:
http://www.amibroker.com/

Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html



Yahoo! Groups Sponsor
ADVERTISEMENT
click here


Yahoo! Groups Links