Hi, If you are planning to trade more than a single stock, your approach will not work. The Equity() function is equivalent to running a backtest using the current symbol as the one and only symbol in a watchlist.
In other words; Equity() does not support portfolio management and thus will not give the correct portfolio equity when trading more than the current symbol. If you plan to trade more than a single symbol and still want to tweak position size based on equity, then write custom backtester logic to change the PosSize property of the Signal objects. See the custom backtester document by gp_sydney in the files section of this forum to learn how to write custom backtester code. Mike --- In [email protected], "lucianomt" <lucian...@...> wrote: > > I am trying to write a code extensively without using the built-in AB > features such as trailing stops and position sizes. So far I was able > to put in the entries and exits but am having some trouble with the > trade size which uses the current equity curve. This is the current code > (ignore the strategy itself, as it is just random): > > priceatbuy = 0; > for(i=0; i<20; i++) > { > Buy[i] = 0; > Sell[i] = 0; > } > for(i=20; i<BarCount; i++) > { > if( priceatbuy == 0 & BuyPrice[i] > entryLevel[i] ) > { > Buy[i] = 1; > BuyPrice[i] = Max(entryLevel[i], Low[i]); > priceatbuy = BuyPrice[i]; > } > else > Buy[i] = 0; > > if( priceatbuy > 0 & SellPrice[i] < exitLevel[i] ) > { > Sell[i] = 1; > SellPrice[i] = Min(exitLevel[i], High[i]); > priceatbuy = 0; > } > else > Sell[i] = 0; > } > > Now I want to buy shares equal to 50% of current equity (updated daily, > not initial equity). I tried adding the following line into the FOR > statement but that didn't work: > SetPositionSize( equity()*0.5/priceatbuy, spsShares ); > > Any suggestions? I know that SetPositionSize(-50, spsPercentofEquity ) > would do the job, but I would like to be able to tweak the number of > shares manually. Thanks! >
