Automatic Quadrant Lines for ThinkorSwim

@FreefallJM03 Which other indicators do you use this with ?
I use a reversal indicator with it. It generally works pretty well, but that crazy week last week took a bit of a hit on Thursday and early in the day on Friday. One of the most difficult thing is placing stops making them tight enough not to get crushed, but also not making them too tight that you get whipsawed out every 2-3% move that takes place. Trading low float stocks is risky because they can gain or lose 10% in a day. I also make sure that the trade is moving in the right direction in the next higher time frame. If I'm trading on a daily chart then the stock has to be moving positive on the weekly chart. If it is declining strongly on a weekly, it likely will be risky on a daily. If it is starting to reverse trend on a weekly, then it might be alright to enter the daily because you might hit at the right time for the weekly reversal to trend upward, but, as stated before those are riskier trades and not good to take in October which is often a high flying month that can see the market rise drastically or come crashing down. I plan to do simulation trading through at least the first two weeks of October. One rule I have is three bad trades in a row, take two weeks off. I usually come back a lot stronger. I have over 300% return for the year thus far so not doing too bad, but that hit last week dropped me down from about a 370% return for the year.
 

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

What would be absolutely amazing if someone has the time for it, is to add upper labels that highlight green or red for the different timeframes when price is above or below short/long entries
 
Capture.png


Can someone define these variables for me? I didn't see it anywhere in the thread.

n = the amount of bars that are considered based on the time frame selected. For example if I choose daily, It will look back 20 days?
fractal energy length = ? (Maybe the amount of bars to determine a fractal pattern)?
fractal energy threshold = ?
atr mult = If the average true range is =0.53 the profit and short targets at 50% and 75% lines are shown at =ATR x 0.7 with apart?
natr = ?
avg type=?

Trying to figure this out to make sure I'm using the right settings. I basically use this with the default settings and take what I get. I used the scans and have changed it to daily time period.

I don't know if you have to change the variables per chart, for example if I should go in there and set the atr and the multiplier or if the default settings work for all charts. Open to ideas and suggestions.

Thanks for any help you guys can give. @chewie76
 
What would be absolutely amazing if someone has the time for it, is to add upper labels that highlight green or red for the different timeframes when price is above or below short/long entries
Im looking for something along these lines, this was done with the RSM indicator is it possible for this one?

  1. Provides chart labels (upper left corner of price chart) with current status of MTF RSM Trend for the following TF's
    • 1m, 2m, 3m, 4m, 5m, 10m, 15m, 20m, 30m, 1h, 2h, 4h, 1d, 2d, 3d, 4d, 1wk, 1mnth
    • Add indicator for each time frame you would like shown
Ruby:
#START OF RSI/Stochastic/MACD Confluence Strategy for ThinkOrSwim
# RSM_MTF_Labels
#
#CHANGELOG
# 2020.12.30 V2.1 @SuryaKiranC - Fork from @cos251 Version, to reduce the number of lines in code and optimize for performance.
#
# 2020.12.11 V1.1 @cos251 - Added 2D, 3D, 4D, 1WK, 1MNTH Agg Period Labels
#
# 2020.12.02 V1.0 @cos251 - Added RSM signal calculation for following timeframes:
# - 1m, 2m, 5m, 15m, 30m, 1h, 2h, 4h, D
# - Label will be added to top of chart for every allowed TF
# - Label will read "TF:L(Long):S(Short):I(Idle)"
# - Label Color will be green, red or gray accordingly
#
#
#REQUIREMENTS - RSI Set to 7, EXPONENTIAL
# Stoch Slow 14 and 3 WILDERS
# MACD 12,26,9 WEIGHTED
#
#ORIGINAL REQUEST - @Joseph Patrick 18
# - Link: https://usethinkscript.com/threads/mimicking-power-x-strategy-by-markus-heitkoetter.4283/
#
#

input period = AggregationPeriod.DAY;

DefineGlobalColor("UpTrend", Color.Green);
DefineGlobalColor("DownTrend", Color.RED);
DefineGlobalColor("NoTrend", Color.GRAY);

