Repaints MTF Oliver Velez's Fabulous 4 For ThinkOrSwim

Repaints

GoLo

Member
VIP
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);
 
Last edited by a moderator:

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

One follow up, noticed on a stock this morning it was pulling high as of 1500 vs 1515. If you change the period to 15m it seemed to fix it and plot as of 1515. I've changed the code above accordingly
https://cdn.discordapp.com/attachments/1139523883712655421/1148987907139448994/image.png
Wondering if you could actually create a 'box' for the 'no trade zone' like the guy in the video mentioned that way it would be easier to place stops. Just downloaded ur code and im trying to figure out the line/area where the last 45 mins trade happened. Thanks for coding btw; wish i had known how to code.
 
Wondering if you could actually create a 'box' for the 'no trade zone' like the guy in the video mentioned that way it would be easier to place stops. Just downloaded ur code and im trying to figure out the line/area where the last 45 mins trade happened. Thanks for coding btw; wish i had known how to code.
I'm pretty new just picking up stuff here and there. I'm away but when I get back I was thinking the same and would like to extend box for about the 1st hour to hour and half of market open. I was looking last night and I saw mashume helped do a box for someone trying to plot London, Asia and US high lows. So I'll take a look at his code when I get back. I was having a hard time plucking the ema's at a specific point in time and his code is what I ended up using. Hope you find it useful. I foundt it's an easy auto trade plan that you can scan through early am without having to create a trade plan for each stock you follow.
 
Thank you for your efforts. I love using the Fab 4 in the first hour or two of trading. Look forward to trying your code. Quick question once this is set will it work on all time frames? Especially the 2 minute. Thanks again.
 
1694040857596.png
 
