Help Needed - ORB + 100 EMA <> 200 EMA + SPY 100 EMA <> SPY 200 EMA

viswa

New member
Hi All,

I am trying to create a custom watchlist column with below conditions

1) Close is > 5 Minute ORB High + Close is above 21 EMA + 100 EMA > 200 EMA + SPY 100 EMA > SPY 200 EMA == If all conditions are met then display "Calls"
2) Close is < 5 Minute ORB Low + Close is under 21 EMA + 100 EMA < 200 EMA + SPY 100 EMA < SPY 200 EMA == If all conditions are met then display "Puts"

Below is the script. All the conditions work except SPY 100 EMA > SPY 200 EMA and SPY 100 EMA < SPY 200 EMA. Could you please help me understand what I am missing here. Thanks in advance and let me know if you have any questions.



# 5M ORB + Stock Trend + SPY Trend

def OpenRangeMinutes = 5;
def MarketOpenTime = 0930;
input ShowTodayOnly = yes;

def Today = if GetDay() == GetLastDay() then 1 else 0;
def FirstMinute = if SecondsFromTime(MarketOpenTime) < 60 then 1 else 0;
def OpenRangeTime = if SecondsFromTime(MarketOpenTime) < 60 * OpenRangeMinutes then 1 else 0;

def ORHigh = if FirstMinute then high else if OpenRangeTime and high > ORHigh[1] then high else ORHigh[1];
def ORLow = if FirstMinute then low else if OpenRangeTime and low < ORLow[1] then low else ORLow[1];

def OpenRangeHigh = if ShowTodayOnly and !Today then Double.NaN else if !OpenRangeTime then ORHigh else Double.NaN;
def OpenRangeLow = if ShowTodayOnly and !Today then Double.NaN else if !OpenRangeTime then ORLow else Double.NaN;

def dailyRange = high(period = "day" )[1] - low(period = "day" )[1];
def range = Average(dailyRange, 10);

plot status = if close > OpenRangeHigh then 1 else if close < OpenRangeLow then 0 else -1; status.AssignValueColor(if status == 1 then Color.Dark_Green else if status == 0 then Color.Dark_Red else Color.Dark_Orange);
AssignBackgroundCOlor(if status == 1 then Color.Dark_Green else if status == 0 then Color.Dark_Red else Color.Dark_Orange);

#EMA Stack of stock
def EMA21 = MovAvgExponential("length" = 21)."AvgExp";
def EMA100 = MovAvgExponential("length" = 100)."AvgExp";
def EMA200 = MovAvgExponential("length" = 200)."AvgExp";
def EMABullStack = EMA100 >= EMA200;
def EMABearStack = EMA100 < EMA200;

#EMA Stack of SPY

input marketIndex = "SPY";
def SPYEMA100 = ExpAverage(close(marketIndex), 100);
def SPYEMA200 = ExpAverage(close(marketIndex), 200);
def SPYEMABullStack = SPYEMA100 >= SPYEMA200;
def SPYEMABearStack = SPYEMA100 < SPYEMA200;

AddLabel(1, if close > ORhigh and close > EMA21 and EMA100 > EMA200 and SPYEMABullStack
then "Calls"
else if ORlow > close and EMA21 > close and EMA200 > EMA100 and SPYEMABearStack
then "Puts"
else "Listen to Songs",
if close > ORhigh and close > EMA21 and EMA100 > EMA200 and SPYEMABullStack
then color.BLACK
else if ORlow > close and EMA21 > close and EMA200 > EMA100 and SPYEMABearStack
then color.BLACK
else color.BLACK);
 
Solution
Hi All,

I am trying to create a custom watchlist column with below conditions

1) Close is > 5 Minute ORB High + Close is above 21 EMA + 100 EMA > 200 EMA + SPY 100 EMA > SPY 200 EMA == If all conditions are met then display "Calls"
2) Close is < 5 Minute ORB Low + Close is under 21 EMA + 100 EMA < 200 EMA + SPY 100 EMA < SPY 200 EMA == If all conditions are met then display "Puts"

