Convert Expanded Floor Pivots to thinkscript?

S

Saylarr

Member
Hi, can someone help me convert a tradingview indicator to Thinkorswim?

This is the code:
Code:
study("Expanded Floor Pivots", overlay = true)
mode =input(title = "HTF Method", defval = 'Auto', options=['Auto', 'User Defined'])
HTFm = input('D', title = "Time Frame (if HTF Method=User Defined)", type=input.resolution)
showlast = input(title = "Show Only Last Period", defval = true)
showlabels = input(title = "Show Labels", defval = true)
lstyle = input(title = "Line Style", options = ['Solid', 'Circles', 'Cross'], defval ='Solid')
 
//auto higher time frame
HTFo =timeframe.period == '1' ? '30' :
  timeframe.period == '3' ? '60' :
  timeframe.period == '5' ? '240' :
  timeframe.period == '15' ? 'D' :
  timeframe.period == '30' ? 'D' :
  timeframe.period == '45' ? 'D' :
  timeframe.period == '60' ? 'D' :
  timeframe.period == '120' ? 'D' :
  timeframe.period == '180' ? 'D' :
  timeframe.period == '240' ? 'D' :
  timeframe.period == 'D' ? 'W' :
  '5W'
 
HTF = mode == 'Auto' ? HTFo : HTFm
    
highhtf = security(syminfo.tickerid, HTF, high[1], lookahead = barmerge.lookahead_on)
lowhtf = security(syminfo.tickerid, HTF, low[1], lookahead = barmerge.lookahead_on)
closehtf = security(syminfo.tickerid, HTF, close[1], lookahead = barmerge.lookahead_on)

// is this last bar for HTF?
islast = showlast ? security(syminfo.tickerid, HTF, barstate.islast, lookahead = true) : true

// Line Style
linestyle = lstyle == 'Solid' ? plot.style_line :
   lstyle == 'Circle' ? plot.style_circles : plot.style_cross

pivot = (highhtf + lowhtf + closehtf) / 3
bc = (highhtf + lowhtf) / 2
tc = (pivot - bc) + pivot
r1 = 2 * pivot - lowhtf
r2 = pivot + (highhtf - lowhtf)
r3 = r1 + (highhtf - lowhtf)
r4 = r3 + (r2 - r1)
s1 = 2 * pivot - highhtf
s2 = pivot - (highhtf - lowhtf)
s3 = s1 - (highhtf - lowhtf)
s4 = s3 - (s1 - s2)

plot(islast ? pivot : na, color = color.blue, linewidth = 1, style = linestyle, transp = 0)
plot(islast ? r1 : na, title = "R1", color = color.red, linewidth = 1, style = linestyle, transp = 0)
plot(islast ? r2 : na, title = "R2", color = color.red, linewidth = 1, style = linestyle, transp = 0)
plot(islast ? r3 : na, title = "R3", color = color.red, linewidth = 1, style = linestyle, transp = 0)
plot(islast ? r4 : na, title = "R4", color = color.red, linewidth = 1, style = linestyle, transp = 0)
plot(islast ? s1 : na, title = "S1", color = color.lime, linewidth = 1, style = linestyle, transp = 0)
plot(islast ? s2 : na, title = "S2", color = color.lime, linewidth = 1, style = linestyle, transp = 0)
plot(islast ? s3 : na, title = "S3", color = color.lime, linewidth = 1, style = linestyle, transp = 0)
plot(islast ? s4 : na, title = "S4", color = color.lime, linewidth = 1, style = linestyle, transp = 0)
tcline = plot(islast ? tc : na, title = "TC", color = color.blue, linewidth = 1, style = plot.style_line, transp = 50)
bcline = plot(islast ? bc : na, title = "BC", color = color.blue, linewidth = 1, style = plot.style_line, transp = 50)
fill(tcline, bcline, color = color.blue, transp = 70)

// Label for S/R
chper = time - time[1]
chper := change(chper) > 0 ? chper[1] : chper

Round_it(valu)=>
    a = 0
    num = syminfo.mintick
    s = valu
    if na(s)
        s := syminfo.mintick
    if num < 1
        for i = 1 to 20
            num := num * 10
            if num > 1
                break
            a := a +1
    
    for x = 1 to a
        s := s * 10
    s := round(s)
    for x = 1 to a
        s := s / 10
    s := s < syminfo.mintick  ? syminfo.mintick : s
    s

