
이 전략은 양수 흔들림 지표에 기반하여 시장의 흐름을 판단하고, 이에 따라 장단 포지션을 구축한다. 양수 흔들림 지표는 가격 근처의 최근 양수와 가격의 차이를 계산하고, 양수는 다단 경향을 나타내고, 마이너스 값은 공중 경향을 나타낸다. 이 전략은 가격 흔들림 때 숨겨진 경향 정보를 포착할 수 있어, 돌파 거래에 대한 지침이 중요하다.
이 전략은 먼저 PrimeNumber Oscillator 함수를 정의하고, 가격과 AllowedPercent을 입력한다. 이 함수는 가격의 양-저 AllowedPercent의 범위에서 가격에 가장 가까운 직수를 찾아내고, 둘의 차이를 반환한다. 0보다 큰 차이는 다단계 경향을 나타내고, 0보다 작은 차이는 공방향 경향을 나타낸다.
다음으로 전략에서 PrimeNumberOscillator 함수를 호출하여 xPNO 값을 계산한다. xPNO에 따라 포지션 위치를 긍정적으로 판단하고, reverseFactor에 의해 최종 거래 방향을 결정한다. 거래 방향에 따라 포지션을 개시하고 더 많은 공백을 한다.
이 전략은 주로 양수 흔들림 지표에 의존하여 트렌드 방향을 판단한다. 지표는 그 자체는 다소 거칠기 때문에 거래 신호를 검증하기 위해 다른 요소와 결합해야 한다. 그러나 그것은 수학 원리에 기반하여 약간의 객관적 지침을 제공 할 수 있다.
이 전략은 양수 흔들림 원칙에 기초하여 트렌드 방향을 판단하여 간단하고 논리적으로 명확하다. 그러나 양수 흔들림 자체는 일정 한계가 있으며 신중하게 사용해야 한다. 다른 기술 지표를 조합하여 신호를 검증하고 거래 위험을 제어 할 수 있다. 이 전략은 수학 거래 전략의 전형적인 대표자이며 학습과 연구에 약간의 참고 가치가 있다.
/*backtest
start: 2023-10-02 00:00:00
end: 2023-11-01 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
////////////////////////////////////////////////////////////
// Copyright by HPotter v1.0 29/03/2018
// Determining market trends has become a science even though a high number or people
// still believe it’s a gambling game. Mathematicians, technicians, brokers and investors
// have worked together in developing quite several indicators to help them better understand
// and forecast market movements.
//
// Developed by Modulus Financial Engineering Inc., the prime number oscillator indicates the
// nearest prime number, be it at the top or the bottom of the series, and outlines the
// difference between that prime number and the respective series.
//
// You can change long to short in the Input Settings
// WARNING:
// - For purpose educate only
// - This script to change bars colors.
////////////////////////////////////////////////////////////
PrimeNumberOscillator(price, percent) =>
res = 0
res1 = 0
res2 = 0
for j = price to price + (price * percent / 100)
res1 := j
for i = 2 to sqrt(price)
res1 := iff(j % i == 0 , 0, j)
if res1 == 0
break
if res1 > 0
break
for j = price to price - (price * percent / 100)
res2 := j
for i = 2 to sqrt(price)
res2 := iff(j % i == 0 , 0, j)
if res2 == 0
break
if res2 > 0
break
res := iff(res1 - price < price - res2, res1 - price, res2 - price)
res := iff(res == 0, res[1], res)
res
strategy(title="Prime Number Oscillator Backtest")
percent = input(5, minval=0.01, step = 0.01, title="Tolerance Percentage")
reverse = input(false, title="Trade reverse")
xPNO = PrimeNumberOscillator(close, percent)
pos = iff(xPNO > 0, 1,
iff(xPNO < 0, -1, nz(pos[1], 0)))
possig = iff(reverse and pos == 1, -1,
iff(reverse and pos == -1, 1, pos))
if (possig == 1)
strategy.entry("Long", strategy.long)
if (possig == -1)
strategy.entry("Short", strategy.short)
barcolor(possig == -1 ? red: possig == 1 ? green : blue )
clr = iff(xPNO > 0, green, red)
p1 = plot(xPNO, color=blue, title="KPO")
p2 = plot(0, color=black, title="0")
fill(p1,p2,color=clr)