Message Alert TOO long .. Shorten plz

bigpemby

New member
One of my favorite indicators/TOS studies that I use for the basis of some of my strategies is the ATR trailing stop. I am trying to find a way to generate a scan that would give me results of a recent change in this indicator. Meaning it has switched from Buy to Sell or Sell to Buy. In a perfect world I would then be able to setup alerts based on this change and in a dream world be able to setup an alert to when price is within (X) distance of the current ATR trailing stop buy or sell. Ok, that was a mouthful. Any help would be appreciated. THANKS!
 
Solution
The alert in the Message Center is too long. Is there a way to shorten this? Example of original alert:

CHART ALERT 5 d 15m chart for TSLA
ScriptName (3, 2, 0.07) Breakout

Would like to be shorten:

15m TSLA ScriptName Breakout

Thank you for your help.
Those numbers above (3, 2, 0.07) are inputs in the script. Inputs come in handy if you want to change dependent parameters quickly.

If you go edit sources, delete the inputs. (Be aware you may have to edit a lot more in the source code).

Even though TOS allows you to go back to previous versions, Make sure to BACK UP THE CODE BEFORE deleting inputs, just in case.

This is how I truncated my alerts from my custom studies.

Before
10 y D chart for LVS...
hmm probably just need to correct your condition wizard. So on the pop up menu select:

First column select price, close
middle column select "crosses above" (to get a blue dot/bull)
last column select study, ATRtrailingstop and leave the default settings
Hi Dude, please help me understand your solution since I am a newbie at this. Does this mean change your formula that you posted April 25, 2020? I really appreciate your help on scanning for stocks that have broken the ATR trailing stop up or down. I can set up a scan for each type. When I input your scan and use a 3 min timeframe, many of the stocks dont satisfy the condition if I pull up a chart that has the ATR trailing stop formula and see where the price is. Thanks.
 
Hi Dude, please help me understand your solution since I am a newbie at this. Does this mean change your formula that you posted April 25, 2020? I really appreciate your help on scanning for stocks that have broken the ATR trailing stop up or down. I can set up a scan for each type. When I input your scan and use a 3 min timeframe, many of the stocks dont satisfy the condition if I pull up a chart that has the ATR trailing stop formula and see where the price is. Thanks.
Ok so you want to take the code to the CHART tab first. Create a new study and paste the code there. Save it under a memorable name.

Now go to the SCAN tab. Select "add filter" then "study"

where it says "adxcrossover" by default, click the dropdown and select the bottom option which is "custom"

new menu pops up. Click delete next to the adxcrossover line.

near the bottom you'll see "add condition"

click that and itll take you to a menu where you can follow the previous instructions..

If it still doesnt make sense, just youtube "condition wizard" or custom scans, etc. There are tons of tutorials
 
Hey Guys,

I need help devising a custom scan using ATR TrailingStop study as a filter. I would like to scan for stocks with prices just cross ATR TrailingStop line.
Any help will be appreciated!
 
@vasilst Here is an example. Scanning for stocks crossing above the ATRTrailingStop line.

2loxzu7.png


Results:

TgB2Is1.png
 
Hi, everyone. I am trying to modify the TOS ATR Trailing Stop script so that instead of flipping to a down condition, it just continues to plot the last line until it starts a new up. Does that make sense? I only trade long so I don't care about the downtrend, but I do still want the last place that the line was even if the price is now below there. Is there a simplified version of the script somewhere that will do that? I've been chopping out parts of the script, but it just breaks things.

Reference Picture

Using the reference center picture as an example, in Jan the trailing stop was at $43.50. I want it to continue to plot $43.50 until April when it starts a new trend.
 
Hi, everyone. I am trying to modify the TOS ATR Trailing Stop script so that instead of flipping to a down condition, it just continues to plot the last line until it starts a new up. Does that make sense? I only trade long so I don't care about the downtrend, but I do still want the last place that the line was even if the price is now below there. Is there a simplified version of the script somewhere that will do that? I've been chopping out parts of the script, but it just breaks things.

Reference Picture

Using the reference center picture as an example, in Jan the trailing stop was at $43.50. I want it to continue to plot $43.50 until April when it starts a new trend.

See if this helps. It plots the state.long as green and the extension of it yellow until the next state.long, skipping the plot of the state.short line.

Capture.jpg
Code:
#
# TD Ameritrade IP Company, Inc. (c) 2009-2021
#

input trailType = {default modified, unmodified};
input ATRPeriod = 5;
input ATRFactor = 3.5;
input firstTrade = {default long, short};
input averageType = AverageType.WILDERS;

Assert(ATRFactor > 0, "'atr factor' must be positive: " + ATRFactor);

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 trueRange;
switch (trailType) {
case modified:
    trueRange = Max(HiLo, Max(HRef, LRef));
case unmodified:
    trueRange = TrueRange(high, close, low);
}
def loss = ATRFactor * MovingAverage(averageType, trueRange, ATRPeriod);

def state = {default init, long, short};
def 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);

def trailext = if isnan(close) then trailext[1] else if state==state.long then trail else trailext[1];
plot TrailingStop = trailext;

TrailingStop.SetPaintingStrategy(PaintingStrategy.POINTS);
TrailingStop.DefineColor("Buy", GetColor(0));
TrailingStop.DefineColor("Sell", GetColor(1));
TrailingStop.AssignValueColor(if !isnan(close) and state == state.long
    then color.green
    else color.yellow);
 
See if this helps. It plots the state.long as green and the extension of it yellow until the next state.long, skipping the plot of the state.short line.
Yes! This is perfect! Thank you!
Trying to understand what it is doing. When the state filps it has no base number to start with so isnan gives it one to start with. From there it continues to print the last bar until the state flips again. Is that correct? I had been trying to reference the previous bar but that would make sense if the flip was clearing it. Why though is Trailext picking up the Trail value instead of the bar close value?
 
