Repaints MTF Oliver Velez's Fabulous 4 For ThinkOrSwim

Repaints
This is an attempt to autoplot Oliver Velez's Fabulous 4 trading zone. By way of background, essentially trying to plot the highest of the last 45 minutues of RTH, the 20SMA, 200SMA, and close. Then plotting the lowest of last 45 minutues of RTH, the 20SMA, 200SMA, and close. That box is a no trade zone and gives you a bias for next day based on where price opens (Please see his videos for detailed explanation, link provided in code).
This appears to plot the box properly, I'm not an experienced coder so I'm sure there's better coding available, feel free to improve. One thing I wanted to do is extend the horizontal lines/cloud. Below is the code, thanks to investtheory.com for orignal ORB coding and mashume for a thread on how to pull ema/sma at a specific point in time. Although it appears the cloud is printing correctly, the label does not seem to be properly reflecting the SMA's at close (I was just using labels for reference so will likely hide that part of code anyway). Note that the calculations of the FAB 4 are primarily found in lines 90-163.
Below is the code, feel free to enhance/improve.


#hint period: If you don't want the developing range to look jagged, choose a larger timeframe than the chart (but shorter than or equal to the opening range time window) at which the opening range becomes fixed. For instance, if you have a 30' opening range on a 1' chart and you don't want the OR high/low lines moving every single minute, set the timeframe to 15' or 30' so it will only update twice or once during the OR formation.
#hint orStartTime: Choose the time at which the OR begins forming, in HHMM 24 hour format and in the Eastern time zone. 0930 means 9:30 A.M.
#hint orEndTime: Choose the time at which the OR ends forming, in HHMM 24 hour format and in the Eastern time zone. 1600 means 4:00 P.M. Default setting is 1000.
#hint showOnlyToday: Hide lines on prior days.
#hint showCloud: Paint a cloud in the background during the opening range formation.
#hint showMidpoint: Show a line in the middle of the opening range.
#hint showQuarters: Show lines for 75% and 25% of the opening range, on either side of the midpoint.
#hint showTargets: Plot targets at defined multiples of the opening range width.
#hint useTradeSignals: Turn up/down arrows on or off.
#hint useAlerts: Turn all the alerts on or off with one setting.
#hint multiplier1: Choose the multiple of the OR width that you will use for first target. 1.5 = 150% of the opening range.
#hint multiplier2: Choose the multiple of the OR width that you will use for second target. 1.5 = 150% of the opening range.
#hint multiplier3: Choose the multiple of the OR width that you will use for third target. 1.5 = 150% of the opening range.

# Update 09/5/23, Script was modified from original to attempt to draw Fab 4 box as described by Oliver Velez in this video
(Used last 45 minutes of market activity 1515-1600) can change to personal preference
Ruby:
# inputs
input orStartTime = 1515;
input orEndTime = 1600;
input period = aggregationPeriod.FIFTEEN_MIN;
input showOnlyToday = no;
input showCloud = no; # This cloud is only printing high and low of last 45 minutes of RTH if enabled
input showMidpoint = no;
input showGoldenZone = no;
input useTradeSignals = no;

input showTargets = no;
input multiplier1 = 0.236;
input multiplier2 = 0.618;
input multiplier3 = 1.0;
input multiplier4 = 1.382;
input multiplier5 = 1.618;
input multiplier6 = 2.0;
input multiplier7 = 2.618;




# constants
def na = double.nan;
def hi = high(period = period);
def lo = low(period = period);
defineGlobalColor("Cloud", color.gray);

# opening range time logic
def isOr = secondstilltime(orEndTime) > 0
and secondsfromtime(orStartTime) >= 0;
def today = (!showOnlyToday or getday() == getlastday())
and secondsfromtime(orStartTime) >= 0 and !isNAN(close);

# opening range levels logic
rec orhi =
if orhi[1] == 0
or !isOr[1]
and isOr
then hi
else if isOr
and hi > orhi[1]
then hi
else orhi[1];

rec orlo =
if orlo[1] == 0
or !isOr[1]
and isOr
then lo
else if isOr
and lo < orlo[1]
then lo
else orlo[1];