script RSM_ {

input aP = AggregationPeriod.DAY;
# RSI
def lengthRSI = 7;
def averageTypeRSI = AverageType.EXPONENTIAL;
# Stochastic
def over_boughtSt = 80;
def over_soldSt = 20;
def KPeriod = 14;
def DPeriod = 3;
input averageTypeStoch = AverageType.WILDERS;
# MACD
def fastLength = 12;
def slowLength = 26;
def MACDLength = 9;
def averageTypeMACD = AverageType.WEIGHTED;

###############################################################
########## RSI #########
################################################################

def NetChgAvg = MovingAverage(averageTypeRSI, close(period = aP) - close(period = aP)[1], lengthRSI);
def TotChgAvg = MovingAverage(averageTypeRSI, AbsValue(close(period = aP) - close(period = aP)[1]), lengthRSI);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI_ = 50 * (ChgRatio + 1);

################################################################
########## Stochastic Slow #########
################################################################

def SlowK_ = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, high(period = aP), low(period = aP), close(period = aP), 3, if (averageTypeStoch == 1) then AverageType.SIMPLE else AverageType.EXPONENTIAL).FullK;
def SlowD_ = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, high(period = aP), low(period = aP), close(period = aP), 3, if (averageTypeStoch == 1) then AverageType.SIMPLE else AverageType.EXPONENTIAL).FullD;

################################################################
########## MACD ###########
################################################################

def Value_ = MovingAverage(averageTypeMACD, close(period = aP), fastLength) - MovingAverage(averageTypeMACD, close(period = aP), slowLength);
def Avg_ = MovingAverage(averageTypeMACD, Value_, MACDLength);
def Diff_ = Value_ - Avg_;

#################################################################
########## Trend & Labels #########
#################################################################
def UpTrend_ = if RSI_ >= 50 and SlowK_ >= 50 and Value_ > Avg_ then 1 else 0;
def DownTrend_ = if RSI_ < 50 and SlowK_ < 50 and Value_ < Avg_ then 1 else 0;
plot Trend_ = if UpTrend_ then 1 else if DownTrend_ then 0 else -1;

}

def currentPeriod = GetAggregationPeriod();
def RSM;

if period >= currentPeriod {
RSM = RSM_(aP = period);

} else {
RSM = Double.NaN;

}

AddLabel(!IsNaN(RSM), if period == AggregationPeriod.MONTH then "M"
else if period == AggregationPeriod.WEEK then "W"
else if period == AggregationPeriod.FOUR_DAYS then "4D"
else if period == AggregationPeriod.THREE_DAYS then "3D"
else if period == AggregationPeriod.TWO_DAYS then "2D"
else if period == AggregationPeriod.DAY then "D"
else if period == AggregationPeriod.FOUR_HOURS then "4H"
else if period == AggregationPeriod.TWO_HOURS then "2H"
else if period == AggregationPeriod.HOUR then "60m"
else if period == AggregationPeriod.THIRTY_MIN then "30m"
else if period == AggregationPeriod.TWENTY_MIN then "20m"
else if period == AggregationPeriod.FIFTEEN_MIN then "15m"
else if period == AggregationPeriod.TEN_MIN then "10m"
else if period == AggregationPeriod.FIVE_MIN then "5m"
else if period == AggregationPeriod.FOUR_MIN then "4m"
else if period == AggregationPeriod.THREE_MIN then "3m"
else if period == AggregationPeriod.TWO_MIN then "2m"
else if period == AggregationPeriod.MIN then "1m"
else "", if RSM == 1 then GlobalColor("UpTrend") else if RSM == 0 then GlobalColor("DownTrend") else GlobalColor("NoTrend"));
 
Last edited by a moderator:
Capture.png


Can someone define these variables for me? I didn't see it anywhere in the thread.

n = the amount of bars that are considered based on the time frame selected. For example if I choose daily, It will look back 20 days?
fractal energy length = ? (Maybe the amount of bars to determine a fractal pattern)?
fractal energy threshold = ?
atr mult = If the average true range is =0.53 the profit and short targets at 50% and 75% lines are shown at =ATR x 0.7 with apart?
natr = ?
avg type=?

Trying to figure this out to make sure I'm using the right settings. I basically use this with the default settings and take what I get. I used the scans and have changed it to daily time period.

I don't know if you have to change the variables per chart, for example if I should go in there and set the atr and the multiplier or if the default settings work for all charts. Open to ideas and suggestions.

