EMA + VWAP + MACD Buy/Sell Signal

rewardiaz

New member
VIP
Hello Everyone,

I want to begin by mentioning that I am completely new to the world of trading. Nevertheless, I have been reading Merry's posts and scripts in order to increase my knowledge.

I have been searching for a strategy to scalp the SPY and observed something interesting when combining 3 indicators on a 5-minute chart.

1 - MAE9
2 - VWAP
3 - MACD

Whenever the MAE9 crosses VWAP (either up or down) and at the same time the MACD[value] crosses MACD[Avg], there is a strong likelihood of the price moving in the desired direction. Other important factors include Market Sentiment, Resistance, and Support.

I'm wondering if someone could assist me in creating a script that can draw an arrow either green or red, so that I can further test out this idea.

Many thanks!
 

Attachments

  • Screenshot 2024-05-13 003138.png
    Screenshot 2024-05-13 003138.png
    42.2 KB · Views: 149
Hello Everyone,

I want to begin by mentioning that I am completely new to the world of trading. Nevertheless, I have been reading Merry's posts and scripts in order to increase my knowledge.

I have been searching for a strategy to scalp the SPY and observed something interesting when combining 3 indicators on a 5-minute chart.

1 - MAE9
2 - VWAP
3 - MACD

Whenever the MAE9 crosses VWAP (either up or down) and at the same time the MACD[value] crosses MACD[Avg], there is a strong likelihood of the price moving in the desired direction. Other important factors include Market Sentiment, Resistance, and Support.

I'm wondering if someone could assist me in creating a script that can draw an arrow either green or red, so that I can further test out this idea.

Many thanks!

here is something to experiment with
it draws vertical lines when both signals occur
...green 2 up signals
...red 2 down signals

this looks for signals that are within x bars back. default is 3 bars.
my thought is, it would be rare for 2 conditions to happen on the same bar.
input within_xbars = 3;


Code:
#avg_vwap_macd_signals

#https://usethinkscript.com/threads/ema-vwap-macd-buy-sell-signal.18730/

def na = Double.NaN;
def bn = BarNumber();
#def data = close;

input within_xbars = 3;

#----------------------
# EMA9
input avg1_type = AverageType.EXPONENTIAL;
#input avg1_type = AverageType.Simple;
input avg1_length = 9;
def avg1 = MovingAverage(avg1_type, close, avg1_length );
input show_average_lines = yes;
plot zavg1 = if show_average_lines then avg1 else na;
zavg1.SetDefaultColor(Color.CYAN);
#zavg1.setlineweight(1);
zavg1.HideBubble();

#----------------------
# vwap
input timeFrame = {default DAY, WEEK, MONTH};
def vwap1 = vwap(period = timeFrame);
plot w = vwap1;

#----------------------
# MACD
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
def macd1_v = macd(fastLength, slowLength, MACDLength, averageType).value;
def macd1_a = macd(fastLength, slowLength, MACDLength, averageType).avg;

#---------------------

def upr1 = avg1 crosses above vwap1;
def upr2 = macd1_v crosses above macd1_a;
def uprx1 = sum(upr1, within_xbars) > 0;
def uprx2 = sum(upr2, within_xbars) > 0;
def up = uprx1 and uprx2;

def dwnr1 = avg1 crosses below vwap1;
def dwnr2 = macd1_v crosses below macd1_a;
def dwnrx1 = sum(dwnr1, within_xbars) > 0;
def dwnrx2 = sum(dwnr2, within_xbars) > 0;
def dwn = dwnrx1 and dwnrx2;


addverticalline(up, "-", color.green);
addverticalline(dwn, "-", color.red);
addverticalline(upr2 , "-");


addchartbubble(0, low,
macd1_v  + "\n" +
macd1_a
, color.yellow, no);
#
 
With the help of another developer's code @khpro59 . I used his logic behind the sell/buy signals and I like so far where this is going. However, somthing is not working right.

Below is where I stand:

Code:
#avg_vwap_macd_signals

#https://usethinkscript.com/threads/ema-vwap-macd-buy-sell-signal.18730/