// Labels
if showlabels
    var label plabel = na
    var label s1label = na, var label s2label = na, var label s3label = na, var label s4label = na
    var label r1label = na, var label r2label = na, var label r3label = na, var label r4label = na
    
    label.delete(plabel)
    label.delete(s1label), label.delete(s2label), label.delete(s3label), label.delete(s4label)
    label.delete(r1label), label.delete(r2label), label.delete(r3label), label.delete(r4label)
    plabel := label.new(x = time + chper * 20, y = pivot, text = tostring(Round_it(pivot)), color = color.blue, textcolor=color.black, style=label.style_labeldown, xloc = xloc.bar_time, yloc=yloc.price)
    s1label := label.new(x = time + chper * 20, y = s1, text = tostring(Round_it(s1)), color = color.lime, textcolor=color.black, style=label.style_labeldown, xloc = xloc.bar_time, yloc=yloc.price)
    s2label := label.new(x = time + chper * 20, y = s2, text = tostring(Round_it(s2)), color = color.lime, textcolor=color.black, style=label.style_labeldown, xloc = xloc.bar_time, yloc=yloc.price)
    s3label := label.new(x = time + chper * 20, y = s3, text = tostring(Round_it(s3)), color = color.lime, textcolor=color.black, style=label.style_labeldown, xloc = xloc.bar_time, yloc=yloc.price)
    s4label := label.new(x = time + chper * 20, y = s4, text = tostring(Round_it(s4)), color = color.lime, textcolor=color.black, style=label.style_labeldown, xloc = xloc.bar_time, yloc=yloc.price)
    r1label := label.new(x = time + chper * 20, y = r1, text = tostring(Round_it(r1)), color = color.red, textcolor=color.white, style=label.style_labeldown, xloc = xloc.bar_time, yloc=yloc.price)
    r2label := label.new(x = time + chper * 20, y = r2, text = tostring(Round_it(r2)), color = color.red, textcolor=color.white, style=label.style_labeldown, xloc = xloc.bar_time, yloc=yloc.price)
    r3label := label.new(x = time + chper * 20, y = r3, text = tostring(Round_it(r3)), color = color.red, textcolor=color.white, style=label.style_labeldown, xloc = xloc.bar_time, yloc=yloc.price)
    r4label := label.new(x = time + chper * 20, y = r4, text = tostring(Round_it(r4)), color = color.red, textcolor=color.white, style=label.style_labeldown, xloc = xloc.bar_time, yloc=yloc.price)
 
Last edited:
S

Saylarr

Member
Hello
I was able to get it to work, but I have a problem. The indicator flattens or shrinks the graph to show all areas, it does not have to do that the graph should look normal without scale change.
Does anyone have any idea how to fix it?

Here is the code:
Code:
input aggregationPeriod = AggregationPeriod.DAY;
input tolerance = 0.05;

def PH = high(period = aggregationPeriod)[1];
def PL = low(period = aggregationPeriod)[1];
def PC = close(period = aggregationPeriod)[1];

plot R3;
plot R3M;
plot R2;
plot R2M;
plot R1;
plot R1M;
plot HH;
plot PP;
plot LL;
plot S1M;
plot S1;
plot S2M;
plot S2;
plot S3M;
plot S3;

def DR;
def TR1;
def TR1M;
def TR2;
def TR2M;
def TS1;
def TS1M;
def TS2;
def TS2M;
def TPP1;
def TPP2;

HH = PH;
LL = PL;
PP = (PH + PL + PC) / 3;
DR = PH - PL;

R1 = (0.5 * DR) + PP;
R1M = (0.618 * DR) + PP;

R2 = PP + DR;
R2M = PP + (1.382 * DR);

R3 = 2 * PP + (PH - 2 * PL);
R3M = (R3 - R2) / 2 + R2;

S1 = PP - (0.5 * DR);
S1M = PP - (0.618 * DR);

S2 = PP - DR;
S2M = PP - (1.382 * DR);

S3 = 2 * PP - (2 * DR);
S3M = (S2 - S3) / 2 + S3;

TR1 = R1 - ((R1 * tolerance) / 100) ;
TR1M =   R1M + ((R1M * tolerance) / 100) ;

TR2 = R2 - ((R2 * tolerance) / 100) ;
TR2M = R2M + ((R2M * tolerance) / 100) ;

TS1 = S1 + ((S1 * tolerance) / 100) ;
TS1M = S1M - ((S1M * tolerance) / 100) ;

TS2 = S2 + ((S2 * tolerance) / 100) ;
TS2M = S2M - ((S2M * tolerance) / 100) ;

TPP1 = PP + ((PP * tolerance) / 100) ;
TPP2 = PP - ((PP * tolerance) / 100);

R3.SetDefaultColor(GetColor(5));
R3M.SetDefaultColor(GetColor(5));
R2.SetDefaultColor(GetColor(5));
R2M.SetDefaultColor(GetColor(5));
R1.SetDefaultColor(GetColor(5));
R1M.SetDefaultColor(GetColor(5));
HH.SetDefaultColor(GetColor(4));
PP.SetDefaultColor(GetColor(0));
LL.SetDefaultColor(GetColor(1));
S1.SetDefaultColor(GetColor(6));
S1M.SetDefaultColor(GetColor(6));
S2.SetDefaultColor(GetColor(6));
S2M.SetDefaultColor(GetColor(6));
S3.SetDefaultColor(GetColor(6));
S3M.SetDefaultColor(GetColor(6));

R3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R3M.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R2M.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R1M.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
HH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PP.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S1M.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S2M.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S3M.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

AddCloud(TR1, TR1M, Color.LIGHT_GREEN, Color.LIGHT_GREEN);
AddCloud(TR2, TR2M, Color.LIGHT_GREEN, Color.LIGHT_GREEN);

