2021-12-23|閱讀時間 ‧ 約 3 分鐘

程式碼分析.2

簡單的均線排列加上一個拉回等待買進的條件,運用平均真實區間作為波動度的衡量依據,並以此做為停利目標、停損目標與條件式損益兩平出場策略
{Skinny Dipper} Inputs: LTAvg(50), STAvg(15), ATRLen(10), ProfATR(4), ProtATR(3), BEATRs(4); Variables: PosHigh(0), PosLow(0), PosHL(0), EntryATR(0), ATRValPt(0), ATRValP(0), ATRValBE(0);
ATRValPt = AvgTrueRange(ATRLen) * ProfATR; ATRValP = AvgTrueRange(ATRLen) * ProtATR; ATRValBE = AvgTrueRange(ATRLen) * BEATRs; {Setup} Condition1 = Close XAverage(Close, LTAvg); Condition2 = Close XAverage(Close, STAvg); Condition3 = Close Low[1]; {Long Entry}
If Condition1 AND Condition2 AND Condition3 Then Buy Next Bar at High[1] + 1 Point Stop;
{ATR Profit Target Stop} If BarsSinceEntry = 0 Then EntryATR = ATRValPt; If MarketPosition = 1 Then sell Next Bar at EntryPrice + EntryATR Limit;
{ATR Protective Stop} If MarketPosition = 1 Then sell Next Bar at EntryPrice - ATRValP Stop;
{ATR Breakeven Stop} If BarsSinceEntry = 0 Then PosHL = Close; If MarketPosition = 1 Then Begin If Close PosHL Then PosHL = Close; If PosHL EntryPrice + ATRValBE Then sell Next Bar at EntryPrice Stop; End;
分享至
成為作者繼續創作的動力吧!
© 2024 vocus All rights reserved.