this seems to work?
it changes the bar colors and draws lines
changed,
...defs before first if shouldn't be set to a value
...each branch needs all 4 variables,
...change tococentry to be = 0 or = 1
...the last 2 if thens , replace this , then { if , with , and
. so it looks like this and ref's 1 bar back
. } else if Bullish and !tococentry[1] then {
...add plots to draw 3 lines
Code:
# trend_entry_target_v2_00a
# https://usethinkscript.com/threads/someone-help-me-to-correct-conditional-if-else.12702/
# someone help me to correct conditional if else
# Destructor Start dateToday at 5:13 PM
# when the trend is bullish draw the entry if a bar breaks the entry line stop drawing the entry and start drawing the target... when it is bearish the same logic.
#The code that you modify corresponds to a code that ignapaillet published : #https://usethinkscript.com/threads/expert-trend-locator-xtl-for-thinkorswim.8086/
def na = double.nan;
def PD = 32;
def Value = 25;
def GreenPrice = CCI(PD) > Value; #uptrend
def RedPrice = CCI(PD) < -Value; #downtrend
def NeutralPrice = -Value <= CCI(PD) and CCI(PD) <= Value; #neutral trend
def Bullish = GreenPrice;
def Neutral = NeutralPrice;
def Bearish = RedPrice;
def range_1 = high - low;
def stop;
def entry;
def target;
def tococentry;
if Bullish then {
stop = low - range_1 * 1;
entry = low + range_1 * 2;
target = low + range_1 * 3.5;
tococentry = 1;
} else if Bearish then {
stop = high + range_1 * 1;
entry = high - range_1 * 2.5;
target = high - range_1 * 3.5;
tococentry = 1;
} else if Neutral then {
stop = na;
entry = na;
target = na;
tococentry = 0;
#if the bullish or bearish trend is maintained, the price crosses to the defined lines (entry and target) are controlled
} else if Bullish and !tococentry[1] then {
stop = stop[1];
entry = entry[1];
target = target[1];
tococentry = high > entry[1];
} else if Bearish and !tococentry[1] then {
stop = stop[1];
entry = entry[1];
target = target[1];
tococentry = low < entry[1];
} else {
stop = stop[1];
entry = entry[1];
target = target[1];
tococentry = tococentry[1];
# tococentry = 0;
}
DefineGlobalColor("Bullish", Color.DARK_GREEN);
DefineGlobalColor("Neutral", Color.WHITE);
DefineGlobalColor("Bearish", Color.MAGENTA);
AssignPriceColor(if GreenPrice then GlobalColor("Bullish") else if RedPrice then GlobalColor("Bearish") else GlobalColor("Neutral"));
#----------------------
def x = !isnan(close);
plot ze = if x then entry else na;
ze.setdefaultcolor(color.green);
plot zs = if x then stop else na;
zs.setdefaultcolor(color.red);
plot zt = if x then target else na;
zt.setdefaultcolor(color.yellow);
#