
この戦略は,クラシック双均線トレンドトラッキングとATRダイナミック・ウィンドコントロールを組み合わせた自己適応的取引システムである.この戦略は,2つの取引モードを提供する.基本モードは,シンプルな双均線クロスを使用してトレンドトラッキングを行う.高度なモードは,より高い時間枠のトレンドフィルタリングとATRベースのダイナミック・ストップ・メカニズムを追加している.この戦略は,シンプルなドロップ・メニューで,2つのモードの間で切り替えることができる.
戦略1 ((基礎モード) は21日と49日の双均線システムを採用し,速い平均線がゆっくりとした平均線を上向きに横切るときに複数の信号を生成する.利潤目標はパーセントまたは点数方式を選択し,利潤をロックするための選択可能なモバイルストップ機能を提供する.戦略2 ((高度モード) は,双均線システムの基礎に日線レベルのトレンドフィルターを追加し,価格がより高い時間枠平均線の上にいる場合にのみ入場を許可する.同時に,14ATRサイクルに基づくダイナミックストップを導入し,市場波動に合わせてストップダスト距離を自動的に調整し,利潤の既得部分に利潤の終了保護機能を提供する.
これは,合理的に設計され,機能が充実した取引戦略システムである.双均線トレンド追跡とATR風力制御の組み合わせにより,戦略の信頼性が保証され,優れたリスク管理も提供されている.双モデル設計は,異なるレベルのトレーダーのニーズを満たし,豊富なパラメータ設定が十分な最適化スペースを提供している.トレーダーは,リールで保守的なパラメータから始め,最適化を段階的に調整して最適な効果を達成することを推奨している.
/*backtest
start: 2019-12-23 08:00:00
end: 2024-11-27 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © shaashish1
//@version=5
strategy("Dual Strategy Selector V2 - Cryptogyani", overlay=true, pyramiding=0,
default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=100000)
//#region STRATEGY SELECTION
strategyOptions = input.string(title="Select Strategy", defval="Strategy 1", options=["Strategy 1", "Strategy 2"], group="Strategy Selection")
//#endregion STRATEGY SELECTION
// ####################### STRATEGY 1: Original Logic ########################
//#region STRATEGY 1 INPUTS
s1_fastMALen = input.int(defval=21, title="Fast SMA Length (S1)", minval=1, group="Strategy 1 Settings", inline="S1 MA")
s1_slowMALen = input.int(defval=49, title="Slow SMA Length (S1)", minval=1, group="Strategy 1 Settings", inline="S1 MA")
s1_takeProfitMode = input.string(defval="Percentage", title="Take Profit Mode (S1)", options=["Percentage", "Pips"], group="Strategy 1 Settings")
s1_takeProfitPerc = input.float(defval=7.0, title="Take Profit % (S1)", minval=0.05, step=0.05, group="Strategy 1 Settings") / 100
s1_takeProfitPips = input.float(defval=50, title="Take Profit Pips (S1)", minval=1, step=1, group="Strategy 1 Settings")
s1_trailingTakeProfitEnabled = input.bool(defval=false, title="Enable Trailing (S1)", group="Strategy 1 Settings")
//#endregion STRATEGY 1 INPUTS
// ####################### STRATEGY 2: Enhanced with Recommendations ########################
//#region STRATEGY 2 INPUTS
s2_fastMALen = input.int(defval=20, title="Fast SMA Length (S2)", minval=1, group="Strategy 2 Settings", inline="S2 MA")
s2_slowMALen = input.int(defval=50, title="Slow SMA Length (S2)", minval=1, group="Strategy 2 Settings", inline="S2 MA")
s2_atrLength = input.int(defval=14, title="ATR Length (S2)", group="Strategy 2 Settings", inline="ATR")
s2_atrMultiplier = input.float(defval=1.5, title="ATR Multiplier for Stop-Loss (S2)", group="Strategy 2 Settings", inline="ATR")
s2_partialTakeProfitPerc = input.float(defval=50.0, title="Partial Take Profit % (S2)", minval=10, maxval=100, step=10, group="Strategy 2 Settings")
s2_timeframeTrend = input.timeframe(defval="1D", title="Higher Timeframe for Trend Filter (S2)", group="Strategy 2 Settings")
//#endregion STRATEGY 2 INPUTS
// ####################### GLOBAL VARIABLES ########################
var float takeProfitPrice = na
var float stopLossPrice = na
var float trailingStopPrice = na
var float fastMA = na
var float slowMA = na
var float higherTimeframeTrendMA = na
var bool validOpenLongPosition = false
// Precalculate higher timeframe values (global scope for Strategy 2)
higherTimeframeTrendMA := request.security(syminfo.tickerid, s2_timeframeTrend, ta.sma(close, s2_slowMALen))
// ####################### LOGIC ########################
if (strategyOptions == "Strategy 1")
// Strategy 1 Logic (Original Logic Preserved)
fastMA := ta.sma(close, s1_fastMALen)
slowMA := ta.sma(close, s1_slowMALen)
openLongPosition = ta.crossover(fastMA, slowMA)
validOpenLongPosition := openLongPosition and strategy.opentrades.size(strategy.opentrades - 1) == 0
// Take Profit Price
takeProfitPrice := if (s1_takeProfitMode == "Percentage")
close * (1 + s1_takeProfitPerc)
else
close + (s1_takeProfitPips * syminfo.mintick)
// Trailing Stop Price (if enabled)
if (strategy.position_size > 0 and s1_trailingTakeProfitEnabled)
trailingStopPrice := high - (s1_takeProfitPips * syminfo.mintick)
else
trailingStopPrice := na
else if (strategyOptions == "Strategy 2")
// Strategy 2 Logic with Recommendations
fastMA := ta.sma(close, s2_fastMALen)
slowMA := ta.sma(close, s2_slowMALen)
openLongPosition = ta.crossover(fastMA, slowMA) and close > higherTimeframeTrendMA
validOpenLongPosition := openLongPosition and strategy.opentrades.size(strategy.opentrades - 1) == 0
// ATR-Based Stop-Loss
atr = ta.atr(s2_atrLength)
stopLossPrice := close - (atr * s2_atrMultiplier)
// Partial Take Profit Logic
takeProfitPrice := close * (1 + (s2_partialTakeProfitPerc / 100))
//#endregion STRATEGY LOGIC
// ####################### PLOTTING ########################
plot(series=fastMA, title="Fast SMA", color=color.yellow, linewidth=1)
plot(series=slowMA, title="Slow SMA", color=color.orange, linewidth=1)
plot(series=takeProfitPrice, title="Take Profit Price", color=color.teal, linewidth=1, style=plot.style_linebr)
// Trailing Stop and ATR Stop-Loss Plots (Global Scope)
plot(series=(strategyOptions == "Strategy 1" and s1_trailingTakeProfitEnabled) ? trailingStopPrice : na, title="Trailing Stop", color=color.red, linewidth=1, style=plot.style_linebr)
plot(series=(strategyOptions == "Strategy 2") ? stopLossPrice : na, title="ATR Stop-Loss", color=color.red, linewidth=1, style=plot.style_linebr)
//#endregion PLOTTING
// ####################### POSITION ORDERS ########################
//#region POSITION ORDERS
if (validOpenLongPosition)
strategy.entry(id="Long Entry", direction=strategy.long)
if (strategyOptions == "Strategy 1")
if (strategy.position_size > 0)
if (s1_trailingTakeProfitEnabled)
strategy.exit(id="Trailing Take Profit", from_entry="Long Entry", stop=trailingStopPrice)
else
strategy.exit(id="Take Profit", from_entry="Long Entry", limit=takeProfitPrice)
else if (strategyOptions == "Strategy 2")
if (strategy.position_size > 0)
strategy.exit(id="Partial Take Profit", from_entry="Long Entry", qty_percent=s2_partialTakeProfitPerc, limit=takeProfitPrice)
strategy.exit(id="Stop Loss", from_entry="Long Entry", stop=stopLossPrice)
//#endregion POSITION ORDERS