M a c d using percentages

Status
Not open for further replies.

LetsMakeMoney

New member
VIP
I was looking at Drum Rocker's strategy, and when I went to your thread on the Ultra MACD, which is part of his strategy, and noticed that my indicator plots the same exact curve (the one that turns green or red as the case may be) as yours does. My intent was to do away with the problem of trying to compare the MACD of different stocks that have widely different price levels. So I converted the difference between the fast and slow ema into a percentage difference. The idea being that while the stocks may have greatly different prices, the percentage difference between the averages are comparable. A 5% spread between the 12 and 26 ema is the same relative difference by percentage regardless of the price differences between stocks. Here's my script...will be studying yours intently to see what the other curves represent.
Code:
declare lower;

input FastLength = 12; # Faster of the two moving averages
input SlowLength = 26; # Slower of the two moving averages
input FastAvgSmoothingLength = 9;
input FastEMA_Length = 8;
def FastEMAavg = ExpAverage(close,FastEMA_Length);
def P1L = 1;
def PP5L = 0.5;
def ZL = 0;
def MP5L = -0.5;
def M1L = -1;
def SlowAvg = ExpAverage(close,SlowLength); # ema of the slow moving average
def FastAvg = ExpAverage(close,FastLength); # ema of the fast moving average
plot FastSlowPctDiff = ((FastAvg-SlowAvg)/SlowAvg) * 100; # Percent difference between FastAvg and SlowAvg
def FastPctDiff = ((FastAvg - FastAvg[1])/FastAvg[1]) * 100; # Percent difference betwee current and previous bar
plot FastPctDiffAvg = ExpAverage(FastPctDiff,FastAvgSmoothingLength);
FastPctDiffAvg.SetDefaultColor(color.cyan);
def PDGTP = if FastSlowPctDiff > FastSlowPctDiff[1] then 1 else 0;
def PDLTP = if FastSlowPctDiff < FastSlowPctDiff[1] then 1 else 0;
FastSlowPctDiff.AssignValueColor(if PDGTP then Color.GREEN else if PDLTP then Color.RED else Color.YELLOW);
FastSlowPctDiff.SetLineWeight(2);
plot ZLine = ZL;
ZLine.SetDefaultColor(Color.white);
plot P1Line = P1L;
P1Line.SetDefaultColor(color.green);
Plot M1Line = M1L;
M1Line.SetDefaultColor(color.red);
Plot PP5Line = PP5L;
PP5Line.SetDefaultColor(Color.yellow);
PP5Line.SetPaintingStrategy(PaintingStrategy.DASHES);
Plot MP5Line = MP5L;
MP5Line.SetDefaultColor(color.yellow);
MP5Line.SetPaintingStrategy(PaintingStrategy.DASHES);
plot FastEMAImproving = if FastEMAavg > FastEMAavg[1] then 1 else 0;
FastEMAImproving.Hide();
AddLabel(yes,FastEMA_Length + " EMA Improving", if FastEMAImproving then color.green else if FastEMAavg == FastEMAavg[1]  then color.gray else color.red);
AddLabel(yes,FastLength + " EMA Improving",if FastAvg > FastAvg[1] then color.green else color.red);
def BullConditionGo = if FastPctDiffAvg > FastPctDiffAvg[1] and FastSlowPctDiff > FastSlowPctDiff[1] and FastAvg > FastAvg[1] then 1 else 0;
AddLabel(yes, if BullConditionGo then "   Bull Go   " else "Bull No Go",if BullConditionGo then color.green else color.red);
def BullConditionGoPlus = if BullConditionGo and FastSlowPctDiff > 0 then 1 else 0;
AddLabel(yes,if BullConditionGoPlus then "Bull Go Plus" else "          ", if BullConditionGoPlus then color.green else color.gray);
def BearConditionGo = if FastPctDiffAvg < FastPctDiffAvg[1] and FastSlowPctDiff < FastSlowPctDiff[1] and FastAvg < FastAvg[1] then 1 else 0;
AddLabel(yes, if BearConditionGo then "   Bear Go   " else "Bear No Go",if BearConditionGo then color.green else color.red);
def BearConditionGoPlus = if BearConditionGo and FastSlowPctDiff < 0 then 1 else 0;
AddLabel(yes,if BearConditionGoPlus then "Bear Go Plus" else "          ", if BearConditionGoPlus then color.green else color.gray);
# Conditions for scanning
plot BullGoPlus = if BullConditionGoPlus then 1 else 0;
BullGoPlus.Hide();
plot BearGoPlus = if BearConditionGoPlus then 1 else 0;
BearGoPlus.Hide();
plot highestPos = if Highest(FastSlowPctDiff,5) <= 1 then 1 else 0;
highestPos.Hide();
plot lowestPos = if Highest(FastSlowPctDiff,5) >= 0 then 1 else 0;
lowestPos.Hide();
def TanAngle = ATan(close);
AddLabel(yes,"'Angle Improving'", if (TanAngle > TanAngle[1]) then color.green else color.red);
AddLabel(yes,"Previous 'Angle': " + TanAngle[1],color.gray);
AddLabel(yes,"Current 'Angle': " + TanAngle,color.gray);
 
Status
Not open for further replies.

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