Trend Painter Indicator With Buy & Sell Signals for ThinkorSwim

BenTen

BenTen

Administrative
Staff
VIP
@blake007 Click on the little gear icon under your watchlist > Customize > Custom Quotes
 
D

Diamondlil

New member
VIP
@K_O_Trader I'd like to set up a scanner based on your Trend Painter of June 11th. I'd like it to scan for a buy signal on a smaller time frame (eg. 1 hr. or 30 min.) while the daily chart is in an Uptrend or Strong Uptrend. How would you suggest I do that?
Thanks in advance.
 
K

K_O_Trader

Member
@K_O_Trader I'd like to set up a scanner based on your Trend Painter of June 11th. I'd like it to scan for a buy signal on a smaller time frame (eg. 1 hr. or 30 min.) while the daily chart is in an Uptrend or Strong Uptrend. How would you suggest I do that?
Thanks in advance.
Use a ATR Trailing stop loss indicator with the trend painter, also you can copy and past the trend painter to make a column and it will tell you the trend that that stock is in, just make sure you change the time frame at the top to what ever you prefer
 
S

shakenbake

New member
Just found this tonight and works nicely with on-demand for some randomly picked ETFs i found. Has anyone tested this on paper trading or actually traded with it and just bought on the buy signals and sold on the sell signals. I'd imagine this method works well with some stocks but not with others. Does anyone have realtime experience with it? btw i'm not using in the scanner, i just popped it in the chart studies so it's enabled for whatever chart i have active. I didn't bother with the scanner.
 
D

Diamondlil

New member
VIP
Use a ATR Trailing stop loss indicator with the trend painter, also you can copy and past the trend painter to make a column and it will tell you the trend that that stock is in, just make sure you change the time frame at the top to what ever you prefer
ok, thanks, will try that.
 
BonBon

BonBon

New member
Greetings everyone. For those of you who found the trendpainter useful please see below the addition to the thinkscript. I used the original trendpainter thinkscript to creates a watchlist column for the "current trend" and the buy and sell signals (arrow up and arrow down within the chart) (see chart below). I hope you find this useful as well.

Thumbs Up/Down Watchlist column (based on the trendpainter thinkscript originally coded by @BenTen.) The thumbs up is based on the buysignal section of the thinkscript.

The thumbs up is aligned to the thumps up or thumps down within the chart.) The time frame is the same as the chart 1m but you can change the time frame. Remember if you change the time frame for the trendpainter chart you have to change it for the watchlist as well. I also created a scan for the trendpainter where you can scan for stocks that are only strongbuy, etc. I also use this with the RVI as well. In this way it would only show RVI stocks that are strongbuy.

The below code was added to the original trendpainter code to create the custom Thumbs up/down watchlist.

Code:
def arrowup = buysignal;
def arrowdown = sellsignal;

def trigger = if arrowup then 100 else if arrowdown then -100 else trigger [1];

AddLabel(yes,(if trigger == 100 then "👍" else if trigger == -100 then "👎" else "NA"));

AssignbackgroundColor(if trigger == 100 then Color.dark_Green else if arrowdown == -100 then Color.dark_Red else Color.black);

TrendPainter Watchlist Column

I used the original trendpainter script and added the following script to create the custom watchlist.

Code:
def uptrend = buy;
def Stronguptrend = strongbuy;
def downtrend = sell;
def Strongdowntrend = strongsell;

AssignbackgroundColor (if uptrend then Color.Dark_GREEN else if Stronguptrend then Color.Green else if downtrend then color.dark_RED  else if Strongdowntrend then Color.RED else Color.Black);

AddLabel(yes,if uptrend then "UP" else if Stronguptrend then "Buy" else if downtrend then "Down" else if Strongdowntrend then "Bear" else "Neutral", if stronguptrend then color.black else if strongdowntrend then color.black else color.white );

This is an example using today's aftermarket gapper scan. The watchlist column shows the trendpainter column and the arrowstay column. As you can see they mirror the chart. Before I would review each chart to determine trends. Now that I created the column for the watchlist that is not necessary. I can filter using these columns as well to find all the stocks that are currently in a strong up trend( Up is "uptrend", buy is "strong uptrend," down is "down trend", bear is "strong downtrend."

There are instances where a ticker can be in or coming out of a downtrend and give a buy signal due to the volume etc.

 
Last edited by a moderator:
S

shakenbake

New member
@BonBon This is really cool. Has anyone here tested this and made any sort of profit from it? What's the reliability of the buy and sell signals?
 
K

k8be

New member
@BonBon n are you saying you added your two codes for thumbs and signals to the end of BenTen's trend code as a study, then you also created a custom column with the custom watchlist column creator by selecting that study, and then added that as a column to the watchlist?

Or is this meant to be created as a study first and then added to TOS Scanner?
 
Last edited:
S

shakenbake

New member
has anyone actually traded with this and made a profit?
 
BonBon

BonBon

New member
has anyone actually traded with this and made a profit?

