someone help me to correct conditional if else

Destructor

New member
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 :


tococentry = false;
#if {
if Bullish
then{
stop = low - range_1 ;

target = low + range_1
 
Last edited:
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/

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);
#

3AKLBiy.jpg
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

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);
#

3AKLBiy.jpg
@Svanoy
Thank you
 
Last edited:
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);

#
dzs2FJN.jpg

all , please don't post copies of questions in different threads. new posts are seen, and when someone has time and knowledge , they will look at it.
 
Last edited by a moderator:
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


When high > B in bullish case

The Bearish Case Low > B
 
Last edited:
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


When high > B in bullish case

The Bearish Case Low > B

Without any code to verify, this basic structure parses and may assist with your code

Ruby:
def bullish;
def bearish;
def A ;
def B;
def C ;
If bullish[1]{
bullish=high>b;
bearish=double.nan;
A=0;
B=1;
C=0;
}else if bearish[1]{
bullish=double.nan;
bearish=low>b;
A=0;
B=1;
C=0;
}else{
bullish=high>b;
bearish=double.nan;
A=double.nan;
B=double.nan;
C=double.nan;
}
addlabel(1, bullish+ " " + bearish);
 
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
EfVYuJt.png

I am not what you said above the link. It seems you want to know more than the question you asked that I responded to you.
 
I am not what you said above the link. It seems you want to know more than the question you asked that I responded to you.
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.
 
Last edited:
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.
Here is the code I have tried several times and I can not solve them I attach an example image and source
 
Last edited:
Here is the code I have tried several times and I can not solve them I attach an example image and source code
Code:
#

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);
#

U89CSDH.jpg


-------------------------------


this is another study that draws horizontal lines, until price crosses them
https://usethinkscript.com/threads/help-coding-joseph-stowell-3-bar-net-cup-cap.5746/#post-99787
 
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);
#

U89CSDH.jpg


-------------------------------


this is another study that draws horizontal lines, until price crosses them
https://usethinkscript.com/threads/help-coding-joseph-stowell-3-bar-net-cup-cap.5746/#post-99787
 
Last edited:
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...
[

#
[/CODE]
UGRvVBV.png

Someone managed to solve the error of this code, I am also looking for the same..
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
561 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

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.

What are the benefits of VIP Membership?
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.
Back
Top