# Saty ATR Levels For ThinkOrSwim

#### JE \$\$

##### Member
below is saty levels -- he provides this for free on his website "satyland"
it calculates pivot levels based on ATR and fibonnacci ratios

my question is this:
is there any way to make a scan for price crossing above the long trigger or below the short tirgger?

when i make a scan, it simply gives you all the stocks that at some point duringn the day was above the specified trigger
i'm trying to catch the moment it either crosses above or below either the long or short trigger

thanks!

Code:
``````# Saty_ATR_Levels
# Copyright (C) 2022-2023 Saty Mahajan
# Data provided in this script is not financial advice.
#
# Features:
# - Scalp, Day, Multiday, Swing, Position, Long-term trading modes
# - Range against ATR for each period
# - Put and call trigger idea levels
# - Intermediate levels
# - Full-range levels
# - Extension levels
# - Trend label based on the 8-21-34 Pivot Ribbon
#
# Special thanks to Gabriel Viana.
# Based on my own ideas and ideas from Ripster, drippy2hard,

input trading_type = {"Scalp", default "Day", "Multiday", "Swing", "Position", "Long-term"};
input show_all_fibonacci_levels = yes;
input show_extensions = no;
input use_options_labels = yes;
input atr_length = 14;
input trigger_percentage = 0.236;
input use_current_close = no;
input show_info = yes;
input fast_ema = 8;
input pivot_ema = 21;
input slow_ema = 34;

case "Scalp":
case "Day":
case "Multiday":
case "Swing":
case "Position":
case "Long-term":
}

# Trend
def price = close;
def fast_ema_value = MovAvgExponential(price, fast_ema);
def pivot_ema_value = MovAvgExponential(price, pivot_ema);
def slow_ema_value = MovAvgExponential(price, slow_ema);
def bullish = price >= fast_ema_value and fast_ema_value >= pivot_ema_value and pivot_ema_value >= slow_ema_value;
def bearish = price <= fast_ema_value and fast_ema_value <= pivot_ema_value and pivot_ema_value <= slow_ema_value;

# ATR Levels
def previous_close = close(period = trading_period)[if use_current_close then 0 else 1];
def atr = Round(WildersAverage(TrueRange(high(period = trading_period), close(period = trading_period), low(period = trading_period)), atr_length)[if use_current_close then 0 else 1], 2);
def period_high = Highest(high(period = trading_period), 1);
def period_low = Lowest(low(period = trading_period), 1);
def tr = period_high - period_low;
def tr_percent_of_atr = Round((tr / atr) * 100, 0);
def lower_trigger = previous_close - (trigger_percentage * atr);
def upper_trigger = previous_close + (trigger_percentage * atr);
def lower_0382 = previous_close - (atr * 0.382);
def upper_0382 = previous_close + (atr * 0.382);
def lower_0500 = previous_close - (atr * 0.5);
def upper_0500 = previous_close + (atr * 0.5);
def lower_0618 = previous_close - (atr * 0.618);
def upper_0618 = previous_close + (atr * 0.618);
def lower_0786 = previous_close - (atr * 0.786);
def upper_0786 = previous_close + (atr * 0.786);
def lower_1000 = previous_close - atr;
def upper_1000 = previous_close + atr;
def lower_1236 = (lower_1000) - (atr * 0.236);
def upper_1236 = (upper_1000) + (atr * 0.236);
def lower_1382 = (lower_1000) - (atr * 0.382);
def upper_1382 = (upper_1000) + (atr * 0.382);
def lower_1500 = (lower_1000) - (atr * 0.5);
def upper_1500 = (upper_1000) + (atr * 0.5);
def lower_1618 = (lower_1000) - (atr * 0.618);
def upper_1618 = (upper_1000) + (atr * 0.618);
def lower_1786 = (lower_1000) - (atr * 0.786);
def upper_1786 = (upper_1000) + (atr * 0.786);
def lower_2000 = lower_1000 - atr;
def upper_2000 = upper_1000 + atr;
def lower_2236 = (lower_2000) - (atr * 0.236);
def upper_2236 = (upper_2000) + (atr * 0.236);
def lower_2382 = (lower_2000) - (atr * 0.382);
def upper_2382 = (upper_2000) + (atr * 0.382);
def lower_2500 = (lower_2000) - (atr * 0.5);
def upper_2500 = (upper_2000) + (atr * 0.5);
def lower_2618 = (lower_2000) - (atr * 0.618);
def upper_2618 = (upper_2000) + (atr * 0.618);
def lower_2786 = (lower_2000) - (atr * 0.786);
def upper_2786 = (upper_2000) + (atr * 0.786);
def lower_3000 = lower_2000 - atr;
def upper_3000 = upper_2000 + atr;

