평균선 돌파 전략은 이동 평균을 이용하여 판단하는 짧은 선 거래 전략이다. 이 전략은 평균선 길이를 설정하여 평균선이 돌파될 때 매매를 하는 것이다. 이 전략은 조작이 간단하고 쉽게 습득할 수 있다.
이 전략은 주로 두 개의 이동 평균, 빠른 선과 느린 선을 설정하여 가격 움직임을 판단합니다. 빠른 선의 주기는 짧고 반응 민감합니다. 느린 선의 주기는 길고 반응은 평평합니다.
코드는 입력 파라미터를 설정하여 단선주기 (shortPeriod) 와 느린선주기 (longPeriod) 를 정의한다. 그리고 두 평행선의 값을 계산한다.
단기평균선이 아래로 올라가 긴 주기평균선을 돌파할 때, 가격운동이 하향으로 돌진하여 더 많은 것을 나타냅니다. 단기평균선이 위로 내려가 긴 주기평균선을 돌파할 때, 가격운동이 하향으로 돌진하여 더 많은 것을 나타냅니다.
이 경우, 입장이 가능한 조건은
快线由下向上突破慢线
快线>慢线
코스피 상장 조건:
快线由上向下跌破慢线
快线<慢线
또한, 전략은 위험을 제어하기 위해 스톱로스, 스톱, 금액과 같은 파라미터를 설정합니다.
위험 예방:
평평선 돌파 전략의 개념은 간단하며, 속속 평평선 판단을 통해 더 많은 공백 시간을 수행하고, 조작이 쉽다. 그러나 허위 돌파, 지연 등과 같은 몇 가지 문제도 있다. 변수 최적화, 다른 지표의 조합과 같은 방법을 통해 개선할 수 있다.
/*backtest
start: 2023-08-26 00:00:00
end: 2023-09-25 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © YohanNaftali
//@version=5
///////////////////////////////////////////////////////////////////////////////
// Heikin Ashi Candle Startegy
// ver 2021.12.29
// © YohanNaftali
// This script composed by Yohan Naftali for educational purpose only
// Reader who will use this signal must do own research
///////////////////////////////////////////////////////////////////////////////
strategy(
title = 'Heikin Ashi Candle Startegy Long',
shorttitle = 'HA Strategy Long',
format = format.price,
precision = 0,
overlay = true)
// Input
validationPeriod = input.int(
defval = 3,
title = 'Validation Period',
group = 'Candle')
qtyOrder = input.float(
defval = 1.0,
title = 'Qty',
group = 'Order')
maxActive = input.float(
defval = 1.0,
title = 'Maximum Active Open Position',
group = 'Order')
// Long Strategy
tpLong = input.float(
defval = 1,
title = "Take Profit (%)",
minval = 0.0,
step = 0.1,
group = "Long") * 0.01
slLong = input.float(
defval = 25,
title = "Stop Loss (%)",
minval=0.0,
step=0.1,
group="Long") * 0.01
trailingStopLong = input.float(
defval = 0.2,
title = "Trailing Stop (%)",
minval = 0.0,
step = 0.1,
group = 'Long') * 0.01
// Calculation
haTicker = ticker.heikinashi(syminfo.tickerid)
haClose = request.security(haTicker, timeframe.period, close)
haOpen = request.security(haTicker, timeframe.period, open)
// Long
limitLong = tpLong > 0.0 ? strategy.position_avg_price * (1 + tpLong) : na
stopLong = slLong > 0.0 ? strategy.position_avg_price * (1 - slLong) : na
float trailLong = 0.0
trailLong := if strategy.position_size > 0
trailClose = close * (1 - trailLong)
math.max(trailClose, trailLong[1])
else
0
isGreen = true
for i = 0 to validationPeriod-1
isGreen := isGreen and haClose[i] > haOpen[i]
isLong = isGreen and haClose[validationPeriod] < haOpen[validationPeriod]
plot(
limitLong,
title = 'Limit',
color = color.rgb(0, 0, 255, 0),
style = plot.style_stepline,
linewidth = 1)
plot(
trailLong,
title = 'Trailing',
color = color.rgb(255, 255, 0, 0),
style = plot.style_stepline,
linewidth = 1)
plot(
stopLong,
title = 'Stop',
style = plot.style_stepline,
color = color.rgb(255, 0, 0, 0),
linewidth = 1)
// plotshape(
// isLong,
// title = 'Entry',
// style = shape.arrowup,
// location = location.belowbar,
// offset = 1,
// color = color.new(color.green, 0),
// text = 'Long Entry',
// size = size.small)
// Strategy
strategy.risk.max_position_size(maxActive)
strategy.risk.allow_entry_in(strategy.direction.long)
strategy.entry(
id = "Long",
direction = strategy.long,
qty = qtyOrder,
when = isLong,
alert_message = "LN")
if (strategy.position_size > 0)
strategy.exit(
id = "Long Exit",
from_entry = "Long",
limit = limitLong,
stop = stopLong,
trail_price = trailLong,
alert_message = "LX")