ATR-Based Support & Resistance for ThinkorSwim

Its not a setting to change from Clouds to Plots, it's a change of code. That being said, it's still doesn't work on mobile. The ATR calculation requires an AggregationPeriod but Mobile doesn't support those so I am stuck trying to get the ATR calculation right.
 
Its not a setting to change from Clouds to Plots, it's a change of code. That being said, it's still doesn't work on mobile. The ATR calculation requires an AggregationPeriod but Mobile doesn't support those so I am stuck trying to get the ATR calculation right.
Thank you for the very quick response. I got your point.
 
Hey @BenTen, Thank you for this amazing tool. This indicator probably is on the best out here to spot reversal, especially when you trading a smaller timeframe, like 1-2 minute. I was wondering if this could be turn in to a scanner. I was hoping to scan a 2 minute chart with an aggregation period of 4 hours. Is it even possible? Thank You!!
 
Hey @BenTen, Thank you for this amazing tool. This indicator probably is on the best out here to spot reversal, especially when you trading a smaller timeframe, like 1-2 minute. I was wondering if this could be turn in to a scanner. I was hoping to scan a 2 minute chart with an aggregation period of 4 hours. Is it even possible? Thank You!!
No, you cannot scan for: "a 2-minute chart with an aggregation period of 4 hours"
Secondary aggregations are not allowed in the scanner, watchlists, or conditional orders

It is because of the fundamental way that the condition wizard works.
In the condition wizard, before we start to create the condition filters, we choose the aggregation period.
It is locked in.

In this case, you would choose to set the scan hacker filter to 2min.
The condition wizard will then execute the script using 2min data. When the scanner gets to the part of the script that specifies using 4-hour data; it vomits an error message: "secondary aggregations not allowed".
 
Ultimate ATR Combo
This has
  • 2 ATR's with values 10,3 & 30,9.
  • I find the 10,3 vs 10, 1.75 holds me in trades a little longer,
  • but I do like the 1.75 for shorter trades.
View attachment 1027
Here is my code that colors the bars.
Ruby:
# Ultimate ATR Combo
# Investing to Give
declare upper;
input averageType = AverageType.EXPONENTIAL;

# Fast ATR TS
input trailType = {default modified, unmodified};
input ATRPeriod = 10;
input ATRFactor = 3.0;
input firstTrade = {default long, short};

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 Buy_Zone = state == state.long;
def Sell_Zone = state == state.short;

# plot Buy = Buy_Zone[1] == 0 and Buy_Zone;
# plot Sell = Sell_Zone[1] == 0 and Sell_Zone;

plot TrailingStop = trail;

TrailingStop.SetPaintingStrategy(PaintingStrategy.Line);
TrailingStop.DefineColor("Buy", GetColor(5));
TrailingStop.DefineColor("Sell", GetColor(6));
TrailingStop.SetLineWeight(3);
TrailingStop.AssignValueColor(if state == state.long
then TrailingStop.Color("Sell")
else TrailingStop.Color("Buy"));


# Slow ATR TS
input trailType_Slow = {default modified_Slow, unmodified_Slow};
input ATRPeriod_Slow = 30;
input ATRFactor_Slow = 10.0;
input firstTrade_Slow = {default long_Slow, short_Slow};

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

def HiLo_Slow = Min(high - low, 1.5 * Average(high - low, ATRPeriod_Slow));
def HRef_Slow = if low <= high[1]
then high - close[1]
else (high - close[1]) - 0.5 * (low - high[1]);
def LRef_Slow = if high >= low[1]
then close[1] - low
else (close[1] - low) - 0.5 * (low[1] - high);

def trueRange_Slow;
switch (trailType_Slow) {
case modified_Slow:
trueRange_Slow = Max(HiLo_Slow, Max(HRef_Slow, LRef_Slow));
case unmodified_Slow:
trueRange_Slow = TrueRange(high, close, low);
}
def loss_Slow = ATRFactor_Slow * MovingAverage(averageType, trueRange_Slow, ATRPeriod_Slow);

def state_Slow = {default init_Slow, long_Slow, short_Slow};
def trail_Slow;
switch (state_Slow[1]) {
case init_Slow:
if (!IsNaN(loss_Slow)) {
switch (firstTrade_Slow) {
case long_Slow:
state_Slow = state_Slow.long_Slow;
trail_Slow = close - loss_Slow;
case short_Slow:
state_Slow = state_Slow.short_Slow;
trail_Slow = close + loss_Slow;
}
} else {
state_Slow = state_Slow.init_Slow;
trail_Slow = Double.NaN;
}
case long_Slow:
if (close > trail_Slow[1]) {
state_Slow = state_Slow.long_Slow;
trail_Slow = Max(trail_Slow[1], close - loss_Slow);
} else {
state_Slow = state_Slow.short_Slow;
trail_Slow = close + loss_Slow;
}
case short_Slow:
if (close < trail_Slow[1]) {
state_Slow = state_Slow.short_Slow;
trail_Slow = Min(trail_Slow[1], close + loss_Slow);
} else {
state_Slow = state_Slow.long_Slow;
trail_Slow = close - loss_Slow;
}
}

def BuySignal_Slow = Crosses(state_Slow == state_Slow.long_Slow, 0, CrossingDirection.ABOVE);
def SellSignal_Slow = Crosses(state_Slow == state_Slow.short_Slow, 0, CrossingDirection.ABOVE);

def Buy_Zone_Slow = state_Slow == state_Slow.long_Slow;
def Sell_Zone_Slow = state_Slow == state_Slow.short_Slow;

plot TrailingStop_Slow = trail_Slow;

TrailingStop_Slow.SetPaintingStrategy(PaintingStrategy.Line);
TrailingStop_Slow.DefineColor("Buy", GetColor(5));
TrailingStop_Slow.DefineColor("Sell", GetColor(6));
TrailingStop_Slow.SetLineWeight(3);
TrailingStop_Slow.AssignValueColor(if state_Slow == state_Slow.long_Slow
then TrailingStop_Slow.Color("Sell")
else TrailingStop_Slow.Color("Buy"));




def Buy = Buy_Zone and Buy_Zone_Slow;
def Sell = Sell_Zone and Sell_Zone_Slow;

AssignPriceColor (if Buy then Color.GREEN else if Sell then Color.RED else Color.YELLOW);
# End
This code looks like it was supposed to have three ATR's. Fast, Medium, Slow. Can someone, Please, finish it so it has three?
 

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
362 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