
수면 범위 역전 전략은 가격 변동률이 낮아지는 기간을 포지션 구축 신호로 사용하고 가격 변동률이 다시 상승하면 손익 평준화 포지션을 취한다. 그것은 가격이 좁은 흔들림의 수면 범위 내에 제한되어있는 경우를 식별하여 임박한 가격 추세를 포착한다. 이 전략은 일반적으로 현재 변동률이 낮은 수준이지만 미래의 파동이 있을 때 적용된다.
이 전략은 먼저 잠복 범위를 식별합니다. 즉, 가격이 이전 거래일 가격 범위에 제한되어 있습니다. 이것은 현재 변동률이 며칠 전에 감소했다는 것을 나타냅니다. 우리는 현재 거래일 최고 가격을 n 일 전 (일반적으로 4 일) 의 최고 가격과 비교하여 현재 거래일 최저 가격을 n 일 전의 최저 가격과 비교하여 잠복 범위에 해당하는지 여부를 판단합니다.
일단 휴면 범위가 확인되면, 이 전략은 동시에 두 개의 상장 상장을 열습니다: 하나의 구매 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장 상장
포지션이 설정된 후, 전략은 중지 손실 명령과 중지 주문을 설정한다. 중지 손실 명령은 하향 위험을 제한하고, 중지 주문은 수익을 얻은 후 평정 위치에 사용된다. 중지 손실 명령은 출입 가격으로부터의 비율 거리입니다. 이 비율은 위험 관리 매개 변수에 의해 설정됩니다.
마지막으로, 이 전략에는 자금 관리 모듈도 포함되어 있습니다. 고정 배수법을 통해 주문 거래 자금량을 조정하여 수익을 올릴 때 자금 활용도를 높이고 손실을 줄일 때 위험을 줄입니다.
이 전략에는 다음과 같은 장점이 있습니다.
변동률이 낮아지는 시기를 포지션 신호로 사용하여 가격 추세가 발생하기 전에 기회를 잡을 수 있습니다.
동시에, 상향 또는 하향 트렌드를 포착할 수 있는 다중 공백 양방향 거래 명령을 설정한다.
한 거래의 위험을 효과적으로 통제할 수 있는 전략은 스톱로스 스톱이다.
고정배수자금관리법을 적용하면 자금 사용 효율을 높일 수 있다.
전략적 논리는 간단하고 명확하며 실행하기 쉽다.
이 전략에는 몇 가지 위험도 있습니다.
수면 범위 파열 방향 판단 오류 위험. 가격 상승과 하락의 돌파구가 보이지 않아 입구 방향 오류가 발생할 수 있다.
돌파가 발생하면 방향성으로 운행할 수 없는 위험. 돌파는 단기적인 역전 현상일 뿐이다.
정지값이 넘어갈 위험이 있다.
고정배수법 상장손실 확대의 위험. 고정배수값을 낮출 수 있어 위험을 줄일 수 있다.
잘못된 변수 설정으로 인해 전략이 제대로 작동하지 않을 수 있습니다.
이 전략은 다음과 같은 부분에서 최적화될 수 있습니다.
은 은 은 은 은
손해 중지 전략의 개선, 예를 들어 이동 손해 중지, 상장 손해 중지 등.
트렌드를 판단하는 지표를 늘리고, 역전입을 피한다.
고정배수값을 최적화하고, 이윤/손실 비율을 균형을 잡는다.
여러 시간 주기 분석과 결합하여 수익률을 높여줍니다.
기계 학습 방법을 사용하여 매개 변수를 자동으로 최적화하십시오.
휴면 범위 역전 전략은 전체적인 아이디어가 명확하고 수익 잠재력이 있다. 변수 최적화, 위험 관리, 신호 필터링 등의 수단으로 전략 안정성을 더욱 향상시킬 수 있다. 그러나 모든 추세 역전 전략에는 위험이 있으며 신중하게 사용해야하며 위치 규모를 적절하게 조정해야 한다. 이 전략은 역전 조작에 익숙하고 위험 의식있는 거래 사용자에 적합하다.
/*backtest
start: 2023-09-29 00:00:00
end: 2023-10-29 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/
// © gsanson66
//This code is based on the Narrow Range strategy
//Interactive Broker fees are applied on this strategy
//@version=5
strategy("NARROW RANGE BACKTESTING", shorttitle="NR BACKTESTING", overlay=true, initial_capital=1000, default_qty_type=strategy.fixed, commission_type=strategy.commission.percent, commission_value=0.18)
//--------------------------------FUNCTIONS------------------------------------//
//@function to print label
debugLabel(txt, color) =>
label.new(bar_index, high, text = txt, color=color, style = label.style_label_lower_right, textcolor = color.black, size = size.small)
//@function which looks if the close date of the current bar falls inside the date range
inBacktestPeriod(start, end) => (time >= start) and (time <= end)
//--------------------------------USER INPUTS------------------------------------//
//Narrow Range Length
nrLength = input.int(4, minval=2, title="Narrow Range Length", group="Strategy parameters")
//Risk Management
stopLossInput = input.float(0.5, title="Stop Loss (in percentage of reference range)", group="Strategy parameters")
//Money Management
fixedRatio = input.int(defval=400, minval=1, title="Fixed Ratio Value ($)", group="Money Management")
increasingOrderAmount = input.int(defval=200, minval=1, title="Increasing Order Amount ($)", group="Money Management")
//Backtesting period
startDate = input(title="Start Date", defval=timestamp("1 Janv 2020 00:00:00"), group="Backtesting Period")
endDate = input(title="End Date", defval=timestamp("1 July 2024 00:00:00"), group="Backtesting Period")
//--------------------------------VARIABLES INITIALISATION--------------------------//
strategy.initial_capital = 50000
bool nr = na
var bool long = na
var bool short = na
var float stopPriceLong = na
var float stopLossLong = na
var float takeProfitLong = na
var float stopPriceShort = na
var float stopLossShort = na
var float takeProfitShort = na
var float takeProfit = na
var float stopLoss = na
bool inRange = na
int closedtrades = strategy.closedtrades
equity = math.abs(strategy.equity - strategy.openprofit)
var float capital_ref = strategy.initial_capital
var float cashOrder = strategy.initial_capital * 0.95
//------------------------------CHECKING SOME CONDITIONS ON EACH SCRIPT EXECUTION-------------------------------//
//Checking if the date belong to the range
inRange := true
//Checking performances of the strategy
if equity > capital_ref + fixedRatio
spread = (equity - capital_ref)/fixedRatio
nb_level = int(spread)
increasingOrder = nb_level * increasingOrderAmount
cashOrder := cashOrder + increasingOrder
capital_ref := capital_ref + nb_level*fixedRatio
if equity < capital_ref - fixedRatio
spread = (capital_ref - equity)/fixedRatio
nb_level = int(spread)
decreasingOrder = nb_level * increasingOrderAmount
cashOrder := cashOrder - decreasingOrder
capital_ref := capital_ref - nb_level*fixedRatio
//We check if a trade has been closed to cancel all previous orders
if closedtrades > closedtrades[1]
strategy.cancel("Long")
strategy.cancel("Short")
stopPriceLong := na
stopPriceShort := na
//Checking if we close all trades in case where we exit the backtesting period
if strategy.position_size!=0 and not inRange
debugLabel("END OF BACKTESTING PERIOD : we close the trade", color=color.rgb(116, 116, 116))
strategy.close_all()
long := na
short := na
stopPriceLong := na
stopLossLong := na
takeProfitLong := na
stopPriceShort := na
stopLossShort := na
takeProfitShort := na
takeProfit := na
stopLoss := na
//----------------------------------FINDING NARROW RANGE DAY------------------------------------------//
// We find the Narrow Range Day
if low > low[nrLength] and high < high[nrLength]
nr := true
//------------------------------------STOP ORDERS--------------------------------------------//
// We handle plotting of stop orders and cancellation of other side order if one order is triggered
if strategy.position_size > 0 and not na(stopPriceLong) and not na(stopPriceShort)
long := true
strategy.cancel("Short")
stopPriceLong := na
stopPriceShort := na
takeProfit := takeProfitLong
stopLoss := stopLossLong
if strategy.position_size < 0 and not na(stopPriceLong) and not na(stopPriceShort)
short := true
strategy.cancel("Long")
stopPriceLong := na
stopPriceShort := na
takeProfit := takeProfitShort
stopLoss := stopLossShort
//------------------------------------STOP LOSS & TAKE PROFIT--------------------------------//
// If an order is triggered we plot TP and SL
if not na(takeProfit) and not na(stopLoss) and long
if high >= takeProfit and closedtrades == closedtrades[1] + 1
takeProfit := na
stopLoss := na
long := na
if low <= stopLoss and closedtrades == closedtrades[1] + 1
takeProfit := na
stopLoss := na
long := na
if not na(takeProfit) and not na(stopLoss) and short
if high >= stopLoss and closedtrades == closedtrades[1] + 1
takeProfit := na
stopLoss := na
short := na
if low <= takeProfit and closedtrades == closedtrades[1] + 1
takeProfit := na
stopLoss := na
short := na
//-----------------------------LONG/SHORT CONDITION-------------------------//
// Conditions to create two stop orders (one for Long and one for Short) and SL & TP calculation
if nr and inRange and strategy.position_size == 0
stopPriceLong := high[4]
takeProfitLong := high[4] + (high[4] - low[4])
stopLossLong := high[4] - (high[4] - low[4])*stopLossInput
qtyLong = cashOrder/stopPriceLong
strategy.entry("Long", strategy.long, qtyLong, stop=stopPriceLong)
strategy.exit("Exit Long", "Long", limit=takeProfitLong ,stop=stopLossLong)
stopPriceShort := low[4]
takeProfitShort := low[4] - (high[4] - low[4])
stopLossShort := low[4] + (high[4] - low[4])*stopLossInput
qtyShort = cashOrder/stopPriceShort
strategy.entry("Short", strategy.short, qtyShort, stop=stopPriceShort)
strategy.exit("Exit Short", "Short", limit=takeProfitShort ,stop=stopLossShort)
//--------------------------PLOTTING ELEMENT----------------------------//
plotshape(nr, "NR", shape.arrowdown, location.abovebar, color.rgb(255, 132, 0), text= "NR4", size=size.huge)
plot(stopPriceLong, "Stop Order", color.blue, 3, plot.style_linebr)
plot(stopPriceShort, "Stop Order", color.blue, 3, plot.style_linebr)
plot(takeProfit, "Take Profit", color.green, 3, plot.style_linebr)
plot(stopLoss, "Stop Loss", color.red, 3, plot.style_linebr)