この戦略の主な考えは,均線金叉を多行,均線死叉を空行とし,ポジションに入ると,追跡ストップを設定することである.価格が指定されたストップラインに達すると,追跡ストップを触発し,継続的にストップラインを調整して,利益を最大化することである.
この戦略は以下の部分に構成されています.
急速平均線と遅い平均線を計算する.ここでは急速平均線周期は20で,遅い平均線周期は50である.
入場条件を判断する。快平均線上での慢平均線穿越時に多めにすること;快平均線下での慢平均線穿越時に空置すること。
トレンドの方向を判断する.多頭と空頭のバー数を記録し,現在の多頭トレンドか空頭トレンドかを判断する.
入場価格。取引シグナルを発信した時の価格を入場価格として記録する。
停止線を設定します. 余分な作業で,高点になります.(1 + ストップパーセンテージ) ストップとして;空白時に,低点になります(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