Horizontal Lines In ThinkOrSwim

@SleepyZ How can I plot a simple horizontal line representing the average price over a 52-week period? Thanks in advance.

This will create a horizontal line at your option either across the chart or expansion at the last 52 week average price.

Capture.jpg
Ruby:
input show_on_expansion_only = no;
input show_bubble            = yes;

def avgprice   = if IsNaN(close) then avgprice[1] else HighestAll(Average(close(period = AggregationPeriod.WEEK), 52));

plot avg52week = if show_on_expansion_only and !IsNaN(close) then Double.NaN else avgprice;
avg52week.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

input bubblemover = 4;
def   b  = bubblemover;
def   b1 = b + 1;
AddChartBubble(show_bubble and !IsNaN(close[b1]) and IsNaN(close[b]), avgprice[b], "Avg52W \n" + AsText(avgprice[b1]), if close[b1] > avgprice[b1] then Color.GREEN else Color.RED);
 
This indicator for ThinkorSwim will automatically plot overnight High and Low on your chart. In addition, the indicator will also include Fibonacci retracement based on the highest and lowest values from pre-market.

This can be useful for anyone who often plays pre-market breakout or breakdown. You may want to check out this strategy as well.

uUiRGl0.png


thinkScript Code

Rich (BB code):
# GlobeX or Overnight High / Low with Fibonacci Values 

# Mobius 

# V01.2012 

input PlotOverNightExtremes = yes;

input coeff_1 = .236;

input coeff_2 = .327;

# gmh: added the rest of the Fibs 

input coeff_3 = .500;

input coeff_4 = .618;

input coeff_5 = .789;

input coeff_6 = .882;



def o = open;

def h = high;

def l = low;

def c = close;

def v = volume;

def bar = BarNumber();

def GlobeX = GetTime() < RegularTradingStart(GetYYYYMMDD());

def vol = if GlobeX and !Globex[1]

          then v

          else if GlobeX

               then vol[1] + v

               else Double.NaN;

def GlobeX_Volume = vol;

def ONhigh = if GlobeX and !Globex[1]

             then h

             else if Globex and

                     h > ONhigh[1]

                     then h

                  else ONhigh[1];

def ONhighBar = if GlobeX and h == ONhigh

                then Bar

                else double.nan;

def ONlow = if GlobeX and !GlobeX[1]

            then l

            else if GlobeX and

                    l < ONlow[1]

            then l

                 else ONlow[1];

def ONlowBar = if GlobeX and l == ONlow

               then Bar

               else double.nan;

def OverNightHigh = if BarNumber() == HighestAll(ONhighBar)

                    then ONhigh

                    else OverNightHigh[1];

def OverNightLow = if BarNumber() == HighestAll(ONlowBar)

                   then ONlow

                   else OverNightLow[1];

plot ONH = if OverNightHigh > 0

           then OverNightHigh

           else Double.NaN;

     ONH.SetHiding(!PlotOverNightExtremes);

     ONH.SetPaintingStrategy(PaintingStrategy.SQUARES);

     ONH.SetDefaultColor(Color.BLUE);

     ONH.HideBubble();

     ONH.HideTitle();

plot ONL = if OverNightLow > 0

           then OverNightLow

           else Double.NaN;

     ONL.SetHiding(!PlotOverNightExtremes);

     ONL.SetPaintingStrategy(PaintingStrategy.SQUARES);

     ONL.SetDefaultColor(Color.LIGHT_GRAY);

     ONL.HideBubble();

     ONL.HideTitle();



def MaxBar = Max(HighestAll(ONhighBar), HighestAll(ONlowBar));