# plots
plot orh = if today < 1 then na else orhi;
plot orl = if today < 1 then na else orlo;
plot orm = if !isOr then (orh + orl) / 2.000 else na;

#Method1 - Previous Day Closing Price (PCL)
input display_method1 = yes;
input showtodayonly = yes;
input aggregationPeriod = AggregationPeriod.DAY;
def pc = close(period = aggregationPeriod)[1];
plot previous_close = if showtodayonly and GetDay() != GetLastDay() then Double.NaN else pc;
previous_close.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
previous_close.SetLineWeight(2);
previous_close.SetHiding(!display_method1);


#=========================================== Add 20/200 SMA ===============================================

# -------------------------------------------- EMA/SMA 1 -----------------------------------------


input EMA1 = 20;

input averageType = AverageType.SIMPLE;
def price = close;

plot EMA_1 = MovingAverage(averageType, price, EMA1);
;

EMA_1.SetDefaultColor(GetColor(8));


# -------------------------------------------- EMA/SMA 2 -----------------------------------------


input EMA2 = 200;

input averageType2 = AverageType.SIMPLE;
def price2 = close;

plot EMA_2 = MovingAverage(averageType2, price2, EMA2);
;

EMA_2.SetDefaultColor(GetColor(2));


# ===================================== Derive EMA's at 1600 hours (Thanks to mashume!) for orignal coding idea=================

def SMA20 = SimpleMovingAvg ( close, length = 20);
def expAtSixteenHundo = if
( secondsFromTime(1600) crosses above 0 )
then expAtSixteenHundo[1]
else SMA20;
AddLabel(yes, "20SMA @ 16:00:" + expAtSixteenHundo, color.yellow); # This does not seem to be SMA at close
plot line20 = expAtSixteenHundo;


# 200 SMA

def SMA200 = SimpleMovingAvg ( close, length = 200);
def expAtSixteenHundred = if
( secondsFromTime(1600) crosses above 0 )
then expAtSixteenHundred[1]
else SMA200;
AddLabel(yes, "200SMA @ 16:00:" + expAtSixteenHundred, color.red); # This does not seem to be SMA at close
plot line200 = expAtSixteenHundred;



# ===================================== End coding for Derive EMA's at 1600 hours ===============================


# ===================================== Closing Range Cloud Only ================================

addcloud(if showcloud and isOR then orh else na, if showcloud and isOR then orl else na, color1 = globalColor("Cloud"));


# ===================================== FAB 4 Calculations and Cloud ===============================

input showFAB4Cloud = yes; # This cloud attempts to plot the Fab4 Highest and lowest of last 45mins of trading, 20SMA, 200SMA and DailyClose
defineGlobalColor("FAB4Cloud", color.gray);


plot FAB4maximum = max(orhi,max(SMA20,SMA200));
#plot FaB4maximum = max(orh,max(orl,max(ema1,ema2)));

plot FAB4minimum = min(orlo,min(SMA20,SMA200));

addcloud(if showFAB4Cloud and isOR then FAB4maximum else na, if showFAB4Cloud and isOR then FAB4minimum else na, color1 = globalColor("FAB4Cloud"));


#------------------------------------------------------- Plot Long/Short GZ .618 - .786 ---------------------------------------

plot short_786 = if !isOr then (orh + orm) * 0.786 else na;
plot short_618 = if !isOr then (orh + orm) * 0.618 else na;
plot long_786 = if !isOr then (orl + orm) * 0.214 else na;
plot long_618 = if !isOr then (orl + orm) * 0.382 else na;

orm.setHiding(!showMidpoint);
short_786.setHiding(!showGoldenZone);
short_618.setHiding(!showGoldenZone);
long_786.setHiding(!showGoldenZone);
long_618.setHiding(!showGoldenZone);

def range = orhi - orlo;

plot u1 = if showTargets and !isOr then orh + range * multiplier1 else na;
plot u2 = if showTargets and !isOr then orh + range * multiplier2 else na;
plot u3 = if showTargets and !isOr then orh + range * multiplier3 else na;
plot u4 = if showTargets and !isOr then orh + range * multiplier4 else na;
plot u5 = if showTargets and !isOr then orh + range * multiplier5 else na;
plot u6 = if showTargets and !isOr then orh + range * multiplier6 else na;
plot u7 = if showTargets and !isOr then orh + range * multiplier7 else na;

