常用的停利出場

有句投資名言: 會買是徒弟 會賣才是師傅,好的出場方式讓獲利績效大幅提升。這篇文章整理我常用的一些停利方法,透過 Multicharts 程式幫助我們更輕鬆更即時掌握關鍵買賣點

最簡單直接的方法 適合波動性相對穩定的市場,容易計算風險報酬比。程式碼範例如下

固定點數停損停利


if MarketPosition = 1 then begin
if TrailStop = 0 then TrailStop = EntryPrice – TrailPoints * MinMove * PriceScale
else
TrailStop = MaxList(TrailStop, Close – TrailPoints * MinMove * PriceScale);

if Close <= TrailStop then Sell(“Trail Stop Long”) next bar at market;
end;

if MarketPosition = -1 then begin
if TrailStop = 0 then
TrailStop = EntryPrice + TrailPoints * MinMove * PriceScale
else
TrailStop = MinList(TrailStop, Close + TrailPoints * MinMove * PriceScale);

if Close >= TrailStop then BuyToCover(“Trail Stop Short”) next bar at market;
end;

end;

ATR追蹤停利

根據市場波動性動態調整 在高波動時給予更大停利空間

ATRValue = AvgTrueRange(ATRLength);
if MarketPosition = 1 then begin
if TrailStop = 0 then
TrailStop = Close – ATRMultiple * ATRValue
else
TrailStop = MaxList(TrailStop, Close – ATRMultiple * ATRValue);

if Close <= TrailStop then
Sell(“ATR Trail Long”) next bar at market;
end;


if MarketPosition = -1 then begin
if TrailStop = 0 then
TrailStop = Close + ATRMultiple * ATRValue
else
TrailStop = MinList(TrailStop, Close + ATRMultiple * ATRValue);

if Close >= TrailStop then
BuyToCover(“ATR Trail Short”) next bar at market;
end;

百分比追蹤停利

按價格百分比設定停利 適合股票的商品

if MarketPosition = 1 then begin
if TrailStop = 0 then
TrailStop = Close * (1 – TrailPercent / 100)
else
TrailStop = MaxList(TrailStop, Close * (1 – TrailPercent / 100))

if Close <= TrailStop then
Sell(“Percent Trail Long”) next bar at market;
end;


if MarketPosition = -1 then begin
if TrailStop = 0 then
TrailStop = Close * (1 + TrailPercent / 100)
else
TrailStop = MinList(TrailStop, Close * (1 + TrailPercent / 100));

if Close >= TrailStop then
BuyToCover(“Percent Trail Short”) next bar at market;
end;

通道突破移動停利

利用價格通道作為停利基準 能夠適應趨勢強弱變化 也比較不容易被洗出場

ChannelHigh = Highest(High, ChannelLength);
ChannelLow = Lowest(Low, ChannelLength);


if MarketPosition = 1 then begin
TrailStop = ChannelLow;
if Close <= TrailStop then
Sell(“Channel Trail Long”) next bar at market;
end;

if MarketPosition = -1 then begin
TrailStop = ChannelHigh;
if Close >= TrailStop then
BuyToCover(“Channel Trail Short”) next bar at market;
end;

移動平均追蹤停利

移動平均是技術分析中最經典指標 簡單又好用,不需要透過程式也容易人為判斷

MAValue = Average(Close, MALength);
if MarketPosition = 1 then begin
if Close <= MAValue then
Sell(“MA Trail Long”) next bar at market;
end;


if MarketPosition = -1 then begin
if Close >= MAValue then
BuyToCover(“MA Trail Short”) next bar at market;
end;

end;

拋物線SAR追蹤停利


能自動加速追蹤停利出場速度,當漲勢或跌勢力道趨緩 會隨著價格貼近


SARValue = ParabolicSAR(SARStep, SARMax);

if MarketPosition = 1 then begin
if Close <= SARValue then
Sell(“SAR Trail Long”) next bar at market;
end;


if MarketPosition = -1 then begin
if Close >= SARValue then
BuyToCover(“SAR Trail Short”) next bar at market;
end;

end;

階梯式移動停損停利

當價格創新高 停利(停損)的區間往上;當價格創新低 停利(停損)區間往下

if barssinceentry=0 then begin
longstop=minlist(low,low[1],low[2])-N;
barH=high;
end;
if high>barH then barH=high;
if barssinceentry>0 then begin
if c>barH[1] then longstop=minlist(low,low[1])-N;
end;
if marketposition=1 then sell next bar at longstop stop ;
if barssinceentry=0 then begin
sellstop=maxlist(high,high[1])+N;
barL=low;
end;
if barssinceentry>0 then begin
if c<barL[1] then sellstop=maxlist(high,high[1],high[2])+N
end;
if marketposition=-1 then buytocover next bar at sellstop stop ;

這篇文章整理了很久,用程式碼直接表示也許比較容易懂, 希望對於正在摸索程式交易的新手有所幫助~~覺得有用的話也請多分享

分享你的喜愛