Trend Pivot Points Indicator by Mobius For ThinkOrSwim

dougn

Member
2019 Donor
VIP
Trend Pivot Indicator by Mobius For ThinkOrSwim
knmHfyS.png

Code:
# Mobius
# V01.01.29.2019
# Uses trend of higher highs with higher lows and trend of lower lows with lower highs to locate pivots. Distance for trend is set by the user. Confirmation of a reversal from pivots is set with a multiple of the pivot bars range. That multiple is also a user input.
# Trading Rules
# 1) Trade when price crosses and closes outside the pivot Confirmation line. At that point looking for best entry. Min trade is 2 contracts
# 2) Know your risk point before entering trade. Typical risk point is the pivot line itself. If your risk is crossed look for an exit. Never use hard stops - you'll often get out for little or no loss
# 3) Know your Risk off point before entering. Typical Risk Off is an ATR multiple. Offer Risk Off as soon as possible for a Risk Free trade
# 4) set mental stop one tick above entry when Risk Off is achieved
# 5) if trade continues your way move mental stop for your runner to last support / resistance each time a new support / resistance is hit.

input n = 5;
input R_Mult = .7;

def o = open;
def h = high;
def l = low;
def c = close;
def x = BarNumber();
def nan = Double.NaN;
def ts = tickSize();
def tr = TrueRange(h, c, l);
def hh = if Sum(h > h[1], n) >= n and
            Sum(l > l[1], n) >= n-1
         then h
         else if h > hh[1]
              then h
              else hh[1];
def xh = if h == hh
         then x
         else nan;
plot hh_ = if x >= HighestAll(xh)
           then HighestAll(if IsNaN(c[-1])
                           then hh
                           else nan)
           else nan;
     hh_.SetDefaultColor(Color.RED);
     hh_.HideTitle();
     hh_.HideBubble();
def hR = if h == hh
         then Round(Average(tr, n)/TickSize(), 0)*TickSize()
         else hR[1];
def PrevL = if h == hh
            then l[1]
            else PrevL[1];
plot STO = if x >= HighestAll(xh)
           then HighestAll(if IsNaN(c[-1])
           then Round((Max(PrevL, hh_ - (hR * R_Mult))) / ts, 0) * ts
                           else nan)
           else nan;
     STO.SetDefaultColor(Color.RED);
     STO.HideTitle();
     STO.HideBubble();
plot STO_RO = if x >= HighestAll(xh)
              then HighestAll(if isNaN(c[-1])
                              then STO - Min(hR, TickSize() * 16)
                              else nan)
              else nan;
     STO_RO.SetStyle(Curve.Long_Dash);
     STO_RO.SetDefaultColor(Color.White);
     STO_RO.HideBubble();
     STO_RO.HideTitle();
#AddChartBubble(x == HighestAll(x), STO_RO, "RO", STO_RO.TakeValueColor(), 0);
def ll = if Sum(l < l[1], n) >= n and
            Sum(h < h[1], n) >= n-1
         then l
         else if l < ll[1]
              then l
              else ll[1];
def xl = if l == ll
         then x
         else nan;
plot ll_ = if x >= HighestAll(xl)
           then HighestAll(if IsNaN(c[-1])
                           then ll
                           else nan)
           else nan;
     ll_.SetDefaultColor(Color.GREEN);
     ll_.HideTitle();
     ll_.HideBubble();
def lR = if l == ll
         then Round(Average(tr, n)/TickSize(), 0)*TickSize()
         else lR[1];
def PrevH = if l == ll
            then h[1]
            else PrevH[1];
plot BTO = if x >= HighestAll(xl)
           then HighestAll(if IsNaN(c[-1])
           then Round((Min(PrevH, ll_ + (lR * R_Mult))) / ts, 0) * ts
                           else nan)
           else nan;
     BTO.SetDefaultColor(Color.GREEN);
     BTO.HideTitle();
     BTO.HideBubble();