plot close_level;
close_level = previous_close;
close_level.SetDefaultColor(Color.WHITE);
close_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot lower_trigger_level;
lower_trigger_level = lower_trigger;
lower_trigger_level.SetDefaultColor(Color.ORANGE);
lower_trigger_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot upper_trigger_level;
upper_trigger_level = upper_trigger;
upper_trigger_level.SetDefaultColor(Color.CYAN);
upper_trigger_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot lower_0382_level;
lower_0382_level = if show_all_fibonacci_levels then lower_0382 else Double.NaN;
lower_0382_level.SetDefaultColor(Color.GRAY);
lower_0382_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot upper_0382_level;
upper_0382_level = if show_all_fibonacci_levels then upper_0382 else Double.NaN;
upper_0382_level.SetDefaultColor(Color.GRAY);
upper_0382_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot lower_0500_level;
lower_0500_level = if show_all_fibonacci_levels then lower_0500 else Double.NaN;
lower_0500_level.SetDefaultColor(Color.GRAY);
lower_0500_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot upper_0500_level;
upper_0500_level = if show_all_fibonacci_levels then upper_0500 else Double.NaN;
upper_0500_level.SetDefaultColor(Color.GRAY);
upper_0500_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot lower_0618_level;
lower_0618_level = lower_0618;
lower_0618_level.SetDefaultColor(Color.LIGHT_GRAY);
lower_0618_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot upper_0618_level;
upper_0618_level = upper_0618;
upper_0618_level.SetDefaultColor(Color.LIGHT_GRAY);
upper_0618_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot lower_0786_level;
lower_0786_level = if show_all_fibonacci_levels then lower_0786 else Double.NaN;
lower_0786_level.SetDefaultColor(Color.GRAY);
lower_0786_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot upper_0786_level;
upper_0786_level = if show_all_fibonacci_levels then upper_0786 else Double.NaN;
upper_0786_level.SetDefaultColor(Color.GRAY);
upper_0786_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot lower_1000_level;
lower_1000_level = lower_1000;
lower_1000_level.SetDefaultColor(Color.WHITE);
lower_1000_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot upper_1000_level;
upper_1000_level = upper_1000;
upper_1000_level.SetDefaultColor(Color.WHITE);
upper_1000_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot lower_1236_level;
lower_1236_level = if show_extensions then lower_1236 else Double.NaN;
lower_1236_level.SetDefaultColor(Color.GRAY);
lower_1236_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot lower_1382_level;
lower_1382_level = if show_extensions and show_all_fibonacci_levels then lower_1382 else Double.NaN;
lower_1382_level.SetDefaultColor(Color.GRAY);
lower_1382_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot lower_1500_level;
lower_1500_level = if show_extensions and show_all_fibonacci_levels then lower_1500 else Double.NaN;
lower_1500_level.SetDefaultColor(Color.GRAY);
lower_1500_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot lower_1618_level;
lower_1618_level = if show_extensions then lower_1618 else Double.NaN;
lower_1618_level.SetDefaultColor(Color.LIGHT_GRAY);
lower_1618_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot lower_1786_level;
lower_1786_level = if show_extensions and show_all_fibonacci_levels then lower_1786 else Double.NaN;
lower_1786_level.SetDefaultColor(Color.GRAY);
lower_1786_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot lower_2000_level;
lower_2000_level = if show_extensions then lower_2000 else Double.NaN;
lower_2000_level.SetDefaultColor(Color.WHITE);
lower_2000_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot lower_2236_level;
lower_2236_level = if show_extensions then lower_2236 else Double.NaN;
lower_2236_level.SetDefaultColor(Color.GRAY);
lower_2236_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot lower_2382_level;
lower_2382_level = if show_extensions and show_all_fibonacci_levels then lower_2382 else Double.NaN;
lower_2382_level.SetDefaultColor(Color.GRAY);
lower_2382_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot lower_2500_level;
lower_2500_level = if show_extensions and show_all_fibonacci_levels then lower_2500 else Double.NaN;
lower_2500_level.SetDefaultColor(Color.GRAY);
lower_2500_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot lower_2618_level;
lower_2618_level = if show_extensions then lower_2618 else Double.NaN;
lower_2618_level.SetDefaultColor(Color.LIGHT_GRAY);
lower_2618_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot lower_2786_level;
lower_2786_level = if show_extensions and show_all_fibonacci_levels then lower_2786 else Double.NaN;
lower_2786_level.SetDefaultColor(Color.GRAY);
lower_2786_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot lower_3000_level;
lower_3000_level = if show_extensions then lower_3000 else Double.NaN;
lower_3000_level.SetDefaultColor(Color.WHITE);
lower_3000_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot upper_1236_level;
upper_1236_level = if show_extensions then upper_1236 else Double.NaN;
upper_1236_level.SetDefaultColor(Color.GRAY);
upper_1236_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot upper_1382_level;
upper_1382_level = if show_extensions and show_all_fibonacci_levels then upper_1382 else Double.NaN;
upper_1382_level.SetDefaultColor(Color.GRAY);
upper_1382_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot upper_1500_level;
upper_1500_level = if show_extensions and show_all_fibonacci_levels then upper_1500 else Double.NaN;
upper_1500_level.SetDefaultColor(Color.GRAY);
upper_1500_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot upper_1618_level;
upper_1618_level = if show_extensions then upper_1618 else Double.NaN;
upper_1618_level.SetDefaultColor(Color.LIGHT_GRAY);
upper_1618_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot upper_1786_level;
upper_1786_level = if show_extensions and show_all_fibonacci_levels then upper_1786 else Double.NaN;
upper_1786_level.SetDefaultColor(Color.GRAY);
upper_1786_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot upper_2000_level;
upper_2000_level = if show_extensions then upper_2000 else Double.NaN;
upper_2000_level.SetDefaultColor(Color.WHITE);
upper_2000_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot upper_2236_level;
upper_2236_level = if show_extensions then upper_2236 else Double.NaN;
upper_2236_level.SetDefaultColor(Color.GRAY);
upper_2236_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot upper_2382_level;
upper_2382_level = if show_extensions and show_all_fibonacci_levels then upper_2382 else Double.NaN;
upper_2382_level.SetDefaultColor(Color.GRAY);
upper_2382_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot upper_2500_level;
upper_2500_level = if show_extensions and show_all_fibonacci_levels then upper_2500 else Double.NaN;
upper_2500_level.SetDefaultColor(Color.GRAY);
upper_2500_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot upper_2618_level;
upper_2618_level = if show_extensions then upper_2618 else Double.NaN;
upper_2618_level.SetDefaultColor(Color.LIGHT_GRAY);
upper_2618_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot upper_2786_level;
upper_2786_level = if show_extensions and show_all_fibonacci_levels then upper_2786 else Double.NaN;
upper_2786_level.SetDefaultColor(Color.GRAY);
upper_2786_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot upper_3000_level;
upper_3000_level = if show_extensions then upper_3000 else Double.NaN;
upper_3000_level.SetDefaultColor(Color.WHITE);
upper_3000_level.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

