SafeZone指標 ::走進我的交易室::
本帖最後由 zaqimon 於 12-11-7 14:30 編輯好像沒看到有人發表過SafeZone指標
“走進我的交易室”書上提到使用SafeZone作為停損使用
這是網路找的然後經過自己修改過
/*
from http://www.amibroker.com/library/detail.php?id=569
zaqimon
Some mods and tidy up.
There is also another version with STDEV for its channel width, but I'm OK with this simple original method.
*/
Pd=Param("Period",10,1,50,1);
ShowStop = ParamToggle("Show Stop Breakout?","No|Yes",0);
AvgUpPenMult=Param("Up Multiplier",2,1,4,0.1);
AvgDnPenMult=Param("Down Multiplier",2,1,4,0.1);
DaysInTrade=Param("Days in trade",3,1,50,1);
colorSZShort = ParamColor("Color Safe Zone Short", colorRed );
colorSZLong = ParamColor("Color Safe Zone Long", colorBrightGreen );
H1=Ref(H,-1);
L1=Ref(L,-1);
UpPen=IIf(H>H1,H-H1,0);
DnPen=IIf(L<L1,L1-L,0);
UpPenSum=Sum(UpPen,Pd);
DnPenSum=Sum(DnPen,Pd);
UpPenCount=Sum(H>H1,Pd);
DnPenCount=Sum(L<L1,Pd);
/*
we need to avoid divide-by-zero.
i choose using (yesterday) Close for Stop Price if there is no available value.
you can happily exit anytime and take profit after such a rarely occured winning streak.
or you should be more cautious about your position after such kind of rally.
*/
AvgUpPen=IIf(UpPenCount>0,UpPenSum/UpPenCount,0);
AvgDnPen=IIf(DnPenCount>0,DnPenSum/DnPenCount,0);
StopShort=H+(AvgUpPen*AvgUpPenMult);
StopLong=L-(AvgDnPen*AvgDnPenMult);
// This is the SafeZone "Dot"
SafeZoneStopShort=LLV(StopShort,DaysInTrade);
SafeZoneStopLong=HHV(StopLong,DaysInTrade);
// This calculates the Stop "Line"
// Only move Stop closer except Stop Breakout, then we move Stop (farther) to SafeZone "Dot"
ShortStop=SafeZoneStopShort;
LongStop=SafeZoneStopLong;
for (i=1;i < BarCount; i++)
{
if(H < ShortStop && SafeZoneStopShort > ShortStop)
{
ShortStop = ShortStop;
}
if(L > LongStop && SafeZoneStopLong < LongStop)
{
LongStop = LongStop;
}
}
Plot(SafeZoneStopShort, "Safe Zone Short", colorSZShort, styleDots|styleNoLine);
Plot(SafeZoneStopLong, "Safe Zone Long", colorSZLong, styleDots|styleNoLine);
// EncodeColor force Title color unchanging, or it changes according to the right-most bar, which is irritating.
// Grey line means we move Stop farther, while in real trade, you should always move Stop closer.
Plot(ShortStop, EncodeColor(ColorBlend(colorSZShort,colorBlack))+"Stop Short", IIf(ShortStop>Ref(ShortStop,-1), colorGrey50, ColorBlend(colorSZShort, colorBlack)), ParamStyle("Style Stop Short", styleLine));
Plot(LongStop, EncodeColor(ColorBlend(colorSZLong,colorBlack))+"Stop Long", IIf(LongStop<Ref(LongStop,-1), colorGrey50, ColorBlend(colorSZLong, colorBlack)), ParamStyle("Style Stop Long", styleLine));
if(ShowStop)
{
// touch Yesterday's Stop price then exit, showing a hollow triangle
PlotShapes(IIf(H>=Ref(ShortStop,-1), shapeHollowSmallUpTriangle, shapeNone), colorSZShort, 0, H, 12);
PlotShapes(IIf(L<=Ref(LongStop,-1), shapeHollowSmallDownTriangle, shapeNone), colorSZLong, 0, L, 12);
}
謝謝版大分享{:4_160:}{:4_160:} 謝謝分享好東西{:4_196:} 這對我來說好像火星文{:4_93:} 好東西謝謝分享SafeZone指標
頁:
[1]