Trend Painter Indicator With Buy & Sell Signals for ThinkorSwim

K

kelbadawi

New member
i set the alerts as such; however, it doesnt alert when buy or sell gu gx arrows
 
A

alphabeta

Member
is it possible to creat aerrow when candle color change from blue to green
 
K

kelbadawi

New member
Also I notice that arrows don’t appear when the trend reversed. Like I use ttm scalper that appears soon as it changes anyone know why @BenTen
 
P

Piper2808t

Member
2019 Donor
VIP
Can this be placed in a column when the color changes to green or red thanks
 
K

K_O_Trader

New member
Try using this on your chart its a bit more accurate than the one you have and below is the code for the column just change the time frame in thinkscript at the top for what you prefer @Piper2808t

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(" ", (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);


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(" ", (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);
 
T

thatguytrades

New member
@K_O_Trader is this code a add on to the indicator?
 
D

Diamondlil

New member
@BenTen what addition/change would I need to make to so that I get only Buy signals in a scan with this indicator? Thank you.
 
A

alphabeta

Member
is it possible to add aggregation period for example 1 hour and 1 day in this study thank you
 
D

Diamondlil

New member
@BenTen

Thanks for the Scan video!

* Also, comment appears in indicator code for TrendPainter with Buy&Sell Signals: "invalid statement: 2 at 1:1" How do I correct this? Thank you again! *
I think the "invalid statement" is referring to this?:

2
def HiLo = Min(high - low, 1.5 * Average(high - low, ATRPeriod));
 
BenTen

BenTen

Administrative
Staff
VIP
@Diamondlil I checked both scripts. I don't see any error like that. Can you post a screenshot?
 
D

Diamondlil

New member
@BenTen
I changed the code to the one provided above by K_O_Trader.
Seems ok now.
However, when I add the condition into the scan, the drop down only says "TrailingStop" and not "Bull" or "Bear" as in the video you provided.
Please advise. Thank you very much for your time.
 
BenTen

BenTen

Administrative
Staff
VIP
@Diamondlil GU = Buy and GX = Sell. Use the last two options.

 
D

Diamondlil

New member
@BenTen not sure what I am missing, but the scan does not provide tickers where the "Buy Signal" has fired one bar ago.
 
BonBon

BonBon

New member
@BenTen I have been visiting the site and gaining invaluable insight regarding thinkscript from the forum. I have started using the trendpainter on my charts and I must say thank you to you and the other members. Recently, I decided to try my hand at altering the code as I didn't want to be reviewing charts to determine if there was a buy signal etc. Therefore, I tweaked the trendpainter to use on my watchlist. The watchlist would correspond to the charts. Please see below the watchlist custom thinkscript that I added to the trendpainter script.

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"));
 
A

alphabeta

Member
@BenTen I have been visiting the site and gaining invaluable insight regarding thinkscript from the forum. I have started using the trendpainter on my charts and I must say thank you to you and the other members. Recently, I decided to try my hand at altering the code as I didn't want to be reviewing charts to determine if there was a buy signal etc. Therefore, I tweaked the trendpainter to use on my watchlist. The watchlist would correspond to the charts. Please see below the watchlist custom thinkscript that I added to the trendpainter script.

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"));

hi its great watchlist i want to aks do you know how to get alert when color changes upward blue to green or downward blue to red thank you
 
BonBon

BonBon

New member
@alphabeta I have not created a script for an alert but I know @BenTen created one in this forum.
 
A

alphabeta

Member
@BenTen

i want to aks you do you know how to get an alert when candle color changes example: upward blue to green or downward blue to red thank you
 
blake007

blake007

New member
@BenTen Where do I add this code to show it on the watchlist?
 
Top