Corey, I believe your question is answered here:
http://www.amibroker.com/guide/h_futbacktest.html under the paragraph "Margin deposit" Just tested myself: PositionSize = -10; SetOption("MaxOpenPositions", 3); setting inside Amibroker (Information Window) the Margin Deposit at 5000, Roundlotsize at 1 and initial equity at 100000. What I find is that it indeed increases the number of positions once enough equity is available, however it does not stick to the maximum open positions for some reason. Not sure why, Ed ----- Original Message ----- From: Corey Saxe To: AmiBroker main Sent: Thursday, May 28, 2009 8:16 AM Subject: [amibroker] Using Equity to Compute Position Size 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;
