Adding arrow on chart for CCI and EMA combination

N

Nick

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"



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:
BenTen

BenTen

Administrative
Staff
VIP
What are the two conditions that you were talking about?
 
N

Nick

Active member
2019 Donor
VIP
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
 
BenTen

BenTen

Administrative
Staff
VIP
@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);
 
B

barbaros

Active member
@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);
 
N

Nick

Active member
2019 Donor
VIP
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);
 
BenTen

BenTen

Administrative
Staff
VIP
@Nick Are you trying to count for total of up arrows?
 

Similar threads

Top