Moving Average Crossover

Yohannes24

New member
I have the following conditions I would like to add to this original code which is relatively simple :
Screen Shot 2024-03-07 at 11.34.45 AM.png


I want to add the following conditions :

Screen Shot 2024-03-07 at 11.36.56 AM.png



#This was the closest I got but the code does not signal for the SELL and LIQD conditions. Any aid in adding this to the code or fixing it below would be great. Thank you in advance.

input price = close;
input Length1 = 10;
input Length2 = 20;
input Length3 = 50;
input Length4 = 200;
input displace = 0;
input averageType = AverageType.SIMPLE;

plot Avg1 = MovingAverage(averageType, price[-displace], Length1);
plot Avg2 = MovingAverage(averageType, price[-displace], Length2);
plot Avg3 = MovingAverage(averageType, price[-displace], Length3);
plot Avg4 = MovingAverage(averageType, price[-displace], Length4);

Avg1.SetDefaultColor(GetColor(0));
Avg2.SetDefaultColor(GetColor(1));
Avg3.SetDefaultColor(GetColor(2));
Avg4.SetDefaultColor(GetColor(3));

# Condition One
def condition1 = Avg1 > Avg2 and Avg2 > Avg3;
def cross_above_avg4 = Crosses(Avg1, Avg4, CrossingDirection.ABOVE);
def cross_below_avg2 = Crosses(Avg1, Avg2, CrossingDirection.BELOW);

AddChartBubble(cross_above_avg4 and condition1, high, "LONG", Color.GREEN, no);
AddChartBubble(cross_below_avg2 and condition1, low, "SELL", Color.RED, yes);

# Condition Two
def condition2 = Avg1 < Avg2 and Avg2 < Avg3;
def cross_below_avg4 = Crosses(Avg1, Avg4, CrossingDirection.BELOW);
def cross_above_avg2 = Crosses(Avg1, Avg2, CrossingDirection.ABOVE);

AddChartBubble(cross_below_avg4 and condition2, high, "SHORT", Color.RED, yes);
AddChartBubble(cross_above_avg2 and condition2, low, "LIQD", Color.GREEN, no);
 
Last edited:
I have the following conditions I would like to add to this original code which is relatively simple :
View attachment 21300

I want to add the following conditions :

View attachment 21301


#This was the closest I got but the code does not signal for the SELL and LIQD conditions. Any aid in adding this to the code or fixing it below would be great. Thank you in advance.

input price = close;
input Length1 = 10;
input Length2 = 20;
input Length3 = 50;
input Length4 = 200;
input displace = 0;
input averageType = AverageType.SIMPLE;

plot Avg1 = MovingAverage(averageType, price[-displace], Length1);
plot Avg2 = MovingAverage(averageType, price[-displace], Length2);
plot Avg3 = MovingAverage(averageType, price[-displace], Length3);
plot Avg4 = MovingAverage(averageType, price[-displace], Length4);

Avg1.SetDefaultColor(GetColor(0));
Avg2.SetDefaultColor(GetColor(1));
Avg3.SetDefaultColor(GetColor(2));
Avg4.SetDefaultColor(GetColor(3));

# Condition One
def condition1 = Avg1 > Avg2 and Avg2 > Avg3;
def cross_above_avg4 = Crosses(Avg1, Avg4, CrossingDirection.ABOVE);
def cross_below_avg2 = Crosses(Avg1, Avg2, CrossingDirection.BELOW);

AddChartBubble(cross_above_avg4 and condition1, high, "LONG", Color.GREEN, no);
AddChartBubble(cross_below_avg2 and condition1, low, "SELL", Color.RED, yes);

# Condition Two
def condition2 = Avg1 < Avg2 and Avg2 < Avg3;
def cross_below_avg4 = Crosses(Avg1, Avg4, CrossingDirection.BELOW);
def cross_above_avg2 = Crosses(Avg1, Avg2, CrossingDirection.ABOVE);

AddChartBubble(cross_below_avg4 and condition2, high, "SHORT", Color.RED, yes);
AddChartBubble(cross_above_avg2 and condition2, low, "LIQD", Color.GREEN, no);

sell can't happen
you are asking avg1 to be above AND
below avg2

condition1 = Avg1 > Avg2 and Avg2 > Avg3;

cross_below_avg2 = Crosses(Avg1, Avg2, CrossingDirection.BELOW);


change condition1 to look at previous bar,

AddChartBubble(cross_below_avg2 and condition1[1], low, "SELL", Color.RED, yes);
 

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