plot BTO_RO = if x >= HighestAll(xl)
              then HighestAll(if isNaN(c[-1])
                              then BTO + Min(lR, TickSize() * 16)
                              else nan)
              else nan;
     BTO_RO.SetStyle(Curve.Long_Dash);
     BTO_RO.SetDefaultColor(Color.White);
     BTO_RO.HideBubble();
     BTO_RO.HideTitle();
#AddChartBubble(x == HighestAll(x), BTO_RO, "RO", BTO_RO.TakeValueColor(), 1);
AddCloud(STO, hh_, Color.LIGHT_RED, Color.LIGHT_RED);
AddCloud(ll_, BTO, Color.LIGHT_GREEN, Color.LIGHT_GREEN);
Alert(c crosses below STO, "", Alert.Bar, Sound.Bell);
Alert(c crosses above BTO, "", Alert.Bar, Sound.Chimes);
# End Code Trend Pivots
 
Last edited by a moderator:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

I've also been trying to figure out which one is the confirmation line. Initially, I thought breaking outside the confirmation line meant above the upper most line (be it red or green) or below the lowest line but I'm not sure. And what are the white lines in between the range? I see that @J007RMC is also using this indicator. Maybe @J007RMC can shed some light on how to use it?
 
This is how I understand the indicator to work. A break and close above/below the red or green boundaries {resistance/support.} A break and close is confirmation for me else higher highs/lower lows with the pivots range . Perhaps we should direct these questions to horserider for a definitive answer.
 
Love this indicator! I've been using the STO_RO and BTO-RO plots as confirmation lines. I wait for a close above (for longs) or below (for shorts) to tell me when a pullback has ended.
 
Last edited:
I like this indicator. I use it with confirmation for a swing trade w/ confirmation from the 5 min bar at support/resistance.

It will fail as they are apt to do, but you often get enough decision making time to get out with a scratch. The picture shows LL_ line and BTO line as Cyan Triangles. I only use bull signals on ETFs.
 
Last edited by a moderator:
Hey all, I'm new here (first post). I'm just trying to figure it all out and this is my (humble) interpretation:

BTO = buy to open
LL = lower lows (bottom-most line of green plot)
STO = sell to open
HH = higher highs (top-most line of red plot)
@barbaros said:
STO_RO = Sell to Open Risk On
BTO_RO = Buy to Open Risk On
 
Last edited by a moderator:
@ProcastinatingPerfection The code is in the first post of this thread. Go to the first page.
@IM140.6 Your interpretation of this indicator is correct. However, if I see a confirmation of close above BTO in the previous trend or the Bar/Volume pattern I will go Risk On as you say. If the trend on the day is strong in the opposite direction of the indicator, I will forego.


And a 3rd condition would be chop. In that situation I would go RiskOn.
 
First my apologies for my images disappearing from my previous posts. I had deleted them from Imgur by mistake. (I will remember this for the future.)

Another example of the trend pivot indicator working very nicely from this mornings trade on an ETF I trade. It is set to 3 and .7, to catch pullbacks. In so doing it caught not only 1 nice swing, but confirmed another when price returned to the same position. Beautiful.

8wIxVd6.jpg
 
@murkr I feel it is best to let the creator of the study explain how he trades with this study. :) These are the notes from the study header, written by Mobius, the trader who coded this.

Trading Rules
1) Trade when price crosses and closes outside the pivot Confirmation line. At that point looking for best entry. Min trade is 2 contracts
2) Know your risk point before entering trade. Typical risk point is the pivot line itself. If your risk is crossed look for an exit. Never use hard stops - you'll often get out for little or no loss
3) Know your Risk off point before entering. Typical Risk Off is an ATR multiple. Offer Risk Off as soon as possible for a Risk Free trade
4) set mental stop one tick above entry when Risk Off is achieved
5) if trade continues your way move mental stop for your runner to last support / resistance each time a new support / resistance is hit.

