# Fractal Pivot points Strategy Mobile by Mobius

#### OptionsPirate

##### New member
Hello everyone, I am new here and don't have any experience in coding, it's like a foreign language to me, lol. I was looking for some help that would be greatly appreciated.

I am not sure where I found this code but I would like to see if I can get some help adding alerts when the arrows paint. And if possible, an option in the input window to turn them off and on.

On a side note, is there a script out there for a price-line that changes colors according to direction? e.g., red and green

Any help would be much appreciated. Thank you... here is the code.

Code:
``````# Fractal Pivot Strategy Mobile
# Mobius
# V01.11.2018
#Hint: Mobile applications don't always hold painting strategies as designed in the code. It may be necessary to manually change line types and arrow configurations in the User Interface.

# User Inputs
input n = 8;
input FractalEnergyLength = 8;
input FractalEnergyThreshold = .68;
input AtrMult = .70;
input nATR = 4;
input AvgType = AverageType.HULL;

# Variables
def o = open;
def h = high;
def l = low;
def c = close;
def bar = BarNumber();
def TS = TickSize();
def nan = double.nan;
def ATR = Round((MovingAverage(AvgType, TrueRange(h, c, l), nATR)) / TS, 0) * TS;
def risk = if Between(c, 0, 1500)
then ATR
else if Between(c, 1500, 3500)
then 2
else if Between(c, 3500, 5500)
then 4
else 6;
def FE = Log(Sum((Max(h, c) - Min(l, c)), FractalEnergyLength) /
(Highest(h, FractalEnergyLength) - Lowest(l, FractalEnergyLength)))
/ Log(FractalEnergyLength);
# Parent Aggregation Pivot High
# Pivot High Variables
def p_hh = fold i = 1 to n + 1
with p = 1
while p
do h > GetValue(h, -1);
def p_PivotH = if (bar > n and
h == Highest(h, n) and
p_hh)
then h
else NaN;
def p_PHValue = if !IsNaN(p_PivotH)
then p_PivotH
else p_PHValue;
def p_PHBar = if !IsNaN(p_PivotH)
then bar
else nan;
# Pivot High and Pivot High Exit Variables
# Pivot High Variables
def hh = fold ii = 1 to n + 1
with pp = 1
while pp
do h > GetValue(h, -1);
def PivotH = if (bar > n and
h == Highest(h, n) and
hh)
then h
else Double.NaN;
def PHValue = if !IsNaN(PivotH)
then PivotH
else PHValue;
def PHBar = if !IsNaN(PivotH)
then bar
else nan;
# Pivot High Exit Variables
def PHExit = if (bar > n and
h == Highest(h, n) and
hh)
then if l < l
then l
else fold r = 0 to 20
with a = NaN
while IsNaN(a)
do if GetValue(l, r) < l
then GetValue(l, r)
else NaN
else Double.NaN;
def PHExitValue = if !IsNaN(PHExit)
then PHExit
else PHExitValue;
def PHExitBar = if (bar > n and
h == Highest(h, n) and
hh)
then if l < l
then bar - 1
else fold d = 0 to 20
with y = NaN
while IsNaN(y)
do if GetValue(l, d) < l
then GetValue(bar - 1, d)
else NaN
else NaN;
# Pivot Low and Pivot Low Entry Variables
# Parent Pivot Low Variables
def p_ll = fold j = 1 to n + 1
with q = 1
while q
do l < GetValue(l, -1);
def p_PivotL = if (bar > n and
l == Lowest(l, n) and
p_ll)
then l
else NaN;
def p_PLValue = if !IsNaN(p_PivotL)
then p_PivotL
else p_PLValue;
def p_PLBar = if !IsNaN(p_PivotL)
then bar
else nan;
# Pivot Low Variables
def ll = fold jj = 1 to n + 1
with qq = 1
while qq
do l < GetValue(l, -1);
def PivotL = if (bar > n and
l == Lowest(l, n) and
ll)
then l
else NaN;
def PLValue = if !IsNaN(PivotL)
then PivotL
else PLValue;
def PLBar = if !IsNaN(PivotL)
then bar
else nan;
# Pivot Low Entry Variables
def PLEntry = if (bar > n and
l == Lowest(l, n) and
ll)
then if h > h
then h
else fold t = 0 to 20
with w = NaN
while IsNaN(w)
do if GetValue(h, t) > h
then GetValue(h, t)
else NaN
else NaN;
def PLEntryValue = if !IsNaN(PLEntry)
then PLEntry
else PLEntryValue;
def PLEntryBar =  if (bar > n and
l == Lowest(l, n) and
ll)
then if h > h
then bar - 1
else fold u = 0 to 20
with z = NaN
while IsNaN(z)
do if GetValue(h, u) > h
then GetValue(bar - 1, u)
else NaN
else NaN;
# Plots
plot p_R1 = if bar >= HighestAll(p_PHBar)
then HighestAll(if isNAN(close[-1])
then p_PHValue
else nan)
else nan;
p_R1.SetStyle(Curve.SHORT_DASH);
p_R1.SetLineWeight(3);
p_R1.SetDefaultColor(Color.GRAY);
plot R1 = if bar >= HighestAll(PHBar)
then HighestAll(if isNaN(close[-1])
then PHValue
else nan)
else nan;
R1.SetDefaultColor(Color.WHITE);
plot R1exitPoint = if bar >= HighestAll(PHexitBar)
then HighestAll(if isNaN(close[-1])
then PHExitValue
else nan)
else nan;
R1exitPoint.SetDefaultColor(Color.RED);
plot R1ShortTarget1 = if bar >= HighestAll(PHexitBar)
then HighestAll(if isNaN(close[-1])
then PHExitValue - risk
else nan)
else nan;
R1ShortTarget1.SetStyle(Curve.LONG_DASH);
R1ShortTarget1.SetDefaultColor(Color.RED);
plot p_S1 = if bar >= HighestAll(p_PLBar)
then HighestAll(if isNaN(close[-1])
then p_PLValue
else nan)
else nan;
p_S1.SetStyle(Curve.SHORT_DASH);
p_S1.SetLineWeight(3);
p_S1.SetDefaultColor(Color.GRAY);
plot S1 = if bar >= HighestAll(PLBar)
then HighestAll(if isNaN(c[-1])
then PLValue
else nan)
else nan;
S1.SetDefaultColor(Color.WHITE);
plot S1entryPoint = if bar >= HighestAll(PLEntryBar)
then HighestAll(if isNaN(c[-1])
then PLEntryValue
else nan)
else nan;
S1entryPoint.SetDefaultColor(Color.GREEN);
plot S1LongTarget1 = if bar >= HighestAll(PLEntryBar)
then HighestAll(if isNaN(c[-1])
then PLEntryValue + risk
else nan)
else nan;
S1LongTarget1.SetStyle(Curve.LONG_DASH);
S1LongTarget1.SetDefaultColor(Color.GREEN);
plot priceLine = HighestAll(if IsNaN(c[-1])
then c
else Double.NaN);
priceLine.SetStyle(Curve.SHORT_DASH);
priceLine.SetLineWeight(1);
priceLine.SetDefaultColor(Color.CYAN);
plot UpArrow = if c crosses above S1entryPoint and FE > .5
then l
else Double.NaN;
UpArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpArrow.SetLineWeight(3);
UpArrow.SetDefaultColor(Color.GREEN);
plot DnArrow = if c crosses below R1exitPoint and ((FE > .618)
or (FE < .382))
then h
else Double.NaN;
DnArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
DnArrow.SetLineWeight(3);
DnArrow.SetDefaultColor(Color.RED);``````

