EMA200, MACD, ADX arrows

OicoforPenn

New member
hey any help would be appreciated , trying to get a 2 custom studies to plot arrows over price chart

1. Price close is less than the 200 exponential moving average
MACDHistogramCrossover(exponential) is less then MACD(exponential) zeroline
ADX exponential is equal to or greater than 20

2.Price close is greater than the 200 exponential moving average
MACDHistogramCrossover(exponential) is greater then MACD(exponential) zeroline
ADX exponential is equal to or greater than 20

pretty sure both conditions can go on one study but i'm lost.

pretty sure can edit the MACDStrat from strategies i'm just not sure how to do it
 
Solution
hey any help would be appreciated , trying to get a 2 custom studies to plot arrows over price chart

1. Price close is less than the 200 exponential moving average
MACDHistogramCrossover(exponential) is less then MACD(exponential) zeroline
ADX exponential is equal to or greater than 20

2.Price close is greater than the 200 exponential moving average
MACDHistogramCrossover(exponential) is greater then MACD(exponential) zeroline
ADX exponential is equal to or greater than 20

pretty sure both conditions can go on one study but i'm lost.

pretty sure can edit the MACDStrat from strategies i'm just not sure how to do it

Since TOS studies and strategies codes, when available, are open source. You can copy and paste them into a...
hey any help would be appreciated , trying to get a 2 custom studies to plot arrows over price chart

1. Price close is less than the 200 exponential moving average
MACDHistogramCrossover(exponential) is less then MACD(exponential) zeroline
ADX exponential is equal to or greater than 20

2.Price close is greater than the 200 exponential moving average
MACDHistogramCrossover(exponential) is greater then MACD(exponential) zeroline
ADX exponential is equal to or greater than 20

pretty sure both conditions can go on one study but i'm lost.

pretty sure can edit the MACDStrat from strategies i'm just not sure how to do it

Since TOS studies and strategies codes, when available, are open source. You can copy and paste them into a new study or strategy, respectively, and then modify them.

The code below modifies the Strategy with my understanding of your ideas.

The Stategy will plot large green/red arrows where if the buy/sell conditions are not true on the bar previously and then true on the current bar.

The Strategy's addorders are based upon a buy until a sell occurs and vice versa. So the same corored large arrows can occur multiple times between addorders.

The image below has the 200 moving average, MACD Histogram and ADX for testing purposes.


Capture.jpg
Ruby:
#
# TD Ameritrade IP Company, Inc. (c) 2013-2022
#



input fastLength = 12;
input slowLength = 26;
input macdLength = 9;
input averageType = AverageType.EXPONENTIAL;

def diff = reference MACD(fastLength, slowLength, macdLength, averageType).Diff;

def sell = close < movingaverage(averagetype, close, 200) and
           diff < 0 and  
           adx() >= 20;
def buy = close > movingaverage(averagetype, close, 200) and
          diff > 0 and  
          adx() >= 20;

#Arrows
input show_arrows = yes;

plot down = if show_arrows and sell[1] == 0 and sell
            then high else double.nan;
down.setpaintingStrategy(PaintingStrategy.ARROW_DOWN);
down.setlineWeight(5);
down.setdefaultColor(color.red);

plot up   = if show_arrows and buy[1] == 0 and buy
            then low else double.nan;
up.setpaintingStrategy(paintingStrategy.ARROW_UP);
up.setlineWeight(5);
up.setdefaultColor(color.green);

AddOrder(OrderType.BUY_AUTO, buy, tickColor = GetColor(0), arrowColor = GetColor(0), name = "MACDStratLE");
AddOrder(OrderType.SELL_AUTO, sell, tickColor = GetColor(1), arrowColor = GetColor(1), name = "MACDStratSE");
 
Last edited:
Solution
Thank you very much. This definitely help me find the breakouts I'm looking for better. Only issue is it's not respecting your 0. i was looking for crossover under and over 0 line on the macd itself. it seems to show an arrow every time there is a crossover regardless the signal is under zero line. if you could me out. i'll gladly cash app you some bread for help
 
@SleepyZ
I applied your code and I found an example of it working perfectly and second arrow giving faulty alert. The first green arrow shows adx above 20 and macd crossover happening beneath the purple zeroline. That is what i'm looking for. the second arrow meets all the right criteria except macd crossover happens above the zero purple line.

see link
I really would appreciate the help and willing give a tip too
 
for anyone that stumbles across thread i figured it out by using modifying macdcrossover. i'll drop code both ways following.

Buy indicator arrows:

input fastLength = 12;

input slowLength = 26;

input MACDLength = 9;

input averageType = AverageType.EXPONENTIAL;

input crossingType = {default "Positive to Negative", "Negative to Positive"};



def Diff = MACD(fastLength, slowLength, MACDLength, averageType).Diff;
def buy = close is greater than MovAvgExponential("length" = 200)."AvgExp" and ADX("average type" = "EXPONENTIAL") is greater than or equal to 20;
def con1 = MACD(fastLength, slowLength, MACDLength, averageType).value;


plot signal = con1 < 0 and buy and crosses(Diff, 0, crossingType == CrossingType."Negative to Positive");



signal.DefineColor("Negative to Positive", GetColor(2));

signal.DefineColor("Positive to Negative", GetColor(3));

signal.AssignValueColor(if crossingType == CrossingType."Negative to Positive" then signal.color("Negative to Positive") else signal.color("Positive to Negative"));



signal.SetPaintingStrategy(if crossingType == CrossingType."Negative to Positive"

then PaintingStrategy.BOOLEAN_ARROW_UP

else PaintingStrategy.BOOLEAN_ARROW_DOWN);

Sell indicator arrows:

input fastLength = 12;

input slowLength = 26;

input MACDLength = 9;

input averageType = AverageType.EXPONENTIAL;

input crossingType = {default "Positive to Negative", "Negative to Positive"};



def Diff = MACD(fastLength, slowLength, MACDLength, averageType).Diff;
def sell = close is less than MovAvgExponential("length" = 200)."AvgExp" and ADX("average type" = "EXPONENTIAL") is greater than or equal to 20;
def con1 = MACD(fastLength, slowLength, MACDLength, averageType).value;


plot signal = con1 > 0 and sell and crosses(Diff, 0, crossingType == CrossingType."Negative to Positive");



signal.DefineColor("Negative to Positive", GetColor(2));

signal.DefineColor("Positive to Negative", GetColor(3));

signal.AssignValueColor(if crossingType == CrossingType."Negative to Positive" then signal.color("Negative to Positive") else signal.color("Positive to Negative"));



signal.SetPaintingStrategy(if crossingType == CrossingType."Negative to Positive"

then PaintingStrategy.BOOLEAN_ARROW_UP

else PaintingStrategy.BOOLEAN_ARROW_DOWN);



 

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