Adding arrow on chart for CCI and EMA combination

8Nick8

Active member
2019 Donor
VIP
Hi all, this is my first attempt to combine two indicators and create a scan. I have two request

1. how to automatically plot an Up arrow on the chart whenever both conditions are met.
2. how should I change the def scan code, if i want the valid candle "close" must be higher than the previous candle "high"

gaVqUWf.jpg


Please feel free to clean up this mess work 😅
Thank You

Code:
################################
input price1 = close;
input ema = 9;
input displace =0;
plot AvgExp = ExpAverage(price1[-displace], ema);

def ma = MovAvgExponential(close, 10);
def MA1 = close ;
def scan = MA1 crosses above ma;

#####################################################
input length = 14;
input over_sold = -100;
input over_bought = 100;
input showBreakoutSignals = no;

def price = close + low + high;
def linDev = LinDev(price, length);
plot CCI = if linDev == 0 then 0 else (price - Average(price, length)) / linDev / 0.015;
#plot OverBought = over_bought;
plot ZeroLine = 0;
#plot OverSold = over_sold;
#plot UpSignal = if CCI crosses above 0 then 0 else Double.Nan;
#plot DownSignal = if CCI crosses below 100 then 100 else Double.Nan;

plot  signal = scan and CCI crosses above ZeroLine;
 
Last edited by a moderator:
What are the two conditions that you were talking about?

Hi @BenTen the two conditions for the first scan are as follows

Condition 1. when the "close" is above the 10EMA
def scan = MA1 crosses above ma;

Condition 2. when the CCI cuts above the zeroline

when both of the conditions are met, i have a plot :
plot signal = scan and CCI crosses above ZeroLine;

what i would like is to have an uparrow on the chart for the scanned stocks that met the two conditions.

if i may also ask, inorder to find trending stocks, how to add a condition above to scan for the stocks are above 34 EMA for at least 3mth?

############################
Separately, i m just enquiring, if i want to replace condition 1, instead of using close above the ema, i want to find the last candle close to be higher than the previous candle high.

So my questions, is how should i write the code if i want to scan for candles when the last candle "close" is higher than the previous candle "high"

Thanks again
 
@Nick Sorry for the late response. Try this code:

Code:
input price_ema = close;
input length_ema = 10;
input displace = 0;

def AvgExp = ExpAverage(price_ema[-displace], length_ema);

input length = 14;
input over_sold = -100;
input over_bought = 100;

def price = close + low + high;
def linDev = lindev(price, length);
def CCI = if linDev == 0 then 0 else (price - Average(price, length)) / linDev / 0.015;
def ZeroLine = 0;

def condition1 = close > AvgExp;
def condition2 = close crosses above ZeroLine;

plot pUp = condition1 and condition2;
pUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
pUp.SetLineWeight(1);
pUp.AssignValueColor(COLOR.CYAN);
 
@BenTen slight correction...

Python:
input price_ema = close;
input length_ema = 10;
input displace = 0;

def AvgExp = ExpAverage(price_ema[-displace], length_ema);

input length = 14;
input over_sold = -100;
input over_bought = 100;

def price = close + low + high;
def linDev = lindev(price, length);
def CCI = if linDev == 0 then 0 else (price - Average(price, length)) / linDev / 0.015;
def ZeroLine = 0;

def condition1u = close > AvgExp;
def condition2u = CCI crosses above ZeroLine;

plot pUp = condition1u and condition2u;
pUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
pUp.SetLineWeight(1);
pUp.AssignValueColor(COLOR.CYAN);

def condition1d = close < AvgExp;
def condition2d = CCI crosses below ZeroLine;

plot pDown = condition1d and condition2d;
pDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
pDown.SetLineWeight(1);
pDown.AssignValueColor(COLOR.CYAN);
 
Hi @BenTen @barbaros ,

I have added a count code to count the number of uUp arrow in this script but it was unsuccessful...

The label is correctly display but unable to count.....

May I request you help to check what is wrong?

Thank u

Code:
input price_ema = close;
input length_ema = 10;
input displace = 0;

def AvgExp = ExpAverage(price_ema[-displace], length_ema);

input length = 14;
input over_sold = -100;
input over_bought = 100;

def price = close + low + high;
def linDev = lindev(price, length);
def CCI = if linDev == 0 then 0 else (price - Average(price, length)) / linDev / 0.015;
def ZeroLine = 0;

def condition1u = close > AvgExp;
def condition2u = CCI crosses above ZeroLine;

plot pUp = condition1u and condition2u;
pUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
pUp.SetLineWeight(1);
pUp.AssignValueColor(COLOR.CYAN);

def condition1d = close < AvgExp;
def condition2d = CCI crosses below ZeroLine;

plot pDown = condition1d and condition2d;
pDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
pDown.SetLineWeight(1);
pDown.AssignValueColor(COLOR.CYAN);

def count = TotalSum(pUp);
AddLabel(1,"pUp = " + count, color.white);
 

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