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

[amibroker] Reduction of position size when volatility gets high



PureBytes Links

Trading Reference Links

Hi,

having a simple MA rule I want to reduce position size (from 100% to 50%) if volatility gets above its 120 day average (and back to 100% if volatility gets below its average). I have tried the following code but without success:

Buy = Cross( Close , MA(Close,30));
Sell = Cross(MA(Close,30), Close);

Short = Sell;
Cover = Buy;

vola=StDev(ln(C/Ref(C,-1)),50)*sqrt(250)*100;

InTradeBuy=Flip(Buy,Sell);
InTradeShort=Flip(Short,Cover);

DoScaleInBuy=ExRem(InTradeBuy AND vola>MA(vola,120),Sell OR vola<MA(vola,120));
DoScaleOutBuy=ExRem(InTradeBuy AND vola<MA(vola,120),Sell OR vola>MA(vola,120));
Buy = Buy + sigScaleIn * DoScaleInBuy + sigScaleOut * DoScaleOutBuy;

DoScaleInShort=ExRem(InTradeShort AND vola>MA(vola,120),Cover OR Vola<MA(vola,120));
DoScaleOutShort=ExRem(inTradeShort AND vola<MA(vola,120),Cover OR Vola>MA(vola,120));
Short = Short + sigScaleIn * DoScaleInShort + sigScaleOut * DoScaleOutShort;

PositionSize=IIf(DoScaleInBuy OR DoScaleInShort,-50,-100);

Any ideas what´s wrong.

Regards
Daphne


      


------------------------------------

**** IMPORTANT ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

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

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

For other support material please check also:
http://www.amibroker.com/support.html

*********************************
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/