0% found this document useful (1 vote)
1K views1 page

Indicator Code

This document outlines a trading strategy for buying and selling based on the opening and closing prices of a stock on an hourly basis. The strategy buys when the current open price is higher than the previous close and sells when a 3% profit target is reached. It includes visual indicators for buy and sell actions on the trading chart.

Uploaded by

rajesh.yadavgoa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
1K views1 page

Indicator Code

This document outlines a trading strategy for buying and selling based on the opening and closing prices of a stock on an hourly basis. The strategy buys when the current open price is higher than the previous close and sells when a 3% profit target is reached. It includes visual indicators for buy and sell actions on the trading chart.

Uploaded by

rajesh.yadavgoa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

//@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")

You might also like