Join useThinkScript to post your question to a community of 21,000+ developers and traders.
https://usethinkscript.com/threads/support-and-resistance-fractal-pivots-for-thinkorswim.11639/I have tried to search useThinkScript side, but cannot find any reference to Fractal Pivots. Nor does TOS provide any default Fractal Pivots studies.
Given some of the recent discussion on consolidation and Mobius ECI study, for those folks that might be interested to scan the universe of stocks for such setups, I have converted Mobius ECI study into a scan. Two scan conditions are created - one for the bullish case and another for the bearish case. I have also removed extraneous variables not required for the scan.
Tested this on a scan of the S&P 500 (Daily aggregation) with the following results
Bullish scan - 138 hits, e.g. AMZN
Bearish scan - 20 hits e.go. PSX
Please remember that the scanner only expects one plot so comment out the scan plot statement you do not wish.
Here then is the scan code
Code:# ECI Scan # tomsk # 11.25.2019 # Given some of the recent discussion on consolidation and Mobius ECI study, # for those folks that might be interested to scan the universe of stocks for # such setups, I have converted Mobius ECI study into a scan. Two scan conditions # are created - one for the bullish case and another for the bearish case. I # have also removed variables not required for the scan. # Expansion Contraction Indication # Flags: Uses Fractal enregy to locate price compression or flag areas # Mobius # 3.18.2017 # User Inputs input EciLength = 5; #hint EciLength: Length for calculations. input AvgType = AverageType.Simple; #hint AvgType: Average Type input MeanValue = HL2; #hint MeanValue: Point of origen. input betaDev = 4; script G { input p = close; input n = 2; input b = 1.05; def w; def beta; def alpha; def G; w = (2 * Double.Pi / n); beta = (1 - Cos(w)) / (Power(1.414, 2.0 / b) - 1 ); alpha = (-beta + Sqrt(beta * beta + 2 * beta)); G = Power(alpha, 4) * p + 4 * (1 – alpha) * G[1] – 6 * Power( 1 - alpha, 2 ) * G[2] + 4 * Power( 1 - alpha, 3 ) * G[3] - Power( 1 - alpha, 4 ) * G[4]; plot data = G; } # Variables: def bar = barNumber(); def o = g(open, ECIlength, betaDev); def h = g(high, ECIlength, betaDev); def l = g(low, ECIlength, betaDev); def c = g(close, ECIlength, betaDev); def ECI = Log(Sum(Max(h, c[1]) - Min(l, c[1]), ECIlength) / (Highest(h, ECIlength) - Lowest(l, ECIlength))) / Log(ECIlength); def Avg = MovingAverage(AverageType = AvgType, ECI, ECILength); def S1 = if ECI crosses above Avg then MeanValue else S1[1]; def S = ECI > Avg; def SBars = if ECI > Avg then bar else Double.NaN; def StartBar = if ECI crosses above Avg then bar else StartBar[1]; def LastSBar = if ECI crosses below Avg then bar else LastSBar[1]; def PP = if ECI crosses above Avg then MeanValue else PP[1]; def Mean_Limit = if bar != StartBar then bar - StartBar else if bar == StartBar then Double.NaN else Mean_Limit[1]; def SHigh = if ECI crosses above Avg then h else SHigh[1]; def SHighBar = if S and h == SHigh then bar else SHighBar[1]; def SHigh_Limit = if bar == StartBar then Double.NaN else if bar > StartBar then bar - SHighBar else SHigh_Limit[1]; def SLow = if ECI crosses above Avg then l else SLow[1]; def SLowBar = if S and l == SLow then bar else SLowBar[1]; def SLow_Limit = if bar == StartBar then Double.NaN else if bar > StartBar then bar - SLowBar else SLow_Limit[1]; # Comment out (#) the ONE not needed plot BullScan = close crosses above SHigh; #plot BearScan = close crosses below SLow; # ECI Scan
# Comment out the bread-out/ bread-down; Use this instead if looking for a price within the bounds of the study;
plot BetweenScan = close >= SLow and close <= SHigh;
Did not find this in a search. Sorry if it already was posted.
It is a compression study is very fast at showing compression. Has some hints of when compression turns into expansion.
Code:#hint: Expansion Contraction Indicator (ECI): \n ECI Identifies areas of price compression which leads to price expansion. ECI doesn't show the direction of a trend but does indicate when a trend is going to resume (price flagging) or if a change in trend polarity is happening.\n ECI plots the areas where price becomes compressed with colored and clouded bands. The indicator also leaves legacy points in areas of past compression. # ECI is based on the FE algorithm # Original plot style by Mobius # Note: Default Lengths are not optimized. My personal experience has been length ranges between 8 and 13 are generally effective. # Here's another way to look at Fractal Energy. This study plots it on the chart graph with clouded areas for the current price compression, exhaustion area and leaves colored points as a legacy plot for past areas. # Good CSA choices with this study are: # ECI + SuperTrend + Fractal Pivots # ECI + SuperTrend + RSI in Laguerre Time # ECI + SuperTrend + Standard Deviation Bands # ECI + Linear Regression Standard Deviation Bands # This version Modified to filter price to a normalized distribution # User Inputs input EciLength = 14; #hint EciLength: Length for calculations. input AvgLength = 10; #hint AvgLength: Length for smoothing. input AvgType = AverageType.Simple; #hint AvgType: Average Type input MeanValue = HL2; #hint MeanValue: Point of origen. input DisplayPoints = yes; #hint DisplayPoints: No Points. input OnExpansion = yes; #hint OnExpansion: Line extensions. # Variables script g { input data = close; def w = (2 * Double.Pi / 8); def beta = (1 - Cos(w)) / (Power(1.414, 2.0 / 4) - 1 ); def alpha = (-beta + Sqrt(beta * beta + 2 * beta)); def G = Power(alpha, 4) * data + 4 * (1 – alpha) * G[1] – 6 * Power( 1 - alpha, 2 ) * G[2] + 4 * Power( 1 - alpha, 3 ) * G[3] - Power( 1 - alpha, 4 ) * G[4]; plot Line = G; } def o = g(data = open); def h = g(data = high); def l = g(data = low); def c = g(data = close); def bar = BarNumber(); def HMax = Highest(Max(h, c[1]), EciLength); def LMax = Lowest(Min(l, c[1]), EciLength); def TR = HMax - LMax; def ECI = Round((Log(Sum(TrueRange(h, c, l), EciLength) / TR) / Log(EciLength)) / TickSize(), 0) * TickSize(); def Avg = MovingAverage(AverageType = AvgType, ECI, AvgLength); def S1 = if ECI crosses above Avg then MeanValue else S1[1]; def S = ECI > Avg; def SBars = if ECI > Avg then bar else Double.NaN; def StartBar = if ECI crosses above Avg then bar else StartBar[1]; def LastSBar = if ECI crosses below Avg then bar else LastSBar[1]; def PP = if ECI crosses above Avg then MeanValue else PP[1]; def Mean_Limit = if bar != StartBar then bar - StartBar else if bar == StartBar then Double.NaN else Mean_Limit[1]; def SHigh = if ECI crosses above Avg then h else SHigh[1]; def SHighBar = if S and h == SHigh then bar else SHighBar[1]; def SHigh_Limit = if bar == StartBar then Double.NaN else if bar > StartBar then bar - SHighBar else SHigh_Limit[1]; def SLow = if ECI crosses above Avg then l else SLow[1]; def SLowBar = if S and l == SLow then bar else SLowBar[1]; def SLow_Limit = if bar == StartBar then Double.NaN else if bar > StartBar then bar - SLowBar else SLow_Limit[1]; # Internal Script Reference script LinePlot { input LineLimit = 0; input OnExpansion = yes; input data = close; input bar = 0; def ThisBar = HighestAll(bar); def cLine = if bar == ThisBar then data else Double.NaN; def cond1 = CompoundValue(1, if IsNaN(data) then cond1[1] else data, data); plot P = if ThisBar - LineLimit <= bar then HighestAll(cLine) else Double.NaN; plot ExpLine = if OnExpansion and IsNaN(data[-1]) then cond1 else Double.NaN; } # Plots plot SD_Pivot = LinePlot(data = PP, LineLimit = Mean_Limit, OnExpansion = OnExpansion, bar = StartBar).P; plot SD_Pivot_X = LinePlot(data = PP, LineLimit = StartBar).ExpLine; SD_Pivot.SetDefaultColor(Color.CYAN); SD_Pivot_X.SetDefaultColor(Color.CYAN); plot SD_R1 = LinePlot(data = SHigh, LineLimit = SHigh_Limit, OnExpansion = OnExpansion, bar = SHighBar).P; plot SD_R1_X = LinePlot(data = SHigh, LineLimit = SHigh_Limit).ExpLine; SD_R1.SetDefaultColor(Color.Light_GREEN); SD_R1_X.SetDefaultColor(Color.Light_GREEN); plot SD_S1 = LinePlot(data = SLow, LineLimit = SLow_Limit, OnExpansion = OnExpansion, bar = SLowBar).P; plot SD_S1_X = LinePlot(data = SLow, LineLimit = SLow_Limit).ExpLine; SD_S1.SetDefaultColor(Color.Light_RED); SD_S1_X.SetDefaultColor(Color.Light_RED); plot SPlot = if S then S1 #l - (2 * TickSize()) else Double.NaN; SPlot.SetHiding(!DisplayPoints); SPlot.SetPaintingStrategy(PaintingStrategy.POINTS); SPlot.SetLineWeight(1); SPlot.SetDefaultColor(Color.Yellow); addCloud(SD_pivot, SD_R1, CreateColor(50,150,75), CreateColor(50,150,70)); addCloud(SD_S1, SD_pivot, CreateColor(175,0,50), CreateColor(175,0,50)); addCloud(SD_pivot_X, SD_R1_X, CreateColor(50,150,75), CreateColor(50,150,70)); addCloud(SD_S1_X, SD_pivot_X, CreateColor(175,0,50), CreateColor(175,0,50)); # Audible Alerts Alert(ECI crosses below Avg, "Exit", Alert.BAR, Sound.Bell); AddLabel(1, "Energy Level = " + ECI, color.white); # End Code Modified ECI
# MTF Moving Average
input Period = aggregationPeriod.HOUR;
input AvgType = averageType.EXPONENTIAL;
input Length = 50;
input priceclose = close;
plot AVG = MovingAverage(AvgType, close(period = Period), Length);
AVG.setdefaultcolor(color.yellow);
Given the sub scripts iterations, I was not able to create an MTF version on this indicatorHI ALL. Thanks for this great community. Another study that I have found useful for a couple of years now. This bear market (hopefully bottoming already) is the best time to do some "housekeeping and upgrades".
Anyway, I just like to ask the originator poster (and also the community) on how to make this study to project on a MTF (multi-time frame) chart. Cause half of the time I am using a laptop when trading while also my entries/exits on 30min aggregation (or less). I need to see if the price is going in/out of the study range on a single screen setup on an intraday aggregation.
Thank you @MerryDay for taking a stab at it. I'm really at elementary school level in terms of thinkscript coding, but when taking a look at the code it seems it's possible. I've had some success when converting some studies in the past, but I mostly based my adjustments off similar ones. This one is pretty unique (IMHO) and beyond my grade.Given the sub scripts iterations, I was not able to create an MTF version on this indicator
@BenTen @MerryDay Can labels be created for the ECI to show if when it's in contraction if it's trending more bearish or bullish, I figured it was possible since you can scan for either of the two.@Miket The notes in that indicator made it very clear what it does.
I don't think it shows support or resistance. Basically just where price consolidate and that suggests the stock will be making a move one way or the other soon.
## Current mod by NeoEon
## For use in watchlist columns as label; Requisite: Daily aggregation only;
# Original: ECI Scan
# tomsk
# 11.25.2019
# https://usethinkscript.com/threads/eci-gaussian-indicator-for-thinkorswim.1160/
# Given some of the recent discussion on consolidation and Mobius ECI study,
# for those folks that might be interested to scan the universe of stocks for
# such setups, I have converted Mobius ECI study into a scan. Two scan conditions
# are created - one for the bullish case and another for the bearish case. I
# have also removed variables not required for the scan.
# Expansion Contraction Indication
# Flags: Uses Fractal enregy to locate price compression or flag areas
# Mobius
# 3.18.2017
# User Inputs
input EciLength = 8; #hint EciLength: Length for calculations.
input AvgType = AverageType.Exponential; #hint AvgType: Average Type
input MeanValue = HL2; #hint MeanValue: Point of origen.
input betaDev = 4;
script G {
input p = close;
input n = 2;
input b = 1.05;
def w;
def beta;
def alpha;
def G;
w = (2 * Double.Pi / n);
beta = (1 - Cos(w)) / (Power(1.414, 2.0 / b) - 1 );
alpha = (-beta + Sqrt(beta * beta + 2 * beta));
G = Power(alpha, 4) * p +
4 * (1 – alpha) * G[1] – 6 * Power( 1 - alpha, 2 ) * G[2] +
4 * Power( 1 - alpha, 3 ) * G[3] - Power( 1 - alpha, 4 ) * G[4];
plot data = G;
}
# Variables:
def bar = barNumber();
def o = g(open, ECIlength, betaDev);
def h = g(high, ECIlength, betaDev);
def l = g(low, ECIlength, betaDev);
def c = g(close, ECIlength, betaDev);
def ECI = Log(Sum(Max(h, c[1]) - Min(l, c[1]), ECIlength) /
(Highest(h, ECIlength) - Lowest(l, ECIlength))) /
Log(ECIlength);
def Avg = MovingAverage(AverageType = AvgType, ECI, ECILength);
def S1 = if ECI crosses above Avg
then MeanValue
else S1[1];
def S = ECI > Avg;
def SBars = if ECI > Avg
then bar
else Double.NaN;
def StartBar = if ECI crosses above Avg
then bar
else StartBar[1];
def LastSBar = if ECI crosses below Avg
then bar
else LastSBar[1];
def PP = if ECI crosses above Avg
then MeanValue
else PP[1];
def Mean_Limit = if bar != StartBar
then bar - StartBar
else if bar == StartBar
then Double.NaN
else Mean_Limit[1];
def SHigh = if ECI crosses above Avg
then h
else SHigh[1];
def SHighBar = if S and
h == SHigh
then bar
else SHighBar[1];
def SHigh_Limit = if bar == StartBar
then Double.NaN
else if bar > StartBar
then bar - SHighBar
else SHigh_Limit[1];
def SLow = if ECI crosses above Avg
then l
else SLow[1];
def SLowBar = if S and
l == SLow
then bar
else SLowBar[1];
def SLow_Limit = if bar == StartBar
then Double.NaN
else if bar > StartBar
then bar - SLowBar
else SLow_Limit[1];
# Comment out (#) the ONE not needed
## plot BullScan = close crosses above SHigh;
# or
## plot BearScan = close crosses below SLow;
## plot BetweenScan1 = Between (close, SHigh,SLow);
# plot BetweenScan = close >= SLow and close <= SHigh;
## plot status = if close >= SLow and close <= SHigh or close < SLow then 1 else 0;
plot status = if close > SHigh then 1 else if close >= SLow and close <= SHigh then 0 else -1;
## status.AssignValueColor(if status == 1 then Color.DARK_Green else Color.Black);
status.AssignValueColor(if status == 1 then Color.Dark_Orange else if status == 0 then Color.Green else Color.Dark_Red);
AssignBackgroundColor(if status == 1 then Color.Dark_Orange else if status ==0 then Color.Green else Color.Red);
Source: https://usethinkscript.com/threads/eci-gaussian-indicator-for-thinkorswim.1160/;
@NeoEon thanks this will most def help with what I'm wanting to see.ECIs (aka consolidation) are by definition are in sideways movement (not in upward or downward direction). The overall trend you either can see on the chart itself or by scanning for recent % change for X number of trading days. Or some other trend scanner.
Having said that, here's a column label that I use. Green indicates current price is within the consolidation range, Orange is above, Red is below. I use this to easily sort my universe of tickers with recent significant movement and find which are within consolidation. Much faster than the scanner itself.
Code:## Current mod by NeoEon ## For use in watchlist columns as label; Requisite: Daily aggregation only; # Original: ECI Scan # tomsk # 11.25.2019 # https://usethinkscript.com/threads/eci-gaussian-indicator-for-thinkorswim.1160/ # Given some of the recent discussion on consolidation and Mobius ECI study, # for those folks that might be interested to scan the universe of stocks for # such setups, I have converted Mobius ECI study into a scan. Two scan conditions # are created - one for the bullish case and another for the bearish case. I # have also removed variables not required for the scan. # Expansion Contraction Indication # Flags: Uses Fractal enregy to locate price compression or flag areas # Mobius # 3.18.2017 # User Inputs input EciLength = 8; #hint EciLength: Length for calculations. input AvgType = AverageType.Exponential; #hint AvgType: Average Type input MeanValue = HL2; #hint MeanValue: Point of origen. input betaDev = 4; script G { input p = close; input n = 2; input b = 1.05; def w; def beta; def alpha; def G; w = (2 * Double.Pi / n); beta = (1 - Cos(w)) / (Power(1.414, 2.0 / b) - 1 ); alpha = (-beta + Sqrt(beta * beta + 2 * beta)); G = Power(alpha, 4) * p + 4 * (1 – alpha) * G[1] – 6 * Power( 1 - alpha, 2 ) * G[2] + 4 * Power( 1 - alpha, 3 ) * G[3] - Power( 1 - alpha, 4 ) * G[4]; plot data = G; } # Variables: def bar = barNumber(); def o = g(open, ECIlength, betaDev); def h = g(high, ECIlength, betaDev); def l = g(low, ECIlength, betaDev); def c = g(close, ECIlength, betaDev); def ECI = Log(Sum(Max(h, c[1]) - Min(l, c[1]), ECIlength) / (Highest(h, ECIlength) - Lowest(l, ECIlength))) / Log(ECIlength); def Avg = MovingAverage(AverageType = AvgType, ECI, ECILength); def S1 = if ECI crosses above Avg then MeanValue else S1[1]; def S = ECI > Avg; def SBars = if ECI > Avg then bar else Double.NaN; def StartBar = if ECI crosses above Avg then bar else StartBar[1]; def LastSBar = if ECI crosses below Avg then bar else LastSBar[1]; def PP = if ECI crosses above Avg then MeanValue else PP[1]; def Mean_Limit = if bar != StartBar then bar - StartBar else if bar == StartBar then Double.NaN else Mean_Limit[1]; def SHigh = if ECI crosses above Avg then h else SHigh[1]; def SHighBar = if S and h == SHigh then bar else SHighBar[1]; def SHigh_Limit = if bar == StartBar then Double.NaN else if bar > StartBar then bar - SHighBar else SHigh_Limit[1]; def SLow = if ECI crosses above Avg then l else SLow[1]; def SLowBar = if S and l == SLow then bar else SLowBar[1]; def SLow_Limit = if bar == StartBar then Double.NaN else if bar > StartBar then bar - SLowBar else SLow_Limit[1]; # Comment out (#) the ONE not needed ## plot BullScan = close crosses above SHigh; # or ## plot BearScan = close crosses below SLow; ## plot BetweenScan1 = Between (close, SHigh,SLow); # plot BetweenScan = close >= SLow and close <= SHigh; ## plot status = if close >= SLow and close <= SHigh or close < SLow then 1 else 0; plot status = if close > SHigh then 1 else if close >= SLow and close <= SHigh then 0 else -1; ## status.AssignValueColor(if status == 1 then Color.DARK_Green else Color.Black); status.AssignValueColor(if status == 1 then Color.Dark_Orange else if status == 0 then Color.Green else Color.Dark_Red); AssignBackgroundColor(if status == 1 then Color.Dark_Orange else if status ==0 then Color.Green else Color.Red); Source: https://usethinkscript.com/threads/eci-gaussian-indicator-for-thinkorswim.1160/;
Hi @Dupre, I don't see any green or red levels from this indicator? Only see yellow dots? How can I enable the green and red levels in the script? Thanks in Advance.@tome10 At the top of the code, Mobius suggests other indicators (SuperTrend, RSI, Deviation Bands, Linear Regression, etc ...) to use in conjunction with the ECI study. I've previously seen Mobius say that he will go long at the lowest level (default color is red) of the ECI on an uptrend and go short at the highest level (default color is green) in a downtrend.
Hopefully this helps clarify some.
No the Expansion & Compression Indicator E.C.I will not repaint as the lengths are constant.But does ECI Gaussian Indicators yellow dots repaint ie, do they get disappeared?
don't see any green or red levels from this indicator? Only see yellow dots? How can I enable the green and red levels in the script? Thanks in Advance.
@Musk335im3 The following link looks to be for an MTF version of ECI that Mobius posted.HI ALL. Thanks for this great community. Another study that I have found useful for a couple of years now. This bear market (hopefully bottoming already) is the best time to do some "housekeeping and upgrades".
Anyway, I just like to ask the originator poster (and also the community) on how to make this study to project on a MTF (multi-time frame) chart. Cause half of the time I am using a laptop when trading while also my entries/exits on 30min aggregation (or less). I need to see if the price is going in/out of the study range on a single screen setup on an intraday aggregation.
As a reference, I am posting a picture below of the SPY where the left image has the ECI study with some moving averages at daily aggregation. The right image, on the other hand, at 30 minute aggregation also has the daily 8 and 21 EMAs projected to it via MTF. I drew some lines (green, yellow, and red) to simulate what I was trying to achieve with the ECI study (similar to the 8, 21 MTF EMA's), but with hundreds of charts to look at, it's a bit taxing to do this manually.
I'm also posting the code below of the moving average MTF for reference. My thinkscript coding skills is still pretty amateurish to be able to combine the two (hopefully with Clouds). Though I tried with no luck.
Thank you in advance.
@horserider @theLEMband @SleepyZ
View attachment 15032
Code:# MTF Moving Average input Period = aggregationPeriod.HOUR; input AvgType = averageType.EXPONENTIAL; input Length = 50; input priceclose = close; plot AVG = MovingAverage(AvgType, close(period = Period), Length); AVG.setdefaultcolor(color.yellow);
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
Gaussian Rainbow MA Indicator for ThinkorSwim | Indicators | 13 | ||
Repaints Cup and Handle Indicator for ThinkorSwim | Indicators | 24 | ||
The Ultimate Buy and Sell Indicator for ThinkOrSwim | Indicators | 5 | ||
Z-Score Probability Indicator for ThinkOrSwim | Indicators | 26 | ||
HTF PO3 Indicator For ThinkOrSwim | Indicators | 42 |
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.