How to add a horizontal line at stop price?

masonbarnard

New member
Hello,
I trade a strategy that involves shorting the Open, Covering at the previous day close with a stop loss that is 1/3rd the price target above open... I currently have a horizonal line for previous day close and current days open, but can't figure out how to add a line for the stop, which is a pretty simple formula based on those two lines...

stopline = Open price + (open-previousdayclose / 3)
- say a stock gaps up from $3(previous day close) to $6(open), the stop loss would be at $7.... 6+(6-3/31)

---- This is what i have for previous day close and open price, but dont know how to add the formula
input time = 930;
input price = open;

rec time_value = If(SecondsTillTime(time) == 0, price, time_value[1]);

plot open = If(time_value == 0, Double.NaN, time_value);


input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;
plot PrevDayClose;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
PrevDayClose = Double.NaN;
} else {
PrevDayClose = Highest(close(period = aggregationPeriod)[-displace], length);
}
PrevDayClose.SetDefaultColor(GetColor(9));
PrevDayClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
 
Solution
Maybe this?
Had to clean it up a bit.
I think it is doing what you want.

Code:
input sPeriod = {default DAY};
input time = 0930;

def PreviousDayOpen = open(period = sPeriod)[1];
def PreviousDayClose = close(period = sPeriod)[1];
def time_value = If SecondsTillTime(time) == 0 then open else time_value[1];

plot TimeValuePlot = Time_Value;
TimeValuePlot.SetDefaultColor(GetColor(4));
TimeValuePlot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot PrevDayClose = PreviousDayClose;
PrevDayClose.SetDefaultColor(GetColor(1));
PrevDayClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot stopline = Time_Value + ((Time_Value-PreviousDayClose) / 3);
stopline.SetDefaultColor(GetColor(2))...
Maybe this?
Had to clean it up a bit.
I think it is doing what you want.

Code:
input sPeriod = {default DAY};
input time = 0930;

def PreviousDayOpen = open(period = sPeriod)[1];
def PreviousDayClose = close(period = sPeriod)[1];
def time_value = If SecondsTillTime(time) == 0 then open else time_value[1];

plot TimeValuePlot = Time_Value;
TimeValuePlot.SetDefaultColor(GetColor(4));
TimeValuePlot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot PrevDayClose = PreviousDayClose;
PrevDayClose.SetDefaultColor(GetColor(1));
PrevDayClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot stopline = Time_Value + ((Time_Value-PreviousDayClose) / 3);
stopline.SetDefaultColor(GetColor(2));
stopline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
 
Solution
Maybe this?
Had to clean it up a bit.
I think it is doing what you want.

Code:
input sPeriod = {default DAY};
input time = 0930;

def PreviousDayOpen = open(period = sPeriod)[1];
def PreviousDayClose = close(period = sPeriod)[1];
def time_value = If SecondsTillTime(time) == 0 then open else time_value[1];

plot TimeValuePlot = Time_Value;
TimeValuePlot.SetDefaultColor(GetColor(4));
TimeValuePlot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot PrevDayClose = PreviousDayClose;
PrevDayClose.SetDefaultColor(GetColor(1));
PrevDayClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot stopline = Time_Value + ((Time_Value-PreviousDayClose) / 3);
stopline.SetDefaultColor(GetColor(2));
stopline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Wow, you are an angel.
Thank you
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
431 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top