Code to assign value

Experts

can anyone help me with getting this error fixed?

A = 1
B = True

if A==1 and B== True
then XXX and B = False else double.nan

TOS shows an error when I do this

Still brushing my basics
 
Solution
Here is an example code for your observation:

Code:
declare lower;
def data = close > open;
def data2 = close < open;
plot item = if data == 1 and data is true and data2 is false then 2 else double.nan;
Here is an example code for your observation:

Code:
declare lower;
def data = close > open;
def data2 = close < open;
plot item = if data == 1 and data is true and data2 is false then 2 else double.nan;
 
Solution
Here is an example code for your observation:

Code:
declare lower;
def data = close > open;
def data2 = close < open;
plot item = if data == 1 and data is true and data2 is false then 2 else double.nan;
Thanks @BenTen

still struggling and appreciate if you can fix this?

Concept: The indicator should trigger a signal if

Supertrend1+Supertrend2+RSI (based on overbought and over sold).

I am able to achieve this but it giving me signal every time RSI goes in and out of the OB/OS levels. so I need only 1 trigger during the super trend run before it changes its course.

would be really helpful


Code:
# Variables for trade entry signals
Input TradeEntryStartTimeEST = 945;
Input TradeEntryEndTimeEST = 1600;
def TradeEntryRange = if SecondsTillTime(TradeEntryStartTimeEST) <= 0 and
SecondsTillTime(TradeEntryEndTimeEST) >= 0 then 1 else 0;

# EMA Difference - to know the different between EMA and candle close
input EMALength = 10;
def EMADiff = AbsValue(ExpAverage(close, EMALength)) - close;

# Super Trend 1
Input st1AltMult = 2;
input st1_Length = 10;
def ATR1 = ATR(ST1_Length, AverageType.HULL);
def UP_Band_Basic = HL2 + (ST1AltMult * ATR1);
def LW_Band_Basic = HL2 + (-ST1AltMult * ATR1);
def UP_Band = if ((UP_Band_Basic < UP_Band[1]) or (close[1] > UP_Band[1])) then UP_Band_Basic else UP_Band[1];
def LW_Band = if ((LW_Band_Basic > LW_Band[1]) or (close[1] < LW_Band[1])) then LW_Band_Basic else LW_Band[1];

def ST = if ((ST[1] == UP_Band[1]) and (close < UP_Band)) then UP_Band
else if ((ST[1] == UP_Band[1]) and (close > UP_Band)) then LW_Band
else if ((ST[1] == LW_Band[1]) and (close > LW_Band)) then LW_Band
else if ((ST[1] == LW_Band) and (close < LW_Band)) then UP_Band
else LW_Band;

def Long = if close > ST then ST else Double.NaN;
def Short = if close < ST then ST else Double.NaN;

def LTrigger = isNaN(Long[1]) and !isNaN(Long);
def STrigger = isNaN(Short[1]) and !isNaN(Short);



# Super Trend 2
Input st2_AltMult = 4;
input st2_Length = 10;
def ATR2 = ATR(ST2_Length, AverageType.HULL);
def UP_Band_Basic1 = HL2 + (ST2_AltMult * ATR2);
def LW_Band_Basic1 = HL2 + (-ST2_AltMult * ATR2);
def UP_Band1 = if ((UP_Band_Basic1 < UP_Band1[1]) or (close[1] > UP_Band1[1])) then UP_Band_Basic1 else UP_Band1[1];
def LW_Band1 = if ((LW_Band_Basic1 > LW_Band1[1]) or (close[1] < LW_Band1[1])) then LW_Band_Basic1 else LW_Band1[1];

def ST1 = if ((ST1[1] == UP_Band1[1]) and (close < UP_Band1)) then UP_Band1
else if ((ST1[1] == UP_Band1[1]) and (close > UP_Band1)) then LW_Band1
else if ((ST1[1] == LW_Band1[1]) and (close > LW_Band1)) then LW_Band1
else if ((ST1[1] == LW_Band1) and (close < LW_Band1)) then UP_Band1
else LW_Band1;

def Long1 = if close > ST1 then ST1 else Double.NaN;
def Short1 = if close < ST1 then ST1 else Double.NaN;

def LTrigger1 = isNaN(Long1[1]) and !isNaN(Long1);
def STrigger1 = isNaN(Short1[1]) and !isNaN(Short1);


# RSI
input RSIOverbought= 60;
input RSIOversold = 40;
input RSILength = 14;
def NetChange = MovingAverage(AverageType.WILDERS, close - close[1], rsilength);
def TotChange = MovingAverage(AverageType.WILDERS, AbsValue(close - close[1]), rsilength);
def ChgRatio = if TotChange != 0 then NetChange / TotChange else 0;
def RSI = 50 * (ChgRatio + 1);
def longRSI = RSI > rsioverbought;
def shortRSI = RSI < rsioversold;

def bullcrossovercondST =  TradeEntryRange and long and long1 and longRSI and EMADiff < 10;
def bearcrossovercondST =  TradeEntryRange and  Short and short1 and shortRSI and EMADiff < 10;

plot Bullish =
if (long1 and ltrigger) or  (long and ltrigger1) then
if longrsI then bullcrossovercondST else double.nan
else if (!bullcrossovercondST[1] and bullcrossovercondST) then bullcrossovercondST else double.nan ;
Bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Bullish.SetDefaultColor(GetColor(8));
Bullish.SetLineWeight(2);

plot Bearish =
if (short1 and strigger) or  (short and strigger1) then
if shortrsI then bearcrossovercondST else double.nan
else if (!bearcrossovercondST[1] and bearcrossovercondST) then bearcrossovercondST else double.nan ;
Bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Bearish.SetDefaultColor(GetColor(8));
Bearish.SetLineWeight(2);


aUt1Dor.png
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
354 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