Re: [amibroker] Need help with PositionSize using an optimization for ATR

 

See if this works for you.  I have set it up as an indicator.  You can change the parameters.  Test with one of your securities.  If it works we can modify to work with each security.

//Start code
Period = Param("ATR Period",10,1,200,1);
TotalEquity = Param("Total Equity in $",100000,1000,1000000,1000);
MinPercentEquity = Param("Min Equity in %",25,1,100,1);
MaxPercentEquity = Param("Max Equity in %",50,1,100,1);
PercentATRlookback = Param("%ATR Lookback Period (Finds Highest and Lowest %ATR over Lookback Period)",200,10,1000,10);

var1 = ATR(Period)/close; //Percent Average True Range
var2 = HHV(var1,PercentATRlookback); //Highest Percent Average True Range over lookback period
var3 = LLV(var1,PercentATRlookback); //Lowest Percent Average True Range over lookback period
atrrange = (var2 - var3); // Percent ATR range 


Equity1 = TotalEquity; // $100,000
MinEquity = Equity1*MinPercentEquity/100; //$25000
MaxEquity = Equity1*MaxPercentEquity/100; //$50000

position_size = MaxEquity - (((var1 - var3)*(MaxEquity - MinEquity))/(var2 - var3));

Plot(position_size,"Position Size",colorBlack);
//End code



On 2/22/2016 12:10 PM, steve@optimusadvisory.com [amibroker] wrote:
 

I have been using 25% to 50% of equity position sizes with the strategy.  I want to change that so that based on recent volatility in each symbol, the coding will adjust the position size accordingly.  For example, if RRPIX has barely been moving, I want the position size on any new buy to greatly increase, say to 50%.  On the other hand, if RRPIX's volatility has recently been crazy, I want the position size on any new buy to decrease, say to 25%.  Each symbol is different, as they can be 1x, 2x or 3x leverage, so I would need different ranges for each (1x symbols maybe vary between 50%-100%; 2x symbols from 25%-50% and 3x from 12.5% to 25%, as examples).




__._,_.___

Posted by: Alan <alan@thenorthams.us>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (7)
**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/


.

__,_._,___


EmoticonEmoticon