Risk Off is closing out 1 contract, leaving 1 as a runner. The picture shows my interpretation of this method.

knmHfyS.png
 
Hi Pensar,

Yes I really like the chart bubbles, but I also like the arrows above and below the sell and buy candles. How do I also add that?

@David45 Here you go. I included a yes/no input for the arrows as well.
Code:
# Trend Pivots
# Mobius
# V01.01.29.2019
# Uses trend of higher highs with higher lows and trend of lower lows with lower highs to locate pivots. Distance for trend is set by the user. Confirmation of a reversal from pivots is set with a multiple of the pivot bars range. That multiple is also a user input.
# Trading Rules
# 1) Trade when price crosses and closes outside the pivot Confirmation line. At that point looking for best entry. Min trade is 2 contracts
# 2) Know your risk point before entering trade. Typical risk point is the pivot line itself. If your risk is crossed look for an exit. Never use hard stops - you'll often get out for little or no loss
# 3) Know your Risk off point before entering. Typical Risk Off is an ATR multiple. Offer Risk Off as soon as possible for a Risk Free trade
# 4) set mental stop one tick above entry when Risk Off is achieved
# 5) if trade continues your way move mental stop for your runner to last support / resistance each time a new support / resistance is hit.

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Code has added historical pivot plots as well as visual trade signals.
# No guarantees as to accuracy or reliability.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

input n = 5;
input R_Mult = .7;

def h = high;
def l = low;
def c = close;
def x = BarNumber();
def nan = Double.NaN;
def ts = TickSize();
def tr = TrueRange(h, c, l);
def hh = if Sum(h > h[1], n) >= n and
            Sum(l > l[1], n) >= n - 1
         then h
         else if h > hh[1]
              then h
              else hh[1];
def xh = if h == hh
         then x
         else nan;
plot hh_ = if x >= HighestAll(xh)
           then HighestAll(if IsNaN(c[-1])
                           then hh
                           else nan)
           else nan;
hh_.SetDefaultColor(Color.RED);
hh_.HideTitle();
hh_.HideBubble();
def hR = if h == hh
         then Round(Average(tr, n) / TickSize(), 0) * TickSize()
         else hR[1];
def PrevL = if h == hh
            then l[1]
            else PrevL[1];
plot STO = if x >= HighestAll(xh)
           then HighestAll(if IsNaN(c[-1])
           then Round((Max(PrevL, hh_ - (hR * R_Mult))) / ts, 0) * ts
                           else nan)
           else nan;
STO.SetDefaultColor(Color.RED);
STO.HideTitle();
STO.HideBubble();
plot STO_RO = if x >= HighestAll(xh)
              then HighestAll(if IsNaN(c[-1])
                              then STO - Min(hR, TickSize() * 16)
                              else nan)
              else nan;
STO_RO.SetStyle(Curve.LONG_DASH);
STO_RO.SetDefaultColor(Color.WHITE);
STO_RO.HideBubble();
STO_RO.HideTitle();
def ll = if Sum(l < l[1], n) >= n and
            Sum(h < h[1], n) >= n - 1
         then l
         else if l < ll[1]
              then l
              else ll[1];
def xl = if l == ll
         then x
         else nan;
plot ll_ = if x >= HighestAll(xl)
           then HighestAll(if IsNaN(c[-1])
                           then ll
                           else nan)
           else nan;
ll_.SetDefaultColor(Color.GREEN);
ll_.HideTitle();
ll_.HideBubble();
def lR = if l == ll
         then Round(Average(tr, n) / TickSize(), 0) * TickSize()
         else lR[1];
def PrevH = if l == ll
            then h[1]
            else PrevH[1];
plot BTO = if x >= HighestAll(xl)
           then HighestAll(if IsNaN(c[-1])
           then Round((Min(PrevH, ll_ + (lR * R_Mult))) / ts, 0) * ts
                           else nan)
           else nan;