def rangeNotAvailable = IsNaN(tr);
def atrNotAvailable = IsNaN(atr);

DefineGlobalColor("Long Label", Color.CYAN);
DefineGlobalColor("Short Label", Color.ORANGE);

# Labels
AddLabel(show_info, "ATRLevels ", if bullish then Color.GREEN else if bearish then Color.RED else Color.ORANGE);
AddLabel (show_info, (if trading_period == AggregationPeriod.YEAR then "Long-term " else if trading_period == AggregationPeriod.QUARTER then "Position "  else if trading_period == AggregationPeriod.MONTH then "Swing " else if trading_period == AggregationPeriod.WEEK then "Multiday " else if trading_period == AggregationPeriod.FOUR_HOURS then "Scalp " else "Day ") + (if (rangeNotAvailable) then "Range N/A Pre-Market" + " | ATR (\$" + Round (atr, 2) + ")   " else if (atrNotAvailable) then " Range - Not Enough Data" else "Range (\$" + Round (tr , 2) + ") is " + Round (tr_percent_of_atr, 0) + "% of ATR (\$" + Round (atr, 2) + ")   ") , (if (rangeNotAvailable or atrNotAvailable) then Color.GRAY else (if tr_percent_of_atr <= 70 then Color.GREEN else if tr_percent_of_atr >= 90 then Color.RED else Color.ORANGE)));
AddLabel (show_info, (if use_options_labels then "Calls" else "Long") + " > \$" + Round (upper_trigger, 2) + " | +1 ATR: \$" + Round (upper_1000, 2) + "   ", GlobalColor("Long Label"));
AddLabel (show_info, (if use_options_labels then "Puts" else "Short") + " < \$" + Round (lower_trigger, 2) + " | -1 ATR: \$" +  Round (lower_1000, 2) + "   ", GlobalColor("Short Label"));``````

Have you tried scanning with the certain criteria like "scanning within the last bar" and make sure it says "price crosses call/put trigger" instead of "price greater than call/put trigger"

Help changing cloud to horizontal line

I've been using this Saty ATR Levels indicator that i found a while back on twitter, and im trying to get it to function on my mobile thinkorswim app because its very helpful. I think it would be possible if i change the clouds to horizontal lines but i really don't know how to go about making that happen. The only lines i really care about are the upper trigger and lower trigger clouds, and maybe the close cloud. Anyways here is the code:
Code:
``````# Saty_ATR_Levels
# Copyright (C) 2022 Saty Mahajan
# Data provided in this script is not financial advice.
#
# Special thanks to Gabriel Viana.
# Based on my own ideas and ideas from Ripster, drippy2hard,
#
# Features:
# - Day, Multiday, Swing, Position trading modes
# - Range against ATR for each period
# - Put and call trigger levels
# - Mid-range level
# - Full-range levels
# - Optional Extension Level

input trading_type = {"Scalp", default "Day", "Multiday", "Swing", "Position", "Long-term"};
input use_options_labels = yes;
input atr_Length = 14;
input trigger_percentage = 0.236;
input use_current_close = no;
input cloud_size = 1.0;
input close_cloud_on = yes;
input lower_trigger_cloud_on = yes;
input lower_middle_cloud_on = yes;
input lower_atr_cloud_on = yes;
input lower_extension_clouds_on = no;
input upper_trigger_cloud_on = yes;
input upper_middle_cloud_on = yes;
input upper_atr_cloud_on = yes;
input upper_extension_clouds_on = no;
input show_info = yes;
input fast_ema = 8;
input pivot_ema = 21;
input slow_ema = 34;

DefineGlobalColor("Previous Close Cloud", Color.WHITE);
DefineGlobalColor("Lower Trigger Cloud", Color.ORANGE);
DefineGlobalColor("Lower Midrange Cloud", Color.GRAY);
DefineGlobalColor("Lower ATR Clouds", Color.WHITE);
DefineGlobalColor("Lower Extension Clouds", Color.GRAY);
DefineGlobalColor("Upper Trigger Cloud", Color.CYAN);
DefineGlobalColor("Upper Midrange Cloud", Color.GRAY);
DefineGlobalColor("Upper ATR Clouds", Color.WHITE);
DefineGlobalColor("Upper Extension Clouds", Color.GRAY);

case "Scalp":
case "Day":
case "Multiday":
case "Swing":
case "Position":
case "Long-term":
}

# Trend
def price = close;
def fast_ema_value = MovAvgExponential(price, fast_ema);
def pivot_ema_value = MovAvgExponential(price, pivot_ema);
def slow_ema_value = MovAvgExponential(price, slow_ema);
def bullish = price >= fast_ema_value and fast_ema_value >= pivot_ema_value and pivot_ema_value >= slow_ema_value;
def bearish = price <= fast_ema_value and fast_ema_value <= pivot_ema_value and pivot_ema_value <= slow_ema_value;

