
이것은 이동 평균선을 기반으로 한 돌파 거래 전략이다. 그것은 일정 주기 동안의 평균 가격을 평균선으로 계산하여, 가격이 평균선을 돌파할 때 거래 신호를 발생시킨다.
이 전략은 주로 이동 평균선 지표를 기반으로 한다. 그것은 sma 함수를 사용하여 일정 주기 동안의 평균 폐쇄 가격을 계산하여 이동 평균선을 얻는다. 최신 폐쇄 가격이 아래에서 위로 이동 평균선을 돌파 할 때 구매 신호를 생성하고 최신 폐쇄가 위에서 아래로 이동 평균선을 돌파 할 때 판매 신호를 생성한다.
구체적으로, 그것은 전략에서 이동 평균의 계산 소스 ((최근의 종료 가격) 와 주기 길이를 정의하고 이동 평균 데이터의 시퀀스를 얻습니다. 다음에는 두 가지 조건을 설정합니다: 가격이 평균선을 통과할 때 구매 주문을 생성하고, 가격이 평균선을 통과할 때 판매 주문을 생성합니다. 주문이 생성 된 후, 그것은 또한 중지 손실을 설정합니다: 주문이 수익이 설정된 비율에 도달 할 때 입장의 일부를 매장하고, 주문이 설정된 중지 또는 중지 가격에 도달 할 때 전체 위치를 매장합니다.
이것은 간단하고 실용적인 트렌드 추적 전략입니다. 다음과 같은 장점이 있습니다:
이 전략은 장점이 많지만 위험도 있습니다.
이러한 위험을 통제하기 위해, 우리는 다른 지표와 함께 필터링 최적화를 수행할 수 있습니다. 우리는 대량 단기 추세 판단을 도입하거나, 기계 학습 방법을 사용하여 최적의 파라미트 조합을 찾을 수 있습니다.
이 전략은 다음의 몇 가지 측면에서 최적화될 수 있습니다.
다른 기술 지표 판단을 추가하고 거래 시스템을 구성하여 전략 승률을 높인다. 예를 들어 MACD, KD와 같은 보조 판단 지표가 추가된다.
스톱 메커니즘에 가입하십시오. 추적 스톱 또는 시간 스톱을 사용하여 수익을 고정하고 손실을 확대하지 마십시오.
변수 최적화를 수행한다. 이동 평균의 주기 변수를 변경하여 최적의 변수 조합을 찾는다. 또한 다른 유형의 이동 평균을 테스트 할 수 있다.
기계학습 판단을 증가시킨다. 무작위 숲, LSTM 등의 알고리즘을 사용하여 여러 요인을 결합하여 추세 방향을 판단한다.
진입/탈출 논리를 최적화한다. 트렌드 필터 조건을 설정하고, 트렌드 종료 시 역작업을 피한다. 배열 평仓 논리를 사용하는 것을 고려한다.
이 모바일 평행선 돌파 전략은 전반적으로 양적 거래의 입문 전략으로 매우 적합합니다. 이 전략은 간단하고 이해하기 쉽고 실제 효과도 있습니다. 또한 후속 테스트 및 최적화에 많은 공간이 남아 있습니다. 우리는 더 많은 기술 지표와 모델을 도입하여 더 효과적인 양적 전략을 개발할 수 있습니다.
/*backtest
start: 2023-11-20 00:00:00
end: 2023-11-22 08:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=3
// |-- Initialize Strategy Parameters:
strategy(
// |-- Strategy Title.
title='[Tutorial][RS]Working with orders',
// |-- if shorttitle is specified, it will overwrite the name on the chart window.
shorttitle='WwO',
// |-- if true it overlays current chart window, otherwise it creates a drawer to display plotting outputs.
overlay=true,
// |-- Strategy unit type for default quantity, possible arguments: (strategy.cash, strategy.fixed, strategy.percent_of_equity)
default_qty_type=strategy.cash,
// |-- Value to use for default trade size
default_qty_value=1000,
// |-- Default Account size
initial_capital=100000,
// |-- Account Currency parameter
currency=currency.USD
)
// |-- Strategy Profit/loss parameters:
profit = input(defval=5000, title='Take Profit')
loss = input(defval=5000, title='Stop Loss')
ratio = input(defval=2.0, title='Ratio at wich to take out a percentage off the table (take profit / ratio).')
percent = input(defval=50.0, title='Percentage of position to take profit.')
// |-- Signal Parameters:
// |
// |-- Moving Average input source and length parameters.
src = input(defval=close)
length = input(defval=100)
// |-- Moving Average Data series.
ma = sma(src, length)
// |-- Condition for triggering a buy(long) order(trade).
if crossover(src, ma)
// |-- Create the order.
strategy.order(id='Buy', long=true)
// |-- Issue a exit order to close a percentage of the trade when a specified ratio(take profit / ratio) is reached.
strategy.exit(id='Buy Half Exit', from_entry='Buy', qty_percent=percent, profit=profit/ratio)
// |-- Issue a exit order to close the full position, when take profit or stop loss's are reached.
strategy.exit(id='Buy Full Exit', from_entry='Buy', qty_percent=100, profit=profit, loss=loss)
if crossunder(src, ma)
// |-- Create the order.
strategy.order(id='Sell', long=false)
// |-- Issue a exit order to close a percentage of the trade when a specified ratio(take profit / ratio) is reached.
strategy.exit(id='Sell Half Exit', from_entry='Sell', qty_percent=percent, profit=profit/ratio)
// |-- Issue a exit order to close the full position, when take profit or stop loss's are reached.
strategy.exit(id='Sell Full Exit', from_entry='Sell Half Exit', qty_percent=100, profit=profit, loss=loss)
// |-- Output Functions.
plot(series=ma, title='MA', color=black)