Color bars of chart based on ATRTrailingStop


Category:
0
0

Hi Pete! Thanks for the great forum!!!

Attached is a 5 day one tick RANGE chart of UB.

The style chart type is LINE. See attached Appearance settings for the LINE chart.   Up Tick Down Tick and Neutral tick are all set to white in this example.

There is one study on this chart: ATR Trailing Stop with buy set to red and sell set to green.  An image of the ATR Ts settings is attached.

I would like to configure the LINE of the LINE chart so that it is one color when close is greater than ATRTrailingStop.  And a different color when close is less than ATRTrailingStop.  Ideally, the color for greater than and the color for less than would be configurable using inputs.

Thanks for any help!

 

 

 

Attachments:
Marked as spam
Posted by (Questions: 7, Answers: 1)
Asked on November 20, 2022 5:53 pm
194 views
0
Private answer

This solution is nothing more than just a simple paintbar study. Which is why I have updated the title of your question to make it easier for folks to locate this using search.

For this solution, I use the AssignPriceColor() function to set the color of each bar on the chart based on its relative position to the ATRTrailingStop values. By using the AssignPriceColor() function to solve this, the solution works for every single "Chart Type" available on Thinkorswim. (Area chart type does work, but it doesn't look very appealing).

I have included a screenshot below which shows how this solution shows up on four different chart types available on Thinkorswim. Your line chart is shown in the bottom left.

The colors can be adjusted exactly the same way as the original ATRTrailingStop chart study.

input trailType = {default modified, unmodified};
input ATRPeriod = 5;
input ATRFactor = 3.5;
input firstTrade = {default long, short};
input averageType = AverageType.WILDERS;
plot trailStop = ATRTrailingStop(trailType, ATRPeriod, ATRFactor, firstTrade, averageType).TrailingStop;
trailStop.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
trailStop.DefineColor("Buy", Color.GREEN);
trailStop.DefineColor("Sell", Color.RED);
trailStop.AssignValueColor(if close < trailStop then trailStop.Color("Sell") else trailStop.Color("Buy"));
AssignPriceColor(if close < trailStop then trailStop.Color("Sell") else trailStop.Color("Buy"));

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on November 21, 2022 9:21 am
0
Private answer

...

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on November 21, 2022 9:22 am