plot l1 = if showTargets and !isOr then orl - range * multiplier1 else na;
plot l2 = if showTargets and !isOr then orl - range * multiplier2 else na;
plot l3 = if showTargets and !isOr then orl - range * multiplier3 else na;
plot l4 = if showTargets and !isOr then orl - range * multiplier4 else na;
plot l5 = if showTargets and !isOr then orl - range * multiplier5 else na;
plot l6 = if showTargets and !isOr then orl - range * multiplier6 else na;
plot l7 = if showTargets and !isOr then orl - range * multiplier7 else na;

plot highBreak = useTradeSignals and !isOr and close crosses above orh;
plot lowBreak = useTradeSignals and !isOr and close crosses below orl;

plot midhighbreak = useTradeSignals and !isOr and close crosses above orm;
plot midlowbreak = useTradeSignals and !isOr and close crosses below orm;

plot highQBreak = useTradeSignals and !isOr and close crosses above short_786;
plot lowQBreak = useTradeSignals and !isOr and close crosses below long_786;

plot longTarget1 = useTradeSignals and !isOr and close crosses above u1;
plot longTarget2 = useTradeSignals and !isOr and close crosses above u2;
plot longTarget3 = useTradeSignals and !isOr and close crosses above u3;
plot longTarget4 = useTradeSignals and !isOr and close crosses above u4;
plot longTarget5 = useTradeSignals and !isOr and close crosses above u5;
plot longTarget6 = useTradeSignals and !isOr and close crosses above u6;
plot longTarget7 = useTradeSignals and !isOr and close crosses above u7;



plot shortTarget1 = useTradeSignals and !isOr and close crosses below l1;
plot shortTarget2 = useTradeSignals and !isOr and close crosses below l2;
plot shortTarget3 = useTradeSignals and !isOr and close crosses below l3;
plot shortTarget4 = useTradeSignals and !isOr and close crosses below l4;
plot shortTarget5 = useTradeSignals and !isOr and close crosses below l5;
plot shortTarget6 = useTradeSignals and !isOr and close crosses below l6;
plot shortTarget7 = useTradeSignals and !isOr and close crosses below l7;



# look and feel
orh.setPaintingStrategy(paintingStrategy.HORIZONTAL);
orl.setPaintingStrategy(paintingStrategy.HORIZONTAL);
orm.setPaintingStrategy(paintingStrategy.HORIZONTAL);
short_786.setPaintingStrategy(paintingStrategy.HORIZONTAL);
short_618.setPaintingStrategy(paintingStrategy.HORIZONTAL);
long_786.setPaintingStrategy(paintingStrategy.HORIZONTAL);
long_618.setPaintingStrategy(paintingStrategy.HORIZONTAL);
orh.setdefaultcolor(color.gray);
orl.setdefaultcolor(color.gray);
orm.setdefaultcolor(color.dark_gray);
short_786.setdefaultcolor(color.yellow);
short_618.setdefaultcolor(color.yellow);
long_786.setdefaultcolor(color.yellow);
long_618.setdefaultcolor(color.yellow);

u1.setPaintingStrategy(paintingStrategy.HORIZONTAL);
u2.setPaintingStrategy(paintingStrategy.HORIZONTAL);
u3.setPaintingStrategy(paintingStrategy.HORIZONTAL);
u4.setPaintingStrategy(paintingStrategy.HORIZONTAL);
u5.setPaintingStrategy(paintingStrategy.HORIZONTAL);
u6.setPaintingStrategy(paintingStrategy.HORIZONTAL);
u7.setPaintingStrategy(paintingStrategy.HORIZONTAL);


l1.setPaintingStrategy(paintingStrategy.HORIZONTAL);
l2.setPaintingStrategy(paintingStrategy.HORIZONTAL);
l3.setPaintingStrategy(paintingStrategy.HORIZONTAL);
l4.setPaintingStrategy(paintingStrategy.HORIZONTAL);
l5.setPaintingStrategy(paintingStrategy.HORIZONTAL);
l6.setPaintingStrategy(paintingStrategy.HORIZONTAL);
l7.setPaintingStrategy(paintingStrategy.HORIZONTAL);