Below is the script. All the conditions work except SPY 100 EMA > SPY 200 EMA and SPY 100 EMA < SPY 200 EMA. Could you please help me understand what I am missing here. Thanks in advance and let me know if you have any questions.



# 5M ORB + Stock Trend + SPY Trend

def OpenRangeMinutes = 5;
def MarketOpenTime = 0930;
input ShowTodayOnly = yes;

def...
Hi All,

I am trying to create a custom watchlist column with below conditions

1) Close is > 5 Minute ORB High + Close is above 21 EMA + 100 EMA > 200 EMA + SPY 100 EMA > SPY 200 EMA == If all conditions are met then display "Calls"
2) Close is < 5 Minute ORB Low + Close is under 21 EMA + 100 EMA < 200 EMA + SPY 100 EMA < SPY 200 EMA == If all conditions are met then display "Puts"

Below is the script. All the conditions work except SPY 100 EMA > SPY 200 EMA and SPY 100 EMA < SPY 200 EMA. Could you please help me understand what I am missing here. Thanks in advance and let me know if you have any questions.



# 5M ORB + Stock Trend + SPY Trend

def OpenRangeMinutes = 5;
def MarketOpenTime = 0930;
input ShowTodayOnly = yes;

def Today = if GetDay() == GetLastDay() then 1 else 0;
def FirstMinute = if SecondsFromTime(MarketOpenTime) < 60 then 1 else 0;
def OpenRangeTime = if SecondsFromTime(MarketOpenTime) < 60 * OpenRangeMinutes then 1 else 0;

def ORHigh = if FirstMinute then high else if OpenRangeTime and high > ORHigh[1] then high else ORHigh[1];
def ORLow = if FirstMinute then low else if OpenRangeTime and low < ORLow[1] then low else ORLow[1];

def OpenRangeHigh = if ShowTodayOnly and !Today then Double.NaN else if !OpenRangeTime then ORHigh else Double.NaN;
def OpenRangeLow = if ShowTodayOnly and !Today then Double.NaN else if !OpenRangeTime then ORLow else Double.NaN;

def dailyRange = high(period = "day" )[1] - low(period = "day" )[1];
def range = Average(dailyRange, 10);

plot status = if close > OpenRangeHigh then 1 else if close < OpenRangeLow then 0 else -1; status.AssignValueColor(if status == 1 then Color.Dark_Green else if status == 0 then Color.Dark_Red else Color.Dark_Orange);
AssignBackgroundCOlor(if status == 1 then Color.Dark_Green else if status == 0 then Color.Dark_Red else Color.Dark_Orange);

#EMA Stack of stock
def EMA21 = MovAvgExponential("length" = 21)."AvgExp";
def EMA100 = MovAvgExponential("length" = 100)."AvgExp";
def EMA200 = MovAvgExponential("length" = 200)."AvgExp";
def EMABullStack = EMA100 >= EMA200;
def EMABearStack = EMA100 < EMA200;

#EMA Stack of SPY

input marketIndex = "SPY";
def SPYEMA100 = ExpAverage(close(marketIndex), 100);
def SPYEMA200 = ExpAverage(close(marketIndex), 200);
def SPYEMABullStack = SPYEMA100 >= SPYEMA200;
def SPYEMABearStack = SPYEMA100 < SPYEMA200;

AddLabel(1, if close > ORhigh and close > EMA21 and EMA100 > EMA200 and SPYEMABullStack
then "Calls"
else if ORlow > close and EMA21 > close and EMA200 > EMA100 and SPYEMABearStack
then "Puts"
else "Listen to Songs",
if close > ORhigh and close > EMA21 and EMA100 > EMA200 and SPYEMABullStack
then color.BLACK
else if ORlow > close and EMA21 > close and EMA200 > EMA100 and SPYEMABearStack
then color.BLACK
else color.BLACK);


a watchlist study wants only 1 output function. your study has 2, plot and addlabel. that may be part of the problem.
i changed the plot to a def, and disabled the plot parameter.
changed this,
plot status = if close > OpenRangeHigh then 1 else if close < OpenRangeLow then 0 else -1;


after altering this, i put this code on a chart and added bubbles. (at the end of the study).
the bubbles displayed values for spyema100 and 200.