Yes I use this to trade with profits

Yesterday, I used my premarket scanner just to get a feel for the pm movers. Then at 9:30 I ran my RVI scanner (using the thinkscript "buysignal" instead of the thinkscript strongbuyl). IPDN, PEIX, IZEA and ARC were the top ones based on my scan. I usually scan .05-$3.00

The buy signal for IPDN came at $1.20 and it went to a high of $2.20 before retracing.
The buy signal for PEIX came at $1.93 and it went to a high of $2.48. It has not retraced or made a significant dip as yet.
The buy signal for ARC came at $1.09 and it went to a high of $1.39.
The buy signal for IZEA came at $1.36 and it went to a high of $1.72.

I created a scanner for the trendpainter as well. This correlates with the chart and watchlist columns. (see my post on Relative Volume Strategy and Momentum Scanner for ThinkorSwim pages 9 -10
 
BonBon

BonBon

New member
has anyone actually traded with this and made a profit?
@BonBon n are you saying you added your two codes for thumbs and signals to the end of BenTen's trend code as a study, then you also created a custom column with the custom watchlist column creator by selecting that study, and then added that as a column to the watchlist?

Or is this meant to be created as a study first and then added to TOS Scanner?

Yes I did. However, first I created the watchlist columns months ago. Recently, I had an "ah ha" moment that resulted in the creation of the trendpainter scanner. I added them to the end of BenTen's code but had to make some tweaks (I could only use one plot in the scan). see my post on Relative Volume Strategy and Momentum Scanner for ThinkorSwim pages 9 -10.

I also embedded the study within my RVI scan as well. This enabled me to use the "buy signal" resulting in RVI stocks that showed an increase in volumn that were on the uptrend based on the signal.

Hope this helps.
 
CDJay

CDJay

Member
VIP
@BonBon, am I understanding correctly that you used the TrendPainter code in two areas — as well as added your script — with one location being a study, and the second location custom columns?

Thanks....
 
BonBon

BonBon

New member
@CDJay I used it in three areas. I have the original code on my chart. Then I created the watchlist column to alleviate having to check charts to determine those that are strongbuy or sell etc. (depending if I am going long or short). The watchlist column correlates with the signals and trends that are found on the chart. Finally, I tweaked the code from the watchlist to create the trendpainter scan (in one scan I plotted the strongbuy, in another I plotted the buysignal etc.). The scan also correlates with the chart and watchlist columns which allows for consistency and validity regarding the results of the scan etc.
 
CDJay

CDJay

Member
VIP
@CDJay I used it in three areas. I have the original code on my chart. Then I created the watchlist column to alleviate having to check charts to determine those that are strongbuy or sell etc. (depending if I am going long or short). The watchlist column correlates with the signals and trends that are found on the chart. Finally, I tweaked the code from the watchlist to create the trendpainter scan (in one scan I plotted the strongbuy, in another I plotted the buysignal etc.). The scan also correlates with the chart and watchlist columns which allows for consistency and validity regarding the results of the scan etc.
That sounds interesting about using it in the scans, @BonBon. I'm assuming you put the TrendPainter into a custom study? And how did you tweak it?
 
P

pga0008

Member
Ok for the life of me i cannot get my screener to show the trendpainter, arrow up, rsi - mine just shows a 1 or 0 - can you share you full code please.
 
murkr

murkr

Member
VIP
@BonBon I really like the code you did on post #66

I'm new to adding these custom things to a watchlist. Can you let me know if I'm doing this right?

#1. First, I took the script in post #1 and created a study with it and overlayed it onto my chart. Then my chart looked like post #1 image.

#2. I went back into that script I just created, edited, and added this code to the bottom of the code.

Code:
def arrowup = buysignal;
def arrowdown = sellsignal;

def trigger = if arrowup then 100 else if arrowdown then -100 else trigger [1];

AddLabel(yes,(if trigger == 100 then "👍" else if trigger == -100 then "👎" else "NA"));

AssignbackgroundColor(if trigger == 100 then Color.dark_Green else if arrowdown == -100 then Color.dark_Red else Color.black);

Then for some reason, the background of my chart went green.



So I feel like I messed up already. Either way, I moved forward and went to the Scan tab, customize button on watchlist>Custom Quotes> Deleted the(simplemovingAvg) that I see the default and went to the "thinkscript editor" and pasted the code that you see below. But it doesn't work. What am I doing wrong?

 
Last edited:
T

twitty_twit

New member
Dear @BonBon

I exactly have the same issue as @murkr.

Can you please give us noobs a step by step process?
 
BonBon

BonBon

New member
Greetings everyone

Please see below. These are the changes I made to the original trendpainter code so it can be used as a watchlist column and and as a scan. The original code is to be used within the chart study.

#Revised TrendPainter code for Watchlist Column (thermolookbackbars and the trading session must mirror that of the trendpainter on the chart). I removed the original "asignbackground color" and "addlabel' script and replaced it with the below.

def uptrend = buy;
def Stronguptrend = strongbuy;
def downtrend = sell;
def Strongdowntrend = strongsell;

AssignbackgroundColor (if uptrend then Color.Dark_GREEN else if Stronguptrend then Color.Green else if downtrend then color.dark_RED else if Strongdowntrend then Color.RED else Color.Black);

AddLabel(yes,if uptrend then "UP" else if Stronguptrend then "Buy" else if downtrend then "Down" else if Strongdowntrend then "Bear" else "Neutral", if stronguptrend then color.black else if strongdowntrend then color.black else color.white );

#Revised TrendPainter code for Stock Hacker scan (thermolookbackbars and the trading session must mirror that of the trendpainter on the chart and watchlist column). I removed the "asignbackground color" and "addlabel' script and replaced the 'plot" with "def". The only plot statement is the one below. This was added at the end of the script.

plot scan = strongbuy;

If you want to plot the buysignal, sell signal, strongsell etc simply replace strongbuy.

Hope this helps.
 
murkr

murkr

Member
VIP
@BonBon Okay so what am I doing with this new code? Does this go at the end of the code in post #1?

Code:
def uptrend = buy;
def Stronguptrend = strongbuy;
def downtrend = sell;
def Strongdowntrend = strongsell;

AssignbackgroundColor (if uptrend then Color.Dark_GREEN else if Stronguptrend then Color.Green else if downtrend then color.dark_RED else if Strongdowntrend then Color.RED else Color.Black);

AddLabel(yes,if uptrend then "UP" else if Stronguptrend then "Buy" else if downtrend then "Down" else if Strongdowntrend then "Bear" else "Neutral", if stronguptrend then color.black else if strongdowntrend then color.black else color.white );

So at the end the entire code is supposed to look like this?
Code:
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 GU = BuySignal;
GU.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
GU.SetDefaultColor(GetColor(8));
GU.SetLineWeight(2);

plot GX = SellSignal;
GX.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
GX.SetDefaultColor(GetColor(8));
GX.SetLineWeight(2);

AssignPriceColor(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);

AddLabel(yes, Concat("Current Reading is ", (if Buy then "Up Trend" else if StrongBuy then "Strong Up Trend" else if Sell then "Down Trend" else if StrongSell then "Strong Down Trend" else "Neutral")),  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.GRAY);

def uptrend = buy;
def Stronguptrend = strongbuy;
def downtrend = sell;
def Strongdowntrend = strongsell;

AssignbackgroundColor (if uptrend then Color.Dark_GREEN else if Stronguptrend then Color.Green else if downtrend then color.dark_RED else if Strongdowntrend then Color.RED else Color.Black);

AddLabel(yes,if uptrend then "UP" else if Stronguptrend then "Buy" else if downtrend then "Down" else if Strongdowntrend then "Bear" else "Neutral", if stronguptrend then color.black else if strongdowntrend then color.black else color.white );

I'm trying so hard to follow lol.
 
BonBon

BonBon

New member
@BonBon Okay so what am I doing with this new code? Does this go at the end of the code in post #1?

Code:
def uptrend = buy;
def Stronguptrend = strongbuy;
def downtrend = sell;
def Strongdowntrend = strongsell;

AssignbackgroundColor (if uptrend then Color.Dark_GREEN else if Stronguptrend then Color.Green else if downtrend then color.dark_RED else if Strongdowntrend then Color.RED else Color.Black);

AddLabel(yes,if uptrend then "UP" else if Stronguptrend then "Buy" else if downtrend then "Down" else if Strongdowntrend then "Bear" else "Neutral", if stronguptrend then color.black else if strongdowntrend then color.black else color.white );

So at the end the entire code is supposed to look like this?
Code:
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 GU = BuySignal;
GU.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
GU.SetDefaultColor(GetColor(8));
GU.SetLineWeight(2);

plot GX = SellSignal;
GX.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
GX.SetDefaultColor(GetColor(8));
GX.SetLineWeight(2);

AssignPriceColor(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);

AddLabel(yes, Concat("Current Reading is ", (if Buy then "Up Trend" else if StrongBuy then "Strong Up Trend" else if Sell then "Down Trend" else if StrongSell then "Strong Down Trend" else "Neutral")),  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.GRAY);

def uptrend = buy;
def Stronguptrend = strongbuy;
def downtrend = sell;
def Strongdowntrend = strongsell;

AssignbackgroundColor (if uptrend then Color.Dark_GREEN else if Stronguptrend then Color.Green else if downtrend then color.dark_RED else if Strongdowntrend then Color.RED else Color.Black);

AddLabel(yes,if uptrend then "UP" else if Stronguptrend then "Buy" else if downtrend then "Down" else if Strongdowntrend then "Bear" else "Neutral", if stronguptrend then color.black else if strongdowntrend then color.black else color.white );

I'm trying so hard to follow lol.

The assignpricecolor and first addlabel must be removed.
 

Similar threads

Top