Green to Red Strategy

beedee

New member
Hi,
I'm new to TOS. I'm trying to build scanner for Greed to Red Strategy, here is the script that I developed but it appears not working. Can you point where I'm gone wrong.

Rich (BB code):
# Green to Red - Short sell
# current day Open price should be > prevDayClose price 
# scanner shows when current 5min candle is 1% away (above) from VWAP, enter when new high is <= VWAP; so scanner should catch before it crosses VWAP
# exit when price near prevDayClose 
# Do not run during exnt.hours

def close_price = Fundamental(FundamentalType.CLOSE, period = getAggregationPeriod());

def prev_day_close = if SecondsTillTime(1555) == 0 and
                   SecondsFromTime(1555) == 0
                then close
                else prev_day_close[1];

def open_price = if SecondsFromTime(0930.0) >= 0 and SecondsTillTime(0935.0) > 0  then
                     Fundamental(FundamentalType.HIGH, period = getAggregationPeriod())
                 else double.nan;

plot GreenToRed =
if SecondsFromTime(0930.0) >= 0 and
    SecondsTillTime(1000.0) > 0 and
    open_price >= prev_day_close * 1.10 and
    close_price > VWAP and  close_price <= 1.01*VWAP then 1 else 0;
 
Solution
Hi,
I'm new to TOS. I'm trying to build scanner for Greed to Red Strategy, here is the script that I developed but it appears not working. Can you point where I'm gone wrong.

Rich (BB code):
# Green to Red - Short sell
# current day Open price should be > prevDayClose price
# scanner shows when current 5min candle is 1% away (above) from VWAP, enter when new high is <= VWAP; so scanner should catch before it crosses VWAP
# exit when price near prevDayClose
# Do not run during exnt.hours

def close_price = Fundamental(FundamentalType.CLOSE, period = getAggregationPeriod());

def prev_day_close = if SecondsTillTime(1555) == 0 and
                   SecondsFromTime(1555) == 0
                then close
                else prev_day_close[1];

def...
Hi,
I'm new to TOS. I'm trying to build scanner for Greed to Red Strategy, here is the script that I developed but it appears not working. Can you point where I'm gone wrong.

Rich (BB code):
# Green to Red - Short sell
# current day Open price should be > prevDayClose price
# scanner shows when current 5min candle is 1% away (above) from VWAP, enter when new high is <= VWAP; so scanner should catch before it crosses VWAP
# exit when price near prevDayClose
# Do not run during exnt.hours

def close_price = Fundamental(FundamentalType.CLOSE, period = getAggregationPeriod());

def prev_day_close = if SecondsTillTime(1555) == 0 and
                   SecondsFromTime(1555) == 0
                then close
                else prev_day_close[1];

def open_price = if SecondsFromTime(0930.0) >= 0 and SecondsTillTime(0935.0) > 0  then
                     Fundamental(FundamentalType.HIGH, period = getAggregationPeriod())
                 else double.nan;

plot GreenToRed =
if SecondsFromTime(0930.0) >= 0 and
    SecondsTillTime(1000.0) > 0 and
    open_price >= prev_day_close * 1.10 and
    close_price > VWAP and  close_price <= 1.01*VWAP then 1 else 0;

hello and welcome

don't need to use Fundamental()
don't need decimal points for time numbers. they should be integers. minute is the smallest usable time. although it says secondsfrom... it only returns seconds in multiples of 60.
def open_price = if SecondsFromTime(0930) >= 0 and SecondsTillTime(0935) > 0 then high else double.nan;


can't use 2nd aggregation in scanner code.

this is wrong
, period = getAggregationPeriod());

getAggregationPeriod() is used to read the agg of the chart, not set a 2nd agg.

to set a 2nd agg time, use something like this
def agg = AggregationPeriod.HOUR;
def data = close(period = agg);

https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/AggregationPeriod
https://tlc.thinkorswim.com/center/...ants/AggregationPeriod/AggregationPeriod-HOUR
 
Solution

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

Thank you halcyonguy, for your time, I modified but still doesn't return anything..

Code:
# Green to Red - Short sell
# current day Open price is > prevDayClose price
# scanner shows when current 5min candle is 1% away (above) from VWAP, we need to enter when new high is <= VWAP so scanner should before it crosses VWAP
# exit when price crosses prevDayClose
# Do not run during exnt.hours

#def close_price = Fundamental(FundamentalType.CLOSE, period = getAggregationPeriod());

def prev_day_close = if SecondsTillTime(1555) == 0 and
                   SecondsFromTime(1555) == 0
                then close
                else prev_day_close[1];

def open_price = if SecondsFromTime(0930) >= 0 and SecondsTillTime(0935) > 0  then
                     high
                 else double.nan;

plot GreenToRed =
if SecondsFromTime(0930) >= 0 and
    SecondsTillTime(1000) > 0 and            # Tried at different times of trade day 1100 , 1200
    open_price >= prev_day_close * 1.10 and
    close > VWAP and  close <= 1.01*VWAP then 1 else 0;
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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