Thanks for any help you guys can give. @chewie76
n is the number of bars to look back. I keep as default, but sometimes I may look at a length of 40 or so to back test. I don't change any of the other inputs. This was original code from Mobius. Thanks.
 
What specific changes would I make to expand the lines on an hour chart? N?

EDIT: I changed N to 50 and only the solid bars got longer. Dashed bars stayed the same.
 
i know this might be uncessary but is there a way to bring the labels of short and long targets the the complete left side of the lines, not above. i have to zoom really in sometimes to see the candle sticks. thank you @chewie76
 
i know this might be uncessary but is there a way to bring the labels of short and long targets the the complete left side of the lines, not above. i have to zoom really in sometimes to see the candle sticks. thank you @chewie76
I'm not sure if that can be done.
 
The Automatic Quadrant Lines is a trading strategy upper indicator that projects where price might go in the future. Use weekly/daily/4 hr chart for swing trading. Use 30 min or less for day trading. This indicator shows you the long entry and long target. It shows you a short entry and short target. In the indicator, L/E is Long Entry, and S/E is Short Entry. The targets show the price in the chart bubble. There is a break down target line (dark green) that indicates if price breaks lower than the support line, this is where price may break down to. The indicator includes an up and down arrow that indicates when price breaks through the Long or Short Entry line. There are also alerts built in when the arrows appear.

Long strategy lines are dashed and have a (2) weight while short strategy are solid and single weighted lines.

(NOTE: If price breaks down or up from the dark red support and resistance lines, a new set of lines will appear. There are no guarantees price will hit the target.)

Here are some examples.

/RTY on 4 hr chart.
QHCgUTb.jpg


/ES on 15m chart. Price broke above target on FED news.
eXuBWHZ.jpg


/NQ on 4 hr chart. Hit target.
6f667mU.jpg


Tesla on 4 hr chart. Above the 50% line. Target at $751.80.
xZ8fu65.jpg


/SI on 10 min chart. Hit target.
nTh5CZH.jpg


Shareable Link:
http://tos.mx/2pnajoG

Long Entry Scan Alert
http://tos.mx/3Jppd0g

Short Entry Scan Alert
http://tos.mx/KGlOVLi

CODE:

Code:
#Automatic Quadrant Lines

#based on Mobius's Fractal Pivot Strategy

#developed by Chewie76 on 8/27/2021



# User Inputs

input n = 20;

input FractalEnergyLength = 8;

input FractalEnergyThreshold = .68;

input AtrMult = .70;

input nATR = 4;

input AvgType = AverageType.HULL;

input LabelsOn = yes;

input AlertsOn = yes;



# 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[1]) - Min(l, c[1])), 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[1];

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[1];

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[1] < l

                  then l[1]

                  else fold r = 0 to 20

                       with a = NaN

                       while IsNaN(a)

                       do if GetValue(l[1], r) < l

                          then GetValue(l[1], r)

                          else NaN

            else Double.NaN;

def PHExitValue = if !IsNaN(PHExit)

                  then PHExit

                  else PHExitValue[1];

def PHExitBar = if (bar > n and

                    h == Highest(h, n) and

                    hh)

                then if l[1] < l

                then bar - 1

                else fold d = 0 to 20

                     with y = NaN

                     while IsNaN(y)

                     do if GetValue(l[1], 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[1];

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[1];

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[1] > h

              then h[1]

              else fold t = 0 to 20

                   with w = NaN

                   while IsNaN(w)

                   do if GetValue(h[1], t) > h

                      then GetValue(h[1], t)

                      else NaN

              else NaN;

def PLEntryValue = if !IsNaN(PLEntry)

                   then PLEntry

                   else PLEntryValue[1];

def PLEntryBar =  if (bar > n and

                  l == Lowest(l, n) and

                  ll)

                  then if h[1] > h

                       then bar - 1

                       else fold u = 0 to 20

                            with z = NaN

                            while IsNaN(z)

                            do if GetValue(h[1], u) > h

                               then GetValue(bar - 1, u)

                               else NaN

              else NaN;



# Plots



plot R1 = if bar >= HighestAll(PHBar)

          then HighestAll(if isNaN(close[-1])

                          then PHValue

                          else nan)

         else nan;

R1.SetDefaultColor(Color.dark_red);

R1.SetLineWeight(1);

plot ShortEntry = if bar >= HighestAll(PHexitBar)

                   then HighestAll(if isNaN(close[-1])

                                   then PHExitValue

                                   else nan)

                   else nan;

ShortEntry.SetDefaultColor(Color.red);

def SE =(if isNaN(ShortEntry[1]) then ShortEntry else Double.NaN);

addchartBubble(LabelsOn and ShortEntry, SE,"S/E",color.red);



plot S1 = if bar >= HighestAll(PLBar)

          then HighestAll(if isNaN(c[-1])

                          then PLValue

                          else nan)

          else nan;

S1.SetDefaultColor(Color.dark_red);

S1.SetLineWeight(3);

plot LongEntry = if bar >= HighestAll(PLEntryBar)

                    then HighestAll(if isNaN(c[-1])

                                    then PLEntryValue

                                    else nan)

                    else nan;

LongEntry.SetDefaultColor(Color.GREEN);

LongEntry.SetStyle(Curve.long_DASH);

LongEntry.SetLineWeight(2);

def LE =(if isNaN(LongEntry[1]) then LongEntry else Double.NaN);

addchartBubble(LabelsOn and LongEntry, LE,"L/E",color.green);


plot UpArrow = if c crosses above LongEntry and FE > .5

               then l

               else Double.NaN;

UpArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);