Last edited by a moderator:
• RickAns

#### BenTen

Staff member
Staff
VIP
I assume you'll be using this on the ToS mobile app? If so, alerts won't work.

#### OptionsPirate

##### New member
Actually no, I will be using it on the desktop TOS platform.

#### BenTen

Staff member
Staff
VIP
@Jmo63 How do you want to get alerted? When price crosses a certain level?

#### OptionsPirate

##### New member
When the arrows paint with email, text, and desktop alert.

#### BenTen

Staff member
Staff
VIP

Code:
``````# Alerts

You'll receive alerts for the stock you're currently watching on your chart. This doesn't support email or text alerts.

#### OptionsPirate

##### New member
Thank you @BenTen ... One question, this only alerts for the chart I have open? Not for other charts I have this indicator on in the background?

Staff member
Staff
VIP

#### OptionsPirate

##### New member
Thank you, Mr. @BenTen and I will use what you gave me. Unfortunately, what I need are alerts for all charts that have this indicator applied, especially the ones in the background. I don't necessarily need the alert for the chart I am actually looking at, unless I step away from the computer. I appreciate your help...

#### OptionsPirate

##### New member
Thank you, Mr. @BenTen and I will use what you gave me. Unfortunately, what I need are alerts for all charts that have this indicator applied, especially the ones in the background. I don't necessarily need the alert for the chart I am actually looking at, unless I step away from the computer. I appreciate your help...
Actually it does work with charts in the background which is great. I have several charts set up in the flexible grid and even if I maximize just one chart, I get alerts from the others. Thanks again Mr. @BenTen

• BenTen

#### Bendu

##### Member
VIP
Is there a way to keep the previous pivots as a line across the chart?

#### BenTen

Staff member
Staff
VIP ## 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
• 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.