Hello-
How would you alter this script for a simple indicator that shows the the current price line across a chart to show the "Mark" price of an option rather than the last "Close" (or traded) price of the option:
input barsBack = 1000;
def c = if !IsNaN(close) and IsNaN(close[-1])
then close
else c[1];
plot line = if isNaN(close[-barsBack])
then c[-barsBack]
else Double.NaN;
line.SetLineWeight(2);
line.SetDefaultColor(Color.LIME);
Thanks!
you would use something like this,
input priceType = PriceType.MARK;
def MarkPrice = close(priceType = priceType);
but for options, to get mark price, you might have to use (bid+ask)/2 ?
https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/PriceType
https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/PriceType/PriceType-MARK
-----------------------
it is after hours, so not sure how this will work on options
tested with /ES on a 1 minute chart
pick a price parameter to draw a horizontal line across the chart.
calculate bid, ask, mark, last, price levels.
draw lines for bid, ask, mark, last, price levels, after the last bar.
4 labels display the 4 prices.
the 4 prices have consistant colors , in labels and lines.
...bid, ask, mark, last
...yellow, cyan, magenta, white
------------------------
inputs,
...input price_level_horizontal_line = { bid, ask, default mark, last };
can choose which price level to use to draw a horizontal line
...input show_horizontal_line = yes;
show a horizontal line, across the chart
...input show_four_labels = yes;
show the 4 price levels in labels
...input show_four_lines_after_lastbar = yes;
show the bid, ask, mark, last, price levels, as 1 bar lines, after the last bar.
can adjust how many bars away they are from the last bar.
bid, ask, mark, are set to 2, to be stacked.
last is set to 3, to be 1 bar after them.
Ruby:
# horz_lines_bid_ask_mark_last_0b
#https://usethinkscript.com/threads/how-to-alter-this-script.12001/
#How to alter this script
# sbtyme Start dateFriday at 11:28 AM Tagsunanswered
#How would you alter this script for a simple indicator that shows the the current price line across a chart to show the "Mark" price of an option rather than the last "Close" (or traded) price of the option:
#input priceType = PriceType.MARK;
#def MarkPrice = close(priceType = priceType);
def na = double.nan;
def bidPrice = close(priceType = PriceType.bid);
def askPrice = close(priceType = priceType.ask);
def markPrice = close(priceType = priceType.mark);
def lastPrice = close(priceType = priceType.last);
input pick_price_level = { bid, ask, default mark, last };
# bid, ask, mark, last
# yellow , cyan , magenta , white
# getcolor() , 4 , 1 , 0 , 9
def price;
def pick;
switch (pick_price_level) {
case bid:
price = bidPrice;
pick = 1;
case ask:
price = askPrice;
pick = 2;
case mark:
price = markPrice;
pick = 3;
case last:
price = lastPrice;
pick = 4;
}
#def price = close;
input show_horizontal_line = yes;
def barsBack = 1000;
def c = if !IsNaN(close) and IsNaN(close[-1])
then price
else c[1];
def c2 = if isNaN(close[-barsBack])
then c[-barsBack]
else Double.NaN;
plot line = if show_horizontal_line then c2 else na;
line.SetLineWeight(1);
#line.SetDefaultColor(Color.LIME);
line.AssignValueColor(
if pick == 1 then color.yellow
else if pick == 2 then color.cyan
else if pick == 3 then color.magenta
else if pick == 4 then color.white
else color.current);
# test data--------------
input show_four_labels = yes;
addlabel(show_four_labels, "bid " + bidPrice , color.yellow);
addlabel(show_four_labels, "ask " + askPrice , color.cyan);
addlabel(show_four_labels, "mark " + markPrice , color.magenta);
addlabel(show_four_labels, "last " + lastPrice , color.white);
# offsets, bars after last bar to show 1 bar lines , bid ask mark last
def b1 = 2;
def a2 = 2;
def m3 = 2;
def l4 = 3;
def x1 = (!isnan(close[b1]) and isnan(close[b1-1]));
def x2 = (!isnan(close[a2]) and isnan(close[a2-1]));
def x3 = (!isnan(close[m3]) and isnan(close[m3-1]));
def x4 = (!isnan(close[l4]) and isnan(close[l4-1]));
input show_four_lines_after_lastbar = yes;
plot z1 = if show_four_lines_after_lastbar and x1 then bidPrice[b1] else na;
z1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z1.SetDefaultColor(Color.yellow);
#z1.setlineweight(1);
#z1.hidebubble();
plot z2 = if show_four_lines_after_lastbar and x2 then askPrice[a2] else na;
z2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z2.SetDefaultColor(Color.cyan);
#z2.setlineweight(1);
#z2.hidebubble();
plot z3 = if show_four_lines_after_lastbar and x3 then markPrice[m3] else na;
z3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z3.SetDefaultColor(Color.magenta);
#z3.setlineweight(1);
#z3.hidebubble();
plot z4 = if show_four_lines_after_lastbar and x4 then lastPrice[l4] else na;
z4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z4.SetDefaultColor(Color.white);
#z4.setlineweight(1);
#z4.hidebubble();
#
/ES 1 min
4 price levels after the last bar
horizontal line turned off