plot coeff1 = if HighestAll(ONhighBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then ((OverNightHigh - OverNightLow) * coeff_1) + OverNightLow

              else if HighestAll(ONlowBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then OverNightHigh - ((OverNightHigh - OverNightLow) * coeff_1)

              else double.nan;

plot coeff2 = if HighestAll(ONhighBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then ((OverNightHigh - OverNightLow) * coeff_2) + OverNightLow

               else if HighestAll(ONlowBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then OverNightHigh - ((OverNightHigh - OverNightLow) * coeff_2)

              else double.nan;

plot coeff3 = if HighestAll(ONhighBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then ((OverNightHigh - OverNightLow) * coeff_3) + OverNightLow

              else if HighestAll(ONlowBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then OverNightHigh - ((OverNightHigh - OverNightLow) * coeff_3)

              else double.nan;

plot coeff4 = if HighestAll(ONhighBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then ((OverNightHigh - OverNightLow) * coeff_4) + OverNightLow

              else if HighestAll(ONlowBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then OverNightHigh - ((OverNightHigh - OverNightLow) * coeff_4)

              else double.nan;

plot coeff5 = if HighestAll(ONhighBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then ((OverNightHigh - OverNightLow) * coeff_5) + OverNightLow

              else if HighestAll(ONlowBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then OverNightHigh - ((OverNightHigh - OverNightLow) * coeff_5)

              else double.nan;

plot coeff6 = if HighestAll(ONhighBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then ((OverNightHigh - OverNightLow) * coeff_6) + OverNightLow

              else if HighestAll(ONlowBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then OverNightHigh - ((OverNightHigh - OverNightLow) * coeff_6)

              else double.nan;

# 

# End Code GlobeX High Low with Fibs 

Shareable Link

https://tos.mx/oNY5Yw
How can I include the high in the AFTERMARKET?
 
Ruby:
input StartDate = 20191003;
def hh = if GetYYYYMMDD() == StartDate then high else if high > hh[1] then high else hh[1];
plot higherHigh = if GetYYYYMMDD() < StartDate then Double.NaN else hh;
higherHigh.SetPaintingStrategy(12);

TBijo9h.png
Happy Holidays,

would you post revised code for that plots higher highs for 5 minute charts?

regards,
 
@jmtraderguy try this

Code:
#
input price = close;
input length1 = 15;
input length2 = 30;
input averageType1 = AverageType.SIMPLE;
input averageType2 = AverageType.SIMPLE;
input crossingType = {default above, below};

plot avg1 = MovingAverage(averageType1, price, length1);
plot avg2 = MovingAverage(averageType2, price, length2);
def sigtest;
switch(crossingType){
case above:
sigtest = avg1 crosses above avg2;
case below:
sigtest = avg1 crosses below avg2;
}

def sigline = if sigtest then (avg1+avg2)/2 else if sigtest[1] and !sigtest then (avg1[1]+avg2[1])/2 else sigline[1];
plot signal = sigline;
signal.DefineColor("Above", GetColor(6));
signal.DefineColor("Below", GetColor(7));
signal.AssignValueColor(if crossingType == crossingType.above then signal.Color("Above") else signal.Color("Below"));

signal.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

#-------------------------------------
I know this was posted a while ago, but would it be possible to run the same scenario using the TOS demand index that:
  • Draws a green horizontal line on the close of a candle where the demand Index is greater than the demand index from one bar ago
  • Draws a red horizontal line on the close of a candle where the demand Index is less than the demand index from one bar ago
  • Draws a green horizontal line on the close of a candle where the demand Index crosses above zero
  • Draws a red horizontal line on the close of a candle where the demand Index crosses below zero
It would be ideal if the horizontal line extends across the chart for the remainder of the day (Like pivot points).

Thank you in advance!!!
 
I know this was posted a while ago, but would it be possible to run the same scenario using the TOS demand index that:
  • Draws a green horizontal line on the close of a candle where the demand Index is greater than the demand index from one bar ago
  • Draws a red horizontal line on the close of a candle where the demand Index is less than the demand index from one bar ago
  • Draws a green horizontal line on the close of a candle where the demand Index crosses above zero
  • Draws a red horizontal line on the close of a candle where the demand Index crosses below zero
It would be ideal if the horizontal line extends across the chart for the remainder of the day (Like pivot points).

Thank you in advance!!!

you had 2 sets of rules, that drew the same colors at the same place. because of this, you would not know which rule was triggered. so i changed the colors for the signal crossing zero, to cyan and yellow.
i added a 5th color, gray, just in case the signal moves horizontal, the same number for 2 bars in a row.

i copied the original demandindex study. sometimes i do this if the original isn't too long and too be able to better understand all of the finished code.

i have it set to start drawing a horizontal, dashed line, 1 bar after the last bar, and extend to the right of the screen.

i left my test bubbles and labels at the end. they can be turned on, to show some variable values.

on my charts, i added the original lower study, demandindex, to compare and verify.
this may not work as expected with extended hours turned on.

Ruby:
# demand_horz_lines_00e
# ----------------------------------------
# copy the original demandindex study
# TD Ameritrade IP Company, Inc. (c) 2010-2021
#declare lower;
input length = 5;
def wClose = (high + low + 2 * close) * 0.25;
def wCRatio = (wClose - wClose[1]) / Min(wClose, wClose[1]);
def closeRatio = 3 * wClose / Average(Highest(High, 2) - Lowest(Low, 2), length) * AbsValue(wCRatio);
def volumeRatio = Volume / Average(Volume, length);
def volumePerClose = volumeRatio / exp(Min(88, closeRatio));
def buyP;
def sellP;
if (wCRatio > 0) {
    buyP = volumeRatio;
    sellP = volumePerClose;
} else {
    buyP = volumePerClose;
    sellP = volumeRatio;
}
def buyPres = if IsNaN(buyPres[1]) then 0 else ((buyPres[1] * (length - 1)) + buyP) / length;
def sellPres = if IsNaN(sellPres[1]) then 0 else ((sellPres[1] * (length - 1)) + sellP) / length;
def tempDI;
if ((((sellPres[1] * (length - 1)) + sellP) / length - ((buyPres[1] * (length - 1)) + buyP) / length) > 0) {
    tempDI = - if (sellPres != 0) then buyPres / sellPres else 1;
} else {
    tempDI = if (buyPres != 0) then sellPres / buyPres else 1;
}

def DMIndx = if IsNaN(close) then Double.NaN else if tempDI < 0 then -1 - tempDI else 1 - tempDI;
def ZeroLine = 0;
#plot DMIndx = if IsNaN(close) then Double.NaN else if tempDI < 0 then -1 - tempDI else 1 - tempDI;
#plot ZeroLine = 0;
#DMIndx.setDefaultColor(GetColor(1));
#ZeroLine.SetDefaultColor(GetColor(5));

# --------------------------------------

def na = double.nan;
def bn = barnumber();

def lastbarbn = HighestAll(If(IsNaN(close), 0, bn));
def lastbar = if (bn == lastbarbn) then 1 else 0;

# ------------------------------

# create a priceline level, at the last bar close
input barsBack = 1000;
def c = if !IsNaN(close) and IsNaN(close[-1])
        then close
        else c[1];

def close_line = if isNaN(close[-barsBack])
        then c[-barsBack]
        else Double.NaN;

# line only after last bar. +1 , line starts 1 bar after lastbar
def close_line2 = if bn < (lastbarbn+1) then na else close_line;

# ------------------------------

# Draws a green horizontal line , when the demand Index > prev bar demand index
def DMIndx_up = (DMIndx > DMIndx[1]);

# Draws a red horizontal line , when the demand Index < prev bar demand index
def DMIndx_dwn = (DMIndx < DMIndx[1]);

def DMIndx_flat = ( !DMIndx_up and !DMIndx_dwn);

# Draws a cyan horizontal line , when the demand Index crosses above zero
def DMIndx_crossup = (DMIndx crosses above ZeroLine);

# Draws a yellow horizontal line , when the demand Index crosses below zero
def DMIndx_crossdwn = (DMIndx crosses below ZeroLine);


# keep values after last bar
def DMIndx_up2 = if lastbar then DMIndx_up else DMIndx_up2[1];
def DMIndx_dwn2 = if lastbar then DMIndx_dwn else DMIndx_dwn2[1];
def DMIndx_flat2 = if lastbar then DMIndx_flat else DMIndx_flat2[1];
def DMIndx_crossup2 = if lastbar then  DMIndx_crossup else  DMIndx_crossup2[1];
def DMIndx_crossdwn2 = if lastbar then DMIndx_crossdwn else DMIndx_crossdwn2[1];

# --------------------------------------

plot z = close_line2;
z.DefineColor("Up", color.green);
z.DefineColor("dwn", color.red);
z.DefineColor("xup", color.cyan);
z.DefineColor("xdwn", color.yellow);
z.definecolor("flat", color.gray);
z.AssignValueColor( if DMIndx_crossup2 then z.color("xup")
 else if DMIndx_crossdwn2 then z.color("xdwn")
 else if DMIndx_up2 then z.color("up")
 else if DMIndx_dwn2 then z.color("dwn")
 else z.color("flat"));

z.SetStyle(Curve.MEDIUM_DASH);
# x.SetDefaultColor(Color.red);
#z.setlineweight(2);
# x.hidebubble();

# ------------------------------------

input test_labels = no;
addlabel( test_labels, "DMIndx, prev " + dmindx[1], color.magenta);
addlabel( test_labels, "DMIndx " + DMIndx , color.magenta);

addlabel( test_labels, "DMIndx_up  " + DMIndx_up2 , (if DMIndx_up2 then color.green else color.gray));
addlabel( test_labels, "DMIndx_dwn  " + DMIndx_dwn2 , (if DMIndx_dwn then color.red else color.gray));
addlabel( test_labels, "DMIndx_flat  " + DMIndx_flat2 , ( if DMIndx_flat2 then color.light_gray else color.gray));

addlabel( test_labels, "DMIndx_crossup  " + DMIndx_crossup2 , (if DMIndx_crossup2 then color.cyan else color.gray));
addlabel( test_labels, "DMIndx_crossdwn  " + DMIndx_crossdwn2 , (if DMIndx_crossdwn2 then color.yellow else color.gray));


input test_bubbles2 = no;
addchartbubble(test_bubbles2, low*0.98,
bn  + "\n" +
"P " + dmindx[1] + "\n" +
" " + DMIndx + "\n" +
"up " + DMIndx_up2 + "\n" +
"dwn " + DMIndx_dwn2 + "\n" +
"F " + DMIndx_flat2 + "\n" +
"Xup " + DMIndx_crossup2 + "\n" +
"Xd " + DMIndx_crossdwn2
, color.yellow, no);
#


examples of the 4 colors

green
9pVyXyY.jpg


red
Fg0gl9Q.jpg


cyan, crossing up
2uaClpJ.jpg


yellow , crossing down
UUONhPN.jpg


https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/C-D/DemandIndex
 
you had 2 sets of rules, that drew the same colors at the same place. because of this, you would not know which rule was triggered. so i changed the colors for the signal crossing zero, to cyan and yellow.
i added a 5th color, gray, just in case the signal moves horizontal, the same number for 2 bars in a row.

i copied the original demandindex study. sometimes i do this if the original isn't too long and too be able to better understand all of the finished code.

i have it set to start drawing a horizontal, dashed line, 1 bar after the last bar, and extend to the right of the screen.

i left my test bubbles and labels at the end. they can be turned on, to show some variable values.

on my charts, i added the original lower study, demandindex, to compare and verify.
this may not work as expected with extended hours turned on.




https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/C-D/DemandIndex
Thank you so much! Is there a way to keep the lines visible for the day? I just tried it and there's only one line at the current bar.
 
Thank you so much! Is there a way to keep the lines visible for the day? I just tried it and there's only one line at the current bar.
o sorry, having 1 line at a time is how interpreted your rules,
when do you want a line to stay on the chart ?
 
Yes, please :)

version 2 of demandindex lines

this will,
. show a short line after every bar,
. or 1 line after the last bar.

lines colored by the movement of the demandindex study.
. move up , green
. move down , red
. cross above 0 , cyan
. cross below 0 , yellow
. flat , gray


study settings

show_many_lines = yes
with this set to yes, it draws lines from each bar, spanning 3 bars.
with it set no, it draws 1 line, after the last bar.

lines_offset = 0
with this set to 0, the short lines start at the data bar.
if it is set to 1, then the lines start 1 bar after the data bar.

barsBack = 1000
this is used for the line after the last bar.
if there are more than 1000 bars on the chart, make this bigger.

i left my test bubble code in. they display variable values. set to yes to see them.


Ruby:
# demand_horz_lines_2

# ----------------------------------------
# copy the original demandindex study
# TD Ameritrade IP Company, Inc. (c) 2010-2021
#declare lower;

input length = 5;

def wClose = (high + low + 2 * close) * 0.25;
def wCRatio = (wClose - wClose[1]) / Min(wClose, wClose[1]);
def closeRatio = 3 * wClose / Average(Highest(High, 2) - Lowest(Low, 2), length) * AbsValue(wCRatio);
def volumeRatio = Volume / Average(Volume, length);
def volumePerClose = volumeRatio / exp(Min(88, closeRatio));
def buyP;
def sellP;
if (wCRatio > 0) {
    buyP = volumeRatio;
    sellP = volumePerClose;
} else {
    buyP = volumePerClose;
    sellP = volumeRatio;
}
def buyPres = if IsNaN(buyPres[1]) then 0 else ((buyPres[1] * (length - 1)) + buyP) / length;
def sellPres = if IsNaN(sellPres[1]) then 0 else ((sellPres[1] * (length - 1)) + sellP) / length;
def tempDI;
if ((((sellPres[1] * (length - 1)) + sellP) / length - ((buyPres[1] * (length - 1)) + buyP) / length) > 0) {
    tempDI = - if (sellPres != 0) then buyPres / sellPres else 1;
} else {
    tempDI = if (buyPres != 0) then sellPres / buyPres else 1;
}

def DMIndx = if IsNaN(close) then Double.NaN else if tempDI < 0 then -1 - tempDI else 1 - tempDI;
def ZeroLine = 0;
#plot DMIndx = if IsNaN(close) then Double.NaN else if tempDI < 0 then -1 - tempDI else 1 - tempDI;
#plot ZeroLine = 0;
#DMIndx.setDefaultColor(GetColor(1));
#ZeroLine.SetDefaultColor(GetColor(5));

# --------------------------------------

def na = double.nan;
def bn = barnumber();

def lastbarbn = HighestAll(If(IsNaN(close), 0, bn));
def lastbar = if (bn == lastbarbn) then 1 else 0;

# ------------------------------

# create a priceline level, at the last bar close
input barsBack = 1000;
def c = if !IsNaN(close) and IsNaN(close[-1])
        then close
        else c[1];

def close_line = if isNaN(close[-barsBack])
        then c[-barsBack]
        else Double.NaN;

# line only after last bar. +1 , line starts 1 bar after lastbar
def close_line2 = if bn < (lastbarbn+1) then na else close_line;

# ------------------------------

# Draws a green horizontal line , when the demand Index > prev bar demand index
def DMIndx_up = (DMIndx > DMIndx[1]);

# Draws a red horizontal line , when the demand Index < prev bar demand index
def DMIndx_dwn = (DMIndx < DMIndx[1]);

def DMIndx_flat = ( !DMIndx_up and !DMIndx_dwn);

# Draws a cyan horizontal line , when the demand Index crosses above zero
def DMIndx_crossup = (DMIndx crosses above ZeroLine);

# Draws a yellow horizontal line , when the demand Index crosses below zero
def DMIndx_crossdwn = (DMIndx crosses below ZeroLine);

# ----------------------

# keep values after last bar
def DMIndx_up2 = if lastbar then DMIndx_up else DMIndx_up2[1];
def DMIndx_dwn2 = if lastbar then DMIndx_dwn else DMIndx_dwn2[1];
def DMIndx_flat2 = if lastbar then DMIndx_flat else DMIndx_flat2[1];
def DMIndx_crossup2 = if lastbar then  DMIndx_crossup else  DMIndx_crossup2[1];
def DMIndx_crossdwn2 = if lastbar then DMIndx_crossdwn else DMIndx_crossdwn2[1];

# --------------------------------------

input show_many_lines = yes;
#  yes = 1 line on each bar
#  no  = only 1 line after last bar

# ------------------------------

plot z = if show_many_lines then na else close_line2;
z.DefineColor("Up", color.green);
z.DefineColor("dwn", color.red);
z.DefineColor("xup", color.cyan);
z.DefineColor("xdwn", color.yellow);
z.definecolor("flat", color.gray);
z.AssignValueColor( if DMIndx_crossup2 then z.color("xup") 
 else if DMIndx_crossdwn2 then z.color("xdwn")
 else if DMIndx_up2 then z.color("up") 
 else if DMIndx_dwn2 then z.color("dwn") 
 else z.color("flat"));

z.SetStyle(Curve.MEDIUM_DASH);
# x.SetDefaultColor(Color.red);
#z.setlineweight(2);
# x.hidebubble();


# ------------------------------------

# create 1 var, with 5 values, to determine signal type
# crossing = 2, -2
# up/dwn = 1 , -1
# flat = 0
def dm_num = if DMIndx_crossup then 2
  else if DMIndx_crossdwn then -2
  else if DMIndx_up then 1
  else if DMIndx_dwn then -1
  else 0;

# ----------------------

# plot line after each bar , spanning 3 bars

# need a counter , 1,2,3,4,1,2,3,4,1,..
def bnindex = (bn % 4) + 1;
# addchartbubble(1, low*0.99, bn + "\n" + bnindex, color.cyan, no);

# start line 1 bar after the data bar
input lines_offset = 0;

def p1;
def p2;
def p3;
def p4;
def p1y;
def p2y;
def p3y;
def p4y;
if bn == 1 then {
  p1 = na;
  p2 = na;
  p3 = na;
  p4 = na;
  p1y = na;
  p2y = na;
  p3y = na;
  p4y = na;
} else if bnindex == 1 then {
  p1 = dm_num[lines_offset];
  p2 = p2[1];
  p3 = p3[1];
  p4 = p4[1];
  p1y = close[lines_offset];
  p2y = na;
  p3y = p3y[1];
  p4y = p4y[1];  
} else if bnindex == 2 then {
  p1 = p1[1];
  p2 = dm_num[lines_offset];
  p3 = p3[1];
  p4 = p4[1];  
  p1y = p1y[1];
  p2y = close[lines_offset];
  p3y = na;
  p4y = p4y[1];  
} else if bnindex == 3 then {
  p1 = p1[1];
  p2 = p2[1];
  p3 = dm_num[lines_offset];
  p4 = p4[1];  
  p1y = p1y[1];
  p2y = p2y[1];
  p3y = close[lines_offset];
  p4y = na;  
} else if bnindex == 4 then {
  p1 = p1[1];
  p2 = p2[1];
  p3 = p3[1];
  p4 = dm_num[lines_offset];
  p1y = na;
  p2y = p2y[1];
  p3y = p3y[1];
  p4y = close[lines_offset];
} else {
  p1 = na;
  p2 = na;
  p3 = na;
  p4 = na;
  p1y = na;
  p2y = na;
  p3y = na;
  p4y = na;
}


input test_bubbles1 = no;

input test_bubbles2 = no;
addchartbubble(test_bubbles2, low*0.99, 
  bn
  + "\n" + bnindex
  + "\n" + dm_num
  + "\n" + "---"
  + "\n" + p1
  + "\n" + p2
  + "\n" + p3
  + "\n" + p4
  + "\n" + p1y
  + "\n" + p2y
  + "\n" + p3y
  + "\n" + p4y
  , color.cyan, no);

# --------------------------
# plot 3 lines

plot v1 = if show_many_lines then p1y else na;
plot v2 = if show_many_lines then p2y else na;
plot v3 = if show_many_lines then p3y else na;
plot v4 = if show_many_lines then p4y else na;


# crossing = 2, -2
# up/dwn = 1 , -1
# flat = 0
v1.AssignValueColor( if p1 == 2 then color.cyan
 else if p1 == 1  then color.green
 else if p1 == -1 then color.red
 else if p1 == -2 then color.yellow
 else color.gray);

v2.AssignValueColor( if p2 == 2 then color.cyan
 else if p2 == 1  then color.green
 else if p2 == -1 then color.red
 else if p2 == -2 then color.yellow
 else color.gray);

v3.AssignValueColor( if p3 == 2 then color.cyan
 else if p3 == 1  then color.green
 else if p3 == -1 then color.red
 else if p3 == -2 then color.yellow
 else color.gray);

v4.AssignValueColor( if p4 == 2 then color.cyan
 else if p4 == 1  then color.green
 else if p4 == -1 then color.red
 else if p4 == -2 then color.yellow
 else color.gray);

# ------------------------------------

input test_labels = no;
addlabel( test_labels, "DMIndx, prev " + dmindx[1], color.magenta);
addlabel( test_labels, "DMIndx " + DMIndx , color.magenta);

addlabel( test_labels, "DMIndx_up  " + DMIndx_up2 , (if DMIndx_up2 then color.green else color.gray));
addlabel( test_labels, "DMIndx_dwn  " + DMIndx_dwn2 , (if DMIndx_dwn then color.red else color.gray));
addlabel( test_labels, "DMIndx_flat  " + DMIndx_flat2 , ( if DMIndx_flat2 then color.light_gray else color.gray));

addlabel( test_labels, "DMIndx_crossup  " + DMIndx_crossup2 , (if DMIndx_crossup2 then color.cyan else color.gray));
addlabel( test_labels, "DMIndx_crossdwn  " + DMIndx_crossdwn2 , (if DMIndx_crossdwn2 then color.yellow else color.gray));


#input test_bubbles1 = no;
addchartbubble(test_bubbles1, low*0.98,
bn  + "\n" +
"P " + dmindx[1] + "\n" +
" " + DMIndx + "\n" +
"up " + DMIndx_up2 + "\n" +
"dwn " + DMIndx_dwn2 + "\n" +
"F " + DMIndx_flat2 + "\n" +
"Xup " + DMIndx_crossup2 + "\n" +
"Xd " + DMIndx_crossdwn2 
, color.yellow, no);
#


many short lines
lines_offset , set to 0
SawcKaW.jpg


settings
H1PaCG9.jpg
 
zoXkQiq.gif


https://tos.mx/h5zl6vb

applies to any timeframe automatically but doesn't
have 25% or 75% lines if someone wanted to
improve on that

Code:
def value = (high + low) / 2;
def value_fix = if isnan(value) then value_fix[1] else value;

plot Fib50 = if isnan(close[-1]) then value_fix else double.nan;
Fib50.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib50.SetDefaultColor(color.white);
edited by mod to include actual code
 
Last edited by a moderator:
How do I show a horizontal line at price action on charts
I want a horizontal line to move with price action. See if i can use it to find intraday support and resistance. Maybe? Thank You.
 
Last edited by a moderator:
@SeriousAF
I moved your question to this thread. There are 11 pages of line plot scripts. Plug&Play and see what fits your needs.
Have fun!
 
Last edited:
I'm trying to print a horizontal line with this code. The label works, but the line won't. I know its something dumb.

def parsar = reference parabolicSAR();
addlabel(yes, "PARSAR[1]) " + astext(parsar[1]), color.white);


input level = (parsar[1]);

plot a = level + 0;
 
I'm trying to print a horizontal line with this code. The label works, but the line won't. I know its something dumb.

def parsar = reference parabolicSAR();
addlabel(yes, "PARSAR[1]) " + astext(parsar[1]), color.white);


input level = (parsar[1]);

plot a = level + 0;

Here are 2 ways to display the horizontal line.
Plot a will pot the last value of parsar[1] across the whole chart.
Plot b will plot the parsar[1] and extend the last parsar[1] to the right.

Capture.jpg
Ruby:
def parsar = reference parabolicSAR();
addlabel(yes, "PARSAR[1]) " + astext(parsar[1]), color.white);

def level = if isnan(close) then level[1] else parsar[1];

plot a = highestall(if !isnan(parsar) and isnan(parsar[-1]) then level else double.nan);
plot b = level;
a.setpaintingStrategy(paintingStrategy.HORIZONTAL);
b.setpaintingStrategy(paintingStrategy.HORIZONTAL);
 
Here are 2 ways to display the horizontal line.
Plot a will pot the last value of parsar[1] across the whole chart.
Plot b will plot the parsar[1] and extend the last parsar[1] to the right.
Thank you,

That solved one of the problems I was having with the other psar break code. It would put a line at the high/low of where the psar broke not the actual spot.

I see now that what I have is referencing the one before, not where it broke the last cycle.

The blue line is the one from your code.

I'm trying to make the red lines happen.
https://1drv.ms/u/s!AgXNDtw32l9YgpZPIAbNcGcHB8jNSw?e=pS4tnZ
 
Thank you,

That solved one of the problems I was having with the other psar break code. It would put a line at the high/low of where the psar broke not the actual spot.

I see now that what I have is referencing the one before, not where it broke the last cycle.

The blue line is the one from your code.

I'm trying to make the red lines happen.
https://1drv.ms/u/s!AgXNDtw32l9YgpZPIAbNcGcHB8jNSw?e=pS4tnZ

Regrettably, TOS does not have a way to repeat extended horizontal lines to the right edge of the chart without a separate plot for each.

Here is code for 3 up and 3 down plots you requested. You can create more using the same logic you can see between extended u and d plots.

The image includes the ParabolicSAR indicator for testing purposes.

Capture.jpg
Ruby:
def parsar = reference ParabolicSAR();
AddLabel(yes, "PARSAR[1]) " + AsText(parsar), Color.WHITE);

###############
def psarup = if IsNaN(close) then psarup[1] else if parsar < close and parsar[1] > close[1] then parsar[1] else psarup[1];
plot pup = psarup;
pup.SetLineWeight(2);
pup.SetPaintingStrategy(PaintingStrategy.DASHES);
pup.SetDefaultColor(Color.RED);

def u = if IsNaN(parsar) then u[1] else if psarup != psarup[1] then psarup else u[1];
plot uu0 = u;
uu0.SetLineWeight(2);
uu0.SetPaintingStrategy(PaintingStrategy.DASHES);
uu0.SetDefaultColor(Color.RED);

def u1 = if IsNaN(psarup) then u1[1] else if u != u[1] then u[1] else u1[1];
plot uu1 = u1;
uu1.SetLineWeight(2);
uu1.SetPaintingStrategy(PaintingStrategy.DASHES);
uu1.SetDefaultColor(Color.RED);

def u2 = if IsNaN(psarup) then u2[1] else if u1 != u1[1] then u1[1] else u2[1];
plot uu2 = u2;
uu2.SetLineWeight(2);
uu2.SetPaintingStrategy(PaintingStrategy.DASHES);
uu2.SetDefaultColor(Color.RED);

def u3 = if IsNaN(psarup) then u3[1] else if u2 != u2[1] then u2[1] else u3[1];
plot uu3 = u3;
uu3.SetLineWeight(2);
uu3.SetPaintingStrategy(PaintingStrategy.DASHES);
uu3.SetDefaultColor(Color.RED);

###############
def psardn = if isnan(close) then psardn[1] else if parsar > close and parsar[1] < close[1] then parsar[1] else psardn[1];
plot pdn = psardn;
pdn.SetLineWeight(2);
pdn.SetPaintingStrategy(PaintingStrategy.DASHES);
pdn.SetDefaultColor(Color.RED);

def d = if IsNaN(parsar) then d[1] else if psardn != psardn[1] then psardn else d[1];
plot dd0 = u;
dd0.SetLineWeight(2);
dd0.SetPaintingStrategy(PaintingStrategy.DASHES);
dd0.SetDefaultColor(Color.RED);

def d1 = if IsNaN(psardn) then d1[1] else if d != d[1] then d[1] else d1[1];
plot dd1 = d1;
dd1.SetLineWeight(2);
dd1.SetPaintingStrategy(PaintingStrategy.DASHES);
dd1.SetDefaultColor(Color.RED);

def d2 = if IsNaN(psardn) then d2[1] else if d1 != d1[1] then d1[1] else d2[1];
plot dd2 = d2;
dd2.SetLineWeight(2);
dd2.SetPaintingStrategy(PaintingStrategy.DASHES);
dd2.SetDefaultColor(Color.RED);

def d3 = if IsNaN(psarup) then d3[1] else if d2 != d2[1] then d2[1] else d3[1];
plot dd3 = d3;
dd3.SetLineWeight(2);
dd3.SetPaintingStrategy(PaintingStrategy.DASHES);
dd3.SetDefaultColor(Color.RED);

###############
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
330 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top