OPEN-SOURCE SCRIPT

Daily Trend with ATR Strategy

//version=5
strategy("Daily Trend with ATR Strategy", overlay=true)

// تنظیمات
atrLength = input.int(22, title="ATR Length (Daily)")
atrMultiplier = input.float(3.0, title="ATR Multiplier")
atrH1Length = input.int(24, title="ATR Length (Hourly)")
tolerance = input.float(0.05, title="Tolerance")

// محاسبه ATR روزانه
dailyATR = request.security(syminfo.tickerid, "D", ta.atr(atrLength))

// محاسبه معیار حرکت
moveCriterion = (dailyATR * atrMultiplier) * 0.66

// تعیین روند دیلی
dailyTrendUp = request.security(syminfo.tickerid, "D", close[0] - close[2] >= moveCriterion and ta.change(close[1]) == ta.change(close[2]) and ta.change(close[1]) == ta.change(close[0]))
dailyTrendDown = request.security(syminfo.tickerid, "D", close[0] - close[2] <= -moveCriterion and ta.change(close[1]) == ta.change(close[2]) and ta.change(close[1]) == ta.change(close[0]))

// تعیین ناحیه حمایت و مقاومت
resistanceZone = moveCriterion * 0.5
supportZone = moveCriterion * 0.66

// محاسبه ATR ساعتی
hourlyATR = ta.atr(atrH1Length)

// تعیین برخوردها
cond1 = ta.crossover(close, resistanceZone)
cond2 = ta.crossover(close, supportZone)
cond3 = ta.crossunder(close, supportZone)
cond4 = ta.crossunder(close, resistanceZone)

// شناسایی برخوردها با ناحیه
zoneTouches = (cond1 or cond2 or cond3 or cond4)

// بررسی نسبت ATR برخوردها
validTouch = close - open > hourlyATR * (1 + tolerance) or close - open < -hourlyATR * (1 - tolerance)

// شرایط ورود به معامله
longCondition = dailyTrendUp and zoneTouches and validTouch
shortCondition = dailyTrendDown and zoneTouches and validTouch

// ورود به معامله
if (longCondition)
strategy.entry("Buy", strategy.long)
if (shortCondition)
strategy.entry("Sell", strategy.short)

// تنظیم استاپ لاس و تیک پرافیت
stopLoss = hourlyATR
takeProfit = stopLoss * 2

strategy.exit("Exit Buy", from_entry="Buy", loss=stopLoss, profit=takeProfit)
strategy.exit("Exit Sell", from_entry="Sell", loss=stopLoss, profit=takeProfit)
Candlestick analysisChart patternsCycles

Script de código aberto

No verdadeiro espírito do TradingView, o autor desse script o publicou como código aberto, para que os traders possam compreendê-lo e analisá-lo. Parabéns ao autor! Você pode usá-lo gratuitamente, mas a reutilização desse código em publicações é regida pelas Regras da Casa. Você pode favoritá-lo para usá-lo em um gráfico.

Quer usar esse script no gráfico?

Aviso legal