Price cross 2 moving averages

jtbro

New member
Hey guys, I am looking to see if someone could help me with coding an idea.

I would like an arrow plotted on a candle when
Price crosses two moving averages within the body of the current candle.
Would also like the option to displace .

Any help would be greatly appreciated.

Example:
Price crosses above the 10 sma and 40sma within the same bar an up arrow will appear, and the opposite when it crosses back below in the same bar( on any time frame)

I can figure out crossing of 1, 2 within the same bar is a little tricky for me
 
Last edited:
Solution
Hey guys, I am looking to see if someone could help me with coding an idea.

I would like an arrow plotted on a candle when
Price crosses two moving averages within the body of the current candle.
Would also like the option to displace .

Any help would be greatly appreciated.

Example:
Price crosses above the 10 sma and 40sma within the same bar an up arrow will appear, and the opposite when it crosses back below in the same bar( on any time frame)

I can figure out crossing of 1, 2 within the same bar is a little tricky for me


create a formula for each condition.
then check the desired combinations.

Code:
# ma1 and ma2 are 2 averages.

def a = close crosses above ma1;
def b = close crosses above ma2;

def c = close crosses...
Hey guys, I am looking to see if someone could help me with coding an idea.

I would like an arrow plotted on a candle when
Price crosses two moving averages within the body of the current candle.
Would also like the option to displace .

Any help would be greatly appreciated.

Example:
Price crosses above the 10 sma and 40sma within the same bar an up arrow will appear, and the opposite when it crosses back below in the same bar( on any time frame)

I can figure out crossing of 1, 2 within the same bar is a little tricky for me


create a formula for each condition.
then check the desired combinations.

Code:
# ma1 and ma2 are 2 averages.

def a = close crosses above ma1;
def b = close crosses above ma2;

def c = close crosses below ma1;
def d = close crosses below ma2;

plot up = if (a and b) then low else double.nan;
up.SetPaintingStrategy(PaintingStrategy.Arrow_UP);

plot down = if (c and d) then high else double.nan;
down.SetPaintingStrategy(PaintingStrategy.Arrow_down);
#
 
Solution

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

create a formula for each condition.
then check the desired combinations.

Code:
# ma1 and ma2 are 2 averages.

def a = close crosses above ma1;
def b = close crosses above ma2;

def c = close crosses below ma1;
def d = close crosses below ma2;

plot up = if (a and b) then low else double.nan;
up.SetPaintingStrategy(PaintingStrategy.Arrow_UP);

plot down = if (c and d) then high else double.nan;
down.SetPaintingStrategy(PaintingStrategy.Arrow_down);
#
Thank you so much...
 
It may need some tweaks but here's what I got thus far:


# ma1 and ma2 are 2 averages.
input price = close;
input length1 = 9;
input length2 = 9;
input displace = 0;

plot SMA1 = Average(price[-displace], length1);
plot SMA2 = Average(price[-displace], length2);


def a = close crosses above sma1;
def b = close crosses above sma2;

def c = close crosses below sma1;
def d = close crosses below sma2;


plot up = if (a and b) then low else Double.NaN;
up.SetPaintingStrategy(PaintingStrategy.ARROW_UP);

plot down = if (c and d) then high else Double.NaN;
down.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
#
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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