//@version=6
strategy("1 Hour Open vs Close Buy Strategy", overlay=true,
default_qty_type=strategy.percent_of_equity, default_qty_value=100)
// Define the buy condition: current open is higher than the previous close
buyCondition = open > close[1] and strategy.position_size == 0 // Only buy if there is no
active position
// Execute the buy order and plot buy price
if (buyCondition)
strategy.entry("Buy", strategy.long)
label.new(x=bar_index, y=low, text="Buy at: " + str.tostring(open),
style=label.style_label_up, color=color.green, size=size.normal, textcolor=color.white)
// Define the sell condition based on 3% profit target from the buy price
targetPrice = strategy.position_avg_price * 1.03
// Check if the current price has reached the target price and close the position
if (strategy.position_size > 0 and close >= targetPrice)
strategy.close("Buy")
label.new(x=bar_index, y=high, text="Sell at: " + str.tostring(close),
style=label.style_label_down, color=color.red, size=size.normal, textcolor=color.white)
// Plotting to visualize entries and exits on the chart
plotshape(series=buyCondition, location=location.belowbar, color=color.green,
style=shape.labelup, text="Buy")
plotshape(series=(strategy.position_size > 0 and close >= targetPrice),
location=location.abovebar, color=color.red, style=shape.labeldown, text="Sell")