def IsUp = close > open;
def IsDown = close < open;
def IsDoji = IsDoji();
def avgRange = 0.05 * Average(high - low, 20);
def Two1TwoDN =
IsDown[3] and
IsDown[2] and
IsUp[1] and
IsDown[0] and
close[2] < open[1] and
open[1] > close[0] and
open[3] > open[2] and
close[3] > close[2] and
open[2] > close[1];
def Two1TwoUP =
IsUp[3] and
IsUp[2] and
IsDown[1] and
IsUp[0] and
open[3] < open[2] and
open[2] < close[1] and
close[2] > open[1] and
close[3] < close[2] and
open[1] < close[0];
###########################
input price = close;
input displace = 0;
def AvgExp = ExpAverage(price[-displace], 9);
input Num_Dev_up = 0.250;
input Num_Dev_dn = -0.250;
#def sDev = StDev(data = price[-displace], length = 9);
#def LowerBand = AvgExp + Num_Dev_dn * sDev;
#def UpperBand = AvgExp + Num_Dev_up * sDev;
#AddCloud(AvgExp, LowerBand, Color.RED, Color.RED);
#AddCloud(AvgExp, UpperBand, Color.GREEN, Color.GREEN);
###########################
def Value = MovingAverage(AverageType.EXPONENTIAL, close, 8) - MovingAverage(AverageType.EXPONENTIAL, close, 21);
def Avg = MovingAverage(AverageType.EXPONENTIAL, Value, 5);
def BullMACD = Value is greater than Avg;
def BearMACD = Value is less than Avg;
###########################
input length = 14;
input averageType = AverageType.WILDERS;
def hiDiff = high - high[1];
def loDiff = low[1] - low;
def plusDM = if hiDiff > loDiff and hiDiff > 0 then hiDiff else 0;
def minusDM = if loDiff > hiDiff and loDiff > 0 then loDiff else 0;
def ATR = MovingAverage(averageType, TrueRange(high, close, low), length);
def "DI+" = 100 * MovingAverage(averageType, plusDM, length) / ATR;
def "DI-" = 100 * MovingAverage(averageType, minusDM, length) / ATR;
def BullDI = "DI+" is greater than "DI-";
def BearDI = "DI+" is less than "DI-";
############################
def UPCON1 = close is greater than AvgExp;
def UPCON2 = BullMACD and BullDI is true;
def UPcon3 = UPCON1 and UPCON2 is true;
def UP = Two1TwoUP and UPcon3 is true;
AddChartBubble(UP, high, "UP" , Color.YELLOW, yes);
alert(up,"up",alert.bar,sound.bell);
def DNCON1 = close is less than AvgExp;
def DNCON2 = BearMACD and BearDI is true;
def DNcon3 = DNCON1 and DNCON2 is true;
def DN = Two1TwoDN and DNcon3 is true;
AddChartBubble(DN, high, "DN" , Color.WHITE, yes);
alert(dn,"DN",alert.bar,sound.bell);
# leftlines_01c
# chg signal offset
# draw lines before a signal ( to the left)
#--------------------------
def na = double.nan;
def bn = BarNumber();
input len = 500;
input signal_offset = -1;
#def up = if (MACD()."Value" crosses above MACD()."Avg" and MACD()."Value" < 0) then 1 else 0;
# draw an up arrow under the original up signal bar
input test_arrow_up_original = yes;
plot u1 = (test_arrow_up_original and up);
u1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
u1.SetDefaultColor(Color.white);
u1.setlineweight(1);
u1.hidebubble();
def top;
def bot;
if bn == 1 then {
top = na;
bot = na;
} else if up[signal_offset+1] then {
top = fold i = 1 to len
while !getvalue(up[signal_offset+1], -i)
do getvalue(high, -i);
bot = fold k = 1 to len
while !getvalue(up[signal_offset+1], -k)
do getvalue(low, -k);
} else {
top = top[1];
bot = bot[1];
}
plot t = top;
t.SetDefaultColor(Color.cyan);
t.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot b = bot;
b.SetDefaultColor(Color.cyan);
b.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
# errors
#AddCloud(top, bot, Color.CYAN, Color.CYAN);
# find first bar of line
def first = if (t[1] <> t[0] and !isnan(close) ) then 1 else 0;
input show_cloud = yes;
def t2 = if first then na else if show_cloud then t else na;
AddCloud(t2, b, Color.CYAN, Color.CYAN);
# -------------------------
input test1_up_signals = no;
addchartbubble(test1_up_signals and up[signal_offset+0], top, "up " + up + "\nH " + high + "\nL " + low, ( if up[0] then color.cyan else color.gray), yes);
plot D1 = (test_arrow_up_original and dn);
d1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
d1.SetDefaultColor(Color.white);
d1.setlineweight(1);
d1.hidebubble();
def top2;
def bot2;
if bn == 1 then {
top2 = na;
bot2 = na;
} else if dn[signal_offset+1] then {
top2 = fold i2 = 1 to len
while !getvalue(dn[signal_offset+1], -i2)
do getvalue(high, -i2);
bot2 = fold k2 = 1 to len
while !getvalue(dn[signal_offset+1], -k2)
do getvalue(low, -k2);
} else {
top2 = top2[1];
bot2 = bot2[1];
}
plot td = top2;
td.SetDefaultColor(Color.red);
td.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot bd = bot2;
bd.SetDefaultColor(Color.red);
bd.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
# errors
#AddCloud(top, bot, Color.CYAN, Color.CYAN);
# find first bar of line
def firstd = if (t2[1] <> t2[0] and !isnan(close) ) then 1 else 0;
def t2D = if firstd then na else if show_cloud then td else na;
AddCloud(t2d, bd, Color.red, Color.red);
# -------------------------
#input test1_up_signals = no;
#addchartbubble(test1_up_signals and up[signal_offset+0], top, "up " + up + "\nH " + high + "\nL " + low, ( if up[0] then color.cyan else color.gray), yes);