ATRTrailingStop long short or within x percent for neutral


Category:
0
0

Hey Pete, I’m interested in a watchlist column that references the ATR Trailing Stop. What I want is different from what you addressed in this thread: https://www.hahn-tech.com/ans/trailing-stop-alert-column/.

Ideally, the column I want would have 3 states: Buy signal, sell signal, and a “within 3%” signal. I looked and found that there is an “ATR Trailing Stop” column that can be added (I’ll call it ATRTS). ATRTS just puts the price of the stop in the column. I’m interested in knowing when price action is approaching the ATR Stop from either direction. I think within 3% would be great. As far as I can work out, the logic would be something like this, I just don’t know how to code it:

The cell would display the ATRTS as a dollar value like it normally does, and then have the following backgrounds:

Green background if Mark>ATRTS

Red background if Mark<ARTS

Yellow background if Mark is 3% +/- of ATRTS

Thanks for any help,

Dave

Marked as spam
Posted by (Questions: 3, Answers: 1)
Asked on September 11, 2020 9:46 pm
111 views
0
Private answer

I updated the title of you question to include the full name of the chart study as it appears in Thinkorswim. I also included the details about the three different conditions you requested. This will make sure our viewers can quickly identify exactly what this post is all about and locate this through search when they have a similar question.

Thanks for referencing the previous post and providing a link to it. For this solution I copied the code from that post, added one new line and modified the last line.

input percentThreshold = 3.0;
input trailType = {default modified, unmodified};
input ATRPeriod = 5;
input ATRFactor = 3.5;
input firstTrade = {default long, short};
input averageType = AverageType.WILDERS;
def thisATR = ATRTrailingStop(trailType, ATRPeriod, ATRFactor, firstTrade, averageType).TrailingStop;
def withinPercentTreshold = close < thisATR * (1 + percentThreshold * 0.01) and close > thisATR * (1 - percentThreshold * 0.01);
AddLabel(yes, if withinPercentTreshold then "Neutral" else if close > thisATR then "Buy Signal" else "Sell Signal", if withinPercentTreshold then Color.YELLOW else if close > thisATR then Color.GREEN else Color.RED);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on September 12, 2020 8:52 am