UpArrow.SetLineWeight(5);

UpArrow.SetDefaultColor(Color.GREEN);

plot DnArrow = if c crosses below ShortEntry and ((FE > .618)

                or (FE < .382))

               then h

               else Double.NaN;

DnArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

DnArrow.SetLineWeight(5);

DnArrow.SetDefaultColor(Color.RED);



plot Fifty = (LongEntry - S1) + LongEntry;

Fifty.setdefaultcolor(color.yellow);

Fifty.SetStyle(Curve.long_DASH);

Fifty.setlineweight(2);



plot SeventyFive = (LongEntry - S1) + Fifty;

SeventyFive.setdefaultcolor(color.cyan);

SeventyFive.SetStyle(Curve.long_DASH);

SeventyFive.setlineweight(2);



plot Target = (LongEntry - S1) + SeventyFive;

Target.setdefaultcolor(color.red);

Target.SetStyle(Curve.long_DASH);

Target.setlineweight(3);

def LT =(if isNaN(TARGET[1]) then Target else Double.NaN);

addchartBubble(LabelsOn and Target, LT,"LONG TARGET: " + asDollars(LT),color.red);



plot BreakDownTarget = S1 -(LongEntry - S1);

BreakDownTarget.setdefaultcolor(color.dark_Green);

BreakDownTarget.SetStyle(Curve.long_DASH);

BreakDownTarget.setlineweight(3);



plot S_Fifty = ShortEntry - (R1 - ShortEntry);

S_Fifty.setdefaultcolor(color.yellow);

S_Fifty.setlineweight(1);



plot S_SeventyFive = S_Fifty - (R1 - ShortEntry);

S_SeventyFive.setdefaultcolor(color.cyan);

S_SeventyFive.setlineweight(1);



plot S_ShortTarget = S_SeventyFive - (R1 - ShortEntry);

S_ShortTarget.setdefaultcolor(color.green);

S_ShortTarget.setlineweight(1);

def ST =(if isNaN(S_ShortTarget[1]) then S_ShortTarget else Double.NaN);

addchartBubble(LabelsOn and S_ShortTarget, ST,"SHORT TARGET: " + asDollars(ST),color.light_green);



# Alerts

Alert(AlertsOn and UpArrow, " ", Alert.Bar, Sound.ding);

Alert(AlertsOn and DnArrow, " ", Alert.Bar, Sound.ding);
Thank you for a great indicator testing it with some charts. Is there anyway to use a scan on the LE SE when they pop up on the chart .This could give an early indication of the buy sell signals coming .Also testing to see if could use them as a signal. I only know how to change a little coding not how to code.Would greatly appreciate any help.THANKS
 
Thank you for a great indicator testing it with some charts. Is there anyway to use a scan on the LE SE when they pop up on the chart .This could give an early indication of the buy sell signals coming .Also testing to see if could use them as a signal. I only know how to change a little coding not how to code.Would greatly appreciate any help.THANKS
Yes, you can create a scan with that setting.
 
