Moving Average Cross When Above VWAP

Looking for a moving average study like this:
https://usethinkscript.com/threads/moving-average-scalping-strategy-for-thinkorswim.16093/
with Signals Down only if the MA are under VWAP and Up for Over the VWAP?

1. This will plot arrows (Cyan/Magenta) when postion of VWAP considered.
2. If input ARROWS_SHOW_ALL = YES then arrows (White/Yellow) will plot in additon to arrows, in #1 above, even when the VWAP condition is NOT MET
3. Plots are defaulted to be hidden. Mainly used for testing code.
Screenshot 2024-03-09 134614.png
Code:
# Created by Ricky_Gaspard 7-16-2023
# Buying and Selling Indicator Arrows for Scalping
# Modified to Condition Arrows in relation to VWAP

input SHOW_Vwap_MovAvg_PLOTS  = {default "NO", "YES"};
input ARROWS_SHOW_ALL         = {default "NO", "YES"};#NO = ONLY SHOW ARROWS above/bwlow VWAP

plot vwap  = reference VWAP();
plot sma5  = SimpleMovingAvg("length" = 5)."SMA";
plot ema5  = MovAvgExponential("length" = 5)."AvgExp";
plot ema10 = MovAvgExponential("length" = 10)."AvgExp";

vwap.SetHiding(!SHOW_Vwap_MovAvg_PLOTS);
sma5.SetHiding(!SHOW_Vwap_MovAvg_PLOTS);
ema5.SetHiding(!SHOW_Vwap_MovAvg_PLOTS);
ema10.SetHiding(!SHOW_Vwap_MovAvg_PLOTS);

####################################
# Position of VWAP Matters
# Buying Conditions - All MovingAverages must be above VWAP when Condition Occurs

def buycondition1 =
sma5 > vwap and 
ema5 > vwap and
ema10 > vwap and
sma5 is greater than ema10 and
ema5 is greater than ema10 and
ema5 crosses above sma5;

def buycondition2 =
sma5 is greater than ema10 and
ema5 is greater than ema10 and
ema5 crosses above sma5;

#Selling Conditions - All MovingAverages must be below VWAP when Condition Occurs

def sellcondition1 = 
ema5 < vwap and 
ema10 < vwap and
ema5 crosses below ema10;

def sellcondition2 =
ema5 crosses below ema10;

#Determins Conditions of an UP Arrow

plot bullish = if buycondition1 then 1 else 0;

#Determies Conditions of a Down Arrow

plot bearish = if sellcondition1 then 1 else 0;

#Paints Up Arrow On Chart

bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

#Sets Default UP Arrow Color

bullish.SetDefaultColor(Color.CYAN);

#Paints Down Arrow On Chart

bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

#Sets Default Down Arrow Color

bearish.SetDefaultColor(Color.MAGENTA);

#Sets Thickness of Arrows

bullish.SetLineWeight(5);
bearish.SetLineWeight(5);

#########################
#Position of VWAP NOT considered when plotting Arrows

#Determines Conditions of an UP Arrow

plot bullish2 = if buycondition2 then 1 else 0;
bullish2.SetHiding(!ARROWS_SHOW_ALL);

#Determies Conditions of a Down Arrow

plot bearish2 = if sellcondition2 then 1 else 0;
bearish2.SetHiding(!ARROWS_SHOW_ALL);

#Paints Up Arrow On Chart

bullish2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

#Sets Default UP Arrow Color

bullish2.SetDefaultColor(Color.WHITE);

#Paints Down Arrow On Chart

bearish2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

#Sets Default Down Arrow Color

bearish2.SetDefaultColor(Color.YELLOW);

#Sets Thickness of Arrows

bullish2.SetLineWeight(2);
bearish2.SetLineWeight(2);

#
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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