
이 전략은 고스 오차 함수를 기반으로 가격 변화의 P-Signal 지표를 계산하는 양적 거래 전략이다. P-Signal 지표를 사용하여 가격 동향과 전환점을 판단하고, 이를 통해 진입 및 퇴출 시간을 결정한다.
이 전략의 핵심 지표는 P-Signal. P-Signal의 계산 공식은 다음과 같다:
fPSignal(ser, int) =>
nStDev = stdev(ser, int)
nSma = sma(ser, int)
fErf(nStDev > 0 ? nSma/nStDev/sqrt(2) : 1.0)
여기서 ser는 가격의 순서를, int는 nPoints의 변수를 나타냅니다. 즉, 얼마나 많은 K줄을 보는지 살펴봅니다. 이 공식은 세 부분으로 구성됩니다:
전체 공식은 가격의 이동 평균을 가격의 표준 차로 나누고, 다시 sqrt ((2) 로 나누고, 가스의 오류 함수를 통해 ((-1, 1) 영역으로 지도합니다. 즉, 가격의 변동이 평균보다 크면 P-Signal은 1에 가깝습니다. 가격의 변동이 평균보다 작다면 P-Signal은 -1에 가깝습니다.
전략은 P-Signal의 수와 그 변화된 기호를 사용하여 입출소를 결정한다:
strategy.entry("long", strategy.long, 1, when = nPSignal < 0 and ndPSignal > 0)
strategy.close("long", when = nPSignal > 0 and ndPSignal < 0)
P-Signal이 0보다 작고 긍정적으로 변할 때 더 많이; P-Signal이 0보다 크고 부정적으로 변할 때 평형한다.
이 전략은 다음과 같은 장점을 가지고 있습니다.
이 전략에는 다음과 같은 위험도 있습니다.
이러한 위험을 줄이기 위해, 필터링 조건을 추가하고 거래 횟수를 줄이는 것을 고려할 수 있습니다. 파라미터 조합과 거래 비용 설정을 최적화하고, 적당한 품종을 선택하여 실 디스크 마찰을 고려할 수 있습니다.
이 전략에는 더 많은 최적화가 가능하며, 주요 방향은 다음과 같습니다.
전체적으로 이 전략의 핵심 아이디어는 새로운 것으로, 가우스 함수를 사용하여 가격 분포를 맞추고, 자동으로 파라미터 범위를 조정한다. 하지만, 고주파 거래 전략으로서, 더 많은 테스트와 최적화가 필요하며, 특히 위험 제어와 파라미터 조정 측면에서, 실물 상에서 수익을 안정화하기 위해 필요하다.
/*backtest
start: 2023-01-12 00:00:00
end: 2024-01-18 00:00:00
period: 1d
basePeriod: 1h
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/
// P-Signal Strategy © Kharevsky
// @version=4
// **********************************************************************************************************
strategy("P-Signal Strategy", precision = 3)
// Parameters and const of P-Signal.
nPoints = input(title = "Number of Bars", type = input.integer, defval = 9, minval = 4, maxval = 100, group = "Parameters of observation.")
int nIntr = nPoints - 1
// Horner's method for the error (Gauss) & P-Signal functions.
fErf(x) =>
nT = 1.0/(1.0 + 0.5*abs(x))
nAns = 1.0 - nT*exp(-x*x - 1.26551223 +
nT*( 1.00002368 + nT*( 0.37409196 + nT*( 0.09678418 +
nT*(-0.18628806 + nT*( 0.27886807 + nT*(-1.13520398 +
nT*( 1.48851587 + nT*(-0.82215223 + nT*( 0.17087277 ))))))))))
x >= 0 ? nAns : -nAns
fPSignal(ser, int) =>
nStDev = stdev(ser, int)
nSma = sma(ser, int)
fErf(nStDev > 0 ? nSma/nStDev/sqrt(2) : 1.0)
// Strat.
float nPSignal = sma(fPSignal(change(ohlc4), nIntr), nIntr)
float ndPSignal = sign(nPSignal[0] - nPSignal[1])
strategy.entry("long", strategy.long, 1, when = nPSignal < 0 and ndPSignal > 0)
strategy.close("long", when = nPSignal > 0 and ndPSignal < 0)
// Plotting.
hline(+1.0, color = color.new(color.orange,70), linestyle = hline.style_dotted)
hline(-1.0, color = color.new(color.orange,70), linestyle = hline.style_dotted)
plot(nPSignal, color = color.blue, style = plot.style_line)
plot(strategy.position_size, color = color.white, style = plot.style_cross)
// Alerts.
if(strategy.position_size[0] > strategy.position_size[1])
alert("P-Signal strategy opened the long position: " + syminfo.tickerid + " " + timeframe.period, alert.freq_once_per_bar)
if(strategy.position_size[0] < strategy.position_size[1])
alert("P-Signal strategy closed the long position: " + syminfo.tickerid + " " + timeframe.period, alert.freq_once_per_bar)
// The end.