# Data
def previous_close = close(period = trading_period)[if use_current_close then 0 else 1];
def atr = Round(WildersAverage(TrueRange(high(period = trading_period), close(period = trading_period), low(period = trading_period)), atr_Length)[if use_current_close then 0 else 1], 2);
def period_high = Highest(high(period = trading_period), 1);
def period_low = Lowest(low(period = trading_period), 1);
def tr = period_high - period_low;
def tr_percent_of_atr = Round((tr / atr) * 100, 0);
def lower_trigger = previous_close - (trigger_percentage * atr);
def upper_trigger = previous_close + (trigger_percentage * atr);
def lower_atr = previous_close - atr;
def upper_atr = previous_close + atr;
def lower_midrange = previous_close - (atr * 0.618);
def upper_midrange = previous_close + (atr * 0.618);
def lower_extension = (lower_atr) - (atr * 0.236);
def upper_extension = (upper_atr) + (atr * 0.236);
def lower_midrange_extension = (lower_atr) - (atr * 0.618);
def upper_midrange_extension = (upper_atr) + (atr * 0.618);
def lower_2atr_extension = lower_atr - atr;
def upper_2atr_extension = upper_atr + atr;

def rangeNotAvailable = IsNaN(tr);
def atrNotAvailable = IsNaN(atr);
# Labels
AddLabel(show_info,"Trend ",if bullish then Color.GREEN else if bearish then Color.RED else Color.ORANGE);
AddLabel (show_info, (if trading_period == AggregationPeriod.YEAR then "Long-term " else if trading_period == AggregationPeriod.QUARTER then "Position "  else if trading_period == AggregationPeriod.MONTH then "Swing " else if trading_period == AggregationPeriod.WEEK then "Multiday " else if trading_period == AggregationPeriod.FOUR_HOURS then "Scalp " else "Day ") + (if (rangeNotAvailable) then "Range N/A Pre-Market" else if (atrNotAvailable) then " Range - Not Enough Data" else "Range (\$" + Round (tr , 2) + ") is " + Round (tr_percent_of_atr, 0) + "% of ATR (\$" + Round (atr, 2) + ")   ") , (if (rangeNotAvailable or atrNotAvailable) then Color.GRAY else (if tr_percent_of_atr <= 70 then Color.GREEN else if tr_percent_of_atr >= 90 then Color.RED else Color.ORANGE)));
AddLabel (show_info, (if use_options_labels then "Calls" else "Long") + " > \$" + Round (upper_trigger, 2) + " | +1 ATR: \$" + Round (upper_atr, 2) + "   ", GlobalColor("Upper Trigger Cloud"));
AddLabel (show_info, (if use_options_labels then "Puts" else "Short") + " < \$" + Round (lower_trigger, 2) + " | -1 ATR: \$" +  Round (lower_atr, 2) + "   ", GlobalColor("Lower Trigger Cloud"));

def cloud_size_factor = 0.01 * cloud_size;

# Previous Close cloud
AddCloud(if close_cloud_on then (previous_close - (atr * cloud_size_factor / 2)) else Double.NaN, (previous_close + (atr * cloud_size_factor / 2)), GlobalColor("Previous Close Cloud"), GlobalColor("Previous Close Cloud"));

# Trigger clouds
AddCloud(if lower_trigger_cloud_on then lower_trigger else Double.NaN, (lower_trigger - (atr * cloud_size_factor)), GlobalColor("Lower Trigger Cloud"), GlobalColor("Lower Trigger Cloud"));
AddCloud(if upper_trigger_cloud_on then upper_trigger else Double.NaN, (upper_trigger + (atr * cloud_size_factor)), GlobalColor("Upper Trigger Cloud"), GlobalColor("Upper Trigger Cloud"));

# Middle clouds
AddCloud(if lower_middle_cloud_on then lower_midrange else Double.NaN, (lower_midrange - (atr * cloud_size_factor)), GlobalColor("Lower Midrange Cloud"), GlobalColor("Lower Midrange Cloud"));
AddCloud(if upper_middle_cloud_on then upper_midrange else Double.NaN, (upper_midrange + (atr * cloud_size_factor)), GlobalColor("Upper Midrange Cloud"), GlobalColor("Upper Midrange Cloud"));

# +/- 1 ATR clouds
AddCloud(if lower_atr_cloud_on then lower_atr else Double.NaN, (lower_atr - (atr * cloud_size_factor)), GlobalColor("Lower ATR Clouds"), GlobalColor("Lower ATR Clouds"));
AddCloud(if upper_atr_cloud_on then upper_atr else Double.NaN, (upper_atr + (atr * cloud_size_factor)), GlobalColor("Upper ATR Clouds"), GlobalColor("Upper ATR Clouds"));

# Extension clouds
AddCloud(if lower_extension_clouds_on then lower_extension else Double.NaN, (lower_extension - (atr * cloud_size_factor)), GlobalColor("Lower Extension Clouds"), GlobalColor("Lower Extension Clouds"));
AddCloud(if upper_extension_clouds_on then upper_extension else Double.NaN, (upper_extension + (atr * cloud_size_factor)), GlobalColor("Upper Extension Clouds"), GlobalColor("Upper Extension Clouds"));

