OPEN-SOURCE SCRIPT

Camarilla Trading Strategy

//version=5
strategy("Camarilla Trading Strategy", overlay=true)

// Input levels
S1 = input(100, title="S1")
S2 = input(98, title="S2")
S3 = input(96, title="S3")
S4 = input(94, title="S4")
R1 = input(104, title="R1")
R2 = input(106, title="R2")
R3 = input(108, title="R3")
R4 = input(110, title="R4")
open_price = input(97, title="Open Price")

// Current price
current_price = close

// Trading Logic
var string trade_signal = "No trade signal"
var float stoploss = na
var float target1 = na
var float target2 = na
var float target3 = na

if open_price > S3 and open_price < R3
if current_price < S3
trade_signal := "BUY if price moves above S3"
stoploss := (S3 + S4) / 2
target1 := R1
target2 := R2
target3 := R3
if current_price > R3
trade_signal := "SELL if price moves below R3"
stoploss := (R3 + R4) / 2
target1 := S1
target2 := S2
target3 := S3

if open_price >= R3 and open_price <= R4
if current_price > R4
trade_signal := "BUY"
stoploss := R3
target1 := R3 * 1.005
target2 := R3 * 1.01
target3 := R3 * 1.015
if current_price < R3
trade_signal := "SELL"
stoploss := (R3 + R4) / 2
target1 := S1
target2 := S2
target3 := S3

if open_price >= S4 and open_price <= S3
if current_price > S3
trade_signal := "BUY"
stoploss := (S3 + S4) / 2
target1 := R1
target2 := R2
target3 := R3
if current_price < S4
trade_signal := "SELL"
stoploss := (S3 + S4) / 2
target1 := S4 * 0.995
target2 := S4 * 0.99
target3 := S4 * 0.985

if open_price >= R4
if current_price < R3
trade_signal := "SELL"
stoploss := (R3 + R4) / 2
target1 := S1
target2 := S2
target3 := S3

if open_price <= S4
if current_price > S3
trade_signal := "BUY"
stoploss := (S3 + S4) / 2
target1 := R1
target2 := R2
target3 := R3

// Plot trade signals on chart
label = label.new(x=time, y=current_price, text=trade_signal, color=color.white, size=size.small)

// Execute trades
if trade_signal == "BUY"
strategy.entry("Long", strategy.long)
strategy.exit("Exit Long", from_entry="Long", stop=stoploss, limit=target3)

if trade_signal == "SELL"
strategy.entry("Short", strategy.short)
strategy.exit("Exit Short", from_entry="Short", stop=stoploss, limit=target3)

إخلاء المسؤولية