Price Average Crossover Signal

MAC

New member
Just curious if anyone can help?
Is there a way to just show most recent crossover signals and block the past signals, just to clean chart up a bit
input price = close;
input length = 15;
input averageType = AverageType.Simple;
input crossingType = {default above, below};

def avg = MovingAverage(averageType, price, length);

plot signal = crosses(price, avg, crossingType == CrossingType.above);

signal.DefineColor("Above", GetColor(6));
signal.DefineColor("Below", GetColor(7));
signal.AssignValueColor(if crossingType == CrossingType.above then signal.color("Above") else signal.color("Below"));

signal.SetPaintingStrategy(if crossingType == CrossingType.above
then PaintingStrategy.BOOLEAN_ARROW_UP
else PaintingStrategy.BOOLEAN_ARROW_DOWN);
 
Solution
Just curious if anyone can help?
Is there a way to just show most recent crossover signals and block the past signals, just to clean chart up a bit
input price = close;
input length = 15;
input averageType = AverageType.Simple;
input crossingType = {default above, below};

def avg = MovingAverage(averageType, price, length);

plot signal = crosses(price, avg, crossingType == CrossingType.above);

signal.DefineColor("Above", GetColor(6));
signal.DefineColor("Below", GetColor(7));
signal.AssignValueColor(if crossingType == CrossingType.above then signal.color("Above") else signal.color("Below"));

signal.SetPaintingStrategy(if crossingType == CrossingType.above
then PaintingStrategy.BOOLEAN_ARROW_UP
else...
Just curious if anyone can help?
Is there a way to just show most recent crossover signals and block the past signals, just to clean chart up a bit
input price = close;
input length = 15;
input averageType = AverageType.Simple;
input crossingType = {default above, below};

def avg = MovingAverage(averageType, price, length);

plot signal = crosses(price, avg, crossingType == CrossingType.above);

signal.DefineColor("Above", GetColor(6));
signal.DefineColor("Below", GetColor(7));
signal.AssignValueColor(if crossingType == CrossingType.above then signal.color("Above") else signal.color("Below"));

signal.SetPaintingStrategy(if crossingType == CrossingType.above
then PaintingStrategy.BOOLEAN_ARROW_UP
else PaintingStrategy.BOOLEAN_ARROW_DOWN);

Use the input number_signals_displayed = 2; to choose how many signals will plot.

This is done by assigning a count to each cross through the def signals from 1 to 68
Then the def cond then finds the highestall count and reorders the count from 68 to 1. See the yellow bubbles in the first image below that show the original count and then the reordered count.

Then in the arrow plot statement signal, any arrow plots greater than input number_signals_displayed = 2, these are set to not display (double.nan).

Code:
addchartBubble(Crosses(price, avg, crossingType == crossingType.above), low, signals + "\n" + cond, color.yellow, no);
1706893597718.png
Here is the full code with the 2 arrows displayed.
Screenshot 2024-02-02 090815.png
Code:
input number_signals_displayed = 2;

input price = close;
input length = 15;
input averageType = AverageType.Simple;
input crossingType = {default above, below};

def avg = MovingAverage(averageType, price, length);

def signals = compoundValue(1,
              if crosses(price, avg, crossingType == CrossingType.above)
              then signals[1] + 1
              else signals[1], 0);
def cond    = highestall(signals) - signals + 1;
plot signal = if cond > number_signals_displayed
              then double.nan
              else crosses(price, avg, crossingType == CrossingType.above);

signal.DefineColor("Above", GetColor(6));
signal.DefineColor("Below", GetColor(7));
signal.AssignValueColor(if crossingType == CrossingType.above then signal.color("Above") else signal.color("Below"));

signal.SetPaintingStrategy(if crossingType == CrossingType.above
then PaintingStrategy.BOOLEAN_ARROW_UP
else PaintingStrategy.BOOLEAN_ARROW_DOWN);
 
Solution

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