# Middle Extension clouds
AddCloud(if lower_extension_clouds_on then lower_midrange_extension else Double.NaN, (lower_midrange_extension - (atr * cloud_size_factor)), GlobalColor("Lower Extension Clouds"), GlobalColor("Lower Extension Clouds"));
AddCloud(if upper_extension_clouds_on then upper_midrange_extension else Double.NaN, (upper_midrange_extension + (atr * cloud_size_factor)), GlobalColor("Upper Extension Clouds"), GlobalColor("Upper Extension Clouds"));

# +/- 2 ATR clouds
AddCloud(if lower_extension_clouds_on then lower_2atr_extension else Double.NaN, (lower_2atr_extension - (atr * cloud_size_factor)), GlobalColor("Lower ATR Clouds"), GlobalColor("Lower ATR Clouds"));
AddCloud(if upper_extension_clouds_on then upper_2atr_extension else Double.NaN, (upper_2atr_extension + (atr * cloud_size_factor)), GlobalColor("Upper ATR Clouds"), GlobalColor("Upper ATR Clouds"));``````

Last edited by a moderator:
I was wondering if anyone uses SATY ATR for futures and if you think the levels are off. What I mean is that on SPX Saty ATR levels use a close of 4 PM the previous day even if you are showing extended hours. But for ES the close time it is using on a 1 minute chart with extended hours turned off is 16:10. So when the levels are plotted the next day it is not using the close of 4 PM the previous day. Is there a way to force it to use a 4 PM close time in the code? Do you concur that this is what should be used? The code block doing this is pasted below.

Thanks!

Code:
``````trading_period = AggregationPeriod.DAY;
def previous_close = close(period = trading_period)[if use_current_close then 0 else 1];``````

Help changing cloud to horizontal line

I've been using this Saty ATR Levels indicator that i found a while back on twitter, and im trying to get it to function on my mobile thinkorswim app because its very helpful. I think it would be possible if i change the clouds to horizontal lines but i really don't know how to go about making that happen. The only lines i really care about are the upper trigger and lower trigger clouds, and maybe the close cloud. Anyways here is the code:
Code:
``````# Saty_ATR_Levels
# Copyright (C) 2022 Saty Mahajan
# Data provided in this script is not financial advice.
#
# Special thanks to Gabriel Viana.
# Based on my own ideas and ideas from Ripster, drippy2hard,
#
# Features:
# - Day, Multiday, Swing, Position trading modes
# - Range against ATR for each period
# - Put and call trigger levels
# - Mid-range level
# - Full-range levels
# - Optional Extension Level

input trading_type = {"Scalp", default "Day", "Multiday", "Swing", "Position", "Long-term"};
input use_options_labels = yes;
input atr_Length = 14;
input trigger_percentage = 0.236;
input use_current_close = no;
input cloud_size = 1.0;
input close_cloud_on = yes;
input lower_trigger_cloud_on = yes;
input lower_middle_cloud_on = yes;
input lower_atr_cloud_on = yes;
input lower_extension_clouds_on = no;
input upper_trigger_cloud_on = yes;
input upper_middle_cloud_on = yes;
input upper_atr_cloud_on = yes;
input upper_extension_clouds_on = no;
input show_info = yes;
input fast_ema = 8;
input pivot_ema = 21;
input slow_ema = 34;

DefineGlobalColor("Previous Close Cloud", Color.WHITE);
DefineGlobalColor("Lower Trigger Cloud", Color.ORANGE);
DefineGlobalColor("Lower Midrange Cloud", Color.GRAY);
DefineGlobalColor("Lower ATR Clouds", Color.WHITE);
DefineGlobalColor("Lower Extension Clouds", Color.GRAY);
DefineGlobalColor("Upper Trigger Cloud", Color.CYAN);
DefineGlobalColor("Upper Midrange Cloud", Color.GRAY);
DefineGlobalColor("Upper ATR Clouds", Color.WHITE);
DefineGlobalColor("Upper Extension Clouds", Color.GRAY);

case "Scalp":
case "Day":
case "Multiday":
case "Swing":
case "Position":
case "Long-term":
}

# Trend
def price = close;
def fast_ema_value = MovAvgExponential(price, fast_ema);
def pivot_ema_value = MovAvgExponential(price, pivot_ema);
def slow_ema_value = MovAvgExponential(price, slow_ema);
def bullish = price >= fast_ema_value and fast_ema_value >= pivot_ema_value and pivot_ema_value >= slow_ema_value;
def bearish = price <= fast_ema_value and fast_ema_value <= pivot_ema_value and pivot_ema_value <= slow_ema_value;

# Data
def previous_close = close(period = trading_period)[if use_current_close then 0 else 1];
def atr = Round(WildersAverage(TrueRange(high(period = trading_period), close(period = trading_period), low(period = trading_period)), atr_Length)[if use_current_close then 0 else 1], 2);
def period_high = Highest(high(period = trading_period), 1);
def period_low = Lowest(low(period = trading_period), 1);
def tr = period_high - period_low;
def tr_percent_of_atr = Round((tr / atr) * 100, 0);
def lower_trigger = previous_close - (trigger_percentage * atr);
def upper_trigger = previous_close + (trigger_percentage * atr);
def lower_atr = previous_close - atr;
def upper_atr = previous_close + atr;
def lower_midrange = previous_close - (atr * 0.618);
def upper_midrange = previous_close + (atr * 0.618);
def lower_extension = (lower_atr) - (atr * 0.236);
def upper_extension = (upper_atr) + (atr * 0.236);
def lower_midrange_extension = (lower_atr) - (atr * 0.618);
def upper_midrange_extension = (upper_atr) + (atr * 0.618);
def lower_2atr_extension = lower_atr - atr;
def upper_2atr_extension = upper_atr + atr;

def rangeNotAvailable = IsNaN(tr);
def atrNotAvailable = IsNaN(atr);
# Labels
AddLabel(show_info,"Trend ",if bullish then Color.GREEN else if bearish then Color.RED else Color.ORANGE);
AddLabel (show_info, (if trading_period == AggregationPeriod.YEAR then "Long-term " else if trading_period == AggregationPeriod.QUARTER then "Position "  else if trading_period == AggregationPeriod.MONTH then "Swing " else if trading_period == AggregationPeriod.WEEK then "Multiday " else if trading_period == AggregationPeriod.FOUR_HOURS then "Scalp " else "Day ") + (if (rangeNotAvailable) then "Range N/A Pre-Market" else if (atrNotAvailable) then " Range - Not Enough Data" else "Range (\$" + Round (tr , 2) + ") is " + Round (tr_percent_of_atr, 0) + "% of ATR (\$" + Round (atr, 2) + ")   ") , (if (rangeNotAvailable or atrNotAvailable) then Color.GRAY else (if tr_percent_of_atr <= 70 then Color.GREEN else if tr_percent_of_atr >= 90 then Color.RED else Color.ORANGE)));
AddLabel (show_info, (if use_options_labels then "Calls" else "Long") + " > \$" + Round (upper_trigger, 2) + " | +1 ATR: \$" + Round (upper_atr, 2) + "   ", GlobalColor("Upper Trigger Cloud"));
AddLabel (show_info, (if use_options_labels then "Puts" else "Short") + " < \$" + Round (lower_trigger, 2) + " | -1 ATR: \$" +  Round (lower_atr, 2) + "   ", GlobalColor("Lower Trigger Cloud"));

def cloud_size_factor = 0.01 * cloud_size;

# Previous Close cloud
AddCloud(if close_cloud_on then (previous_close - (atr * cloud_size_factor / 2)) else Double.NaN, (previous_close + (atr * cloud_size_factor / 2)), GlobalColor("Previous Close Cloud"), GlobalColor("Previous Close Cloud"));

# Trigger clouds
AddCloud(if lower_trigger_cloud_on then lower_trigger else Double.NaN, (lower_trigger - (atr * cloud_size_factor)), GlobalColor("Lower Trigger Cloud"), GlobalColor("Lower Trigger Cloud"));
AddCloud(if upper_trigger_cloud_on then upper_trigger else Double.NaN, (upper_trigger + (atr * cloud_size_factor)), GlobalColor("Upper Trigger Cloud"), GlobalColor("Upper Trigger Cloud"));

# Middle clouds
AddCloud(if lower_middle_cloud_on then lower_midrange else Double.NaN, (lower_midrange - (atr * cloud_size_factor)), GlobalColor("Lower Midrange Cloud"), GlobalColor("Lower Midrange Cloud"));
AddCloud(if upper_middle_cloud_on then upper_midrange else Double.NaN, (upper_midrange + (atr * cloud_size_factor)), GlobalColor("Upper Midrange Cloud"), GlobalColor("Upper Midrange Cloud"));

# +/- 1 ATR clouds
AddCloud(if lower_atr_cloud_on then lower_atr else Double.NaN, (lower_atr - (atr * cloud_size_factor)), GlobalColor("Lower ATR Clouds"), GlobalColor("Lower ATR Clouds"));
AddCloud(if upper_atr_cloud_on then upper_atr else Double.NaN, (upper_atr + (atr * cloud_size_factor)), GlobalColor("Upper ATR Clouds"), GlobalColor("Upper ATR Clouds"));

# Extension clouds
AddCloud(if lower_extension_clouds_on then lower_extension else Double.NaN, (lower_extension - (atr * cloud_size_factor)), GlobalColor("Lower Extension Clouds"), GlobalColor("Lower Extension Clouds"));
AddCloud(if upper_extension_clouds_on then upper_extension else Double.NaN, (upper_extension + (atr * cloud_size_factor)), GlobalColor("Upper Extension Clouds"), GlobalColor("Upper Extension Clouds"));

# Middle Extension clouds
AddCloud(if lower_extension_clouds_on then lower_midrange_extension else Double.NaN, (lower_midrange_extension - (atr * cloud_size_factor)), GlobalColor("Lower Extension Clouds"), GlobalColor("Lower Extension Clouds"));
AddCloud(if upper_extension_clouds_on then upper_midrange_extension else Double.NaN, (upper_midrange_extension + (atr * cloud_size_factor)), GlobalColor("Upper Extension Clouds"), GlobalColor("Upper Extension Clouds"));

# +/- 2 ATR clouds
AddCloud(if lower_extension_clouds_on then lower_2atr_extension else Double.NaN, (lower_2atr_extension - (atr * cloud_size_factor)), GlobalColor("Lower ATR Clouds"), GlobalColor("Lower ATR Clouds"));
AddCloud(if upper_extension_clouds_on then upper_2atr_extension else Double.NaN, (upper_2atr_extension + (atr * cloud_size_factor)), GlobalColor("Upper ATR Clouds"), GlobalColor("Upper ATR Clouds"));``````

+1 on this. Can someone edit the code so this works on mobile?

Thanks in advance - I use SATY's ATR Levels with Chewie's HotZones and find it very useful. I have successfully slightly modified the upper study Chewie provided to allow me to effectively scan for stocks in either the hot or caution zones, which has been working very well. Now, I am trying to figure out how to scan for stocks that are near either the call or put trigger lines from SATY's ATR Levels study. So, I would like it if there was a white dot that was on the close of a candle that is within \$.5 of the call and or put trigger lines and the ability to change the value in the settings of SATY's ATR Levels study without having to rewrite code every time I want to change the value. Then I would like to be able to scan for this white dot so that I can get a list of stocks that are all near the put and call trigger lines. I believe I can figure out how to setup the scan but adding to the code to get the white dot is holding me up.

I was wondering if anyone uses SATY ATR for futures and if you think the levels are off.
Yes, I use them. Personally, I don't worry if the levels don't precisely match his because they are ballpark targets. YMMV Best wishes and happy trading.

Help changing cloud to horizontal line

I've been using this Saty ATR Levels indicator that i found a while back on twitter, and im trying to get it to function on my mobile thinkorswim app because its very helpful. I think it would be possible if i change the clouds to horizontal lines but i really don't know how to go about making that happen. The only lines i really care about are the upper trigger and lower trigger clouds, and maybe the close cloud. Anyways here is the code:
Code:
``````# Saty_ATR_Levels
# Copyright (C) 2022 Saty Mahajan
# Data provided in this script is not financial advice.
#
# Special thanks to Gabriel Viana.
# Based on my own ideas and ideas from Ripster, drippy2hard,
#
# Features:
# - Day, Multiday, Swing, Position trading modes
# - Range against ATR for each period
# - Put and call trigger levels
# - Mid-range level
# - Full-range levels
# - Optional Extension Level

input trading_type = {"Scalp", default "Day", "Multiday", "Swing", "Position", "Long-term"};
input use_options_labels = yes;
input atr_Length = 14;
input trigger_percentage = 0.236;
input use_current_close = no;
input cloud_size = 1.0;
input close_cloud_on = yes;
input lower_trigger_cloud_on = yes;
input lower_middle_cloud_on = yes;
input lower_atr_cloud_on = yes;
input lower_extension_clouds_on = no;
input upper_trigger_cloud_on = yes;
input upper_middle_cloud_on = yes;
input upper_atr_cloud_on = yes;
input upper_extension_clouds_on = no;
input show_info = yes;
input fast_ema = 8;
input pivot_ema = 21;
input slow_ema = 34;

DefineGlobalColor("Previous Close Cloud", Color.WHITE);
DefineGlobalColor("Lower Trigger Cloud", Color.ORANGE);
DefineGlobalColor("Lower Midrange Cloud", Color.GRAY);
DefineGlobalColor("Lower ATR Clouds", Color.WHITE);
DefineGlobalColor("Lower Extension Clouds", Color.GRAY);
DefineGlobalColor("Upper Trigger Cloud", Color.CYAN);
DefineGlobalColor("Upper Midrange Cloud", Color.GRAY);
DefineGlobalColor("Upper ATR Clouds", Color.WHITE);
DefineGlobalColor("Upper Extension Clouds", Color.GRAY);

case "Scalp":
case "Day":
case "Multiday":
case "Swing":
case "Position":
case "Long-term":
}

# Trend
def price = close;
def fast_ema_value = MovAvgExponential(price, fast_ema);
def pivot_ema_value = MovAvgExponential(price, pivot_ema);
def slow_ema_value = MovAvgExponential(price, slow_ema);
def bullish = price >= fast_ema_value and fast_ema_value >= pivot_ema_value and pivot_ema_value >= slow_ema_value;
def bearish = price <= fast_ema_value and fast_ema_value <= pivot_ema_value and pivot_ema_value <= slow_ema_value;

# Data
def previous_close = close(period = trading_period)[if use_current_close then 0 else 1];
def atr = Round(WildersAverage(TrueRange(high(period = trading_period), close(period = trading_period), low(period = trading_period)), atr_Length)[if use_current_close then 0 else 1], 2);
def period_high = Highest(high(period = trading_period), 1);
def period_low = Lowest(low(period = trading_period), 1);
def tr = period_high - period_low;
def tr_percent_of_atr = Round((tr / atr) * 100, 0);
def lower_trigger = previous_close - (trigger_percentage * atr);
def upper_trigger = previous_close + (trigger_percentage * atr);
def lower_atr = previous_close - atr;
def upper_atr = previous_close + atr;
def lower_midrange = previous_close - (atr * 0.618);
def upper_midrange = previous_close + (atr * 0.618);
def lower_extension = (lower_atr) - (atr * 0.236);
def upper_extension = (upper_atr) + (atr * 0.236);
def lower_midrange_extension = (lower_atr) - (atr * 0.618);
def upper_midrange_extension = (upper_atr) + (atr * 0.618);
def lower_2atr_extension = lower_atr - atr;
def upper_2atr_extension = upper_atr + atr;

def rangeNotAvailable = IsNaN(tr);
def atrNotAvailable = IsNaN(atr);
# Labels
AddLabel(show_info,"Trend ",if bullish then Color.GREEN else if bearish then Color.RED else Color.ORANGE);
AddLabel (show_info, (if trading_period == AggregationPeriod.YEAR then "Long-term " else if trading_period == AggregationPeriod.QUARTER then "Position "  else if trading_period == AggregationPeriod.MONTH then "Swing " else if trading_period == AggregationPeriod.WEEK then "Multiday " else if trading_period == AggregationPeriod.FOUR_HOURS then "Scalp " else "Day ") + (if (rangeNotAvailable) then "Range N/A Pre-Market" else if (atrNotAvailable) then " Range - Not Enough Data" else "Range (\$" + Round (tr , 2) + ") is " + Round (tr_percent_of_atr, 0) + "% of ATR (\$" + Round (atr, 2) + ")   ") , (if (rangeNotAvailable or atrNotAvailable) then Color.GRAY else (if tr_percent_of_atr <= 70 then Color.GREEN else if tr_percent_of_atr >= 90 then Color.RED else Color.ORANGE)));
AddLabel (show_info, (if use_options_labels then "Calls" else "Long") + " > \$" + Round (upper_trigger, 2) + " | +1 ATR: \$" + Round (upper_atr, 2) + "   ", GlobalColor("Upper Trigger Cloud"));
AddLabel (show_info, (if use_options_labels then "Puts" else "Short") + " < \$" + Round (lower_trigger, 2) + " | -1 ATR: \$" +  Round (lower_atr, 2) + "   ", GlobalColor("Lower Trigger Cloud"));

