무작위 입국 및 출국 전략

저자:차오장, 날짜: 2023-10-11 15:17:28
태그:

전반적인 설명

랜덤 엔트리 앤 엑시트 전략 (random entry and exit strategy) 은 거래 중에 랜덤으로 출입 및 출입 시기를 결정하는 전략이다. 랜덤 숫자 생성기를 사용하여 출입 및 출입 결정을 시뮬레이션합니다.

전략 논리

이 전략의 핵심 논리는 다음과 같습니다.

  1. 각각의 촛불은 무작위로 0에서 100 사이의 숫자를 생성합니다.

  2. 무작위 숫자가 설정된 진입 문턱보다 낮으면, 포지션이 열립니다. 기본 진입 확률은 10%입니다.

  3. 무작위 숫자가 설정된 출구 문턱보다 낮으면, 포지션은 종료됩니다. 기본 출구 확률은 3%입니다.

  4. 3가지 방향 선택이 있습니다. 길게만, 짧게만, 또는 무작위 방향으로. 기본 설정은 길게만입니다.

  5. 또한 시장 변동이 큰 해를 피하기 위해 시작 해를 설정할 수 있습니다.

진입 확률, 출입 확률 및 방향의 다른 조합을 설정함으로써, 우리는 다양한 유형의 거래자의 무작위 거래 행동을 시뮬레이션하고 다른 시장에서 무작위 거래의 성능을 조사할 수 있습니다.

이점 분석

  • 실제 시장 상황에 가까운 실제 거래자의 무작위 의사결정을 시뮬레이션합니다.

  • 다양한 시장에서 무작위 거래의 성능 차이를 테스트 할 수 있습니다.

  • 어떤 시장에서 어떤 시장에서 어떤 시장에서 어떤 시장에서 어떤 시장에서 어떤 시장에서 어떤 시장에서 어떤 시장에서 어떤 시장에서 어떤 시장에서

  • 다른 전략의 장점을 테스트하기 위해 랜덤 트레이딩을 벤치마크 전략으로 사용할 수 있습니다.

위험 분석

  • 시장 동향에서 이익을 얻지 못하고 최적의 진입 시기를 결정할 수 없습니다.

  • 무작위 출입은 불리한 수준에서 손실을 멈출 수 있습니다.

  • 시장에서 성적은 좋지 않습니다.

  • 과도한 거래 또는 불충분한 보유 기간을 피하기 위해 진입/출출 확률을 최적화해야 합니다.

  • 최대 손실을 피하기 위해 스톱 로스를 추가하는 것을 고려하십시오.

최적화 방향

  • 각기 다른 시장에 적합한 조합을 찾기 위해 출입/출출 확률을 조정합니다.

  • 단일 거래 손실을 통제하기 위해 스톱 로스 전략을 추가합니다.

  • 단일 거래 위험을 낮추기 위해 포지션 크기를 최적화하십시오.

  • 트렌드가 명확해지면 트렌드를 따르는 전략으로 전환합니다.

  • 통계 분석을 사용하여 어떤 시장이 무작위 거래를 선호하는지 알아보십시오.

요약

무작위 엔트리 및 출구 전략은 시뮬레이션 된 무작위 거래자 결정 하에서 다른 시장의 성능을 테스트합니다. 전략 논리는 간단하며 다른 전략을 조사하는 기준으로 사용될 수 있습니다. 그러나 트렌드를 파악하지 못하고 적절한 스톱 로스 관리 부족과 같은 결함이 있습니다. 우리는 파라미터 조합을 조정하고 스톱을 추가하고 포지션 사이징을 최적화하여 전략을 개선하여 실행 가능한 양적 거래 전략으로 전환 할 수 있습니다.


/*backtest
start: 2022-10-04 00:00:00
end: 2023-10-10 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
args: [["v_input_1",2]]
*/

