Trend Painter Indicator With Buy & Sell Signals for ThinkorSwim

@murkr I made it a lower study for you:

Code:
declare lower;

input ThermoLookBackBars = 50;
input PlotType = {default AdaptiveMovingAverages, Standard};

def HighLowScore = 1000 * ((high - high[1]) / (high[1]) +
(low - low[1]) / low[1]);

#ATR TrailingStop Code
input trailType = {default modified, unmodified};
input ATRPeriod = 5;
input ATRFactor = 3.5;
input firstTrade = {default long, short};

def HiLo = Min(high - low, 1.5 * Average(high - low, ATRPeriod));
def HRef = if low <= high[1]
    then high - close[1]
    else (high - close[1]) - 0.5 * (low - high[1]);
def LRef = if high >= low[1]
    then close[1] - low
    else (close[1] - low) - 0.5 * (low[1] - high);
def ATRMod = ExpAverage(Max(HiLo, Max(HRef, LRef)), 2 * ATRPeriod - 1);

def loss;
switch (trailType) {
case modified:
    loss = ATRFactor * ATRMod;
case unmodified:
    loss = ATRFactor * Average(TrueRange(high,  close,  low),  ATRPeriod);
}

rec state = {default init, long, short};
rec trail;
switch (state[1]) {
case init:
    if (!IsNaN(loss)) {
        switch (firstTrade) {
        case long:
            state = state.long;
            trail =  close - loss;
        case short:
            state = state.short;
            trail = close + loss;
    }
    } else {
        state = state.init;
        trail = Double.NaN;
    }
case long:
    if (close > trail[1]) {
        state = state.long;
        trail = Max(trail[1], close - loss);
    }
    else {
        state = state.short;
        trail = close + loss;
    }
case short:
    if (close < trail[1]) {
        state = state.short;
        trail = Min(trail[1], close + loss);
    }
    else {
        state = state.long;
        trail =  close - loss;
    }
}

def BuySignal = Crosses(state == state.long, 0, CrossingDirection.ABOVE);
def SellSignal = Crosses(state == state.short, 0, CrossingDirection.ABOVE);

plot TrailingStop = trail;
TrailingStop.Hide();
#End ATR Trailing Stop Code

def A = Highest(high[1], ThermoLookBackBars);
def B = Lowest(low[1], ThermoLookBackBars);

def FiftyTwoWeekHigh = A;

def FiftyTwoWeekLow = B;

def FiftyTwoWeekScore = 10 * (((high
- FiftyTwoWeekHigh) / FiftyTwoWeekHigh) +
((low - FiftyTwoWeekLow) / FiftyTwoWeekLow));

def ThermoScore = ExpAverage(HighLowScore + FiftyTwoWeekScore, ThermoLookBackBars);

input FastLengthShort = 5;
input SlowLengthShort = 15;
input EffRatioShort = 10;
input FastLengthLong = 10;
input SlowLengthLong = 25;
input EffRatioLong = 5;

def AMA = MovAvgAdaptive(ThermoScore, FastLengthShort, SlowLengthShort, EffRatioShort);
def AMA2 = MovAvgAdaptive(ThermoScore, FastLengthLong, SlowLengthLong, EffRatioLong);

plot Line1;
Line1.Hide();
plot Line2;
Line2.Hide();

switch (PlotType) {
case AdaptiveMovingAverages:
    Line1 = AMA;
    Line2 = AMA2;
case Standard:
    Line1 = ThermoScore;
    Line2 = ThermoScore;
}

def InvisibleLine = close * 0;
plot Line3 = InvisibleLine;
Line3.Hide();

def Buy = Line1 > 0 and Line2 < 0 and state == state.long;
def StrongBuy = Line1 > 0 and Line2 >= 0 and state == state.long;
def Sell = Line1 < 0 and Line2 > 0 and state == state.short;
def StrongSell = Line1 < 0 and Line2 <= 0 and state == state.short;

plot value = 0;
Value.AssignValueColor(if Buy then Color.DARK_GREEN else if StrongBuy then Color.GREEN else if Sell then Color.DARK_RED else if StrongSell then Color.RED else Color.BLUE);
 

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

@BenTen THANKS! This works great!
EDIT: It's a little hard to see the color transition because the line is so thin.

Is there a way you can change that line to bars? Similar to this Advanced Volume Indicator?

image.png


image.png
 
Last edited by a moderator:
@murkr Sure, find the last two lines in the modified script I posted and replace them with the following:

Code:
plot value = volume;
Value.AssignValueColor(if Buy then Color.DARK_GREEN else if StrongBuy then Color.GREEN else if Sell then Color.DARK_RED else if StrongSell then Color.RED else Color.BLUE);
Value.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
 
Hey, @BenTen I was wondering if it's possible to have a label or some type of other indication for a reversal trend instead of the arrows. With this indicator, I've had plenty of success over the last 5 weeks and I had to test different strategies to make it as profitable as possible; however, I place limit orders instead of market orders, so it would be really helpful to see where the trend reverses by seeing a specific dollar amount it has to hit for a reversal arrow to appear.

For instance, in the picture I provided the down trend reversal arrow appeared around $1.73 and the up trend reversal arrow appeared around $1.95. I wanted to know if there's anyway we can see that price before the arrow were to appear. That way I can place a limit order expecting a reversal. I would try myself, but I'm not the best coder.

jDY5s4b.jpg


Thanks
 
@Gabrielx77 The arrow will appear during the formation of the candle. If you really want to get technical, you would have to dig deep into the code and figure it out. But in short, it would be almost impossible to figure out at which price point you will see the reversal arrow.
 
@Gabrielx77 The arrow will appear during the formation of the candle. If you really want to get technical, you would have to dig deep into the code and figure it out. But in short, it would be almost impossible to figure out at which price point you will see the reversal arrow.
Yeah that's what I was thinking too. Thanks anyways. I usually buy at the break of the 5m high and go based off of the 1m candle. That's when I usually get an exact entry point for when the arrow reverses.
 
@jonmac303 I have no issue adding it.

UeIpCiK.png


Watch the second half of the video below if you don't know where to add the custom watchlist column.

 
@BenTen I'm new to TOS and to coding as well. I added this script and getting the following error message: "AddLabel is not allowed in this context"

Any help will be highly appreciated.
 
Hi @BenTen I am new here and hope you can help. If possible, would you please explain the error I am getting for this act?

Basically, I am trying to add Buy signals in a scan so I used the same script as one used for the watchlist (with exception that I removed the
"asignbackground color" and "addlabel' script and replaced the 'plot" with "def". add statement "plot scan = strongbuy;"

The issue is: when adding the condition into scan (GU and GX) I get an error stated "com.devexperts.tos.thinkscript.runtime.TooComplexException: The complexity of the expression suggests that it may not be reliable with real-time data."

Although I tried to follow the video provided on post #49 but still can't get that to work.

Thoughts/inputs?
 
@SAA448 Why aren't you using the code provided on the first page of this thread? I have no trouble using the scanner with it.

uYgqO3G.png


KmAoItr.png
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
277 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