Trend Pivot Indicator by Mobius For ThinkOrSwim

David45

Member
2019 Donor
@David45 I updated the above post.

@Yo Adrian Are you using the original code in post #1? If so, replace the current alerts with the below code.

Code:
Alert(c crosses below STO_RO, "", Alert.Bar, Sound.Bell);
Alert(c crosses above BTO_RO, "", Alert.Bar, Sound.Chimes);

@Pensar Thank you so much for taking the time to tweak the code for what I am trying to achieve. It is so much appreciated. The most recent code is SO CLOSE to doing what I was hoping for. The only remaining issue is that there are still instances when I will get consecutive long entry or short entry bubbles. I think the fix for this is what I have bolded:

No other Short Entry bubbles can appear until after price has a close above the upper red line (most recent high).

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).

So after a long entry or short entry bubble appears, the code would not allow another long entry or short entry bubble to appear in the same direction until after I was stopped out. I would only be acting upon the first bubble that appears and remain in the trade unless I was stopped out or the opposite direction bubble appears.

Note to admin: Please do not delete this post. It is not the same as the previous post and contains additional clarification.
 

Pensar

Well-known member
VIP
@David45 - In the code you currently have, find the bubbles segment and replace it with this below code.

Code:
#~~~~~~~~~~~~~~~~~~~~~~~~ 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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 

David45

Member
2019 Donor
@Pensar You nailed it! Thanks so much again my friend for your time and efforts with this. I truly appreciate it and hope this good deed comes back to you in the form of much trading $uccess!
 

kelbadawi

New member
can someone post the finalized link to the script? mine does not look like the last one. if just has clouds along top and bottom with arrows
thank you @Pensar
 

dmillz

Member
VIP
I have mixed feelings about this indicator. when a stock is bullish the red bar comes and repaints as the stock is going up...
 

Brijanko

New member
VIP
Hello there,

I’m new to ThinkScript and I believe is fabulous..I thank you all of you in advance for making it such a fun and interesting forum to be a member off..

I’ve been learning and experimenting with TrendPivot and ProjectionPivot indicators and I wonder if there is a Mobile edition for them??
Kind regards
 

sean1970ss

New member
VIP
Trying my best to understand the chart. Where is is (shaded red) At the bottom it says (entry line) at the top it says (pivot line) Then shaded in green we have (pivot line) at the bottom and (entry line) at the top of the shaded area and RISK OFF DOTTED LINES WHITE. Which area is best to work off of? or to make best entry? TY
 

MerryDay

Administrative
Staff member
Staff
VIP
xIxTEVe.png

@sean1970ss
After price crosses above the confirmation line, look for entry based on your other indicators
More to read: The Basics for Developing a Good Strategy
 
Last edited:

MerryDay

Administrative
Staff member
Staff
VIP
To Scan For Trend Pivots
Screenshot (124).png
Part One --
1. Load Shared Study Link: http://tos.mx/3c4qg1u
2. Save the study under the name: Trend_Pivots_scan. (if you skip this part the scanner in part two will not work)​

Part Two --
1. Load Shared Scanner Link: http://tos.mx/3CvSWMn
2. The Scanner defaults to scan for price rising above support. Choices are Scan up from Support or Scan down from Resistance​
bitmap.png
Ruby:
# Trend Pivots Scanner Only
# 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 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;
def hh_ = if x >= HighestAll(xh)
           then HighestAll(if IsNaN(c[-1])
                           then hh
                           else nan)
           else nan;

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];
def 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;
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;
def ll_ = if x >= HighestAll(xl)
           then HighestAll(if IsNaN(c[-1])
                           then ll
                           else nan)
           else nan;

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];
def 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;

# End Code Trend Pivots
#~~~~~~~~~~~~~~~~~~~~~~~~ Plot Scan ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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 scan_dn = !datadn[1] and datadn ;
plot scan_up = !dataup[1] and dataup ;
#~~~~~~~~~~~~~~~~~~~~~~~~~ end scan signals ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Last edited:

Kimhad

New member
VIP
@rlove1221 the study you named trend_pivots_scan is not the trend_pivots_scan.
You have to delete everything and start again with step1

Sorry for all your frustrations. This scan is worth it.
MerryDay is correct. If you follow his/her instructions exactly, the scan works exactly as it is supposed to. Follow the instructions in post #70 to the letter and it works. Thanks MerryDay!
 

imonlysleeping

New member
@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
hi @Pensar, is there a post that includes this exact final version but that still has the RiskOff lines?
 
Top