Skip to content

Instantly share code, notes, and snippets.

@sherwind
Created January 23, 2018 16:43
Show Gist options
  • Save sherwind/a1e4fee836318149e603676535d5c721 to your computer and use it in GitHub Desktop.
Save sherwind/a1e4fee836318149e603676535d5c721 to your computer and use it in GitHub Desktop.
An implementation of Floor Pivot Points for TradingView
{
// An implementation of Floor Pivot Points for TradingView
// by sherwin@daganato.com, 20180124
// See https://en.wikipedia.org/wiki/Pivot_point_(technical_analysis)
name: "Floor Pivots",
metainfo: {
_metainfoVersion: 27,
isTVScript: !1,
isTVScriptStub: !1,
is_hidden_study: !1,
defaults: {
styles: {
plot_0: { linestyle: 0, linewidth: 1, plottype: 6, trackPrice: !1, transparency: 35, visible: !0, color: "#656565" },
plot_1: { linestyle: 0, linewidth: 1, plottype: 6, trackPrice: !1, transparency: 35, visible: !0, color: "#4985e7" },
plot_2: { linestyle: 0, linewidth: 1, plottype: 6, trackPrice: !1, transparency: 35, visible: !0, color: "#4985e7" },
plot_3: { linestyle: 0, linewidth: 1, plottype: 6, trackPrice: !1, transparency: 35, visible: !0, color: "#4985e7" },
plot_4: { linestyle: 0, linewidth: 1, plottype: 6, trackPrice: !1, transparency: 35, visible: !0, color: "#4985e7" },
plot_5: { linestyle: 0, linewidth: 1, plottype: 6, trackPrice: !1, transparency: 35, visible: !1, color: "#4985e7" },
plot_6: { linestyle: 0, linewidth: 1, plottype: 6, trackPrice: !1, transparency: 35, visible: !1, color: "#4985e7" }
},
precision: 4,
inputs: {
in_0: "Monthly"
}
},
plots: [
{ id: "plot_0", type: "line" },
{ id: "plot_1", type: "line" },
{ id: "plot_2", type: "line" },
{ id: "plot_3", type: "line" },
{ id: "plot_4", type: "line" },
{ id: "plot_5", type: "line" },
{ id: "plot_6", type: "line" }
],
styles: {
plot_0: { title: "PP", histogramBase: 0, joinPoints: !1 },
plot_1: { title: "S1", histogramBase: 0, joinPoints: !1 },
plot_2: { title: "R1", histogramBase: 0, joinPoints: !1 },
plot_3: { title: "S2", histogramBase: 0, joinPoints: !1 },
plot_4: { title: "R2", histogramBase: 0, joinPoints: !1 },
plot_5: { title: "S3", histogramBase: 0, joinPoints: !1 },
plot_6: { title: "R3", histogramBase: 0, joinPoints: !1 }
},
description: "Floor Pivots",
shortDescription: "Floor Pivots",
is_price_study: !0,
inputs: [{
id: "in_0",
name: "Pivots Timeframe",
defval: "Monthly",
type: "string",
options: ["Daily", "Weekly", "Monthly", "Yearly"]
}],
id: "Floor Pivots@tv-basicstudies-1",
scriptIdPart: "",
name: "Floor Pivots"
},
constructor: function() {
this.f_0 = function(t) {
var t_ = this._context.new_var(t);
return this._context.new_var(t_.get(1));
},
this.f_1 = function(t) {
switch (t) {
case "Daily":
return "D";
case "Weekly":
return "W";
case "Monthly":
return "M";
case "Yearly":
return "12M";
}
}, this.init = function(t, e) {
return this._context = t, this._context.new_sym(PineJS.Std.ticker(this._context), this.f_1(e(0)), this.f_1(e(0)));
}, this.main = function(t, e) {
var i, n, pivot, high, low, s1, r1, s2, r2, s3, r3, pp_, s1_, r1_, s2_, r2_, s3_, r3_;
return this._context = t,
this._input = e,
i = this._context.new_var(this._context.symbol.time),
this._context.select_sym(1),
n = this._context.new_var(this._context.symbol.time),
pivot = PineJS.Std.hlc3(this._context),
high = PineJS.Std.high(this._context),
low = PineJS.Std.low(this._context),
s1 = 2 * pivot - high,
r1 = 2 * pivot - low,
s2 = pivot - (high - low),
r2 = pivot + (high - low),
s3 = s1 - (high - low),
r3 = r1 + (high - low),
pp_ = this.f_0(pivot),
s1_ = this.f_0(s1),
r1_ = this.f_0(r1),
s2_ = this.f_0(s2),
r2_ = this.f_0(r2),
s3_ = this.f_0(s3),
r3_ = this.f_0(r3),
this._context.select_sym(0),
[pp_.adopt(n, i, 0), s1_.adopt(n, i, 0), r1_.adopt(n, i, 0), s2_.adopt(n, i, 0), r2_.adopt(n, i, 0), s3_.adopt(n, i, 0), r3_.adopt(n, i, 0)]
}
}
}
@minhydo
Copy link

minhydo commented Jul 13, 2020

This code does not run anymore on the new tradingview version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment