# SuperTrend CCI ATR Base
# hguru | Paris | BLT
# 5.27.2019
# Paris: I dissected the ST Supertrend CCI ATR study hguru posted earlier,
# this combo study is a mashup of three major components (1) Super Trend
# Syracuse + BLT Extensions (2) Mobius CCI ATR Trendline and (3) Combo
# Additions from Ghost. I have sectionalized the study, moved some of the
# variable/input definitions to the appropriate segment, and inserted the
# headers for any future work surrounding this study. Loaded it, and it
# works great.
#
# Paris: From an earlier request from hguru, I coordinated an MTF approach
# to this study with "extensive" collaboration from BLT. The code has been
# reorganized as well as introduced other mods to accomodate a MTF look.
#
# Due to the complexities of the info being processed, the approach taken
# does not streamline combining the MTF in a single study as found in many
# other MTF studies previously posted. Rather, we have implemented this
# MTF using the following two studies
#
# [1] SuperTrend CCI ATR Base
# [2] SuperTrend CCI ATR HigherAgg
#
# The 'base' study is used with possible settings made for the chart agg
# while the 'higher agg' study is configured for the type of settings one
# wants for those higher aggs. There are very slight differences between
# these two studies.
#
# To run through an illustration, for a 5m/15m/30m MTF setup, we have a
# 'base' set at 5m with two 'higher agg' set at 15m and 30m. For an actual
# chart setup, please refer to the attached tos.mx link.
#
# If you'd like an alternate MTF setup, say 4hour, Day, and Week, set the
# base aggregation to 4h, and two instances of the higher aggregation study,
# one to Day, and the other to Week. You get the idea.
#
# There is a workaround for the entry/exit arrows/bubbles and vertical
# lines to only display the first bar of the 'higher agg' being displayed
# on the 'lower agg'. Usually, when a condition is met on a 'higher agg'
# being displayed on the 'lower agg', an arrow, bubble or vertical is
# displayed on each bar of the 'lower agg' for the 'higher agg' period.
input agg = AggregationPeriod.FIVE_MIN;
def c = close(period = agg);
def h = high(period = agg);
def l = low(period = agg);
def pricedata = hl2(period = agg);
input pricecolor = {none, default combopricecolor, stpricecolor, CCIATRPriceColor};
input showentrybubble = yes;
input number_entry_bubbles_tobe_displayed = 3;
input showlocationbubble = no;
input showpositionbubble = no;
input show_cloud = yes;
input show_vertLine = yes;
input show_entryarrows = yes;
DefineGlobalColor("TrendUp", CreateColor(0, 255, 255));
DefineGlobalColor("TrendDown", CreateColor(0, 102, 255));
# Super Trend Syracuse + BLT Extensions + PSAR
# Syracuse
# 10.29.2018
# This SuperTrend might be the best one as it does not
# sit on top of a candle it gives room to make decisions
#============================= SuperTrend 2016 ===========================#
#==================== Translation for TOS by Syracusepro =================#
input Factor = 1.3;
input Pd = 60;
input Lookback = 3;
def atr_st = Average(TrueRange(h, c, l), Pd);
def Up = pricedata[Lookback] - (Factor * atr_st);
def Dn = pricedata[Lookback] + (Factor * atr_st);
def TrendUp = if c > TrendUp[1] then Max(Up, TrendUp[1]) else Up;
def TrendDown = if c < TrendDown[1] then Min(Dn, TrendDown[1]) else Dn;
def Trend = if c > TrendDown[1] then 1 else if c < TrendUp[1] then -1 else (Trend[1]);
def Trendbn = if c > TrendDown[1] then BarNumber() else if c < TrendUp[1] then BarNumber() else (Trendbn[1]);
def Trendc = if c > TrendDown[1] then c else if c < TrendUp[1] then c else (Trendc[1]);
plot Tsl = if Trend == 1 then TrendUp else TrendDown;
Tsl.AssignValueColor(if Trend == 1 then GlobalColor("TrendUp") else GlobalColor("TrendDown"));
Tsl.SetLineWeight(1);
plot entryArrow = (if Trend == 1 and Trend[1] == -1 then First(Trendbn) else Double.NaN); #Up Entry Arrow
entryArrow.SetDefaultColor(Color.WHITE);
entryArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
entryArrow.SetHiding(!show_entryarrows);
plot exitArrow = (if Trend == -1 and Trend[1] == 1 then First(Trendbn) else Double.NaN); #Down Entry Arrow
exitArrow.SetDefaultColor(Color.YELLOW);
exitArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
exitArrow.SetHiding(!show_entryarrows);
#========================== End SuperTrend 2016 ===========================#
# CCI_ATR Trendline
# Mobius | Syracusepro
# Chat room request 01.28.2016
# 10.31.2018
# CCI is a study that measures distance from the mean. This study plots
# a trend line based on that distance using ATR as the locator for the line.
input lengthCCI = 20;
input lengthATR = 4;
input AtrFactor = 0.7;
def ATRcci = Average(TrueRange(h, c, l), lengthATR) * AtrFactor;
def price = c + l + h;
def linDev = LinDev(price, lengthCCI);
def CCI = if linDev == 0
then 0
else (price - Average(price, lengthCCI)) / linDev / 0.015;
def MT1 = if CCI > 0
then Max(MT1[1], pricedata - ATRcci)
else Min(MT1[1], pricedata + ATRcci);
plot data = MT1;
data.AssignValueColor(if c < MT1 then Color.RED else Color.GREEN);#TAKEN FROM SUPERTREND AND APPLIED ACCORDING THE VARIABLES FOR GREEN, RED LINE -----#
# End Code CCI_ATR Trend
########################################################
# Combo Additions
# Ghost / Hguru
# 2.3.2019
def ComboUpTrend = data > Tsl;
def ComboDnTrend = data < Tsl;
def crossup = ComboUpTrend == 1 and ComboUpTrend[1] <> 1;
def crossdn = ComboDnTrend == 1 and ComboDnTrend[1] <> 1;
AddCloud(if show_cloud and ComboUpTrend == 1 then data
else Double.NaN, if show_cloud and ComboUpTrend then Tsl
else Double.NaN, GlobalColor("TrendUp"), GlobalColor("TrendUp"));
AddCloud(if show_cloud and ComboDnTrend == 1 then Tsl
else Double.NaN, if show_cloud and ComboDnTrend == 1 then data
else Double.NaN, GlobalColor("TrendDown"), GlobalColor("TrendDown"));
AddVerticalLine(show_vertLine and entryarrow , astext(c), Color.UPTICK, Curve.POINTS);
AddVerticalLine(show_vertLine and exitarrow, astext(c), Color.DOWNTICK, Curve.POINTS);
################################################################
#Price Color
#Combo pricecolor
AssignPriceColor(if pricecolor == pricecolor.combopricecolor
then if ComboUpTrend == 1
then Color.GREEN
else if ComboDnTrend == 1 then Color.RED
else Color.GRAY else Color.CURRENT);
#Supertrend pricecolor
AssignPriceColor(if pricecolor == pricecolor.stpricecolor
then if !IsNaN(entryArrow)
then Color.WHITE
else if !IsNaN(exitArrow)
then Color.YELLOW
else if Trend == 1
then Color.GREEN
else if Trend == -1 then Color.RED
else Color.CURRENT else Color.CURRENT);
#CCI ATR pricecolor
AssignPriceColor(if pricecolor == pricecolor.CCIATRPriceColor and c < MT1
then GlobalColor("TrendDown")
else if pricecolor == pricecolor.CCIATRPriceColor and c > MT1
then GlobalColor("TrendUp")
else Color.CURRENT);
#################################################################
#Bubbles
#Buy/Sell Bubbles
input buysell_bubblemoversideways = 0;
def bm = buysell_bubblemoversideways + 1;
input buysell_bubblemoverupdown = 10;
def dataCount = CompoundValue(1, if !IsNaN(entryArrow) or !IsNaN(exitArrow)
then dataCount[1] + 1
else dataCount[1], 0);
def HUp = if entryarrow then l else double.nan ;
def HDn = if exitarrow then h else double.nan;
AddChartBubble(showentrybubble and crossdn and HighestAll(dataCount) - dataCount <= number_entry_bubbles_tobe_displayed - 1, hdn + ticksize()*buysell_bubblemoverupdown, agg/60000 + " min\nSell @ " + astext(c), Color.MAGENTA, yes);
AddChartBubble(showentrybubble and crossup and HighestAll(dataCount) - dataCount <= number_entry_bubbles_tobe_displayed - 1, hup-ticksize()*buysell_bubblemoverupdown, agg/60000 + " min\nBuy @ " + astext(c), Color.YELLOW, no);
#Location Bubble - Supertrend
input Location_Horizontal = 3;
input Location_Vertical = 0;
def X_h = Location_Horizontal;
def Y_v = Location_Vertical;
def X_h1 = X_h + 1;
input Location_bubbledecimal = 2;
AddChartBubble(showlocationbubble and IsNaN(c[X_h]) and !IsNaN(c[X_h1]), close[X_h1] + TickSize() * Y_v, "ST: " + Round(Tsl[X_h1], Location_bubbledecimal), if Trend[X_h1] == 1 then Color.GREEN else
Color.PINK, no);#if Trend[X_h1] == -1 then Color.MAGENTA else Color.WHITE, no);
#Position Bubble - Supertrend
input Position_bubblemoverside = 3;
def bubm = Position_bubblemoverside + 1;
input Position_bubblemoverVert = 0;
input Position_bubbledec = 2;
AddChartBubble(showpositionbubble and IsNaN(close[Position_bubblemoverside]) and !IsNaN(close[bubm]), Tsl[bubm] + Position_bubblemoverVert * TickSize(), "ST " + Round(Tsl[bubm], Position_bubbledec), if Tsl[bubm]
< data[bubm] then Color.MAGENTA else Color.YELLOW, if Tsl[bubm] < data[bubm] then no else yes);
#Position Bubble - CCI
AddChartBubble(showpositionbubble and IsNaN(close[Position_bubblemoverside]) and !IsNaN(close[bubm]), data[bubm] + Position_bubblemoverVert * TickSize(), "CCI " + Round(data[bubm], Position_bubbledec), if data
[bubm] < Tsl[bubm] then Color.MAGENTA else Color.YELLOW, if data[bubm] < Tsl[bubm] then yes else no);
# END STUDY