It is just plotting the trailing stop for the state.long. It ignores the trailing stop for state.short and instead plots the last trailing value for state.long until a new state.long occurs. Finallly, the isnan(close) is used to extend the last state.long trailing stop value into the right expansion. I am not sure what you are intending when you want to use the bar close value.
 
This is simply the TrailingStop with added price color, thought it worked great for easily finding trends.
PAVlz3F.png


Code:
#
# TD Ameritrade IP Company, Inc. (c) 2009-2021
# added price color

input trailType = {default modified, unmodified};
input ATRPeriod = 5;
input ATRFactor = 3.5;
input firstTrade = {default long, short};
input averageType = AverageType.WILDERS;

Assert(ATRFactor > 0, "'atr factor' must be positive: " + ATRFactor);

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 trueRange;
switch (trailType) {
case modified:
    trueRange = Max(HiLo, Max(HRef, LRef));
case unmodified:
    trueRange = TrueRange(high, close, low);
}
def loss = ATRFactor * MovingAverage(averageType, trueRange, ATRPeriod);

def state = {default init, long, short};
def 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.SetPaintingStrategy(PaintingStrategy.POINTS);
TrailingStop.DefineColor("Buy", GetColor(0));
TrailingStop.DefineColor("Sell", GetColor(1));
TrailingStop.AssignValueColor(if state == state.long
    then TrailingStop.Color("Sell")
    else TrailingStop.Color("Buy"));

def UpBar = close > trailingstop;
def DownBar = close < trailingstop;

input PaintBars = Yes;
AssignPriceColor (if !PaintBars then Color.CURRENT else if UpBar >= 0 and UpBar > DownBar[0] then Color.GREEN else if UpBar <= 1 and UpBar < DownBar[1] then Color.RED else Color.WHITE);
#UpBar > DownBar[0]
 
The alert in the Message Center is too long. Is there a way to shorten this? Example of original alert:

CHART ALERT 5 d 15m chart for TSLA
ScriptName (3, 2, 0.07) Breakout

Would like to be shorten:

15m TSLA ScriptName Breakout

Thank you for your help.
 
@Shaco It is possible to adjust some of the info displayed in an alert. In the upper right corner of the ThinkorSwim platform, click "Setup">"Application Settings...">"Notifications">"Alert is triggered" -

This is with every data point selected to be shown - see the highlighted areas and the "sample message"

all-selected.png


This is with all possible data points removed - notice how the "sample message" is much shorter -

none-selected.png


Any other changes you want would have to be suggested to TOS support as a platform feature request.
 
Last edited by a moderator:
The alert in the Message Center is too long. Is there a way to shorten this? Example of original alert:

CHART ALERT 5 d 15m chart for TSLA
ScriptName (3, 2, 0.07) Breakout

Would like to be shorten:

15m TSLA ScriptName Breakout

Thank you for your help.
Those numbers above (3, 2, 0.07) are inputs in the script. Inputs come in handy if you want to change dependent parameters quickly.

If you go edit sources, delete the inputs. (Be aware you may have to edit a lot more in the source code).

Even though TOS allows you to go back to previous versions, Make sure to BACK UP THE CODE BEFORE deleting inputs, just in case.

This is how I truncated my alerts from my custom studies.

Before
10 y D chart for LVS ScriptName (yes, yes, yes, yes, 200, yes, yes, yes, 14, 70, 30, WILDERS, no, DAY, yes, yes) Oversold

So I deleted the inputs. Now this what I get

10 y D chart for LVS ScriptName Oversold



If anyone else knows a way to hide inputs, then this would be so much easier.
 
Last edited:
Solution
Need a scanner for atr indicator

Ruby:
input trailType = {default modified, unmodified};
input ATRPeriod = 28;
input ATRFactor = 5;
input firstTrade = {default long, short};
input averageType = AverageType.WILDERS;
Assert(ATRFactor > 0, "'atr factor' must be positive: " + ATRFactor);
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 trueRange;
switch (trailType) {
case modified:
trueRange = Max(HiLo, Max(HRef, LRef));
case unmodified:
trueRange = TrueRange(high, close, low);
}
def loss = ATRFactor * MovingAverage(averageType, trueRange, ATRPeriod);
def state = {default init, long, short};
def 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;
}
}
plot BuySignal = if Crosses(state == state.long, 0, CrossingDirection.ABOVE) then low else Double.NaN;
BuySignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
plot SellSignal = if Crosses(state == state.short, 0, CrossingDirection.ABOVE) then high else Double.NaN;
SellSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
plot TrailingStop = trail;
TrailingStop.SetPaintingStrategy(PaintingStrategy.POINTS);
TrailingStop.DefineColor("Buy", GetColor(0));
TrailingStop.DefineColor("Sell", GetColor(1));
TrailingStop.AssignValueColor(if state == state.long
then TrailingStop.Color("Sell")
else TrailingStop.Color("Buy"));
Alert(BuySignal, "Trail Stop Long Entry", Alert.BAR, Sound.DING);
Alert(SellSignal, "Trail Stop Short Entry", Alert.BAR, Sound.DING);

AddChartBubble(BuySignal == BuySignal , BuySignal , "B", Color.dark_GREEN,no);
AddChartBubble(SellSignal == SellSignal , SellSignal , "S", Color.gray, yes);
 
Last edited by a moderator:
Does anyone know if there is a way for me to rewrite the message that I get when an alert goes off? All I want for the message to say is "Chart Alert AAPL Short".

5d410f7f0fefa7594571ee6b2f1242e8.png
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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