고정 그리드 거래 전략


생성 날짜: 2023-11-16 17:09:45 마지막으로 수정됨: 2023-11-16 17:09:45
복사: 0 클릭수: 851
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

고정 그리드 거래 전략

개요

이 전략은 고정 격자 거래 방식을 채택하여 시작 가격과 각 격자 간격 비율을 설정하고, 그 비율에 따라 10 층의 고정 구매 및 판매 가격을 설정하여 낮은 가격과 높은 가격의 격자 거래 전략을 구현합니다.

전략 원칙

이 전략은 먼저 시작 가격 sprice와 각 계층 격자 간격 비율 gridpercent을 설정한다. 그리고 시작 가격과 비율에 따라 10 계층의 구매 및 판매 가격을 계산한다.

구매 가격 공식:

b1=sprice-(sprice*p1)

b2=sprice-(sprice*p2)

b3=sprice-(sprice*p3)

그 중 p1~p10은 gridpercent에 따라 층별로 계산된 비율이다.

판매 가격 공식:

s1=b1+(sprice*p1)

s2=b2+(sprice*p1)

s3=b3+(sprice*p1)

매입 조건은 매입 가격이 매입 가격보다 낮을 때 매입을 촉발한다:

if (close

strategy.entry(“b1”, strategy.long, when=(close

마찬가지로, 매매가격이 매매가격보다 높을 때 매매가격이 발생한다:

if (close>s1)

strategy.exit(“b1”, when=(close>s1))

그리고 이 모든 것은 고정망의 ‘저가고고가다’ 전략이 실현되는 것이다.

전략적 이점

이 고정망 전략은 다음과 같은 장점이 있습니다.

  1. 자동으로 시장을 타이밍하지 않고, 거래의 난이도를 낮춰주는 낮은 가격과 높은 가격의 거래가 가능해졌다.

  2. 합리적인 격자 간격을 설정하면 위험을 효과적으로 제어하고, 추격에 걸리지 않도록 할 수 있다.

  3. 시장이 상승하든 하락하든 수익을 낼 수 있다.

  4. 격자 매개 변수를 조정하여 다른 시장 상황에 맞게 조정할 수 있습니다.

  5. 격자 계층을 늘려서 포지션 규모를 확장할 수 있다.

  6. “지난 해에, 저는 제주도에서 일한 적이 있습니다.

전략적 위험

이 전략에는 몇 가지 위험도 있습니다.

  1. 이 거래가 상쇄되면 거래비용이 수익을 아 버립니다.

  2. 초기 가격과 그리드 설정이 적절하지 않아 손실이 발생하기 쉽다.

  3. 급격한 사건으로 인해 가격이 급격히 하락하면 손실이 발생할 수 있습니다.

  4. 기계 거래 시스템에는 거래 중첩의 위험이 있습니다.

  5. 이 사건으로 인해 손실이 커졌습니다.

그 해결책은 다음과 같습니다.

  1. 거래비용보다 수익이 더 많을 수 있도록 격자 매개 변수를 합리적으로 설정하십시오.

  2. 최적화 매개 변수를 재검토하여 적절한 시작 가격과 격자 간격을 설정합니다.

  3. 위험을 통제하기 위해 스톱로스를 늘리십시오.

  4. 거래가격의 적절한 완화로 인해 줄을 서는 일이 없도록 한다.

  5. 최대 손실을 제한하기 위해 위험 관리를 설정하십시오.

전략 최적화

이 전략은 다음과 같은 방향으로 최적화될 수 있습니다.

  1. 동적으로 격자 간격을 조정하고, 파동이 커지면 간격을 넓히고, 간격을 줄인다.

  2. 역사적인 데이터에 따라 변동 범위를 계산하고, 동적으로 시작 가격을 조정한다.

  3. 기계 학습 모형에 연결하여 가격 움직임을 예측하고, 동적으로 조정하는 격자.

  4. 위험도가 높은 지점에서 스톱를 추가하고, 역사적 스톱 지점을 관찰하여 스톱 위치를 최적화한다.

  5. 자금 관리 전략과 결합하여 수익 상황에 따라 동적으로 포지션을 조정하십시오.

  6. 포지션 관리를 최적화하고 자금 사용 효율을 극대화하십시오.

  7. 거래 실행을 최적화하고 TWAP와 같은 알고리즘을 사용하여 충격 비용을 줄입니다.

요약하다

이 전략은 고정 격자 거래 방식을 채택하고, 시작 가격과 격자 간격의 비율에 따라 구매 및 판매 가격을 설정하여 자동화된 낮은 가격과 높은 가격 거래를 구현하여 시장 변동성을 효과적으로 활용할 수 있습니다. 또한 위험 관리에 주의를 기울이며, 파라미터 최적화, 동적 조정 및 스톱로스를 통해 수익을 고정하고 손실을 제어하십시오.

전략 소스 코드
/*backtest
start: 2022-11-09 00:00:00
end: 2023-11-15 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/
// © Lionkind

//@version=5
strategy("Grid HW", overlay = true, margin_long = 1, margin_short = 1)

// Fix 35k price as starting point and 1% as a distance

sprice=input(40500,"Starting price")
gridpercent=input(1,"Percent")

// calculate the % of the 10 layers 

p1=((gridpercent*1)/100)
p2=((gridpercent*2)/100)
p3=((gridpercent*3)/100)
p4=((gridpercent*4)/100)
p5=((gridpercent*5)/100)
p6=((gridpercent*6)/100)
p7=((gridpercent*7)/100)
p8=((gridpercent*8)/100)
p9=((gridpercent*9)/100)
p10=((gridpercent*10)/100)

//set buy prices 

b1=sprice-(sprice*p1)
b2=sprice-(sprice*p2)
b3=sprice-(sprice*p3)
b4=sprice-(sprice*p4)
b5=sprice-(sprice*p5)
b6=sprice-(sprice*p6)
b7=sprice-(sprice*p7)
b8=sprice-(sprice*p8)
b9=sprice-(sprice*p9)
b10=sprice-(sprice*p10)

//set sell prices

s1=b1+(sprice*p1)
s2=b2+(sprice*p1)
s3=b3+(sprice*p1)
s4=b4+(sprice*p1)
s5=b5+(sprice*p1)
s6=b6+(sprice*p1)
s7=b7+(sprice*p1)
s8=b8+(sprice*p1)
s9=b9+(sprice*p1)
s10=b10+(sprice*p1)

//Long conditions

lc1=close<b1
lc2=close<b2
lc3=close<b3
lc4=close<b4
lc5=close<b5
lc6=close<b6
lc7=close<b7
lc8=close<b8
lc9=close<b9
lc10=close<b10

//exit conditions
ec1=close>s1
ec2=close>s2
ec3=close>s3
ec4=close>s4
ec5=close>s5
ec6=close>s6
ec7=close>s7
ec8=close>s8
ec9=close>s9
ec10=close>s10

//long orders
if (lc1)
    strategy.entry("b1", strategy.long, when=(lc1))
    
if (lc2)
    strategy.entry("b2", strategy.long, when=(lc2))
    
if (lc3)
    strategy.entry("b3", strategy.long, when=(lc3))    
if (lc4)
    strategy.entry("b4", strategy.long, when=(lc4))    
if (lc5)
    strategy.entry("b5", strategy.long, when=(lc5))
if (lc6)
    strategy.entry("b6", strategy.long, when=(lc6))
if (lc7)
    strategy.entry("b7", strategy.long, when=(lc7))    
if (lc8)
    strategy.entry("b8", strategy.long, when=(lc8))    
if (lc9)
    strategy.entry("b9", strategy.long, when=(lc9))    
if (lc10)
    strategy.entry("b10", strategy.long, when=(lc10))
    
//exit orders   
if (ec1)
    strategy.exit("b1", when=(ec1), limit=1)
if (ec2)
    strategy.exit("b2", when=(ec2), limit=1)
if (ec3)
    strategy.exit("b3", when=(ec3), limit=1)
if (ec4)
    strategy.exit("b4", when=(ec4), limit=1)
if (ec5)
    strategy.exit("b5", when=(ec5), limit=1)
if (ec6)
    strategy.exit("b6", when=(ec6), limit=1)
if (ec7)
    strategy.exit("b7", when=(ec7), limit=1)
if (ec8)
    strategy.exit("b8", when=(ec8), limit=1)
if (ec9)
    strategy.exit("b9", when=(ec9), limit=1)
if (ec10)
    strategy.exit("b10", when=(ec10), limit=1)
    

plot(b1,color=color.green)
plot(s1, color=color.red)
plot(b2, color=color.purple)