OPEN-SOURCE SCRIPT

TFEX Futures Strategy with Volume Profile

//version=5
strategy("TFEX Futures Strategy with Volume Profile", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)

// กำหนดพารามิเตอร์
fastLength = input.int(9, title="Fast MA Length")
slowLength = input.int(21, title="Slow MA Length")
rsiLength = input.int(14, title="RSI Length")
overbought = input.float(70, title="Overbought Level")
oversold = input.float(30, title="Oversold Level")
vpLength = input.int(20, title="Volume Profile Length") // ความยาวของ Volume Profile

// คำนวณ Moving Averages
fastMA = ta.sma(close, fastLength)
slowMA = ta.sma(close, slowLength)

// คำนวณ RSI
rsi = ta.rsi(close, rsiLength)

// สัญญาณ Moving Average Crossover
maCrossover = ta.crossover(fastMA, slowMA) // Fast MA ข้าม Slow MA ขึ้น (สัญญาณ Buy)
maCrossunder = ta.crossunder(fastMA, slowMA) // Fast MA ข้าม Slow MA ลง (สัญญาณ Sell)

// สัญญาณ RSI
rsiBuySignal = rsi < oversold // RSI ต่ำกว่า Oversold (สัญญาณ Buy)
rsiSellSignal = rsi > overbought // RSI สูงกว่า Overbought (สัญญาณ Sell)

// Volume Profile
var float vpHigh = na
var float vpLow = na
if bar_index == last_bar_index - vpLength
vpHigh = ta.highest(high, vpLength)
vpLow = ta.lowest(low, vpLength)

// แสดง Volume Profile Zone
bgcolor(bar_index >= last_bar_index - vpLength ? color.new(color.blue, 90) : na, title="Volume Profile Zone")

// เงื่อนไขการเทรดด้วย Volume Profile
volumeProfileFilter = close > vpLow and close < vpHigh // ราคาปิดอยู่ในโซน Volume Profile

// เงื่อนไขการเทรด
if (maCrossover and rsiBuySignal and volumeProfileFilter)
strategy.entry("Buy", strategy.long)
label.new(bar_index, low, text="Buy", style=label.style_label_up, color=color.green, textcolor=color.white, size=size.small)

if (maCrossunder and rsiSellSignal and volumeProfileFilter)
strategy.entry("Sell", strategy.short)
label.new(bar_index, high, text="Sell", style=label.style_label_down, color=color.red, textcolor=color.white, size=size.small)

// แสดง Moving Averages บนกราฟ
plot(fastMA, title="Fast MA", color=color.blue, linewidth=2)
plot(slowMA, title="Slow MA", color=color.red, linewidth=2)

// แสดง RSI บนกราฟ
hline(overbought, "Overbought", color=color.red)
hline(oversold, "Oversold", color=color.green)
plot(rsi, title="RSI", color=color.purple, linewidth=2)

Aviso legal