Formula Quick Reference

Market Data | Date Functions | Reference Functions | Logical Functions | Math Functions | Statistic Functions | Indicator Functions | Drawing Functions | Drawing Descriptors | Miscellaneous Functions | Formula Forum


Math Functions

max
min

max(a, b):
min(a, b):

a: a single number or an array of numbers;
b: a single number or an array of numbers.

max(a, b): return a if a >= b, b otherwise;
min(a, b): return a if a <= b, b otherwise.

# ddi
tr:=max(abs(h-ref(h,1)),abs(l-ref(l,1)));
dmz:=if((h+l)<=(ref(h,1)+ref(l,1)),0,tr);
dmf:=if((h+l)>=(ref(h,1)+ref(l,1)),0,tr);
diz:=sum(dmz,13)/(sum(dmz,13)+sum(dmf,13));
dif:=sum(dmf,13)/(sum(dmf,13)+sum(dmz,13));
ddi:diz-dif;
fillrgn(1, ddi, 0), transparency6;
addi:sma(ddi,30,10);
ad:ma(addi,5);
abs

abs(x):

x: a single number or an array of numbers.

return the absolute value of x.

# dmi
tr := sum(max(max(high-low,abs(high-ref(close,1))),abs(low-ref(close,1))),14);
hd := high-ref(high,1);
ld := ref(low,1)-low;
dmp:= sum(if(hd>0 and hd>ld,hd,0),14);
dmm:= sum(if(ld>0 and ld>hd,ld,0),14);
pdi: dmp*100/tr;
mdi: dmm*100/tr;
adx: ma(abs(mdi-pdi)/(mdi+pdi)*100,6);
adxr:(adx+ref(adx,6))/2;

reverse

reverse(x):

x: a single number or an array of numbers.

return -x.

n:=20;
polyline(1,0), colorred;
l_va :=if(h > l, (2*c-(h+l))/(h-l)*v, 0);
mfi: sum(l_va,n)/sum(v,n); # mfi
reverse: reverse(mfi);
sgn

sgn(x):

x: a single number or an array of numbers.

return 1, 0 or -1 if x > 0, x = 0 or x < 0.

n:=20;
polyline(1,0), colorred;
l_va :=if(h > l, (2*c-(h+l))/(h-l)*v, 0);
mfi: sum(l_va,n)/sum(v,n)*3; # mfi
sign: sgn(mfi);
ceiling
floor

ceiling(x):
floor(x):

x: a single number or an array of numbers.

ceiling(x): round x up, for example, ceiling(12.3) returns 13;

floor(x): round x down, for example, floor(12.3) returns 12.

n:=20;
polyline(1,0), colorred;
l_va :=if(h > l, (2*c-(h+l))/(h-l)*v, 0);
mfi: sum(l_va,n)/sum(v,n)*3; # mfi
ceiling: ceiling(mfi);
floor: floor(mfi);
interpart
mod
intpart(x):
mod(x, divisor):

x: a single number or an array of numbers;
divisor: a single number or an array of numbers.

intpart(x): return the integer part of x;

mod(x, divisor): return the remainder of x divided by divisor.

a:=intpart(c*10);
b:=mod(c*100,10);
d:=if(b<5,0,1);
close_price:c;
rounded:(a+d)*0.1;
pow pow(x, n):

x: a single number or an array of numbers;
n: a single number.

return the value of x raised to the power of n.

pow(c,0.5);
ln
log
ln(x):
log(x):

x: a single number or an array of numbers.

ln(x): return the natural logarithm of x

log(x): return the common logarithm (10-based) of x.

log: log(c);
ln: ln(c)/2;

 

Function Index
abs | align | avedev | backset | barscount | barslast | barssince | between | capital | ceiling | circledot | close | color | colorstick | cost | count | cross | crossdot | date | datediff | day | dma | drawicon | drawline | drawnumber | drawtext | ema | every | exist | fillrgn | filter | finance | floor | hhv | hhvbars | high | if | intpart | iscamarket | isdown | isequal | islastbar | isup | isusmarket | last | linestick | linestyle | linethick | llv | llvbars | ln | log | longcross | low | ma | max | min | mod | month | not | open | partline | peak | peakbars | peaktrough | peaktroughbars | pointdot | polyline | pow | range | ref | relate | reverse | sar | sarturn | sgn | sigperform | slope | sma | std | stick | stickline | sum | sumbars | transparency | trough | troughbars | var | vertline | vol | volstick | weekday | winner | year | zig