alimoee commited on
Commit
8023a80
·
verified ·
1 Parent(s): 990929c

کد رو به زبان پاین اسکریگ ورژن6 و برای استغاده در تریدینگ ویو برام بنویس

Browse files
Files changed (1) hide show
  1. ssl-hybrid-bot.pine +52 -71
ssl-hybrid-bot.pine CHANGED
@@ -1,84 +1,65 @@
1
  //@version=6
2
- strategy("SSL HYBRID Advanced + Trailing Stop", overlay=true, pyramiding=3, default_qty_type=strategy.percent_of_equity, default_qty_value=2, commission_type=strategy.commission.percent, commission_value=0.075)
3
 
4
- // INPUTS
5
- // ======
6
- // SSL Hybrid Settings
7
- sslLength = input(10, title="SSL Hybrid Length")
8
- sslSmoothing = input(3, title="SSL Smoothing Factor")
 
9
 
10
- // MTF HULL Trend Settings
11
- hullPeriod = input(20, title="Hull MA Period")
12
- hullSrc = input(close, title="Hull MA Source")
13
- hullTf = input("15", title="Hull MA Timeframe", input.resolution)
 
14
 
15
- // Baseline Settings
16
- baselineLength = input(50, title="Baseline Length")
17
- baselineSrc = input(hlc3, title="Baseline Source")
18
 
19
- // Risk Management
20
- useTrailingStop = input(true, title="Use Trailing Stop")
21
- trailOffset = input(15, title="Trailing Stop Offset (pips)")
22
- riskPercent = input(2.0, title="Risk % per Trade", minval=0.1, maxval=100)
23
- maxDrawdown = input(20.0, title="Max Drawdown %", minval=1, maxval=50)
24
-
25
- // News Filter
26
- filterNews = input(true, title="Filter High Impact News")
27
- newsBuffer = input(30, title="Minutes Before/After News")
28
 
29
- // INDICATORS
30
- // ==========
31
- // SSL Hybrid Advanced
32
- sslMAHigh = ta.sma(high, sslLength)
33
- sslMALow = ta.sma(low, sslLength)
34
- sslH = ta.ema(sslMAHigh, sslSmoothing)
35
- sslL = ta.ema(sslMAlow, sslSmoothing)
36
- sslDirection = sslH > sslL ? 1 : sslH < sslL ? -1 : 0
37
 
38
- // MTF HULL Trend
39
- hullMA(src, length) =>
40
- ta.wma(2 * ta.wma(src, length / 2) - ta.wma(src, length), math.round(math.sqrt(length)))
41
-
42
- hullMA1 = request.security(syminfo.tickerid, hullTf, hullMA(hullSrc, hullPeriod))
43
- hullDirection = hullMA1 > hullMA1[1] ? 1 : hullMA1 < hullMA1[1] ? -1 : 0
44
 
45
- // Baseline
46
- baseline = ta.sma(baselineSrc, baselineLength)
47
- baselineDirection = close > baseline ? 1 : close < baseline ? -1 : 0
 
48
 
49
- // EMA 200 Filter
50
- ema200 = ta.ema(close, 200)
51
- emaFilter = close > ema200
 
52
 
53
- // SIGNAL LOGIC
54
- // ============
55
- longCondition = sslDirection == 1 and hullDirection == 1 and baselineDirection == 1 and emaFilter
56
- shortCondition = sslDirection == -1 and hullDirection == -1 and baselineDirection == -1 and not emaFilter
 
 
 
 
 
57
 
58
- // RISK MANAGEMENT
59
- // ==============
60
- positionSize = strategy.equity * riskPercent / 100
61
- stopLossPips = trailOffset * syminfo.mintick
62
- takeProfitPips = stopLossPips * 2
63
 
64
- // STRATEGY
65
- // ========
66
- if (longCondition)
67
- strategy.entry("Long", strategy.long, qty=positionSize)
68
- strategy.exit("Exit Long", "Long",
69
- stop=close - stopLossPips,
70
- limit=close + takeProfitPips,
71
- trail_points=useTrailingStop ? stopLossPips : na,
72
- trail_offset=useTrailingStop ? stopLossPips/2 : na)
73
-
74
- if (shortCondition)
75
- strategy.entry("Short", strategy.short, qty=positionSize)
76
- strategy.exit("Exit Short", "Short",
77
- stop=close + stopLossPips,
78
- limit=close - takeProfitPips,
79
- trail_points=useTrailingStop ? stopLossPips : na,
80
- trail_offset=useTrailingStop ? stopLossPips/2 : na)
81
 
