# Bid / Ask Dynamic Line
# Mobius
# Chatroom 09.20.2013
input LineLimit = 200;
input SizeLabels = yes;
def bid = close(priceType = "Bid");
def ask = close(priceType = "Ask");
def barNumber = BarNumber();
def Mark = close(priceType = "Mark");
def Last = close(priceType = "Last");
#Dynamic_Line
script dynamic {
input LineLimit = 200;
input c = close;
def bar = if IsNaN(c)
then bar[1]
else BarNumber();
def ThisBar = HighestAll(bar);
def cLine = if bar == ThisBar
then c
else Double.NaN;
plot P = if ThisBar - LineLimit <= bar
then HighestAll(cLine)
else Double.NaN;
}
plot B = dynamic(linelimit = LineLimit, c = bid);
B .SetDefaultColor(Color.GREEN);
B.SetStyle(Curve.FIRM);
B .SetLineWeight(1);
plot A = dynamic(linelimit = LineLimit, c = ask);
A .SetDefaultColor(Color.MAGENTA);
A.SetStyle(Curve.FIRM);
A .SetLineWeight(1);
def Dir = if Last == bid then 1 else 0;
def NotDir = if (Last != bid) or (Last != ask) then 1 else 0;
AddCloud(if Dir then A else Double.NaN, if Dir then B else Double.NaN, Color.GREEN, Color.CURRENT);
AddCloud(if !Dir then A else Double.NaN, if !Dir then B else Double.NaN, Color.RED, Color.CURRENT);
AddCloud(if NotDir then A else Double.NaN, B, Color.GRAY, Color.CURRENT);
AddLabel(yes, Concat("BID: ", AsDollars(close(priceType = "BID"))), if Dir then Color.GREEN else Color.ORANGE );
AddLabel(yes, Concat("ASK: ", AsDollars(close(priceType = "ASK"))), if Dir then Color.ORANGE else Color.GREEN);
def spread = close(priceType = PriceType.ASK) - close(priceType = PriceType.BID);
def spread_l1 = 0.05;
def spread_l2 = 0.15;
AddLabel(1, "Spread: " + spread, if spread <= spread_l1 then Color.GREEN else if spread_l1 < spread <= spread_l2 then Color.YELLOW else COLOR.RED);
# End Code Bid Ask Lines