Plot Extended Ray on Condition Until Crossed Again By Price

pearldrum

New member
I am looking to code in horizontal lines which extend to the right from the bottom or top of a candle depending on an EMA crossover.

When price closes and a 5 and 10EMA cross has happened as well as a matching PSAR (above or below), then a bubble is added.

What I am looking for is replacing the bubbles in example 1 with horizontal lines.

Ideally the lines would remain on the chart throughout history and only stop if price close above or below the line (example 2)

Here is how this has been made for reference,

Code:
Declare upper;
#Variables
input price = close;
input length1 = 5;
input length2 = 10;
input length3 = 20;
input accelerationFactor = 0.02;
input maxAccelerationFactor = 0.2;
input showBreakoutSignals = yes;

#EMA variables
def AvgExp1 = ExpAverage(price, length1);
def AvgExp2 = ExpAverage(price, length2);
def AvgExp3 = ExpAverage(price, length3);
plot EMA1 = ExpAverage(price, length1);
EMA1.SetDefaultColor(Color.YELLOW);
plot EMA2 = ExpAverage(price, length2);
EMA2.SetDefaultColor(Color.RED);
AddCloud(AvgExp1, AvgExp2, CreateColor(65, 210, 100), CreateColor(240, 75, 90));
plot EMA3 = ExpAverage(price, 20);
EMA3.SetDefaultColor(Color.BLUE);

#PSAR script
def psar = ParabolicSAR(accelerationFactor, maxAccelerationFactor);
def up = close > close[1];
def down = close < close[1];
def isAbovePSAR = close > psar;
def isBelowPSAR = close < psar;
plot PSARPlot = if isAbovePSAR then psar else Double.NaN;
PSARPlot.SetDefaultColor(CreateColor(65, 210, 100));
PSARPlot.SetPaintingStrategy(PaintingStrategy.boolean_ARROW_UP);
PSARPlot.SetLineWeight(2);
plot PSARPlotBelow = if isBelowPSAR then psar else Double.NaN;
PSARPlotBelow.SetDefaultColor(CreateColor(240, 75, 90));
PSARPlotBelow.SetPaintingStrategy(PaintingStrategy.boolean_ARROW_UP);
PSARPlotBelow.SetLineWeight(2);

#Signal
def UpSignal = AvgExp1 crosses above AvgExp2 and isAbovePSAR and up;
def DownSignal = AvgExp1 crosses below AvgExp2 and isBelowPSAR and down;
AddChartBubble(UpSignal, low, "Intial Stop", Color.GREEN, no);
AddChartBubble(DownSignal, high, "New Pivot", Color.RED, yes);
 

Attachments

  • Ex1.PNG
    Ex1.PNG
    140.4 KB · Views: 38
  • Ex2.PNG
    Ex2.PNG
    181.4 KB · Views: 40

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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