def cloud_size_factor = 0.01 * cloud_size;

# Previous Close cloud
AddCloud(if close_cloud_on then (previous_close - (atr * cloud_size_factor / 2)) else Double.NaN, (previous_close + (atr * cloud_size_factor / 2)), GlobalColor("Previous Close Cloud"), GlobalColor("Previous Close Cloud"));

# Trigger clouds
AddCloud(if lower_trigger_cloud_on then lower_trigger else Double.NaN, (lower_trigger - (atr * cloud_size_factor)), GlobalColor("Lower Trigger Cloud"), GlobalColor("Lower Trigger Cloud"));
AddCloud(if upper_trigger_cloud_on then upper_trigger else Double.NaN, (upper_trigger + (atr * cloud_size_factor)), GlobalColor("Upper Trigger Cloud"), GlobalColor("Upper Trigger Cloud"));

# Middle clouds
AddCloud(if lower_middle_cloud_on then lower_midrange else Double.NaN, (lower_midrange - (atr * cloud_size_factor)), GlobalColor("Lower Midrange Cloud"), GlobalColor("Lower Midrange Cloud"));
AddCloud(if upper_middle_cloud_on then upper_midrange else Double.NaN, (upper_midrange + (atr * cloud_size_factor)), GlobalColor("Upper Midrange Cloud"), GlobalColor("Upper Midrange Cloud"));

# +/- 1 ATR clouds
AddCloud(if lower_atr_cloud_on then lower_atr else Double.NaN, (lower_atr - (atr * cloud_size_factor)), GlobalColor("Lower ATR Clouds"), GlobalColor("Lower ATR Clouds"));
AddCloud(if upper_atr_cloud_on then upper_atr else Double.NaN, (upper_atr + (atr * cloud_size_factor)), GlobalColor("Upper ATR Clouds"), GlobalColor("Upper ATR Clouds"));

# Extension clouds
AddCloud(if lower_extension_clouds_on then lower_extension else Double.NaN, (lower_extension - (atr * cloud_size_factor)), GlobalColor("Lower Extension Clouds"), GlobalColor("Lower Extension Clouds"));
AddCloud(if upper_extension_clouds_on then upper_extension else Double.NaN, (upper_extension + (atr * cloud_size_factor)), GlobalColor("Upper Extension Clouds"), GlobalColor("Upper Extension Clouds"));

# Middle Extension clouds
AddCloud(if lower_extension_clouds_on then lower_midrange_extension else Double.NaN, (lower_midrange_extension - (atr * cloud_size_factor)), GlobalColor("Lower Extension Clouds"), GlobalColor("Lower Extension Clouds"));
AddCloud(if upper_extension_clouds_on then upper_midrange_extension else Double.NaN, (upper_midrange_extension + (atr * cloud_size_factor)), GlobalColor("Upper Extension Clouds"), GlobalColor("Upper Extension Clouds"));

# +/- 2 ATR clouds
AddCloud(if lower_extension_clouds_on then lower_2atr_extension else Double.NaN, (lower_2atr_extension - (atr * cloud_size_factor)), GlobalColor("Lower ATR Clouds"), GlobalColor("Lower ATR Clouds"));
AddCloud(if upper_extension_clouds_on then upper_2atr_extension else Double.NaN, (upper_2atr_extension + (atr * cloud_size_factor)), GlobalColor("Upper ATR Clouds"), GlobalColor("Upper ATR Clouds"));``````

Would it be possible to edit this code so the ATR levels are limited to 'x' number of days? Trying to display levels for just yesterday & today.

Thanks!

+1 on this. Can someone edit the code so this works on mobile?
It cannot work on mobile due to the limitations of the mobile architecture not supporting secondary time aggregation.

The levels ATR are based on different timeframes.
Different timeframes cannot be used in a watchlist column.
So no, this script cannot be used in a watchlist.

is it possible to get a scanner for long/short triggers ?

is it possible to get a scanner for long/short triggers ?
The levels ATR are based on different timeframes.
Different timeframes cannot be used in the scan hacker
So no, this script cannot be used in a scanner.

I came up with a mobile work around.
I draw the lines and extend them to the right.
in the morning I just adjust each line to that level for the day and change the start date to the current date.
its very easy once you get the hang of it, takes less then 5 minutes each morning and then your set.
Saty, you are amazing, thanks for all your indicators.

is it possible to get a scanner for long/short triggers ?

paste into the scan hacker custom study

input trigger_percentage = 0.236;
input atr_Length = 14;
def atr = WildersAverage(TrueRange(high , close , low),atr_Length);

def lower_trigger = close[1] - (trigger_percentage * atr);
def upper_trigger = close[1] + (trigger_percentage * atr);

plot triggerlower = close < lower_trigger;
#plot triggerupper = close > upper_trigger;

Last edited by a moderator:

87k+ Posts
309 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?