Skip to content

Commit 2a05841

Browse files
committed
preparing initial release
1 parent a0007cf commit 2a05841

17 files changed

+20050
-0
lines changed

demo/indicator.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
async function indicator(tickerId, timeframe = '1w', periods = 500, stime, etime) {
2+
const pineTS = new PineTS(PineTS.Provider.Binance, tickerId, timeframe, periods, stime, etime);
3+
4+
const { result, plots, marketData } = await pineTS.run((context) => {
5+
// This is a PineTS port of "Squeeze Momentum Indicator" indicator by LazyBear
6+
// List of all his indicators: https://www.tradingview.com/v/4IneGo8h/
7+
const { close, high, low } = context.data;
8+
9+
const ta = context.ta;
10+
const math = context.math;
11+
12+
const input = context.input;
13+
const { plot, plotchar, nz, color } = context.core;
14+
15+
const length = input.int(20, 'BB Length');
16+
const mult = input.float(2.0, 'BB MultFactor');
17+
const lengthKC = input.int(20, 'KC Length');
18+
const multKC = input.float(1.5, 'KC MultFactor');
19+
20+
const useTrueRange = input.bool(true, 'Use TrueRange (KC)');
21+
22+
// Calculate BB
23+
let source = close;
24+
const basis = ta.sma(source, length);
25+
const dev = multKC * ta.stdev(source, length);
26+
const upperBB = basis + dev;
27+
const lowerBB = basis - dev;
28+
29+
// Calculate KC
30+
const ma = ta.sma(source, lengthKC);
31+
const range_1 = useTrueRange ? ta.tr : high - low;
32+
const rangema = ta.sma(range_1, lengthKC);
33+
const upperKC = ma + rangema * multKC;
34+
const lowerKC = ma - rangema * multKC;
35+
36+
const sqzOn = lowerBB > lowerKC && upperBB < upperKC;
37+
const sqzOff = lowerBB < lowerKC && upperBB > upperKC;
38+
const noSqz = sqzOn == false && sqzOff == false;
39+
40+
const val = ta.linreg(
41+
source - math.avg(math.avg(ta.highest(high, lengthKC), ta.lowest(low, lengthKC)), ta.sma(close, lengthKC)),
42+
lengthKC,
43+
0
44+
);
45+
46+
const iff_1 = val > nz(val[1]) ? color.lime : color.green;
47+
const iff_2 = val < nz(val[1]) ? color.red : color.maroon;
48+
const bcolor = val > 0 ? iff_1 : iff_2;
49+
const scolor = noSqz ? color.blue : sqzOn ? color.black : color.gray;
50+
plot(val, 'Momentum', { color: bcolor, style: 'histogram', linewidth: 4 });
51+
plot(0, 'Cross', { color: scolor, style: 'cross', linewidth: 2 });
52+
});
53+
54+
return { result, plots, marketData };
55+
}

demo/instit-bias.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
async function instit_bias(
2+
tickerId,
3+
timeframe = "1w",
4+
periods = 500,
5+
stime,
6+
etime
7+
) {
8+
const pineTS = new PineTS(
9+
PineTS.Provider.Binance,
10+
tickerId,
11+
timeframe,
12+
periods,
13+
stime,
14+
etime
15+
);
16+
17+
const { result, plots, marketData } = await pineTS.run((context) => {
18+
const ema9 = ta.ema(close, 9);
19+
const ema18 = ta.ema(close, 18);
20+
21+
const bull_bias = ema9 > ema18;
22+
const bear_bias = ema9 < ema18;
23+
24+
plot(ema9, "EMA 9", { title: "EMA 9", color: "#2962FF", style: "line" });
25+
plot(ema18, "EMA 18", { title: "EMA 18", color: "#FF6D00", style: "line" });
26+
plot(bull_bias, "Bull Bias", {
27+
title: "Bull Bias",
28+
color: "#2962FF",
29+
style: "background",
30+
});
31+
32+
plot(bear_bias, "Bear Bias", {
33+
title: "Bear Bias",
34+
color: "#FF6D00",
35+
style: "background",
36+
});
37+
38+
//plot(val, 'Momentum', { color: bcolor, style: 'histogram', linewidth: 4 });
39+
//plot(0, 'Cross', { color: scolor, style: 'cross', linewidth: 2 });
40+
});
41+
42+
return { result, plots, marketData };
43+
}

0 commit comments

Comments
 (0)