The Automatic Quadrant Lines is a trading strategy upper indicator that projects where price might go in the future. Use weekly/daily/4 hr chart for swing trading. Use 30 min or less for day trading. This indicator shows you the long entry and long target. It shows you a short entry and short target. In the indicator, L/E is Long Entry, and S/E is Short Entry. The targets show the price in the chart bubble. There is a break down target line (dark green) that indicates if price breaks lower than the support line, this is where price may break down to. The indicator includes an up and down arrow that indicates when price breaks through the Long or Short Entry line. There are also alerts built in when the arrows appear.

Long strategy lines are dashed and have a (2) weight while short strategy are solid and single weighted lines.

(NOTE: If price breaks down or up from the dark red support and resistance lines, a new set of lines will appear. There are no guarantees price will hit the target.)

Here are some examples.

/RTY on 4 hr chart.
QHCgUTb.jpg


/ES on 15m chart. Price broke above target on FED news.
eXuBWHZ.jpg


/NQ on 4 hr chart. Hit target.
6f667mU.jpg


Tesla on 4 hr chart. Above the 50% line. Target at $751.80.
xZ8fu65.jpg


/SI on 10 min chart. Hit target.
nTh5CZH.jpg


Shareable Link:
http://tos.mx/2pnajoG

Long Entry Scan Alert
http://tos.mx/3Jppd0g

Short Entry Scan Alert
http://tos.mx/KGlOVLi

CODE:

Code:
#Automatic Quadrant Lines

#based on Mobius's Fractal Pivot Strategy

#developed by Chewie76 on 8/27/2021



# User Inputs

input n = 20;

input FractalEnergyLength = 8;

input FractalEnergyThreshold = .68;

input AtrMult = .70;

input nATR = 4;

input AvgType = AverageType.HULL;

input LabelsOn = yes;

input AlertsOn = yes;



# 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[1]) - Min(l, c[1])), 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[1];

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[1];

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[1] < l

                  then l[1]

                  else fold r = 0 to 20

                       with a = NaN

                       while IsNaN(a)

                       do if GetValue(l[1], r) < l

                          then GetValue(l[1], r)

                          else NaN

            else Double.NaN;

def PHExitValue = if !IsNaN(PHExit)

                  then PHExit

                  else PHExitValue[1];

def PHExitBar = if (bar > n and

                    h == Highest(h, n) and

                    hh)

                then if l[1] < l

                then bar - 1

                else fold d = 0 to 20

                     with y = NaN

                     while IsNaN(y)

                     do if GetValue(l[1], 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[1];

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[1];

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[1] > h

              then h[1]

              else fold t = 0 to 20

                   with w = NaN

                   while IsNaN(w)

                   do if GetValue(h[1], t) > h

                      then GetValue(h[1], t)

                      else NaN

              else NaN;

def PLEntryValue = if !IsNaN(PLEntry)

                   then PLEntry

                   else PLEntryValue[1];

def PLEntryBar =  if (bar > n and

                  l == Lowest(l, n) and

                  ll)

                  then if h[1] > h

                       then bar - 1

                       else fold u = 0 to 20

                            with z = NaN

                            while IsNaN(z)

                            do if GetValue(h[1], u) > h

                               then GetValue(bar - 1, u)

                               else NaN

              else NaN;



# Plots



plot R1 = if bar >= HighestAll(PHBar)

          then HighestAll(if isNaN(close[-1])

                          then PHValue

                          else nan)

         else nan;

R1.SetDefaultColor(Color.dark_red);

R1.SetLineWeight(1);

plot ShortEntry = if bar >= HighestAll(PHexitBar)

                   then HighestAll(if isNaN(close[-1])

                                   then PHExitValue

                                   else nan)

                   else nan;

ShortEntry.SetDefaultColor(Color.red);

def SE =(if isNaN(ShortEntry[1]) then ShortEntry else Double.NaN);

addchartBubble(LabelsOn and ShortEntry, SE,"S/E",color.red);



plot S1 = if bar >= HighestAll(PLBar)

          then HighestAll(if isNaN(c[-1])

                          then PLValue

                          else nan)

          else nan;

S1.SetDefaultColor(Color.dark_red);

S1.SetLineWeight(3);

plot LongEntry = if bar >= HighestAll(PLEntryBar)

                    then HighestAll(if isNaN(c[-1])

                                    then PLEntryValue

                                    else nan)

                    else nan;

LongEntry.SetDefaultColor(Color.GREEN);

LongEntry.SetStyle(Curve.long_DASH);

LongEntry.SetLineWeight(2);

def LE =(if isNaN(LongEntry[1]) then LongEntry else Double.NaN);

addchartBubble(LabelsOn and LongEntry, LE,"L/E",color.green);


plot UpArrow = if c crosses above LongEntry and FE > .5

               then l

               else Double.NaN;

UpArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);