BTO.SetDefaultColor(Color.GREEN);
BTO.HideTitle();
BTO.HideBubble();
plot BTO_RO = if x >= HighestAll(xl)
              then HighestAll(if IsNaN(c[-1])
                              then BTO + Min(lR, TickSize() * 16)
                              else nan)
              else nan;
BTO_RO.SetStyle(Curve.LONG_DASH);
BTO_RO.SetDefaultColor(Color.WHITE);
BTO_RO.HideBubble();
BTO_RO.HideTitle();
AddCloud(STO, hh_, Color.LIGHT_RED, Color.LIGHT_RED);
AddCloud(ll_, BTO, Color.LIGHT_GREEN, Color.LIGHT_GREEN);

# End Code Trend Pivots

#~~~~~~~~~~~~~~~~~~~~~~~~~ begin historical pivots ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
input show_historical_pivots = no;

plot lowestpivot = if show_historical_pivots then ll else nan;
lowestpivot.SetDefaultColor(Color.GREEN);

plot highestpivot = if show_historical_pivots then hh else nan;
highestpivot.SetDefaultColor(Color.RED);

plot shortoncrossbelow = if show_historical_pivots
                         then Round((Max(PrevL, highestpivot - (hR * R_Mult))) / ts, 0) * ts
                         else nan;
     shortoncrossbelow.SetDefaultColor(Color.RED);

plot longoncrossabove = if show_historical_pivots
                        then Round((Min(PrevH, lowestpivot + (lR * R_Mult))) / ts, 0) * ts
                        else nan;
     longoncrossabove.SetDefaultColor(Color.GREEN);

plot buyRO = if show_historical_pivots then longoncrossabove + Min(lR, TickSize() * 16) else nan;
     buyRO.SetDefaultColor(Color.WHITE);
     buyRO.SetStyle(Curve.LONG_DASH);

plot sellRO = if show_historical_pivots then shortoncrossbelow - Min(hR, TickSize() * 16) else nan;
     sellRO.SetDefaultColor(Color.WHITE);
     sellRO.SetStyle(Curve.LONG_DASH);

AddCloud(highestpivot,shortoncrossbelow,Color.RED,Color.RED);
AddCloud(lowestpivot,longoncrossabove,Color.GREEN,Color.GREEN);
#~~~~~~~~~~~~~~~~~~~~~~ end historical pivots ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#~~~~~~~~~~~~~~~~~~~~~~~~ begin arrow signals ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
input show_arrows = yes;

def SOCB = Round((Max(PrevL, hh - (hR * R_Mult))) / ts, 0) * ts;
def LOCA = Round((Min(PrevH, ll + (lR * R_Mult))) / ts, 0) * ts;
def BRO = LOCA + Min(lR, TickSize() * 16);
def SRO = SOCB - Min(hR, TickSize() * 16);
def datadn = close > SRO and high[1] > SOCB and close < SOCB;
def dataup = close < BRO and low[1] < LOCA and close > LOCA;

plot arrowdn = if show_arrows then !datadn[1] and datadn else nan;
     arrowdn.setpaintingstrategy(paintingstrategy.boolean_arrow_down);
     arrowdn.setdefaultcolor(color.magenta);
     arrowdn.setlineweight(3);
plot arrowup = if show_arrows then !dataup[1] and dataup else nan;
     arrowup.setpaintingstrategy(paintingstrategy.boolean_arrow_up);
     arrowup.setdefaultcolor(color.cyan);
     arrowup.setlineweight(3);
#~~~~~~~~~~~~~~~~~~~~~~~~~ end arrow signals ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#~~~~~~~~~~~~~~~~~~~~~~~~ begin bubble signals ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
input show_bubbles = yes;
input Buy_Sell_Bubble_Data = {default current, historical};

def short;
def long;

switch (Buy_Sell_Bubble_Data)
        {
        case historical:
             short = hh;
             long = ll;
        case current:
             short = hh_;
             long = ll_;
        }

