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

Position size code



PureBytes Links

Trading Reference Links

OK,

For all those who requested it, below is the code to trade variable sized positions based on 
available equity.

It consists of three functions- NumToBuy, StkMargin, and a small utility function called Pct- 
and some code to add to your system:

{----------------------------------------------------------------------
 Begin NumToBuy function
 ----------------------------------------------------------------------}
{create a new function called NumToBuy and use the following code:}

inputs:begineq(numeric);


value1=begineq+netprofit;
value2=value1/c;

numtobuy=value2;

{---------------------------------------------------------------------------------
END NumToBuy function
----------------------------------------------------------------------------------}


{--------------------------------------------------------------------------------
BEGIN StkMargin function
---------------------------------------------------------------------------------}
{create a new function called StkMargin and add the following code:)

Input: Margin(Numeric),bgneqty(Numeric);

STKMARGIN = bgneqty/pct(Margin);

{---------------------------------------------------------------------------------
END StkMargin function
----------------------------------------------------------------------------------}


{----------------------------------------------------------------------------------
BEGIN Pct function
---------------------------------------------------------------------------------}
{create a new function called Pct and use the following code:}
Input:m(Numeric)
Pct=m/100;{make sure you don't divide by zero,though}
{-------------------------------------------------------------------------------
END Pct function
-------------------------------------------------------------------------------}


{---------------------------------------------------------------------------------
Begin System code
----------------------------------------------------------------------------------}
{add the following code to your system:}

inputs:bgneqty(50000),margin(50); 
{add these inputs, initializing with your parameters. 50000 is $50,000. 50 is 50%, 100 would be no margin}



 



if {put your buy condition here} then buy NUMTOBUY((STKMARGIN(Margin,BGNEQTY))) shares  at market;


if {put your exit-long conditions here}  then exitlong at market;

{same thing for the short side}

{----------------------------------------------------------------------------------
END system code
-----------------------------------------------------------------------------------}


Let me know how it works out.

Brett