//@version=4
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © gregoirejohnb
//
// "tHe MaRkEtS aRe RaNdOm", say moron academics.
//
// The purpose of this study is to show that most markets are NOT random! Most markets show a clear bias where we can make such easy money, that a random number generator can do it.
// 
// === HOW THE INDICATOR WORKS ===
// 
// -The study will randomly enter the market
// -The study will randomly exit the market if in a trade
// -You can choose a Long Only, Short Only, or Bidirectional strategy
//
// === DEFAULT VALUES AND THEIR LOGIC ===
// 
// Percent Chance to Enter Per Bar: 10%
// Percent Chance to Exit Per Bar: 1%
// Direction: Long Only
// Commission: 0
//
// Each bar has a 10% chance to enter the market. Each bar has a 1% to exit the market [if in a trade]. It will only enter long.
//
// I included zero commission for simplication. It's a good exercise to include a commission/slippage to see just how much trading fees take from you.
// 
// === TIPS ===
//
// -Increasing "Percent Chance to Exit" will shorten the time in a trade. You can see the "Avg # Bars In Trade" go down as you increase. If "Percent Chance to Exit" is too high, the study won't be in the market long enough to catch any movement, possibly exiting on the same bar most of the time.
// -If you're getting the red screen, that means the strategy lost so much money it went broke. Try reducing the percent equity on the Properties tab.
// -Switch the start year to avoid black swan events like the covid drop in 2020.
// -
// === FINDINGS ===
//
// Most markets lose money with a "Random" direction strategy.
// Most markets lose ALL money with a "Short Only" strategy.
// Most markets make money with a "Long Only" strategy.
// 
// Try this strategy on: Bitcoin (BTCUSD) and the NASDAQ (QQQ).
//
// There are two popular memes right now: "Bitcoin to the moon" and "Stocks only go up". Both are seemingly true. Bitcoin was the best performing asset of the 2010's, gaining several billion percent in gains. The stock market is on a 100 year long uptrend. Why? BECAUSE FIAT CURRENCIES ALWAYS GO DOWN! This is inflation. If we measure the market in terms of others assets instead of fiat, the Long Only strategy doesn't work anymore.
// Try this strategy on: Bitcoin/GLD (BTCUSD/GLD), the Eurodollar (EURUSD), and the S&P 500 measured in gold (SPY/GLD).
// 
// Bitcoin measured in gold (BTCUSD/GLD) still works with a Long Only strategy because Bitcoin increased in value over both USD and gold.
// The Eurodollar (EURUSD) generally loses money no matter what, especially if you add any commission. This makes sense as they are both fiat currencies with similar inflation schedules.
// Gold and the S&P 500 have gained roughly the same amount since ~2000. Some years will show better results for a long strategy, while others will favor a short strategy. Now look at just SPY or GLD (which are both measured in USD by default!) and you'll see the same trend again: a Long Only strategy crushes even when entering and exiting randomly.
//
// === "JUST TELL ME WHAT TO DO, YOU NERD!" ===
//
// Bulls always win and Bears always lose because fiat currencies go to zero.
//
strategy(title="Random Entries Work", shorttitle="REW", overlay=true, pyramiding=0, default_qty_type=strategy.percent_of_equity, default_qty_value=100, currency=currency.USD,commission_type=strategy.commission.percent,commission_value=0)

// === GENERAL INPUTS ===
strategy = input(defval="Long Only",title="Direction",options=["Long Only", "Short Only", "Random"])
enter_frequency = input(defval=10,minval=1,maxval=100,title="Percent Chance to Enter")
exit_frequency = input(defval=3, minval=0,maxval=100,title="Percent Chance to Exit",tooltip="This should be much lower than Percent Chance to Enter. Higher values decrease time in market. Lower values increase time in market.")
start_year = input(defval=2020, title="Start Year")


// === LOGIC ===
r = random(0,100)
enter = enter_frequency > r[0]
exit = exit_frequency > r[0]
direction = random(0,100) >= 50

// === STRATEGY - LONG POSITION EXECUTION ===
enterLong() =>
    strategy.opentrades == 0 and enter and (strategy == "Long Only" or (strategy == "Random") and direction) and 
       time > timestamp(start_year, 01, 01, 01, 01)
exitLong() =>
    exit
strategy.entry(id="Long", long=strategy.long, when=enterLong())
strategy.close(id="Long", when=exitLong())
// === STRATEGY - SHORT POSITION EXECUTION ===
enterShort() =>
    strategy.opentrades == 0 and enter and (strategy == "Short Only" or (strategy == "Random" and not direction)) and 
       time > timestamp(start_year, 01, 01, 01, 01)
exitShort() =>
    exit
strategy.entry(id="Short", long=strategy.short, when=enterShort())
strategy.close(id="Short", when=exitShort())

더 많은