def SOCB1 = Round((Max(PrevL, short - (hR * R_Mult))) / ts, 0) * ts;
def LOCA1 = Round((Min(PrevH, long + (lR * R_Mult))) / ts, 0) * ts;
def BRO1 = LOCA + Min(lR, TickSize() * 16);
def SRO1 = SOCB - Min(hR, TickSize() * 16);
def SE = close > SRO1 and high[1] > SOCB1 and close <= SOCB1;
def LE = close < BRO1 and low[1] < LOCA1 and close >= LOCA1;

def exitbuy = l < long[1];
def exitsell = h > short[1];

def holdLE = if LE and !LE[1] then 1 else if !exitbuy then holdLE[1] else 0;
def holdSE = if SE and !SE[1] then 1 else if !exitsell then holdSE[1] else 0;

def exit_long = holdLE[1] and !holdLE;
def exit_short = holdSE[1] and !holdSE;

AddChartBubble(if show_bubbles then !LE[1] and LE else nan, low, "Enter Long", Color.GREEN, 0);
AddChartBubble(if show_bubbles then !SE[1] and SE else nan, high, "Enter Short", Color.RED, 1);
AddChartBubble(if show_bubbles then exit_long else nan, high, "Exit Long", Color.GREEN, 1);
AddChartBubble(if show_bubbles then exit_short else nan, low, "Exit Short", Color.RED, 0);

#~~~~~~~~~~~~~~~~~~~~~~~~~~ end bubble signals ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#~~~~~~~~~~~~~~~~~~~~~~~ begin explanation bubbles ~~~~~~~~~~~~~~~~~~~~~~~~~
input explanation_bubbles = yes;
AddChartBubble(explanation_bubbles and x == HighestAll(x), STO_RO, "Risk Off", STO_RO.TakeValueColor(), 0);
AddChartBubble(explanation_bubbles and x == HighestAll(x), BTO_RO, "Risk Off", BTO_RO.TakeValueColor(), 1);
AddChartBubble(explanation_bubbles and x == HighestAll(x), STO, "Entry Line", STO.TakeValueColor(), 0);
AddChartBubble(explanation_bubbles and x == HighestAll(x), BTO, "Entry Line", BTO.TakeValueColor(), 1);
AddChartBubble(explanation_bubbles and x == HighestAll(x), hh_, "Pivot Line", hh_.TakeValueColor(), 1);
AddChartBubble(explanation_bubbles and x == HighestAll(x), ll_, "Pivot Line", ll_.TakeValueColor(), 0);
#~~~~~~~~~~~~~~~~~~~~~~~~ end explanation bubbles ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Edit: Added buy/sell bubbles. Please test before using - perform your own due diligence.
 
Last edited:
Hi @Pensar,

Thank you so much for working on this! I just looked at it on my chart and as of now I do not see any bubbles at all over the candlesticks. I assume that's because the updates you made will only show the bubbles if the signal is given for today's bar on a closing basis? I hope that's the case because I prefer not to see historical bubbles or intraday bubbles.

One other point is that my interpretation of this indicator is that the bubbles you have that say Risk Off should actually say Risk On.

On a side note, do you know if the n and r mult values need to be adjusted based on the timeframe you're using or can the default values be used on all time frames?
 
@David45 @rad14733 Alright! I finally was able to complete the fix for the bubbles ( I hope so, anyway). I have again updated the code in this post. I would greatly appreciate feedback, if possible. :) The exit bubbles should only plot one per break of the highest or lowest pivots.

@billgt Take a look at this post or this post. The second has more "lipstick", not necessarily any better or worse than the first.
@Pensar : Definitely looking better... I'll play around with it and see how it performs with different instruments... (y)
 
Hi Pensar,

Thank you so much for working on this! I just looked at it on my chart and as of now I do not see any bubbles at all over the candlesticks. I assume that's because the updates you made will only show the bubbles if the signal is given for today's bar on a closing basis? I hope that's the case because I prefer not to see historical bubbles or intraday bubbles.