UpArrow.SetLineWeight(5);

UpArrow.SetDefaultColor(Color.GREEN);

plot DnArrow = if c crosses below ShortEntry and ((FE > .618)

                or (FE < .382))

               then h

               else Double.NaN;

DnArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

DnArrow.SetLineWeight(5);

DnArrow.SetDefaultColor(Color.RED);



plot Fifty = (LongEntry - S1) + LongEntry;

Fifty.setdefaultcolor(color.yellow);

Fifty.SetStyle(Curve.long_DASH);

Fifty.setlineweight(2);



plot SeventyFive = (LongEntry - S1) + Fifty;

SeventyFive.setdefaultcolor(color.cyan);

SeventyFive.SetStyle(Curve.long_DASH);

SeventyFive.setlineweight(2);



plot Target = (LongEntry - S1) + SeventyFive;

Target.setdefaultcolor(color.red);

Target.SetStyle(Curve.long_DASH);

Target.setlineweight(3);

def LT =(if isNaN(TARGET[1]) then Target else Double.NaN);

addchartBubble(LabelsOn and Target, LT,"LONG TARGET: " + asDollars(LT),color.red);



plot BreakDownTarget = S1 -(LongEntry - S1);

BreakDownTarget.setdefaultcolor(color.dark_Green);

BreakDownTarget.SetStyle(Curve.long_DASH);

BreakDownTarget.setlineweight(3);



plot S_Fifty = ShortEntry - (R1 - ShortEntry);

S_Fifty.setdefaultcolor(color.yellow);

S_Fifty.setlineweight(1);



plot S_SeventyFive = S_Fifty - (R1 - ShortEntry);

S_SeventyFive.setdefaultcolor(color.cyan);

S_SeventyFive.setlineweight(1);



plot S_ShortTarget = S_SeventyFive - (R1 - ShortEntry);

S_ShortTarget.setdefaultcolor(color.green);

S_ShortTarget.setlineweight(1);

def ST =(if isNaN(S_ShortTarget[1]) then S_ShortTarget else Double.NaN);

addchartBubble(LabelsOn and S_ShortTarget, ST,"SHORT TARGET: " + asDollars(ST),color.light_green);



# Alerts

Alert(AlertsOn and UpArrow, " ", Alert.Bar, Sound.ding);

Alert(AlertsOn and DnArrow, " ", Alert.Bar, Sound.ding);
anyway to move bubbles over? i tried code below, no luck,,

also any possibility to add chart bubbles to identifying each line???

any assistance will be greatly appreciated,,

input showBubble = yes;
input ShiftBubble = -75;
def n1 = ShiftBubble + 1;
def cond = showBubble and IsNaN(close[ShiftBubble]) and !IsNaN(close[n1]) ;
 
anyway to move bubbles over? i tried code below, no luck,,

also any possibility to add chart bubbles to identifying each line???

any assistance will be greatly appreciated,,

input showBubble = yes;
input ShiftBubble = -75;
def n1 = ShiftBubble + 1;
def cond = showBubble and IsNaN(close[ShiftBubble]) and !IsNaN(close[n1]) ;
To add more chart bubbles, just use this code and replace "LongEntry" with the plots you want to chart. addchartBubble(LabelsOn and LongEntry, LE,"L/E",color.green);
 
To add more chart bubbles, just use this code and replace "LongEntry" with the plots you want to chart. addchartBubble(LabelsOn and LongEntry, LE,"L/E",color.green);
awesome, will give that a try,,

while i have your attention,,,, do you know if is possible to code a dynamic ema? 8ema turns green when it is above the 21 ema, 21 ema turns green when above the 8ema and red when it is below the 8 ema,,

your time and effort is greatly appreciated
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
408 Online
Create Post

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