SAR MACD for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
z4FXifJ.png

Author Message:
SAR MACD is an idea of implementing Directional MACD with Parabolic SAR to exactly detect and confirm Trend. This p-SAR MACD consist of a HYBRID MACD which acts as MACD TREND oscillator, MACD Oscillator, PSAR Indicator combined with MA line. thus Fake MACD Signals can be eliminated using this SAR MACD. Sideways can be detected using Threshold Levels must be adjusted based on timeframe.

Indicators Hybrid model contains:
1.MACD (12,26,9) Standard with MA Crossovers
2.MACD Trend
3.Parabolic SAR with 0.02
4.Threshold level - indicates Sideways

How to use.
Histogram:
-> HIST MODE: normal MACD indicator
MA Line Color is based on PSAR Direction Blue-Up/ Pink -Down
A crossover upside with a Blue MA line denotes Up confirmation
A Crossover downwards with a red MA line denotes Down Confirmation
Additionally Histogram above zero line and below zero line are to be confirmed

-> MACD MODE: MACD Trend indicator
MA Line Color is based on PSAR Direction Blue-Up/ Pink -Down
A crossover upside with a Blue MA line denotes Up confirmation
A Crossover downwards with a red MA line denotes Down Confirmation
Additionally Histogram above zero line and below zero denotes long term Trend

-> Histogram Color: Indicates candles direction
Yellow indicates Unconfirmed Direction
Green Indicates up direction
Red Indicates Down Direction


Buy Condition:
MA Color - Blue
Histogram- Above Zero
Histogram/Candle -Green
MA Crossover is must
Sell Condition:
MA Color - Red
Histogram- Below Zero
Histogram/Candle -Red
MA Cross under is must

Warning: Must not be used as a standalone indicator. Use for confirmation of your Buy Sell Signals and Entry only.

CODE:

CSS:
#// https://www.tradingview.com/v/uXB6f9Y5/
#// © traderharikrishna
#indicator("SARMACD")
# Converted and mod by Sam4Cok@Samer800    - 05/2023

declare lower;
input ColorBars = yes;
input ShowSignals = no;
input sideways = 5;#,'sideways')
input GraphType = {default MACD, HIST};    # 'Graph Type'
input fastLength = 12;
input slowLength = 26;
input macdLength = 9;
input averageType = AverageType.EXPONENTIAL;

def na = Double.NaN;
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;
def last = isNaN(close);
def macdSel = GraphType==GraphType.MACD;
def HistSel = GraphType==GraphType.HIST;

def sar = ParabolicSAR();
def cross = crosses(close,sar);
def sa = if cross then close else sa[1];
def dir = if sar < close then 1 else -1;

def m = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
def s = MovingAverage(averageType, m, MACDLength);
def h = m - s;

def bc = if dir ==  1 and close > sa and m>0 then  1 else
         if dir == -1 and close < sa and m<0 then -1 else 0;
def hc = if dir ==  1 and close > sa and h>0 then  1 else
         if dir == -1 and close < sa and h<0 then -1 else 0;

plot SigLine = s;
plot Hist = if HistSel then m else na;
plot macd = if macdSel then m else h;

macd.SetLineWeight(3);
macd.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
macd.AssignValueColor(if macdSel then
                      if bc>0 then CreateColor(1, 185, 7) else
                      if bc<0 then CreateColor(224, 4, 4) else Color.YELLOW else
                      if hc>0 then CreateColor(1, 185, 7) else
                      if hc<0 then CreateColor(224, 4, 4) else Color.YELLOW);
Hist.SetLineWeight(2);
Hist.SetDefaultColor(Color.WHITE);
SigLine.SetStyle(Curve.POINTS);
SigLine.AssignValueColor(if dir==1 then Color.CYAN else Color.MAGENTA);

plot limitUp = if last then na else TickSize() * sideways;
plot limitDn = if last then na else TickSize() * -sideways;
plot Mid = if last then na else 0;            # 'Zero line'

limitUp.SetDefaultColor(Color.GRAY);
limitDn.SetDefaultColor(Color.GRAY);
mid.SetDefaultColor(Color.GRAY);
limitUp.SetPaintingStrategy(PaintingStrategy.DASHES);
limitDn.SetPaintingStrategy(PaintingStrategy.DASHES);

# Background
def buy_ = h>0 and dir==1;
def sell_= h<0 and dir==-1;

AddCloud(if buy_ then pos else na, neg, Color.DARK_GREEN);
AddCloud(if sell_ then pos else na, neg, Color.DARK_REd);

#-- Alerts
def buy  = h>0 and dir==1 and dir[1]==-1;
def sell = h<0 and dir==-1 and dir[1]==1;

AddChartBubble(ShowSignals and buy, macd, "B", Color.GREEN, no);
AddChartBubble(ShowSignals and sell, macd, "S", Color.RED, yes);
#--- Bar Color
AssignPriceColor(if !ColorBars then Color.CURRENT else
                 if macdSel then
                 if bc>0 then CreateColor(1, 185, 7) else
                 if bc<0 then CreateColor(224, 4, 4) else Color.YELLOW else
                 if hc>0 then CreateColor(1, 185, 7) else
                 if hc<0 then CreateColor(224, 4, 4) else Color.YELLOW);


#--- END of CODE
 

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