For reference 1 and 2 for Tesla are the last 45 minute range, however the 200 SMA (#3) is below so that is the bottom of the "zone"
 
Last edited:
Thank you for your efforts. I love using the Fab 4 in the first hour or two of trading. Look forward to trying your code. Quick question once this is set will it work on all time frames? Especially the 2 minute. Thanks again.
Very welcome, I coded it to use on 2m timeframe but I pulled up on a 5m and 10m chart and seemed to work as well (theoretically should work on anything less than 45 minutes since pulling last 45 minutes of data for the day).
I just modified an ORB script so that part should pull the high/low of last 45 minutes and then just comparing that to 20 and 200 SMA to find highest/lowest. Didn't code anything for close as that should already be encapsulated by high and low of last 45 minutes.
 
I'm pretty new just picking up stuff here and there. I'm away but when I get back I was thinking the same and would like to extend box for about the 1st hour to hour and half of market open. I was looking last night and I saw mashume helped do a box for someone trying to plot London, Asia and US high lows. So I'll take a look at his code when I get back. I was having a hard time plucking the ema's at a specific point in time and his code is what I ended up using. Hope you find it useful. I foundt it's an easy auto trade plan that you can scan through early am without having to create a trade plan for each stock you follow.
I have spent an hour so far to see how this study is going to work out and will possibly utilize it tmrw. Also i have figured out where u have coded the last 45 mins high/low. Again, thanks for having this study coded.
 
I just want to point out a slight issue with the 200 SMA. It changes quite a bit depending on the time frame you are on. I do not know if this will affect this strategy but in some cases it may. I will test it out.
Try Spy at end of today.
200 SMA Location:
2m - @1600: 445.95
5m - @1600: 448.61
15m - @1600: 448.63
30m -@1600: 449.96
That is a 4 point spread from 2m to 30m.
 
I just want to point out a slight issue with the 200 SMA. It changes quite a bit depending on the time frame you are on. I do not know if this will affect this strategy but in some cases it may. I will test it out.
Try Spy at end of today.
200 SMA Location:
2m - @1600: 445.95
5m - @1600: 448.61
15m - @1600: 448.63
30m -@1600: 449.96
That is a 4 point spread from 2m to 30m.

Is there a way to use this study for extended hours gap ups/downs to regular trading hours since previous day close will be way off?
 
I just want to point out a slight issue with the 200 SMA. It changes quite a bit depending on the time frame you are on. I do not know if this will affect this strategy but in some cases it may. I will test it out.
Try Spy at end of today.
200 SMA Location:
2m - @1600: 445.95
5m - @1600: 448.61
15m - @1600: 448.63
30m -@1600: 449.96
That is a 4 point spread from 2m to 30m.
Thanks for pointing out, yes definitely will move the zone. I believe he uses primarily on 2m. I think the "zone" will still plot correctly on different timeframes but not sure how much it skews strategy.
 
Is there a way to use this study for extended hours gap ups/downs to regular trading hours since previous day close will be way off?
Not sure if I understand question, I believe if RTH opens way off (up or down) you are in a zone 3 which is likely a reversion to the 20 SMA. Throw on AMZN and review last 10 days, here's a picture, I actually throw on Bollinger Bands and see if it opens outside of those (The gray clouds are Bollinger Bands, Green/Red are Keltner Bands for comparison) This is an easy short with that candle formation outside of bands after first candle. If price opens within the "no trade zone" there is no trade to take.

1694057385958.png
 
Last edited:
I just want to point out a slight issue with the 200 SMA. It changes quite a bit depending on the time frame you are on. I do not know if this will affect this strategy but in some cases it may. I will test it out.
Try Spy at end of today.
200 SMA Location:
2m - @1600: 445.95
5m - @1600: 448.61
15m - @1600: 448.63
30m -@1600: 449.96
That is a 4 point spread from 2m to 30m.
Oliver uses 2 min chart for most part
He says this works on whatever timeframe you use, but since these do adjust btwn diff TF's it would make sense for the script to reflect that
 
Not sure if I understand question, I believe if RTH opens way off (up or down) you are in a zone 3 which is likely a reversion to the 20 SMA. Throw on AMZN and review last 10 days, here's a picture, I actually throw on Bollinger Bands and see if it opens outside of those (The gray clouds are Bollinger Bands, Green/Red are Keltner Bands for comparison) This is an easy short with that candle formation outside of bands after first candle. If price opens within the "no trade zone" there is no trade to take.

View attachment 19665
My question was whether its possible to create a no trading zone/box/block during extended hours to trade during regular trading hours but i understand it would make the whole fab4 study invalid since the study itself is about including previous day close and last 45mins high/low. I see u and oliver have mentioned zone 1,2,3... are these fib levels? If u have these zones in the study then where exactly can i find them to activate/turn on? Thanks in advance.


Trading during regular hours what i have noticed like a member few posts above is 20sma and 200sma can be off by few points depending on the time frame u r using. longer the time frame, wider the fab4 range gets generated for the next day. Which time frame works best? Idk... Maybe, mark the fab4 range on 2-5min timeframe premarket and then go back to 10-15 mins chart to trade, if u r not a pro trader like me... Correct me if im wrong.
 
Last edited by a moderator:
My question was whether its possible to create a no trading zone/box/block during extended hours to trade during regular trading hours but i understand it would make the whole fab4 study invalid since the study itself is about including previous day close and last 45mins high/low. I see u and oliver have mentioned zone 1,2,3... are these fib levels? If u have these zones in the study then where exactly can i find them to activate/turn on? Thanks in advance.


Trading during regular hours what i have noticed like a member few posts above is 20sma and 200sma can be off by few points depending on the time frame u r using. longer the time frame, wider the fab4 range gets generated for the next day. Which time frame works best? Idk... Maybe, mark the fab4 range on 2-5min timeframe premarket and then go back to 10-15 mins chart to trade, if u r not a pro trader like me... Correct me if im wrong.
Oh I u understand. I have a 30m ORB with FIB targets on another chart I use after 10:00. I'll post it Monday when I get back to my computer. The Zone 3 is referring to Oliver's strategy video and is a "general area" extended from 20 SMA, no real indicator to denote zones. I just utilize on 2 minute chart for zone, but you can experiment, longer time frames can give a pretty large zone. He has three or so videos on this, I'd suggest watching them before utilizing this indicator. Hope that helps. Happy trading.
 
Last edited:

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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