AddCloud(TS1, TS1M, Color.LIGHT_RED, Color.LIGHT_RED);
AddCloud(TS2, TS2M, Color.LIGHT_RED, Color.LIGHT_RED);

AddCloud(TPP1, TPP2, Color.PINK, Color.PINK);

R3M.SetStyle(Curve.SHORT_DASH);
R2M.SetStyle(Curve.SHORT_DASH);
R1M.SetStyle(Curve.SHORT_DASH);
HH.SetStyle(Curve.MEDIUM_DASH);
LL.SetStyle(Curve.MEDIUM_DASH);
S1M.SetStyle(Curve.SHORT_DASH);
S2M.SetStyle(Curve.SHORT_DASH);
S3M.SetStyle(Curve.SHORT_DASH);

R3.Hide();
R3M.Hide();
HH.Hide();
LL.Hide();
S3M.Hide();
S3.Hide();
 
S

Saylarr

Member
Hello
I did this Fibonacci Support and Resistance Bands script, but I have a problem. The indicator flattens or shrinks the graph to show all areas, it does not have to do that the graph should look normal without scale change.
Does anyone have any idea how to fix it?

Here is the code:

Code:
input aggregationPeriod = AggregationPeriod.DAY;
input tolerance = 0.05;

def PH = high(period = aggregationPeriod)[1];
def PL = low(period = aggregationPeriod)[1];
def PC = close(period = aggregationPeriod)[1];

plot R3;
plot R2;
plot R2M;
plot R1;
plot R1M;
plot HH;
plot PP;
plot LL;
plot S1M;
plot S1;
plot S2M;
plot S2;
plot S3;

def DR;
def TR1;
def TR1M;
def TR2;
def TR2M;
def TS1;
def TS1M;
def TS2;
def TS2M;
def TPP1;
def TPP2;

HH = PH;
LL = PL;
PP = (PH + PL + PC) / 3;
DR = PH - PL;

R1 = (0.5 * DR) + PP;
R1M = (0.618 * DR) + PP;

R2 = PP + DR;
R2M = PP + (1.382 * DR);

R3 = pp +  (2.618 * dr);

S1 = PP - (0.5 * DR);
S1M = PP - (0.618 * DR);

S2 = PP - DR;
S2M = PP - (1.382 * DR);

S3 = PP - (2.618 * DR);

TR1 = R1 - ((R1 * tolerance) / 100) ;
TR1M =   R1M + ((R1M * tolerance) / 100) ;

TR2 = R2 - ((R2 * tolerance) / 100) ;
TR2M = R2M + ((R2M * tolerance) / 100) ;

TS1 = S1 + ((S1 * tolerance) / 100) ;
TS1M = S1M - ((S1M * tolerance) / 100) ;

TS2 = S2 + ((S2 * tolerance) / 100) ;
TS2M = S2M - ((S2M * tolerance) / 100) ;

TPP1 = PP + ((PP * tolerance) / 100) ;
TPP2 = PP - ((PP * tolerance) / 100);

R3.SetDefaultColor(GetColor(5));
R2.SetDefaultColor(GetColor(5));
R2M.SetDefaultColor(GetColor(5));
R1.SetDefaultColor(GetColor(5));
R1M.SetDefaultColor(GetColor(5));
HH.SetDefaultColor(GetColor(4));
PP.SetDefaultColor(GetColor(0));
LL.SetDefaultColor(GetColor(1));
S1.SetDefaultColor(GetColor(6));
S1M.SetDefaultColor(GetColor(6));
S2.SetDefaultColor(GetColor(6));
S2M.SetDefaultColor(GetColor(6));
S3.SetDefaultColor(GetColor(6));

R3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R2M.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R1M.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
HH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PP.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S1M.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S2M.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

AddCloud(TR1, TR1M, Color.LIGHT_GREEN, Color.LIGHT_GREEN);
AddCloud(TR2, TR2M, Color.LIGHT_GREEN, Color.LIGHT_GREEN);

AddCloud(TS1, TS1M, Color.LIGHT_RED, Color.LIGHT_RED);
AddCloud(TS2, TS2M, Color.LIGHT_RED, Color.LIGHT_RED);

AddCloud(TPP1, TPP2, Color.PINK, Color.PINK);

R2M.SetStyle(Curve.SHORT_DASH);
R1M.SetStyle(Curve.SHORT_DASH);
HH.SetStyle(Curve.MEDIUM_DASH);
LL.SetStyle(Curve.MEDIUM_DASH);
S1M.SetStyle(Curve.SHORT_DASH);
S2M.SetStyle(Curve.SHORT_DASH);


R3.Hide();
HH.Hide();
LL.Hide();
S3.Hide();
 
BenTen

BenTen

Administrative
Staff
VIP
@Saylarr Left click on the chart > Scale > Fit to studies...
 
S

Saylarr

Member
@BenTen

Oh, thank you very much! I feel very stupid, I am new to thinkorswim
 

Similar threads

Top