u1.setdefaultcolor(color.cyan);
u2.setdefaultcolor(color.yellow);
u3.setdefaultcolor(color.red);
u4.setdefaultcolor(color.magenta);
u5.setdefaultcolor(color.magenta);
u6.setdefaultcolor(color.orange);
u7.setdefaultcolor(color.orange);


l1.setdefaultcolor(color.cyan);
l2.setdefaultcolor(color.yellow);
l3.setdefaultcolor(color.red);
l4.setdefaultcolor(color.magenta);
l5.setdefaultcolor(color.magenta);
l6.setdefaultcolor(color.orange);
l7.setdefaultcolor(color.orange);

highBreak.setPaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);
lowbreak.setPaintingStrategy(paintingStrategy.BOOLEAN_ARROW_DOWN);
midHighBreak.setPaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);
midLowBreak.setPaintingStrategy(paintingStrategy.BOOLEAN_ARROW_DOWN);
highQBreak.setPaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);
lowQBreak.setPaintingStrategy(paintingStrategy.BOOLEAN_ARROW_DOWN);

highBreak.setdefaultcolor(color.dark_green);
lowbreak.setdefaultcolor(color.dark_red);
midHighBreak.setdefaultcolor(color.dark_green);
midLowBreak.setdefaultcolor(color.dark_red);
highQBreak.setdefaultcolor(color.dark_green);
lowQBreak.setdefaultcolor(color.dark_red);

longTarget1.setPaintingStrategy(paintingStrategy.BOOLEAN_ARROW_DOWN);
longTarget2.setPaintingStrategy(paintingStrategy.BOOLEAN_ARROW_DOWN);
longTarget3.setPaintingStrategy(paintingStrategy.BOOLEAN_ARROW_DOWN);
longTarget4.setPaintingStrategy(paintingStrategy.BOOLEAN_ARROW_DOWN);
longTarget5.setPaintingStrategy(paintingStrategy.BOOLEAN_ARROW_DOWN);

shortTarget1.setPaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);
shortTarget2.setPaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);
shortTarget3.setPaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);
shortTarget4.setPaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);
shortTarget5.setPaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);

longTarget1.setdefaultcolor(color.dark_red);
longTarget2.setdefaultcolor(color.dark_red);
longTarget3.setdefaultcolor(color.dark_red);
longTarget4.setdefaultcolor(color.dark_red);
longTarget5.setdefaultcolor(color.dark_red);

shortTarget1.setdefaultcolor(color.dark_green);
shortTarget2.setdefaultcolor(color.dark_green);
shortTarget3.setdefaultcolor(color.dark_green);
shortTarget4.setdefaultcolor(color.dark_green);
shortTarget5.setdefaultcolor(color.dark_green);
Thumbs up for this concept!

The webinar for this was very good (seems like a good presenter) and reaffirmed some principles of trading. For day trading, however, why is this any different than trading the ORB in the same manner? I will add the 45 minute lines this morning on SPY and QQQ and contrast them with the ORB. It does seem the 200 SMA is a long way out from the 20 SMA for day trading where I usually follow the 8/20 EMAs as probable transition points.
 
Last edited by a moderator:
I'm interested to see how this is working for others? I added the 45 minute lines using "add a drawing" and found that most of these turned out to be pivot points during trading hours. Admittedly I use the 8/20 EMAs and not the 20/200 SMAs for day trading. The ORB breakouts on my charting provided better entry/exit points with the 45 min lines showing as occasional pivot points? If someone is having good success with the fab four I would love the feedback.
 
I'm interested to see how this is working for others? I added the 45 minute lines using "add a drawing" and found that most of these turned out to be pivot points during trading hours. Admittedly I use the 8/20 EMAs and not the 20/200 SMAs for day trading. The ORB breakouts on my charting provided better entry/exit points with the 45 min lines showing as occasional pivot points? If someone is having good success with the fab four I would love the feedback.
I agree with your statement above, I use the ORB I posted in post #20 and seems to work better (for me) than the FAB 4.
 
I agree with your statement above, I use the ORB I posted in post #20 and seems to work better (for me) than the FAB 4.
Maybe there’s something I’m missing but for me my charting with ORB and other indicators is more effective?
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
347 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