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 :
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.
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);
#
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);
#
Could you help me? It's the same idea with if and else.. How would it be for me to draw the first values of the first bullish or bearish bar during the entire trend? as well as in the picture. I can't get it to work.. to see if the input stops drawing when the high and low of a bar. the target would only have to draw when the input rotates by a bar.
Code:
#
def na = double.nan;
input lenghtCCI = 35;
def tgt = 37;
def a_bear = CCI(lenghtCCI) < -tgt; #downtrend
def b_bull = CCI(lenghtCCI) > tgt; #uptrend
def ab_netro = -tgt <= CCI(lenghtCCI) and CCI(lenghtCCI) <= tgt; #neutral trend
#def state = if a > b then -1 else if a == b then 0 else 1;
def range_1 = high - low;
def stop;
def Entry;
def target;
def tococentry;
if b_bull
then {
stop = low - range_1 * 0.5;
Entry = low + range_1 * 1.5;
target = low + range_1 * 3;
tococentry = 1;
} else if a_Bear
then {
stop = high + range_1 * 0.5;
Entry = high - range_1 * 1.5;
target = high - range_1 * 3;
tococentry = 1;
} else if ab_netro then {
stop = na;
entry = na;
target = na;
tococentry = 0;
} else if b_Bull and !tococentry[1]
then {
stop = stop[1];
Entry = Entry[1];
target = target[1];
tococentry = high > Entry[1];
} else if a_Bear 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;
}
AssignPriceColor(if a_bear then Color.red else if b_bull then Color.blue else Color.GRAY);
#----------------------
def x = !IsNaN(close);
plot zs = if x then stop else Double.NaN;
zs.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zs.SetDefaultColor(Color.RED);
plot ze= if x then Entry else na;
ze.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ze.setdefaultcolor(color.cyan);
plot zt = if x then target else na;
zt.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zt.setdefaultcolor(color.yellow);
#
Help in a condition to draw taking into account the values of A B C Q are conditioned by if and else To draw the value of B until a bar touches it and stops drawing B and starts drawing C from there It can be done with the plot function taking into account the conditions defined when it is bullish and bearish.
A ;
B.;
C ;
If bullish
A
B.
C
else bearish
A
B.
C
Help in a condition to draw taking into account the values of A B C Q are conditioned by if and else To draw the value of B until a bar touches it and stops drawing B and starts drawing C from there It can be done with the plot function taking into account the conditions defined when it is bullish and bearish.
A ;
B.;
C ;
If bullish
A
B.
C
else bearish
A
B.
C
Creo que no me entendiste.. aqui esta el codigo: https://usethinkscript.com/threads/someone-help-me-to-correct-conditional-if-else.12702/post-108286
I attach an image to explain what I want to do, everything that is crossed out, I do not want sew to draw, it would be when a bar breaks the cyan line, it stops drawing, there it just begins to draw the yellow line.
the same bullish and bearish format
for example... to draw the line I put: plot ez= if input < high then na else target ; it only stops me from drawing the line downwards... it works well for me but only for the downwards... I would like in that part part how I can condition it so that it works... downwards and upwards
for example... to draw the line I put: plot ez= if input < high then na else target ; it only stops me from drawing the line downwards... it works well for me but only for the downwards... I would like in that part part how I can condition it so that it works... downwards and upwards
As I answered a general question not realizing you were wanting help with one halcyonguy's scripts, it is best to have him answer this. Otherwise, I would need the entire code, even the portion you are trying and having problems with to be able to assist you. I do not know where your code for 'plot ez= if input < high then na else target ; ' is in the link above and what 'input' refers to, for example.
As I answered a general question not realizing you were wanting help with one halcyonguy's scripts, it is best to have him answer this. Otherwise, I would need the entire code, even the portion you are trying and having problems with to be able to assist you. I do not know where 'plot ez= if input < high then na else target ; ' and what 'input' refers to.
post 11 doesn't have any code .. ?
can you try posting it again.
-------------------------------------------------
you didn't list any rules for determining when to draw lines, so i made up 3 price levels. load a SPY chart and set it to daily.
maybe this will help you , or help to come up with different questions.
Code:
# horz_lines_3levels_0
def bn = barnumber();
def na = double.nan;
# made for a daily SPY chart
input target1 = 400;
input target2 = 420;
input target3 = 440;
def c = close[1];
def line = if bn == 1 then na
else if c[1] < target1 and c > target1 then target2
else if c[1] < target2 and c > target2 then target3
else if c[1] > target3 and c < target3 then target2
else if c[1] > target2 and c < target2 then target1
else line[1];
plot z = line;
z.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z.SetDefaultColor(Color.yellow);
#
post 11 doesn't have any code .. ?
can you try posting it again.
-------------------------------------------------
you didn't list any rules for determining when to draw lines, so i made up 3 price levels. load a SPY chart and set it to daily.
maybe this will help you , or help to come up with different questions.
Code:
# horz_lines_3levels_0
def bn = barnumber();
def na = double.nan;
# made for a daily SPY chart
input target1 = 400;
input target2 = 420;
input target3 = 440;
def c = close[1];
def line = if bn == 1 then na
else if c[1] < target1 and c > target1 then target2
else if c[1] < target2 and c > target2 then target3
else if c[1] > target3 and c < target3 then target2
else if c[1] > target2 and c < target2 then target1
else line[1];
plot z = line;
z.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z.SetDefaultColor(Color.yellow);
#
Hi, I'm posting the code here.
This rule would be if the trend is bullish and a current bar is higher than the entry line. The entry line is not drawn during the entire trend.
just there the target begins to draw... during the whole trend when the trend is bearish the same rule...
[
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.
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.