크로스 리미트 오더 크로스 기간 거래 전략

저자:차오장, 날짜: 2023-11-03 17:11:34
태그:

img

요약

이 전략은 트렌드를 따르는 거래 전략으로 단순한 이동 평균을 사용하여 시장 트렌드 방향을 결정하고 트렌드를 따라 이동 평균 라인을 따라 제한 주문을합니다.

전략 논리

  1. 단순 이동 평균 (SMA) 과 트렌드 방향 트렌드를 계산합니다.

  2. 반사 필터가 활성화되면, 마이너 트렌드가 SMA보다 낮을 때, 마이너 트렌드가 SMA보다 낮을 때 확인됩니다.

  3. 트렌드 방향 트렌드 및 활성화 된 거래 방향에 따라 SMA 가격에 제한 주문을 배치하십시오.

    • 긴 거래가 필요한 경우 (needlong는 사실) 그리고 상승 추세에서 SMA 가격에 긴 제한 주문을 두십시오.

    • 짧은 거래가 필요한 경우 (needshort가 맞습니다) 하락 추세에서 SMA 가격에 짧은 제한 명령을 두십시오.

  4. 지점 방향이 트렌드 방향과 일치하지 않는 경우 종료 지점에 Stop Loss 로직을 설정합니다.

  5. 날짜 범위 매개 변수에 기초하여 지정된 날짜 범위 내에서만 거래합니다.

이점 분석

  1. 트렌드를 결정하기 위해 SMA를 사용하면 시장 소음을 효과적으로 필터링하고 장기적인 트렌드를 차단할 수 있습니다.

  2. SMA 가격에 리미트 오더를 배치하면 트렌드가 시작되면 좋은 입구점을 얻을 수 있습니다.

  3. 개인 트레이딩 스타일에 따라 롱 또는 쇼트를 할 수 있는 유연성

  4. 손실을 막기 위해 손실을 막아야 합니다.

  5. 주요 사건에 대한 변동성을 피하기 위해 거래 시간 범위 설정.

위험 분석

  1. 트렌드 지표로서의 SMA는 지연 효과를 가지고 있으며, 트렌드 전환점을 놓치고 손실을 초래할 수 있습니다.

  2. 리미트 오더는 유연성이 부족하고, 단기 트렌드 조정으로 인해 포지션에 들어갈 수 없습니다.

  3. SMA 기간 매개 변수는 적절한 구성이 필요하며, 잘못된 설정은 잘못된 트렌드 결정으로 이어집니다.

  4. 거래 세션의 매개 변수는 합리적이어야 하며, 놓친 기회나 위험 기간에 거래하는 것을 피해야 합니다.

최적화 방향

  1. 여러 지표 확인을 위해 다른 지표를 추가하는 것을 고려하여 SMA 지체 문제를 피하십시오.

  2. 가격이 SMA를 넘으면 시장 주문 추적으로 전환하여 추적 유연성을 향상시킵니다.

  3. 동적으로 SMA 기간을 최적화하여 다른 시장 순환에 적응합니다.

  4. 보다 유연한 스톱을 위해 SMA 가격에 엄격하지 않고 낮은 / 높은 변동으로 스톱 손실을 설정하십시오.

  5. 더 똑똑한 동적 거래 세션을 위해 알고리즘 요소를 늘려 주요 위험 이벤트를 피합니다.

요약

전체적으로 이것은 상대적으로 간단한 트렌드 다음 전략이며, 핵심 아이디어는 SMA로 트렌드 방향을 결정하고 트렌드를 따라하기 위해 SMA 가격에 리미트 오더를 배치하는 것입니다. 특정 최적화와 함께 유연성, 적응력 및 지능을 향상시킬 수 있습니다. 전략은 이해하기 쉽고 구현 할 수 있습니다. 알고리즘 거래 초보자에게 적합하지만 위험 인식, 신중한 백테스트 평가, 엄격한 모니터링 및 실시간 거래에 대한 최적화가 필요합니다.


/*backtest
start: 2022-10-27 00:00:00
end: 2023-03-12 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//Noro
//2020

//@version=4
strategy(title = "Noro's CrossLimit", shorttitle = "CrossLimit", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100.0, pyramiding = 0, commission_value = 0.0)

needlong = input(true, "long")
needshort = input(true, "short")
lotsize = input(100, defval = 100, minval = 1, maxval = 10000, title = "Lot, %")
src = input(close, defval = close, title = "MA Source")
len = input(5, defval = 5, minval = 1, title = "SMA length")
off = input(0, defval = 0, minval = 0, title = "SMA offset")
anti = input(true, defval = true, title = "Anti-saw filter")
rev = input(false, defval = false, title = "Reverse")
showma = input(true, defval = true, title = "Show MA")
showbg = input(false, defval = false, title = "Show background")
fromyear = input(1900, defval = 1900, minval = 1900, maxval = 2100, title = "From Year")
toyear = input(2100, defval = 2100, minval = 1900, maxval = 2100, title = "To Year")
frommonth = input(01, defval = 01, minval = 01, maxval = 12, title = "From Month")
tomonth = input(12, defval = 12, minval = 01, maxval = 12, title = "To Month")
fromday = input(01, defval = 01, minval = 01, maxval = 31, title = "From day")
today = input(31, defval = 31, minval = 01, maxval = 31, title = "To day")

//MA
ma = sma(src, len)[off]
macol = showma ? color.blue : na
plot(ma, color = macol, linewidth = 3, transp = 0)

//Background
trend = 0
trend := anti == false and close > ma ? 1 : anti == false and close < ma ? -1 : low > ma ? 1 : high < ma ? -1 : trend[1]
bgcol = showbg ? trend == 1 ? color.lime : trend == -1 ? color.red : na : na
bgcolor(bgcol, transp = 70)

//Signals
bar = close > open ? 1 : close < open ? -1 : 0
up = (trend == 1 and rev == false) or (trend == -1 and rev == true)
dn = (trend == -1 and rev == false) or (trend == 1 and rev == true)

//Trading
size = strategy.position_size
truetime = time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)
lot = 0.0
lot := size != size[1] ? strategy.equity / close * lotsize / 100 : lot[1]
if trend != 0
    strategy.entry("Long", strategy.long, lot, limit = ma, when = needlong and truetime and up)
    strategy.entry("Short", strategy.short, lot, limit = ma, when = needshort and truetime and dn)
if size > 0 and needshort == false and trend == -1
    strategy.exit("Stop Long", "Long", limit = ma)
if size < 0 and needlong == false and trend == 1
    strategy.exit("Stop Short", "Short", limit = ma)
if time > timestamp(toyear, tomonth, today, 23, 59)
    strategy.close_all()
    strategy.cancel("Long")
    strategy.cancel("Short")

더 많은