One other point is that my interpretation of this indicator is that the bubbles you have that say Risk Off should actually say Risk On.

On a side note, do you know if the n and r mult values need to be adjusted based on the timeframe you're using or can the default values be used on all time frames?
@David45 Look at the code's settings - you can show/hide what you want.

I kept the original labeling of Mobius in regards to Risk On/Risk Off as I feel it is correct; this post can explain more. Change it to show whatever you like. :)

In regards to the n and rMult values . . . it is generally up to your personal method of trading. How/when do you wish to enter? Going into a trade sooner may cause more stop-outs/losses, while going in later can lose potential profits. Adjust them until you are comfortable with the settings and when it suits your style of trading.
 
@Pensar I noticed that sometimes the Sell Entry bubble does not appear. For example, if you look at the hourly chart of QQQ from yesterday, on the second to last bar of the day price broke below and closed below the lower red line, yet no Sell Entry bubble appeared. Another example is if you look at the daily chart of SPY from yesterday, price broke below and closed below the lower red line, yet no Sell Entry bubble appeared.
 
@Pensar I noticed that sometimes the Sell Entry bubble does not appear. For example, if you look at the hourly chart of QQQ from yesterday, on the second to last bar of the day price broke below and closed below the lower red line, yet no Sell Entry bubble appeared. Another example is if you look at the daily chart of SPY from yesterday, price broke below and closed below the lower red line, yet no Sell Entry bubble appeared.

@David45 Test this code below, it has been updated - I realized that I was using "high" and "low" instead of "close". Does it do what you want?
The RiskOff lines have also been removed per your request.

Code:
# Trend Pivots
# Mobius
# V01.01.29.2019
# Uses trend of higher highs with higher lows and trend of lower lows with lower highs to locate pivots. Distance for trend is set by the user. Confirmation of a reversal from pivots is set with a multiple of the pivot bars range. That multiple is also a user input.
# Trading Rules
# 1) Trade when price crosses and closes outside the pivot Confirmation line. At that point looking for best entry. Min trade is 2 contracts
# 2) Know your risk point before entering trade. Typical risk point is the pivot line itself. If your risk is crossed look for an exit. Never use hard stops - you'll often get out for little or no loss
# 3) Know your Risk off point before entering. Typical Risk Off is an ATR multiple. Offer Risk Off as soon as possible for a Risk Free trade
# 4) set mental stop one tick above entry when Risk Off is achieved
# 5) if trade continues your way move mental stop for your runner to last support / resistance each time a new support / resistance is hit.

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Code has added historical pivot plots as well as visual trade signals.
# No guarantees as to accuracy or reliability.
# Removed Risk Off portions from code
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

input n = 5;
input R_Mult = .7;

def h = high;
def l = low;
def c = close;
def x = BarNumber();
def nan = Double.NaN;
def ts = TickSize();
def tr = TrueRange(h, c, l);
def hh = if Sum(h > h[1], n) >= n and
            Sum(l > l[1], n) >= n - 1
         then h
         else if h > hh[1]
              then h
              else hh[1];
def xh = if h == hh
         then x
         else nan;
plot hh_ = if x >= HighestAll(xh)
           then HighestAll(if IsNaN(c[-1])
                           then hh
                           else nan)
           else nan;
hh_.SetDefaultColor(Color.RED);
hh_.HideTitle();
hh_.HideBubble();
def hR = if h == hh
         then Round(Average(tr, n) / TickSize(), 0) * TickSize()
         else hR[1];
def PrevL = if h == hh
            then l[1]
            else PrevL[1];
plot STO = if x >= HighestAll(xh)
           then HighestAll(if IsNaN(c[-1])
           then Round((Max(PrevL, hh_ - (hR * R_Mult))) / ts, 0) * ts
                           else nan)
           else nan;
STO.SetDefaultColor(Color.RED);
STO.HideTitle();
STO.HideBubble();

