Join useThinkScript to post your question to a community of 21,000+ developers and traders.
No, the Supertrend is not a "repainter"should not 'repaints' be appended to the title of this one?
What needs to be smoother to adjust the buy sell arrows to be more restrictive?Supertrend CCI ATR Trend Enchanced
This is the script from post#1 to which I added Mobius's Supertrend Cycle Statistics Labels (many thanks to @sunnybabu, who found these on TOS OneNote). I haven't had time to see how having these statistics will affect my trading, yet. But I find them interesting.
Ruby:# SuperTrend CCI ATR Trend # tomsk # 11.18.2019 # V1.0 - 08.10.2019 - dtek - Initial release of SuperTrend CCI ATR Trend # V2.0 - 11.18.2019 - tomsk - Modified the logic, cleaned up code for consistency # SUPERTREND BY MOBIUS AND CCI ATR TREND COMBINED INTO ONE CHART INDICATOR, # BOTH IN AGREEMENT IS A VERY POWERFUL SIGNAL IF TRENDING. VERY GOOD AT CATCHING # REVERSALS. WORKS WELL ON 1 AND 5 MIN CHARTS. PLOT IS THE COMBINATION LOWEST # FOR UPTREND AND HIGHEST OF THE DOWNTREND. DOTS COLORED IF BOTH IN AGREEMENT # OR GREY IF NOT - 08/10/2019 DTEK # Supertrend, extracted from Mobius original code input ST_Atr_Mult = 1.0; # was .70 input ST_nATR = 4; input ST_AvgType = AverageType.HULL; input ShowLabel = yes; def c = close; def v = volume; def ATR = MovingAverage(ST_AvgType, TrueRange(high, close, low), ST_nATR); def UP = HL2 + (ST_Atr_Mult* ATR); def DN = HL2 + (-ST_Atr_Mult * ATR); def ST = if close < ST[1] then UP else DN; # CCI_ATR measures distance from the mean. Calculates a trend # line based on that distance using ATR as the locator for the line. # Credit goes to Mobius for the underlying logic input lengthCCI = 50; # Was 20 input lengthATR = 21; # Was 4 input AtrFactor = 1.0; # Was 0.7 def ATRCCI = Average(TrueRange(high, close, low), lengthATR) * AtrFactor; def price = close + low + high; 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], HL2 - ATRCCI) else Min(MT1[1], HL2 + ATRCCI); # Alignment of Supertrend and CCI ATR indicators def Pos_State = close > ST and close > MT1; def Neg_State = close < ST and close < MT1; # Combined Signal Approach - Supertrend and ATR CCI plot CSA = MT1; CSA.AssignValueColor(if Pos_State then Color.CYAN else if Neg_State then Color.MAGENTA else Color.YELLOW); # Buy/Sell Signals using state transitions def BuySignal = (!Pos_State[1] and Pos_State); def SellSignal = !Neg_State[1] and Neg_State; # Buy/Sell Arrows plot BuySignalArrow = if BuySignal then 0.995 * MT1 else Double.NaN; BuySignalArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP); BuySignalArrow.SetDefaultColor(Color.CYAN); BuySignalArrow.SetLineWeight(5); plot SellSignalArrow = if SellSignal then 1.005 * MT1 else Double.NaN; SellSignalArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN); SellSignalArrow.SetDefaultColor(Color.PINK); SellSignalArrow.SetLineWeight(5); # Candle Colors AssignPriceColor(if Pos_State then Color.GREEN else if Neg_State then Color.RED else Color.YELLOW); # End SuperTrend CCI ATR Trend def upBars = if c < ST then upBars[1] + 1 else upBars[1]; def upCycles = if c < ST and c[1] > ST[1] then upCycles[1] + 1 else upCycles[1]; def dnBars = if c > ST then dnBars[1] + 1 else dnBars[1]; def dnCycles = if c > ST and c[1] < ST[1] then dnCycles[1] + 1 else dnCycles[1]; def upCycleCount = upBars / upCycles; def dnCycleCount = dnBars / dnCycles; def thisCycle = if c < ST and c[1] > ST[1] then 1 else if c < ST then thisCycle[1] + 1 else if c > ST and c[1] < ST[1] then 1 else if c > ST then thisCycle[1] + 1 else thisCycle[1]; def Volup = (fold i = 0 to thisCycle do if i > 0 then Volup[1] + v else Volup[1]) / thisCycle; DefineGlobalColor("LabelRed", CreateColor(225, 0, 0)) ; DefineGlobalColor("LabelGreen", CreateColor(0, 165, 0)) ; AddLabel(ShowLabel, "Up Bars = " + upBars + "; " + " Up Cycles = " + upCycles + "; " + " Dn Bars = " + dnBars + "; " + " Dn Cycles = " + dnCycles + "; " , if c < ST then GlobalColor("LabelRed") else GlobalColor("LabelGreen") ); #.... This portion of code modofies by jhf AddLabel(ShowLabel, " Avg Up Cycle Count = " + Round(upCycleCount, 0) + " Avg Dn Cycle Count = " + Round(dnCycleCount, 0) + " This Cycle = " + thisCycle, if c < ST then GlobalColor("LabelRed") else GlobalColor("LabelGreen") ); #.... This portion of code modofies by jhf # End Code SuperTrend
What needs to be smoother to adjust the buy sell arrows to be more restrictive?
HI ! Do you have this indicator without the color on the candle ?Thank you in advance
# Candle Colors
AssignPriceColor(if Pos_State then Color.GREEN
else if Neg_State then Color.RED
else Color.YELLOW);
# Candle Colors
input PaintCandles = no ;
AssignPriceColor(if !PaintCandles then color.current else
if Pos_State then Color.GREEN
else if Neg_State then Color.RED
else Color.YELLOW);
Can someone post the code to add an audible alarm when the buy or sell signal is plotted, Thanks
Alert(!Pos_State[1] and Pos_State, "BuySignal", Alert.Bar, Sound.ding);
Alert(!Neg_State[1] and Neg_State, "SellSignal", Alert.Bar, Sound.ring);
I get the following error:Add this code snippet to the bottom of your study:
These are alerts written into studies. They alert ONLY for charts / grids currently populating your workspace.
They cannot be sent to phone/email. They cannot have custom sounds.
https://usethinkscgript.com/resources/how-to-add-alert-script-to-thinkorswim-indicators.9/
https://tlc.thinkorswim.com/center/howToTos/thinkManual/MarketWatch/Alerts/studyalerts
I get the following error:
No such variable: Pos_State at 67:8
No such variable: Pos_State at 67:25
Alert(!Pos_State[1] and Pos_State, "BuySignal", Alert.Bar, Sound.ding);
Alert(!Neg_State[1] and Neg_State, "SellSignal", Alert.Bar, Sound.ring);
plot BuySignal = (!Pos_State[1] and Pos_State);
#plot SellSignal = !Neg_State[1] and Neg_State;
#plot BuySignal = (!Pos_State[1] and Pos_State);
plot SellSignal = !Neg_State[1] and Neg_State;
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
L | Supertrend CCI ATR in 1 Plot For Mobile For ThinkOrSwim | Indicators | 82 | |
S | Smart Supertrend For ThinkOrSwim | Indicators | 13 | |
M | SuperTrend Oscillator [LUX] For ThinkOrSwim | Indicators | 7 | |
B | SuperTrend TradingView Look-A-Like For ThinkOrSwim | Indicators | 64 | |
R | SuperTrend Yahoo Finance Type for ThinkorSwim | Indicators | 51 |
Start a new thread and receive assistance from our community.
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.
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.