이 전략의 주요 아이디어는 실시간 시뮬레이션 거래, 매주 거래 데이터를 수집하고, 전략의 성과를 보다 직관적으로 볼 수 있도록 표의 형태로 통계 결과를 표시하는 것입니다. 그것은 전략의 수익률을 신속하게 평가하고, 전략의 부실한 성과를 파악하고, 그에 따라 전략을 조정하고 최적화하는 데 도움이됩니다.
계산주기의 시작과 끝을 설정합니다.
세트 통계 결과의 정확도와 각 그룹에 포함되는 주 수.
RSI 전략을 모방하여 구매와 판매를 수행합니다.
통계표의 변수를 정의한다.
현재 주기의 결과를 계산한다.
만약 주기가 바뀌고 거래가 가능하다면, 이 주기의 시간과 결과를 기록하라.
만약 마지막 K선이고 거래가 허용된다면, 현재 주기의 시간과 결과를 기록한다.
만약 주기 변화가 있고 거래가 허용되지 않는다면, 지난 주기의 시간과 결과를 기록하라.
가장 높고 가장 낮은 순환값을 찾습니다.
렌딩 통계표
먼저, 통계주기의 총 수를 계산해 봅시다.
모든 주기를 거쳐, 시점과 결과를 니다.
각각의 그룹 사이클 결과에 대해 축적
색으로 표시합니다.
실시간으로 주간 거래 결과를 볼 수 있고, 전략의 성과를 빠르게 평가할 수 있습니다.
직관적인 결과물, 즉, 전략이 실패한 시기를 알아내는 것
이 기간 동안의 수익과 손실에 따라 조정 및 최적화 할 수 있는 전략 매개 변수
수 주간의 누적 수익을 쉽게 추적할 수 있는 장기 지분 전략
서로 다른 기간의 거래 스타일을 비교 분석할 수 있습니다.
사용자 정의 통계 정확도 및 그룹 수주 수요
코드가 단순하고 명확하고, 이해하기 쉽고, 재개발이 가능합니다.
이 전략은 RSI를 기반으로 시뮬레이션 거래를 수행합니다. RSI 전략 자체는 트렌드를 따라갈 수 없을 정도로 약점이 있습니다.
실제 거래에서는 거래비용이 결과에 더 큰 영향을 미칩니다.
재검토에 사용된 역사적 데이터는 실제 거래 환경을 반영할 수 없습니다.
통계 결과는 실제 계좌 자금 수에 의존하며, 재검토에서 기본 자금 수는 정확하지 않을 수 있습니다.
과잉 맞춤을 방지하기 위한 주의가 필요하며, 피드백 결과에 따라 정책 파라미터를 맹목적으로 수정합니다.
더 많은 지표와 결합하여 트렌드를 판단하고, 입출소를 최적화하여 RSI 전략을 강화할 수 있다. 실물 거래할 때 실제 변수에 따라 수수료를 설정하는 것을 주의한다. 재검토 단계에서 자본 금액의 변동을 확대하여 실제 상황에 더 가깝게 만든다.
단편적 손실을 제어하기 위해 Stop Loss Logic을 추가하는 것을 고려할 수 있습니다
RSI를 조정하는 것과 같은 전략 변수를 최적화 할 수 있습니다.
일일 거래 또는 월간 거래와 같은 다른 거래 주파수를 시도할 수 있습니다.
더 많은 지표가 시장의 추세와 진입 시기를 판단할 수 있습니다.
이 경우,
통계 매개 변수를 최적화할 수 있는 설정
다양한 자산에 대한 통계를 고려할 수 있습니다.
스톱로스 스톱을 추가함으로써 위험과 수익률을 더 잘 제어할 수 있다. RSI 파라미터를 최적화하면 승률을 높일 수 있다. 더 많은 지표와 다른 거래 주파수를 채택하면 전략을 더 안정화할 수 있다. 통계적 파라미터를 조정하면 결과를 더 강조할 수 있다. 단일 자산에서 여러 자산 통계로 확장하면 전략의 효과를 전체적으로 판단할 수 있다.
이 전략의 목적은 주기적 거래 결과를 수집하여 통계 표의 형태로 직관적으로 표시하여 다양한 기간 동안의 전략의 수익률을 신속하게 판단할 수 있습니다. 이것은 전략 최적화에 데이터 지원을 제공합니다. 장점은 주간 결과를 실시간으로 볼 수 있다는 것입니다. 직관적으로 명확하고 두 번 개발하기 쉽습니다. 주의해야 할 점은 통계 결과가 과도한 의존과 재검토 데이터의 조화를 초래할 수 있다는 것입니다.
/*backtest
start: 2023-09-12 00:00:00
end: 2023-10-12 00:00:00
period: 3h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
// strategy('Strategy weekly results as numbers v1', overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=25, commission_type=strategy.commission.percent, commission_value=0.04)
after = input(title='Trade after', defval=timestamp('01 Jan 2019 00:00 UTC'), tooltip="Strategy will be executed after this timestamp. The statistic table will include only periods after this date.")
before = input(title='Trade before', defval=timestamp('31 Dec 2024 23:59 UTC'), tooltip="Strategy will be executes before this timestamp. The statistic table will include only periods before this date.")
statisticPrecision = input.int(title='Statistic precision', group='Statistic visualisation', defval=1, tooltip="Defines how many digits should be rendered in every statistic cell.")
statisticGroupSize = input.int(title='Statistic group size', group='Statistic visualisation', defval=12, tooltip="Defines how many cells should be in one group inside the statistic table.")
// determinet whether the starategy should be traded between the period
isTradeEnabled = true
// *******************************************************************************************
// Core strategy simulation logic
// *******************************************************************************************
// calculate rsi strategy emulation data
rsiEmulationData = ta.rsi(close, 7)
rsiEmulationCrossover = ta.crossover(rsiEmulationData, 70)
rsiEmulationCrossunder = ta.crossunder(rsiEmulationData, 30)
// entry loogic based on the rsi calculations
if (isTradeEnabled and rsiEmulationCrossover)
strategy.entry('Long', strategy.long)
if (isTradeEnabled and rsiEmulationCrossunder)
strategy.entry('Short', strategy.short)
// *******************************************************************************************
// Weekly statistics table
// *******************************************************************************************
// define statistic variables
var statisticTable = table(na)
var statisticPeriodTime = array.new_int(0)
var statisticPeriodResult = array.new_float(0)
var statisticIsLatestCalculated = bool(na)
var statisticResultHighest = float(na)
var statisticResultLowest = float(na)
var statisticColorGray = color.new(color.gray, transp = 60)
var statisticColorGreen = color.new(color.green, transp = 60)
var statisticColorRed = color.new(color.red, transp = 60)
// claculate current period result
barResult = not na(strategy.equity[1])
? (strategy.equity / strategy.equity[1] - 1) : 0
isPeriodChanged = not na(time[1]) and weekofyear(time) != weekofyear(time[1])
currentPeriodResult = 0.0
currentPeriodResult := not na(currentPeriodResult[1]) and not isPeriodChanged
? ((1 + currentPeriodResult[1]) * (1 + barResult) - 1) : 0.0
// initialise highest and lowest results variables
statisticResultHighest := na(statisticResultHighest) ? currentPeriodResult : statisticResultHighest
statisticResultLowest := na(statisticResultLowest) ? currentPeriodResult : statisticResultLowest
// search for highest and lowest results
statisticResultHighest := currentPeriodResult > statisticResultHighest ? currentPeriodResult : statisticResultHighest
statisticResultLowest := currentPeriodResult < statisticResultLowest ? currentPeriodResult : statisticResultLowest
// new week while trade is active
if isPeriodChanged and isTradeEnabled
timeCalculated = time - 1000 * 60 * 60 * 24 * 7
resultCalculated = currentPeriodResult[1]
statisticIsLatestCalculated := false
array.push(statisticPeriodTime, timeCalculated)
array.push(statisticPeriodResult, resultCalculated)
// latest bar while trade is active
if barstate.islast and isTradeEnabled
timeCalculated = time - 1000 * 60 * 60 * 24 * (dayofweek(time) - 2)
resultCalculated = currentPeriodResult
array.push(statisticPeriodTime, timeCalculated)
array.push(statisticPeriodResult, resultCalculated)
// new week after trade disabled
if isPeriodChanged and not isTradeEnabled and not na(statisticIsLatestCalculated) and not statisticIsLatestCalculated
timeCalculated = time - 1000 * 60 * 60 * 24 * (dayofweek(time) + 5)
resultCalculated = currentPeriodResult[1]
statisticIsLatestCalculated := true
array.push(statisticPeriodTime, timeCalculated)
array.push(statisticPeriodResult, resultCalculated)
// render statistics table
if barstate.islast
statisticLength = array.size(statisticPeriodResult)
statisticTableSteps = math.floor(statisticLength / statisticGroupSize) + (statisticLength % statisticGroupSize != 0 ? 1 : 0)
statisticTable := table.new(position.bottom_right, columns = statisticGroupSize + 2, rows = statisticTableSteps + 1, border_width = 1)
// render headers
for i = 0 to (statisticGroupSize - 1)
statisticHeaderContent = str.tostring(i + 1)
table.cell(statisticTable, 1 + i, 0, statisticHeaderContent, bgcolor = statisticColorGray)
// render time points
for i = 0 to (statisticTableSteps - 1)
statisticPointContent = str.format("{0,date,medium}", array.get(statisticPeriodTime, i * statisticGroupSize))
table.cell(statisticTable, 0, 1 + i, statisticPointContent, bgcolor = statisticColorGray)
// render the result
statisticResultCummulative = 0.0
for i = 0 to (array.size(statisticPeriodTime) - 1)
statisticColumn = 1 + i % statisticGroupSize
statisticRow = 1 + math.floor(i / statisticGroupSize)
statisticResult = array.get(statisticPeriodResult, i)
statisticResultCummulative := (i % statisticGroupSize == 0) ? 0.0 : statisticResultCummulative
statisticResultCummulative := (1 + statisticResultCummulative) * (1 + statisticResult) - 1
statisticResultColor = statisticResult > 0 ? statisticColorGreen : statisticColorRed
table.cell(statisticTable, statisticColumn, statisticRow, str.tostring(math.round(statisticResult * 100, statisticPrecision)), bgcolor = statisticResultColor)
// if it is the last item of the row or data array
isStatisticLastOfTheRow = ((i + 1) % statisticGroupSize) == 0
isStatisticLastOfTheData = i == (statisticLength - 1)
if (isStatisticLastOfTheRow or isStatisticLastOfTheData)
resultsTableCummulativeCellColor = statisticResultCummulative > 0 ? statisticColorGreen : statisticColorRed
resultsTableCummulativeCellContent = str.tostring(math.round(statisticResultCummulative * 100, statisticPrecision))
table.cell(statisticTable, 1 + statisticGroupSize, statisticRow, resultsTableCummulativeCellContent, bgcolor = resultsTableCummulativeCellColor)