| Logical Functions
| if |
if(condition, a, b):
condition: a single number or an array of numbers;
a: a single number or an array of numbers;
b: a single number or an array of numbers.
return a if condition != 0, b otherwise.
|
n:=24;
lc:=ref(c,1);
d:=if(c>lc,c-lc,0);
e:=if(c<lc,lc-c,0);
a:=sum(d,n)/n; b:=sum(e,n)/n;
rsi:100*a/(a+b);
|
 |
cross |
cross(a, b):
a: a single number or an array of numbers;
b: a single number or an array of numbers.
return 1 if a crosses above b, 0 otherwise.
|
n:=6;
lc:=ref(c,1);
d:=if(c>lc,c-lc,0);
e:=if(c<lc,lc-c,0);
a:=sum(d,n)/n; b:=sum(e,n)/n;
rsi:100*a/(a+b);
new_rsi:sma(max(c-lc,0),n,1)/sma(abs(c-lc),n,1)*100;
drawicon(cross(new_rsi,rsi),0,10);
drawicon(ref(new_rsi,1)<ref(rsi,1) and new_rsi>rsi,10,11);
|
 |
| not |
not(condition):
condition: a single number or an array of numbers;
return 1 if condition = 0, 0 otherwise.
|
not(close > ref(close, 1)); |
 |
|
isup
isequal
isdown
|
isup: return 1 if close > open, 0 otherwise;
isequal: return 1 if close = open, 0 otherwise;
isdown: return 1 if close < open, 0 otherwise.
|
stickline(isequal and c>=ref(c,1),c,c,6,1),colorblack;
stickline(isequal and c<ref(c,1),c,c,6,1),colorred;
stickline(isup,h,c,0,0),colorblack;
stickline(isup,l,o,0,0),colorblack;
stickline(isup,c,o,6,1),colorblack;
stickline(isdown,h,l,0,0),colorred;
stickline(isdown,o,c,6,0),colorred;
|
 |
islastbar
|
return 1 if the current period is the last period in the chart, 0 otherwise.
|
a:backset(islastbar,10);
drawicon(filter(a,10),1,1);
|
 |
isusmarket iscamarket
|
isusmarket: return 1 if the stock is trading in the us market, 0 otherwise.
iscamarket: return 1 if the stock is trading in the canadien market, 0 otherwise.
|
# isusmarket / iscamarket is useful if you just
# want your formulas to generate signals for
# the us / ca market when scanning stocks.
# for example:
us_condition: ...
ca_condition: ...
singal_in_us_market: us_condition and isusmarket;
singal_in_ca_market: ca_condition and iscamarket;
|
|
between
range
|
between(a, b, c):
range(a, b, c):
a: a single number or an array of numbers;
b: a single number or an array of numbers;
c: a single number or an array of numbers.
between(a, b, c): return 1 if a is between b and c, 0 otherwise;
range(a, b, c): return 1 if b <= a <= c, 0 otherwise.
|
between1:between(close,ma(close,5),ma(close,30));
range1:range(close,ma(close,5),ma(close,30));
|
 |
exist
every
|
eixst(cond, n):
every(cond, n):
cond: an array of numbers,
n: period number, it can be either an integer or an integer array.
exist(cond, n): return 1 if in the last n periods, there exists a x with cond != 0, 0 otherwise;
every(cond, n): return 1 if in the last n periods, cond != 0, 0 otherwise.
|
exist1:exist(c<ref(c,1),3);
every1:every(c<ref(c,1),3)*0.5;
|
 |
| last |
last(cond, n1, n2):
cond: a single number or an array of numbers;
n1: period number, it has to be a single integer number;
n2: period number, it has to be a single integer number with n2 <= n1.
return 1 if cond != 0 from the previous n1-th period to the previous n2-th period, 0 otherwise.
|
a:ma(c,5)>ma(c,10);
exists:last(a,4,2)*0.5;
|
 |
| longcross |
longcross(a, b, n):
a: a single number or an array of numbers;
b: a single number or an array of numbers;
n: period number, it has to be an integer.
return 1 if in the current period, a > b and in the preivous n periods, a < b, 0 otherwise.
|
a:=cross(ma(close,5),ma(close,10));
b:=last(ma(c,5)<ma(c,10),5,1);
cross:a and b;
long_cross:0.5*longcross(ma(close,5),ma(close,10),5);
|
 |
|