Ara, The Equity() function is a single symbol "backtester in a box", meaning that it will figure out all your positions (for the current symbol only, ignoring all other symbols) at the point that it appears in your code.
The ~~~Equity symbol is a pseudo symbol generated as a result of a backtest and includes the positions for the entire portfolio as specified by the settings of the AA window. If you want to make reference to ~~~Equity in your code, you need to generate it first. As such, your strategy logic cannot depend on ~~~Equity or you end up with a chicken/egg problem. To achieve what you are trying to accomplish, you must write custom backtester code in which you can, on a bar by bar basis, refer to the Equity property of the backtester object to find the portfolio equity at each bar. You would then use that value to calculate your position size, on a bar by bar basis, and apply it to each of the signals for that bar (i.e. set the PosSize property of each Signal object). Refer to "AmiBroker Custom Backtester Interface.pdf" in the Files section of this group to learn how to write your own backtester code. Mike --- In [email protected], "Ara Kaloustian" <[EMAIL PROTECTED]> wrote: > > Having trouble with Portfolio Equity function > > The code below works OK if I use Equity(0,0); > > It does not work if I use Foreign("~~~Equity",C"); No trades are detected. > > > StartEquity = 100000; > > SetOption("InitialEquity", 100000); > > SetOption("MinShares",100); > > Max_Pos = 30; > > SetOption("MaxOpenPositions",Max_Pos); > > RoundLotSize = 10; > > PointValue = 1; > > // > > > > //Compute Positions and position size > > Port_Equity = Equity(0,0); // <<<< ==== This works OK > > Port_Equity = Foreign("~~~EQUITY()","C"); // <<<< ==== This does not work > > Positions_ = Port_Equity / 10000; > > Positions = IIf(Positions_ > Max_pos,Max_pos,Positions_); > > SetPositionSize(Port_Equity/Positions,spsValue); > > > > Thanks > > > > Ara >
