If I want to say the following: if A=true AND B=true then X else Y. How do I handle double conditionality of if-then statement in thinkscript?
If (A and B,X,Y);
def x=true;
If x then {
code line 1;
code line 2;
code line 3;
};
Var:
vHi(0),
vLo(0),
MyUpFlag(False),
MyDnFlag(False),
thePlotter(0);
If C > vHi and MyUpFlag = False then
Begin
MyUpFlag = True;
MyDnFlag = False;
thePlotter = Green;
End
Else If C < vLo and MyDnFlag = False then
Begin
MyUpFlag = False;
MyDnFlag = True;
thePlotter = Red;
End;
# ConsecutiveBarCount
# Comment out unnecessary portions to preserve TOS memory and enhance speed
declare lower;
declare once_per_bar;
def nan = Double.NaN;
#### What is the Up Flag and What is the Down Flag??? Use whatever you like... RSI MACD whichever
#[B](You can give me an example case to plugin here!) I don't care what but I can't think of anything HigherHigh Lower Low??)[/B]
#Var:
# vHi(0),
# vLo(0),
# MyUpFlag(False),
# MyDnFlag(False),
# thePlotter(0);
def zeroLine = 0;
plot pZeroLine = zeroLine;
pZeroLine.SetDefaultColor(Color.WHITE);
def barUpCount = CompoundValue(1, if MyDnFlag && !MyUpFlag then barUpCount[1] + 1 else 0, 0);
def AscendedProfile = CompoundValue(1, if barUpCount && !MyDnFlag[1] then 1 else if MyUpFlag or MyDnFlag then 0 else if !MyDnFlag && !MyUpFlag && AscendedProfile[1]>0 then AscendedProfile[1]+1 else 0,0);
plot pBarUpCount = if AscendedProfile > 0 within 1 bar && !MyUpFlag then AscendedProfile else 0;
pBarUpCount.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
pBarUpCount.AssignValueColor(Color.GREEN);
def barDownCount = CompoundValue(1, if !MyDnFlag && MyUpFlag then barUpCount[1] + 1 else 0, 0);
def DescendedProfile = CompoundValue(1, if barDownCount && !MyUpFlag[1] then 1 else if MyUpFlag or MyDnFlag then 0 else if !MyDnFlag && !MyUpFlag && AscendedProfile[1]>0 then AscendedProfile[1]+1 else 0,0);
plot pBarDownCount = if AscendedProfile > 0 within 1 bar && !MyDnFlag then DescendedProfile else 0;
pBarUpCount.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
pBarUpCount.AssignValueColor(Color.Red); [CODE]
I could also do a lower with the [Concat]command and those lines of codes stay open and keep counting until a condition is met...I come from TradeStation land. The high and low is basically a channel I paint.
plot Neutral = if (Score >= 4 and Score <= 6) then Score else !Neutral;
plot WeakBull = if (Score[0] > 7 and Score[0] < 11) then Score else !WeakBull;
plot StrongBull = if (Score[0] >= 11) then Score else !StrongBull;
plot WeakBear = if (Score[0] <= 3 and Score[0] >= -2) then Score else !WeakBear;
plot StrongBear = if (Score[0] < -2) then Score else !StrongBear;
Neutral.SetPaintingStrategy(PaintingStrategy.Values_above);
Neutral.SetDefaultColor(Color.Gray);
Neutral.SetLineWeight(5);
WeakBull.SetPaintingStrategy(PaintingStrategy.Values_above);
WeakBull.SetDefaultColor(Color.Plum);
WeakBull.SetLineWeight(5);
StrongBull.SetPaintingStrategy(PaintingStrategy.Values_above);
StrongBull.SetDefaultColor(Color.Magenta);
StrongBull.SetLineWeight(5);
WeakBear.SetPaintingStrategy(PaintingStrategy.Values_above);
WeakBear.SetDefaultColor(Color.Dark_Red);
WeakBear.SetLineWeight(5);
StrongBear.SetPaintingStrategy(PaintingStrategy.Values_above);
StrongBear.SetDefaultColor(Color.Light_Orange);
StrongBear.SetLineWeight(5);
double.nan
is what you're looking for.I thinkdouble.nan
is what you're looking for.
def XR;
def highdiff;
def lowdiff;
if BarNumber() == 1
{XR = hl2;
highdiff = 0;
lowdiff = 0;
}
else
{highdiff = AbsValue(high - XR[1]);
lowdiff = AbsValue(low - XR[1]);
if lowdiff < highdiff
{XR = low;}
else
{XR = high;}
}
plot XRI = XR;
declare lower;
def XR;
def highdiff;
def lowdiff;
if BarNumber() == 1
{XR = hl2;
highdiff = 0;
lowdiff = 0;
}
else
{highdiff = AbsValue(high - XR[1]);
lowdiff = AbsValue(low - XR[1]);
if lowdiff < highdiff
{XR = low;}
else
{XR = high;}
}
plot XRI = lowdiff < highdiff;
@MoneyMagnet Your condition for barnumber() == 1 is never satisfied except for the beginning. Add addlabel(yes, barnumber()) to your script and you'll see what barnumber() is returning.
def XR = CompoundValue(1, if AbsValue(low - XR[1]) > AbsValue(high - XR[1]) then low else high, high);
plot ZIGGY = XR;
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
D | Custom script not executing intraday options trade | Questions | 2 | |
J | 9/28 EMA pullback entry strategy script | Questions | 2 | |
T | Script that finds a study's last high or low? | Questions | 1 | |
K | Run script based on yes no input | Questions | 1 | |
MTF ATR Script | Questions | 1 |
Start a new thread and receive assistance from our community.
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.
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.