price cross 150ma -- moving to 200 ma

anasmatar

New member
Hi
Appreciate your help to code a scan for stocks in a watchlist with price crossing rapidly the 150 SMA and moving toward the 200 SMA
Also, to create a watchlist column that shows the value of the 200 SMA daily
many thanks!
 
Solution
Hi
Appreciate your help to code a scan for stocks in a watchlist with price crossing rapidly the 150 SMA and moving toward the 200 SMA
Also, to create a watchlist column that shows the value of the 200 SMA daily
many thanks!

'crossing rapidly' has no meaning. 2 things either cross or they don't. what are you really asking for?

part of this study could be used to determine if 2 lines are getting closer (has a positive output)
https://usethinkscript.com/threads/future-averages-crosses-for-thinkorswim.19339/
Hi
Appreciate your help to code a scan for stocks in a watchlist with price crossing rapidly the 150 SMA and moving toward the 200 SMA
Also, to create a watchlist column that shows the value of the 200 SMA daily
many thanks!

'crossing rapidly' has no meaning. 2 things either cross or they don't. what are you really asking for?

part of this study could be used to determine if 2 lines are getting closer (has a positive output)
https://usethinkscript.com/threads/future-averages-crosses-for-thinkorswim.19339/
 
Solution

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

Thanks Halcyonguy - sorry for the unclear request.
What i meant is, is there a way to show that the market price getting closer to hit the 200 day moving average in percentage. Hope this is clear?
The purpose is just to prepare me for adding the stocks i like and place cash secure puts when the IV is high while watching it goes down to my price ..
 
Thanks Halcyonguy - sorry for the unclear request.
What i meant is, is there a way to show that the market price getting closer to hit the 200 day moving average in percentage. Hope this is clear?
The purpose is just to prepare me for adding the stocks i like and place cash secure puts when the IV is high while watching it goes down to my price ..

here is something to experiment with
i just tested it as a lower study

it looks for close crossing the 150 average and a price average change > 0.18 %


Code:
# sma200_approach_lower
#https://usethinkscript.com/threads/price-cross-150ma-moving-to-200-ma.19236/
#price cross 150ma -- moving to 200 ma

declare lower;

def na = double.nan;
def bn = barnumber();
def data = close;
def up = close > open;
def dwn = close < open;

input avg1_type = AverageType.Simple;
input avg1_length = 150;
def avg1 = MovingAverage(avg1_type, data, avg1_length );

input avg2_type = AverageType.Simple;
input avg2_length = 200;
def avg2 = MovingAverage(avg2_type, data, avg2_length );


def xup = avg1 crosses above avg2;
def xdwn = avg1 crosses below avg2;

def pr_xup150 = close crosses above avg1;
def pr_xdwn150 = close crosses below avg1;

def x = pr_xup150 or pr_xdwn150;


# price chg
def avg3_type = AverageType.exponential;
def avg3_length = 5;
def avg3 = MovingAverage(avg3_type, data, avg3_length );
#plot z = avg3;
def t = 2;
def chgper = round(100 * (avg3 - avg3[t])/avg3[t],2);

# min chg %
def minper = 0.18;
def triggerup = chgper > minper and pr_xup150;

plot z = triggerup;
#


---------------------------


this is the upper study i used for testing

Code:
# sma200_approach_upper
#https://usethinkscript.com/threads/price-cross-150ma-moving-to-200-ma.19236/
#price cross 150ma -- moving to 200 ma

#declare lower;

def na = double.nan;
def bn = barnumber();
def data = close;
def up = close > open;
def dwn = close < open;

input avg1_type = AverageType.Simple;
input avg1_length = 150;
def avg1 = MovingAverage(avg1_type, data, avg1_length );

input avg2_type = AverageType.Simple;
input avg2_length = 200;
def avg2 = MovingAverage(avg2_type, data, avg2_length );


def xup = avg1 crosses above avg2;
def xdwn = avg1 crosses below avg2;

def pr_xup150 = close crosses above avg1;
def pr_xdwn150 = close crosses below avg1;

def x = pr_xup150 or pr_xdwn150;


# price chg
def avg3_type = AverageType.exponential;
def avg3_length = 5;
def avg3 = MovingAverage(avg3_type, data, avg3_length );
#plot z = avg3;
def t = 2;
def chgper = round(100 * (avg3 - avg3[t])/avg3[t],2);

# min chg %
def minper = 0.18;
def triggerup = chgper > minper and pr_xup150;

#plot z = triggerup;


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

# chart version

input show_arrow = yes;
plot zup = if show_arrow and triggerup then low else na;
zup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zup.SetDefaultColor(Color.cyan);
zup.setlineweight(3);
zup.hidebubble();


input test_bubble = yes;
addchartbubble(test_bubble,low*0.998,
chgper
, (if triggerup then color.yellow else color.gray), no);


input show_avg1_line = yes;
input show_avg2_line = yes;
plot zavg1 = if show_avg1_line then avg1 else na;
plot zavg2 = if show_avg2_line then avg2 else na;
zavg1.SetDefaultColor(Color.cyan);
zavg1.setlineweight(1);
zavg1.hidebubble();
zavg2.SetDefaultColor(Color.yellow);
zavg2.setlineweight(1);
zavg2.hidebubble();

addlabel(show_avg1_line, "MA"+avg1_length , zavg1.takeValueColor());
addlabel(show_avg2_line, "MA"+avg2_length , zavg2.takeValueColor());
#
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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