이 전략의 주요 아이디어는 평행선 금포를 이용해 더 많이 하고, 평행선 사포를 이용해 공백을 하고, 포지션에 진입한 후, 추적 스톱을 설정한다. 가격이 지정된 스톱 라인을 도달하면, 추적 스톱을 트리거하고, 지속적으로 스톱 라인을 조정하여 수익을 극대화한다.
이 전략은 다음과 같은 부분으로 구성됩니다.
빠른 평균선과 느린 평균선을 계산한다. 여기서 빠른 평균선 주기는 20이고, 느린 평균선 주기는 50이다.
진입 조건을 판단한다. 빠른 평균선에서 느린 평균선을 통과할 때 더 많이 한다. 빠른 평균선 아래 느린 평균선을 통과할 때 공백을 한다.
트렌드 방향을 판단한다. 오버 및 오브로 바를 기록하고, 현재 다목적 트렌드 또는 공중적 트렌드인지 판단한다.
입시 가격. 거래 신호가 발신될 때 기록된 가격이 입시 가격이다.
줄을 설정하세요. 줄을 설정하세요.(1+ Stoppercentage) 스톱으로; 공백을 할 때, 낮은 지점에 있을 것입니다(1-정지율) 정지량으로.
추적 스톱. 스톱 라인은 지속적으로 조정되며, 유리 방향으로 이동할 때, 유리 방향으로 계속 이동하여 수익을 극대화한다.
정지선 트리거. 가격이 정지선에 닿을 때, 평행이 정지한다.
또 다른 선택적인 시작 기능이 있습니다. 즉, 시작 중지 경계를 설정하여, 가격이 이 경계를 처음으로 뚫었을 때만 추적 중지 시동을 걸립니다.
이 전략의 가장 큰 장점은 추적 스톱을 활용하여 수익을 극대화 할 수 있다는 것입니다. 시장이 유리하게 움직일 때 스톱 라인은 지속적으로 유리하게 움직여 수익을 보장합니다.
또한, 전략은 평평한 판단의 트렌드 필터를 추가하여, 비 트렌드 시장에서 불필요한 반복적인 포지션을 열기를 줄일 수 있습니다. 시작 기능을 추가하는 것은 가격의 작은 흔들림이 추적 정지를 유발하는 것을 방지 할 수 있습니다.
따라서 이 전략은 트렌드 판단, 입시 조건, 그리고 정지 전략의 여러 측면을 통합하여, 트렌드 상황에서 지속적으로 수익을 창출하고 수익을 극대화 할 수 있습니다.
이 전략의 주요 위험은, 충분한 시장 공간이 있어야 한다는 것입니다. 시장이 빨리 돌아간다면, 손실이 발생할 수 있습니다.
또한, 진동상태에서, 정지선이 자주 작동하는 경우에도 피해가 발생할 수 있다.
마지막으로, 만약 변수가 잘못 설정되면, 예를 들어 막대기 비율이 너무 커지면, 위험도 증가한다.
합리적인 스톱 비율을 설정하여 불안정한 상황에서 거래를 피하거나 스톱 손실을 설정하여 위험을 제어 할 수 있습니다.
이 전략은 다음과 같은 측면에서 최적화될 수 있습니다.
평균선 변수 최적화. 다른 평균선 주기 변수를 테스트하여 더 적합한 조합을 찾을 수 있다.
시동 기능 최적화. 다양한 시동 스톱 크기를 테스트하여 더 적합한 설정을 찾을 수 있습니다.
정지 비율 최적화. 피드백을 통해 더 적합한 정지 비율 매개 변수를 찾을 수 있다.
스톱을 추가한다. 합리적인 스톱 위치를 설정하고, 위험을 통제한다.
필터링 조건을 최적화한다. 거래량, ATR 중지 등과 같은 다른 필터링 조건을 추가하여 테스트할 수 있다.
표지물의 최적화. 주식, 외환, 암호화폐 등과 같은 다른 거래 표지물에 테스트 할 수 있습니다.
이 전략은 트렌드 판단, 진입 조건, 추적 스톱 등과 같은 여러 전략 모듈을 통합하여, 트렌드 상황에서 스톱을 지속적으로 추적하여 수익을 극대화 할 수 있습니다. 그러나 위험을 잘 관리하고, 흔들리는 상황에서 사용을 피하고, 매개 변수를 최적화하여 전략의 최대 효과를 발휘해야합니다. 이 전략은 우리에게 더 큰 수익을 얻기 위해 추적 스톱을 사용하는 아이디어를 제공합니다.
/*backtest
start: 2023-01-01 00:00:00
end: 2023-10-06 00:00:00
period: 2d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
//@author=Daveatt
SystemName = "BEST Trailing Profit Strategy"
// This string is to personalize the text that appears with your orders on the chart through strategy() calls and entry/exit markers, and in the alert default message.
// Although leaving it empty will not cause problems in study mode,
TradeId = "BEST"
// These values are used both in the strategy() header and in the script's relevant inputs as default values so they match.
// Unless these values match in the script's Inputs and the TV backtesting Properties, results between them cannot be compared.
InitCapital = 1000000
InitPosition = 100
InitCommission = 0.075
InitPyramidMax = 1
CalcOnorderFills = true
CalcOnTick = true
DefaultQtyType = strategy.fixed
DefaultQtyValue = strategy.fixed
Precision = 2
Overlay=true
// strategy(title=SystemName, shorttitle=SystemName, overlay=Overlay,
// pyramiding=InitPyramidMax, initial_capital=InitCapital, default_qty_type=DefaultQtyType, default_qty_value=InitPosition, commission_type=strategy.commission.percent,
// commission_value=InitCommission, calc_on_order_fills=CalcOnorderFills, calc_on_every_tick=CalcOnTick, precision=2)
// strategy(title=SystemName, shorttitle=SystemName, overlay=true,
// pyramiding=0, default_qty_value=100, precision=7, currency=currency.USD,
// commission_value=0.2,commission_type=strategy.commission.percent, initial_capital=10000)
//
// Author: Daveatt
// Revision: R0.1 Beta
// Date: 8-Dec-2019
//
// inputs
src = input(defval=close, type=input.source, title="Source")
slowLength = input(20, "Fast Length",minval=2,step=1)
fastLength = input(50, "Fast Length",minval=2,step=1)
// Calculate moving averages
fastSMA = sma(src, slowLength)
slowSMA = sma(src, fastLength)
// Calculate trading conditions
enterLong = crossover(fastSMA, slowSMA)
enterShort = crossunder(fastSMA, slowSMA)
// trend states
since_buy = barssince(enterLong)
since_sell = barssince(enterShort)
buy_trend = since_sell > since_buy
sell_trend = since_sell < since_buy
change_trend = (buy_trend and sell_trend[1]) or (sell_trend and buy_trend[1])
// get the entry price
entry_price = valuewhen(enterLong or enterShort, src, 0)
// Plot moving averages
plot(series=fastSMA, color=color.teal)
plot(series=slowSMA, color=color.orange)
// Plot the entries
plotshape(enterLong, style=shape.circle, location=location.belowbar, color=color.green, size=size.small)
plotshape(enterShort, style=shape.circle, location=location.abovebar, color=color.red, size=size.small)
///////////////////////////////
//======[ Take Profit ]======//
///////////////////////////////
// Use TP?
useTP = input(true, "Use take profit")
// TP trailing
ProfitTrailPerc = input(1.0, "Trailing Profit (%)",minval=0,step=0.5,type=input.float) * 0.01
use_TP_Trigger = input(true, "Use Take Profit Trigger")
// Will trigger the take profit trailing once reached
takeProfitTrigger = input(3.0, "Take Profit Trigger (%)",minval=0,step=0.5,type=input.float) * 0.01
// ttp := ttp>tp ? tp : ttp
takeprofitPriceTrigger = 0.0
takeprofitPriceTrigger := if (use_TP_Trigger)
if (buy_trend)
entry_price * (1 + takeProfitTrigger)
else
entry_price * (1 - takeProfitTrigger)
else
-1
//plot(entry_price, title='entry_price', transp=100)
var TP_Trigger_Long_HIT = false
TP_Trigger_Long_HIT := useTP and use_TP_Trigger and buy_trend and high >= takeprofitPriceTrigger
? true : TP_Trigger_Long_HIT[1]
var TP_Trigger_Short_HIT = false
TP_Trigger_Short_HIT := useTP and use_TP_Trigger and sell_trend and low <= takeprofitPriceTrigger
? true : TP_Trigger_Short_HIT[1]
display_long_TP_trigger = useTP and buy_trend and TP_Trigger_Long_HIT == false
and takeprofitPriceTrigger != -1
display_short_TP_trigger = useTP and sell_trend and TP_Trigger_Short_HIT == false
and takeprofitPriceTrigger != -1
display_TP_trigger = display_long_TP_trigger or display_short_TP_trigger
//🔷🔷🔷
// @hugo: Will display the TP trigger as long as not hit
// once the TP trigger is hit, the TP trailing will activate
plot(display_TP_trigger ? takeprofitPriceTrigger : na, title='takeprofitPriceTrigger', transp=0, color=color.orange,
style=plot.style_cross, linewidth=3)
longTrailTP= 0.0, shortTrailTP = 0.0
// Trailing Profit
// Start trailing once trigger is reached
longTrailTP := if useTP and buy_trend
tpValue = high * (1 + ProfitTrailPerc)
max(tpValue, longTrailTP[1])
else
0
shortTrailTP := if useTP and sell_trend
tpValue = low * (1 - ProfitTrailPerc)
min(tpValue, shortTrailTP[1])
else
999999
//plot(longTrailTP, title='debug longTrailTP', transp=100)
//plot(shortTrailTP, title='debug shortTrailTP', transp=100)
//////////////////////////////////////////////////////////////////////////////////////////
//*** TRAILING TAKE PROFIT HIT CONDITIONS TO BE USED IN ALERTS ***//
//////////////////////////////////////////////////////////////////////////////////////////
//🔷🔷🔷
// @hugo: I use crossover/crossunder for the alerts to trigger the events only once
cond_long_trail_tp_hit = useTP and buy_trend and crossover(high, longTrailTP[1])
and (TP_Trigger_Long_HIT or use_TP_Trigger == false)
cond_short_trail_tp_hit = useTP and sell_trend and crossunder(low, shortTrailTP[1])
and (TP_Trigger_Short_HIT or use_TP_Trigger == false)
// 🔷🔷🔷
// Plot take profits values for confirmation
// Display the trailing TP until not hit
plot(series= useTP and buy_trend and high <= longTrailTP and
(TP_Trigger_Long_HIT or use_TP_Trigger == false) ? longTrailTP : na,
color=color.aqua, style=plot.style_circles,
linewidth=2, title="Long Trail TP")
plot(series= useTP and sell_trend and low >= shortTrailTP and
(TP_Trigger_Short_HIT or use_TP_Trigger == false) ? shortTrailTP : na,
color=color.aqua, style=plot.style_circles,
linewidth=2, title="Short Trail TP")
close_long = cond_long_trail_tp_hit
close_short = cond_short_trail_tp_hit
// Submit entry orders
strategy.entry("EL", long=true, when=enterLong)
strategy.close("EL", when=close_long)
//if (enterShort)
strategy.entry("ES", long=false, when=enterShort)
strategy.close("ES", when=close_short)
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/////////////////////////////////// ALERTS ////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////
//* Put Entry Alerts below *//
//////////////////////////////
// IN STUDY MODE ONLY
// ⚠️⚠️⚠️ For alerts on the signal itself ⚠️⚠️⚠️
//alertcondition(buy_event, "Open Long", "LONG")
//alertcondition(sell_event, "Open Short", "SHORT")
// For the closes you will want to trigger these alerts on condition with alert
// option "Once Per Bar" for TP and SL
if change_trend
TP_Trigger_Long_HIT := false
TP_Trigger_Short_HIT := false