def na = Double.NaN;
def bn = BarNumber();
def data = open;

input within_xbars = 3;

#----------------------
# EMA9
input avg1_type = AverageType.EXPONENTIAL;
input avg1_length = 9;
def avg1 = MovingAverage(avg1_type, data, avg1_length );
input show_average_lines = yes;
plot zavg1 = if show_average_lines then avg1 else na;
zavg1.SetDefaultColor(Color.CYAN);
zavg1.HideBubble();

#----------------------
# vwap
input timeFrame = {default DAY, WEEK, MONTH};
def vwap1 = vwap(period = timeFrame);
plot w = vwap1;

#----------------------
# MACD
input fastLength = 3;
input slowLength = 10;
input MACDLength = 16;
input averageType = AverageType.SIMPLE;
def macd1_v = macd(fastLength, slowLength, MACDLength, averageType).value;
def macd1_a = macd(fastLength, slowLength, MACDLength, averageType).avg;

#---------------------

def upr1 = avg1 crosses above vwap1;
def upr2 = macd1_v crosses above macd1_a;
def uprx1 = sum(upr1, within_xbars) > 0;
def uprx2 = sum(upr2, within_xbars) > 0;
def up = uprx1 and uprx2;

def dwnr1 = avg1 crosses below vwap1;
def dwnr2 = macd1_v crosses below macd1_a;
def dwnrx1 = sum(dwnr1, within_xbars) > 0;
def dwnrx2 = sum(dwnr2, within_xbars) > 0;
def dwn = dwnrx1 and dwnrx2;

#--------------------------------------
# Display Vertical Setup Lines
input show_setup_bars = yes;
input setup_start_time = 0930; #hint setup_start_time: Must be eastern time
input setup_end_time = 1600;   #hint setup_end_time: Must be eastern time
input alert_on_setup = yes;
input show_bubbles = yes;

def trading_active = SecondsFromTime(setup_start_time) > 0 and SecondsTillTime(setup_end_time) > 0;
def show_setups = show_setup_bars and trading_active;

def typebuy = trading_active and up;
def typesell = trading_active and dwn;

AddVerticalLine(show_setups and typebuy, "Buy", color.green, Curve.SHORT_DASH);
AddVerticalLine(show_setups and typesell, "Sell", color.red, Curve.SHORT_DASH);
# End Display Vertical Setup Lines
#--------------------------------------

#--------------------------------------
# Begin Alerts and Bubbles
alert(alert_on_setup and show_setups and typebuy,"TYPE BUY", alert.BAR, sound.Bell);
AddChartBubble(show_setups and show_bubbles and typebuy, data, "BUY signal: " + Round(data, 2), Color.GRAY, no);
alert(alert_on_setup and show_setups and typesell,"TYPE SELL", alert.BAR, sound.Bell);
AddChartBubble(show_setups and show_bubbles and typesell, data, "SELL signal: " + Round(data, 2), Color.GRAY, no);
# End Begin Alerts and Bubbles
#--------------------------------------

I think the errors are coming from this code section, especially when we’re checking within_xbars = 3.

Code:
def upr1 = avg1 crosses above vwap1;
def upr2 = macd1_v crosses above macd1_a;
def uprx1 = sum(upr1, within_xbars) > 0;
def uprx2 = sum(upr2, within_xbars) > 0;
def up = uprx1 and uprx2;

def dwnr1 = avg1 crosses below vwap1;
def dwnr2 = macd1_v crosses below macd1_a;
def dwnrx1 = sum(dwnr1, within_xbars) > 0;
def dwnrx2 = sum(dwnr2, within_xbars) > 0;
def dwn = dwnrx1 and dwnrx2;

I'd love it if you could take another peek and see how we can get it fixed up. Just keep in mind that there can also be a delay on either side of the crossing. Exmaple:

Senario 1: 9EMA crossed VWAP, Fire Signal when MACD crosses SIGNAL.
Senario 2: MACD crosses SIGNAL, Fire Signal when 9EMA crossed VWAP.
Senario 3: All at once.
 

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
230 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