관리 메뉴

Leo's Garage

PineScript4 - 변동성 돌파 알람 본문

파이프라인 만들기/Algo Trading

PineScript4 - 변동성 돌파 알람

LeoBehindK 2023. 1. 14. 23:47
728x90
반응형

TradingView의 pinescript를 이용하여 변동성 돌파 매매 알람을 만들어보자

기본적으로 내가 만든 변동성 돌파 매매 알람 컨셉은 전일 종가 + ATR(Average True Range) 보다 종가가 상승으로 갈 경우 알람을 울리는 방식이다.

아주 간단한 컨셉이므로 해당 기본 아이디어를 바탕으로 세부적인 전략은 추가하면 된다.

간단하게 작성한 스크립트 코드는 다음과 같다. 

 

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © downyK

//@version=4
// Add volatility breakout to the chart
study("Volatility Breakout", overlay=true)

// Define ATR
atrLength = 14
atr = atr(atrLength)

// Define volatility breakout level
volatilityBreakout = close + atr

// Plot the volatility breakout level
plot(volatilityBreakout, color=color.red)

// Create an alert for when the price crosses above the volatility breakout level
alertcondition(close > volatilityBreakout, title='Price Crossed Above Volatility Breakout Level', message='The price has crossed above the volatility breakout level')

 

버전은 pinescript 4이고, ATR은 14일을 기준으로 계산하였다. 

그리고 계산한 변동성 돌파 지수는 빨간색 그래프로 표시하게 했다.

실제 해당 지표를 적용하면 아래와 같이 볼 수 있게 된다. 

그래프 위에 빨간선이 변동성 돌파 지표이다. 

각 종가가 해당 선을 넘게 되면, 알람이 울리는 식이다. 

 

728x90
반응형
Comments