def ll = if Sum(l < l[1], n) >= n and
            Sum(h < h[1], n) >= n - 1
         then l
         else if l < ll[1]
              then l
              else ll[1];
def xl = if l == ll
         then x
         else nan;
plot ll_ = if x >= HighestAll(xl)
           then HighestAll(if IsNaN(c[-1])
                           then ll
                           else nan)
           else nan;
ll_.SetDefaultColor(Color.GREEN);
ll_.HideTitle();
ll_.HideBubble();
def lR = if l == ll
         then Round(Average(tr, n) / TickSize(), 0) * TickSize()
         else lR[1];
def PrevH = if l == ll
            then h[1]
            else PrevH[1];
plot BTO = if x >= HighestAll(xl)
           then HighestAll(if IsNaN(c[-1])
           then Round((Min(PrevH, ll_ + (lR * R_Mult))) / ts, 0) * ts
                           else nan)
           else nan;
BTO.SetDefaultColor(Color.GREEN);
BTO.HideTitle();
BTO.HideBubble();

AddCloud(STO, hh_, Color.LIGHT_RED, Color.LIGHT_RED);
AddCloud(ll_, BTO, Color.LIGHT_GREEN, Color.LIGHT_GREEN);

# End Code Trend Pivots

#~~~~~~~~~~~~~~~~~~~~~~~~~ begin historical pivots ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
input show_historical_pivots = no;

plot lowestpivot = if show_historical_pivots then ll else nan;
lowestpivot.SetDefaultColor(Color.GREEN);

plot highestpivot = if show_historical_pivots then hh else nan;
highestpivot.SetDefaultColor(Color.RED);

plot shortoncrossbelow = if show_historical_pivots
                         then Round((Max(PrevL, highestpivot - (hR * R_Mult))) / ts, 0) * ts
                         else nan;
     shortoncrossbelow.SetDefaultColor(Color.RED);

plot longoncrossabove = if show_historical_pivots
                        then Round((Min(PrevH, lowestpivot + (lR * R_Mult))) / ts, 0) * ts
                        else nan;
     longoncrossabove.SetDefaultColor(Color.GREEN);

AddCloud(highestpivot,shortoncrossbelow,Color.RED,Color.RED);
AddCloud(lowestpivot,longoncrossabove,Color.GREEN,Color.GREEN);
#~~~~~~~~~~~~~~~~~~~~~~ end historical pivots ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#~~~~~~~~~~~~~~~~~~~~~~~~ begin arrow signals ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
input show_arrows = yes;

def SOCB = Round((Max(PrevL, hh - (hR * R_Mult))) / ts, 0) * ts;
def LOCA = Round((Min(PrevH, ll + (lR * R_Mult))) / ts, 0) * ts;
def datadn = close[1] > SOCB and close < SOCB;
def dataup = close[1] < LOCA and close > LOCA;

plot arrowdn = if show_arrows then !datadn[1] and datadn else nan;
     arrowdn.setpaintingstrategy(paintingstrategy.boolean_arrow_down);
     arrowdn.setdefaultcolor(color.magenta);
     arrowdn.setlineweight(3);
plot arrowup = if show_arrows then !dataup[1] and dataup else nan;
     arrowup.setpaintingstrategy(paintingstrategy.boolean_arrow_up);
     arrowup.setdefaultcolor(color.cyan);
     arrowup.setlineweight(3);
#~~~~~~~~~~~~~~~~~~~~~~~~~ end arrow signals ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#~~~~~~~~~~~~~~~~~~~~~~~~ begin bubble signals ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
input show_bubbles = yes;
input Buy_Sell_Bubble_Data = {default current, historical};

def short;
def long;

switch (Buy_Sell_Bubble_Data)
        {
        case historical:
             short = hh;
             long = ll;
        case current:
             short = hh_;
             long = ll_;
        }

