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


      

Reply via email to