i copied the code and put it in a watchlist. i set the time to 5 minutes. it seems to work.

for testing, i disabled your addlabel and added this one, to show just the variables in question.
it disaplys values for the spyema100 and spyema200... so i think it works
addlabel(1, SPYEMABearStack + " " + SPYEMA100 + " " + SPYEMA200 , color.cyan);
change it to 1 and the main addlabel to 0 to test it.


your addlabel has a very long formula for the color, but all choices are black?
i disabled that part and added
, color.cyan);

the color used in addlabel, in a column, is the font color. black is hard to read on dark colors. so i changed it cyan.

watchlist column link
zspy200
http://tos.mx/lfQ5PpN

watchlist column study
Ruby:
# spy200ema0

# 5M ORB + Stock Trend + SPY Trend

def OpenRangeMinutes = 5;
def MarketOpenTime = 0930;
input ShowTodayOnly = yes;

def Today = if GetDay() == GetLastDay() then 1 else 0;
def FirstMinute = if SecondsFromTime(MarketOpenTime) < 60 then 1 else 0;
def OpenRangeTime = if SecondsFromTime(MarketOpenTime) < 60 * OpenRangeMinutes then 1 else 0;

def ORHigh = if FirstMinute then high else if OpenRangeTime and high > ORHigh[1] then high else ORHigh[1];
def ORLow = if FirstMinute then low else if OpenRangeTime and low < ORLow[1] then low else ORLow[1];

def OpenRangeHigh = if ShowTodayOnly and !Today then Double.NaN else if !OpenRangeTime then ORHigh else Double.NaN;
def OpenRangeLow = if ShowTodayOnly and !Today then Double.NaN else if !OpenRangeTime then ORLow else Double.NaN;

def dailyRange = high(period = "day" )[1] - low(period = "day" )[1];
def range = Average(dailyRange, 10);

#plot status = if close > OpenRangeHigh then 1 else if close < OpenRangeLow then 0 else -1;
def status = if close > OpenRangeHigh then 1 else if close < OpenRangeLow then 0 else -1;
#status.AssignValueColor(if status == 1 then Color.Dark_Green else if status == 0 then Color.Dark_Red else Color.Dark_Orange);


AssignBackgroundCOlor(if status == 1 then Color.Dark_Green else if status == 0 then Color.Dark_Red else Color.Dark_Orange);

#EMA Stack of stock
def EMA21 = MovAvgExponential("length" = 21)."AvgExp";
def EMA100 = MovAvgExponential("length" = 100)."AvgExp";
def EMA200 = MovAvgExponential("length" = 200)."AvgExp";
def EMABullStack = EMA100 >= EMA200;
def EMABearStack = EMA100 < EMA200;

#EMA Stack of SPY

input marketIndex = "SPY";
def SPYEMA100 = ExpAverage(close(marketIndex), 100);
def SPYEMA200 = ExpAverage(close(marketIndex), 200);
def SPYEMABullStack = SPYEMA100 >= SPYEMA200;
def SPYEMABearStack = SPYEMA100 < SPYEMA200;


addlabel(0, SPYEMABearStack + " " + SPYEMA100 + " " + SPYEMA200 , color.cyan);

AddLabel(1, if close > ORhigh and close > EMA21 and EMA100 > EMA200 and SPYEMABullStack
then "Calls"
else if ORlow > close and EMA21 > close and EMA200 > EMA100 and SPYEMABearStack
then "Puts"
#else "Listen to Songs",
else "music",
 color.cyan);

#if close > ORhigh and close > EMA21 and EMA100 > EMA200 and SPYEMABullStack
#then color.BLACK
#else if ORlow > close and EMA21 > close and EMA200 > EMA100 and SPYEMABearStack
#then color.BLACK
#else color.BLACK);

#-------------------------------

# test code for use on a chart
#def bn = barnumber();
#input test1 = no;
#addchartbubble(test1, low, bn +"\n" + SPYEMA100 + "\n" + SPYEMA200, (if SPYEMABearStack then color.yellow else color.gray), no);
#
 
Last edited:
Solution

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
124 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