OPEN-SOURCE SCRIPT

My script

59
//version=5
strategy("Backtest: Renko + Fractals Strategy | RVNUSDT", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)

// === Inputs ===
brick_size = input.float(0.0003, title="Simulated Renko Brick Size", step=0.0001)
sl_bricks = input.float(1.5, title="Stop Loss (bricks)")
tp_bricks = input.float(2.0, title="Take Profit (bricks)")
leftBars = input.int(2, title="Fractal Left Bars")
rightBars = input.int(2, title="Fractal Right Bars")

// === Simulated Renko Price ===
var float renko_price = na
var int renko_dir = 0
renko_price := na(renko_price[1]) ? close : renko_price

up_move = close - renko_price >= brick_size
down_move = renko_price - close >= brick_size

if up_move
renko_price += brick_size
renko_dir := 1
else if down_move
renko_price -= brick_size
renko_dir := -1

// === Williams Fractals ===
bullFractal = low[rightBars] < low[rightBars + 1] and low[rightBars] < low[rightBars - 1] and low[rightBars] < low[rightBars - 2]
bearFractal = high[rightBars] > high[rightBars + 1] and high[rightBars] > high[rightBars - 1] and high[rightBars] > high[rightBars - 2]

// === Entry Conditions ===
longCondition = renko_dir == 1 and renko_dir[1] != 1 and bullFractal
shortCondition = renko_dir == -1 and renko_dir[1] != -1 and bearFractal

// === Risk Management ===
long_sl = close - sl_bricks * brick_size
long_tp = close + tp_bricks * brick_size

short_sl = close + sl_bricks * brick_size
short_tp = close - tp_bricks * brick_size

// === Execute Trades ===
if (longCondition)
strategy.entry("Long", strategy.long)
strategy.exit("Long Exit", from_entry="Long", stop=long_sl, limit=long_tp)

if (shortCondition)
strategy.entry("Short", strategy.short)
strategy.exit("Short Exit", from_entry="Short", stop=short_sl, limit=short_tp)

// === Plotting for Visuals ===
plotshape(longCondition, location=location.belowbar, color=color.lime, style=shape.labelup, text="Long")
plotshape(shortCondition, location=location.abovebar, color=color.red, style=shape.labeldown, text="Short")

Feragatname

Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.