82
- // DRAWDOWN PROTECTION
83
- if (strategy.equity < strategy.initial_capital * (1 - maxDrawdown/100))
84
- strategy.close_all()
 
1
  //@version=6
2
+ strategy("SSL Hybrid Advanced + Trailing Stop", overlay=true, margin_long=100, margin_short=100)
3
 
4
+ // Inputs
5
+ inputPeriod = input.int(10, title="SSL Period", minval=1)
6
+ inputSmoothing = input.int(3, title="Smoothing Factor", minval=1)
7
+ inputTrailingStop = input.float(1.5, title="Trailing Stop (%)", minval=0.1, step=0.1)
8
+ inputRiskReward = input.float(2.0, title="Risk/Reward Ratio", minval=1.0, step=0.1)
9
+ inputUseNewsFilter = input.bool(true, title="Use News Event Filter")
10
 
11
+ // SSL Hybrid Calculation
12
+ hmaFast = ta.hma(close, inputPeriod)
13
+ hmaSlow = ta.hma(close, inputPeriod * 2)
14
+ sslUp = ta.sma(hmaFast > hmaSlow ? hmaFast : hmaSlow, inputSmoothing)
15
+ sslDown = ta.sma(hmaFast < hmaSlow ? hmaFast : hmaSlow, inputSmoothing)
16
 
17
+ // Hull Trend Confirmation
18
+ hullTrend = ta.hma(close, inputPeriod * 3)
19
+ trendDirection = hullTrend > hullTrend[1] ? 1 : hullTrend < hullTrend[1] ? -1 : 0
20
 
21
+ // Entry Conditions
22
+ longCondition = close > sslUp and trendDirection == 1
23
+ shortCondition = close < sslDown and trendDirection == -1
 
 
 
 
 
 
24
 
25
+ // Exit Conditions (Trailing Stop)
26
+ trailOffset = inputTrailingStop * 0.01 * close
27
+ longTrailPrice = 0.0
28
+ shortTrailPrice = 0.0
 
 
 
 
29
 
30
+ if longCondition
31
+ longTrailPrice := close - trailOffset
32
+ else
33
+ longTrailPrice := nz(longTrailPrice[1], close - trailOffset)
 
 
34
 
35
+ if shortCondition
36
+ shortTrailPrice := close + trailOffset
37
+ else
38
+ shortTrailPrice := nz(shortTrailPrice[1], close + trailOffset)
39
 
40
+ // Risk Management
41
+ positionSize = strategy.equity * 0.01 / (close * 0.01) // 1% risk per trade
42
+ takeProfitLong = close + (close - longTrailPrice) * inputRiskReward
43
+ takeProfitShort = close - (shortTrailPrice - close) * inputRiskReward
44
 
45
+ // Strategy Execution
46
+ if time > timestamp(2020, 1, 1, 0, 0) // Backtest period filter
47
+ if longCondition and (not inputUseNewsFilter or not na(security("ECONOMIC_CALENDAR", "D")))
48
+ strategy.entry("Long", strategy.long, qty=positionSize)
49
+ strategy.exit("Long Exit", "Long", stop=longTrailPrice, limit=takeProfitLong)
50
+
51
+ if shortCondition and (not inputUseNewsFilter or not na(security("ECONOMIC_CALENDAR", "D")))
52
+ strategy.entry("Short", strategy.short, qty=positionSize)
53
+ strategy.exit("Short Exit", "Short", stop=shortTrailPrice, limit=takeProfitShort)
54
 
55
+ // Plotting
56
+ plot(sslUp, color=color.new(color.green, 0), linewidth=2, title="SSL Up")
57
+ plot(sslDown, color=color.new(color.red, 0), linewidth=2, title="SSL Down")
58
+ plot(hullTrend, color=color.new(color.blue, 0), linewidth=2, title="Hull Trend")
 
59
 
60
+ // Background Color for Trend
61
+ bgcolor(trendDirection == 1 ? color.new(color.green, 90) : trendDirection == -1 ? color.new(color.red, 90) : na)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
+ // Alerts
64
+ alertcondition(longCondition, title="Long Signal", message="SSL Hybrid Long Signal")
65
+ alertcondition(shortCondition, title="Short Signal", message="SSL Hybrid Short Signal")