def SOCB1 = Round((Max(PrevL, short - (hR * R_Mult))) / ts, 0) * ts;
def LOCA1 = Round((Min(PrevH, long + (lR * R_Mult))) / ts, 0) * ts;
def SE = close[1] > SOCB1 and close <= SOCB1;
def LE = close[1] < LOCA1 and close >= LOCA1;

def exitbuy = l < long[1];
def exitsell = h > short[1];

def holdLE = if LE and !LE[1] then 1 else if !exitbuy then holdLE[1] else 0;
def holdSE = if SE and !SE[1] then 1 else if !exitsell then holdSE[1] else 0;

def enter_long = !holdLE[1] and holdLE;
def enter_short = !holdSE[1] and holdSE;
def exit_long = holdLE[1] and !holdLE;
def exit_short = holdSE[1] and !holdSE;

AddChartBubble(if show_bubbles then enter_long else nan, low, "Enter Long", Color.GREEN, 0);
AddChartBubble(if show_bubbles then enter_short else nan, high, "Enter Short", Color.RED, 1);
AddChartBubble(if show_bubbles then exit_long else nan, high, "Exit Long", Color.GREEN, 1);
AddChartBubble(if show_bubbles then exit_short else nan, low, "Exit Short", Color.RED, 0);

#~~~~~~~~~~~~~~~~~~~~~~~~~~ end bubble signals ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#~~~~~~~~~~~~~~~~~~~~~~~ begin explanation bubbles ~~~~~~~~~~~~~~~~~~~~~~~~~
input explanation_bubbles = yes;
AddChartBubble(explanation_bubbles and x == HighestAll(x), STO, "Entry Line", STO.TakeValueColor(), 0);
AddChartBubble(explanation_bubbles and x == HighestAll(x), BTO, "Entry Line", BTO.TakeValueColor(), 1);
AddChartBubble(explanation_bubbles and x == HighestAll(x), hh_, "Pivot Line", hh_.TakeValueColor(), 1);
AddChartBubble(explanation_bubbles and x == HighestAll(x), ll_, "Pivot Line", ll_.TakeValueColor(), 0);
#~~~~~~~~~~~~~~~~~~~~~~~~ end explanation bubbles ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

How it currently looks (with the historical pivot plots turned on) -

TRmMxm1.png
 
Last edited:
@Pensar can you assist in making these changes to the code?

Remove Risk Off lines from the code. I think Mobius referenced the purpose of the Risk Off lines was to sell a portion of your options contracts intraday when price hits those lines. I do not trade intraday or trade options.

The way I envisioned using this indicator was for swing trading SPY on the daily chart. Here's what that would look like:

Short:
Yesterday, the closing price was above the lower red line. Today, the closing price is below the lower red line. When this occurs, Short Entry bubble appears. No other Short Entry bubbles can appear until after price has a close above the upper red line (most recent high). This would indicate I was stopped out and would have to wait for a new entry signal. (This should also significantly reduce the amount of bubbles and false signals)

A Short Exit bubble appears when the closing price is above the upper red line (most recent high).

Long:
Yesterday, the closing price was below the upper green line. Today, the closing price is above the upper green line. When this occurs, Long Entry bubble appears. No other Long Entry bubbles can appear until after price has a close below the lower green line (most recent low). This would indicate I was stopped out and would have to wait for a new entry signal. (This should also significantly reduce the amount of bubbles and false signals)

A Long Exit bubble appears when the closing price is below the lower green line (most recent low).

Thanks very much for any assistance you can provide with this Pensar!
 
Hey guys, been using this indicator for a few weeks and it has been working well. Only complaint is that it fires off too many alerts that aren't actionable. The way I've been using it is getting in after a close beyond the RO dotted line (one parabolic or two mid-sized candles work best). But alerts get triggered on a cross of the first line. Price crosses back and forth this line all the time making for a lot of false positives.

Is there any way to modify the code to trigger an alert on a close beyond the RO dotted line, instead of a cross of the initial line?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
332 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • 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.
Back
Top