The equity is only available during a backtest. The only way to pass a positionsize based on equity is to use a percentage value either eg 10% posisiotnsize = -10; or setpositionsize( 10, spsPercentOfEquity ); You cannot mix types of sizing in the afl. to do this you must use the custom backtest code to change the trade size.
The only time you can refer to a type of equity is if the test is a single symbol, and the equity function calculates basic equity over the entire history for that single symbol. I am not sure if it includes the commissions. This is not a backtest equity. -- Cheers Graham Kav AFL Writing Service http://www.aflwriting.com 2009/5/28 Corey Saxe <[email protected]>: > > > Been taking a look at AB after being gone for a few years. > > Looks like there is still no simple AFL method to retrieve the current > equity > to compute a positionsize for the next trade. > > I tried Equity(), Equity(1), Equity(0), and all the other variants that I > could think of. > Even tried Foreign("~~~EQUITY", "C"); No joy. > > I believe that Herman van den Bergen ran across this some time ago. > I haven't found what his solution was, if he found one. > Herman, you out there? > > Any ideas? > > Thanks, > -CS > > What I am trying is really a very simple test formula like: > > OptimizerSetEngine("cmae"); > > //============== Optimize ======================== > > StopPct = Optimize("StopPct", 15, 1, 15, 1); > //StopPoints = Optimize("StopPoints", 100 , 5, 100, 5); > > T1=Optimize("T1", 3 ,3,25,1); //MACD Short period > T2=Optimize("T2", 28 ,26,30,1); //MACD Long period > > WT=Optimize("WT", 18 ,10,22,1); //Wilders periods > > LTH=27;//Optimize("LTH",25,10,30,2); //Lower threshold line > UTH=73;//Optimize("UTH",73,60,80,2); //Upper threshold line > > THT=Optimize("THT", 8 ,8,21,1); // Dynamic Band periods > > UBC=Optimize("UBC", 1.6 ,0,3,0.1); // UBand change > LBC=Optimize("LBC", 1.3 ,0,3,0.1); // LBand change > > PctEq= 5;//Optimize("Percent of Equity", 5 ,1,15,1); > > //================ Buy & Sell & Short & Cover Formula ============ > M1=MACD(T1,T2);//MA(MACD(T1,T2),MAT); > A1=RSIa(M1,WT); > > //Dynamic Bands > UB=HHV(A1,THT)-(UBC); > LB=LLV(A1,THT)+(LBC); > > Buy=Cross(A1,LB);// AND A1<=LTH; > Sell=Cross(UB,A1);// AND A1>=UTH; > Short=Sell; > Cover=Buy; > > //=============== APPLY STOP ======================= > //ApplyStop( type, mode, amount, exitatstop, volatile = False, ReEntryDelay > = 0 ) > > //------------------ Max Loss Stop in Percent ------------------------- > ApplyStop( 0, 1, StopPct, 1, True, 0 ) ;// Percent Max Loss > > //------------------- Max Loss Stop in Points ------------------------------ > //ApplyStop( 0, 2, StopPoints, 1, True, 0 ) ;// Points Max Loss > > //============== DYNAMIC CONTRACT CONTROL ================= > > MinContracts=1;//Optimize("Min Contracts",1,1,5,1); > MaxContracts=10;//Optimize("Max Contracts",20,5,25,1); > Margin=MarginDeposit; > PctEq=PctEq/100; > Eq=Equity(); // Crashomatic > > PS=Min( MaxContracts * Margin , Max( PctEq * Eq , MinContracts * Margin )); > PositionSize = PS; > > >
