Entry trigger: close crosses above x price

zdantzer

New member
Hi everyone, first time usethinkscript forum poster here. I've been learning paper trading for options using thinkorswim for a little while, and I'm trying to figure out how to accurately trigger a position entry. The thinkorswim software seems a bit buggy, but it's more probable that I simply don't quite understand it in complete depth yet. I've been getting entry triggers that don't conform to the conditions I want. Some seem to trigger randomly. Basically, I want the order to trigger when the stock price either crosses above (for calls) or below (for puts) the threshold of the previous trading day's high or low stock price, but not if it gaps past the previous day's high/low. I only want the entry to trigger if the direction the stock is going is in a favorable direction for the option trade. As you can see from the screenshots I took in thinkorswim, the configuration I have is set up to trigger when the close crosses above a price threshold on the one minute candle. I've previously had the price high/low rather the close trigger it, but I've been getting behavior that I don't expect or understand. Sometimes it seems to trigger correctly, and other times it doesn't. I can't figure out why, either. For example, take the INTC trade that triggered today. Even though the price of INTC opened above 30.67, and the 1m candle was actually red with a close lower than the high, the order triggered after the first minute. I do want quick entries on the 1m time scale, but I don't want it to trigger unless my conditions are met.

Questions: does the 1m trigger w the 2:59 candle from the previous trading day? Do i need to adjust the condition wizard in a certain way?

If anybody has en explanatoin or just a simple fix that is not obvious to me, I would greatly appreciate it!

Thanks
 

Attachments

  • Screen Shot 2024-05-03 at 11.56.28.png
    Screen Shot 2024-05-03 at 11.56.28.png
    128.7 KB · Views: 29
  • Screen Shot 2024-05-03 at 11.57.03.png
    Screen Shot 2024-05-03 at 11.57.03.png
    272.2 KB · Views: 27
  • Screen Shot 2024-05-03 at 11.57.21.png
    Screen Shot 2024-05-03 at 11.57.21.png
    224.2 KB · Views: 24
  • Screen Shot 2024-05-03 at 12.30.14.png
    Screen Shot 2024-05-03 at 12.30.14.png
    8.9 KB · Views: 27
Last edited by a moderator:
Hi everyone, first time usethinkscript forum poster here. I've been learning paper trading for options using thinkorswim for a little while, and I'm trying to figure out how to accurately trigger a position entry. The thinkorswim software seems a bit buggy, but it's more probable that I simply don't quite understand it in complete depth yet. I've been getting entry triggers that don't conform to the conditions I want. Some seem to trigger randomly. Basically, I want the order to trigger when the stock price either crosses above (for calls) or below (for puts) the threshold of the previous trading day's high or low stock price, but not if it gaps past the previous day's high/low. I only want the entry to trigger if the direction the stock is going is in a favorable direction for the option trade. As you can see from the screenshots I took in thinkorswim, the configuration I have is set up to trigger when the close crosses above a price threshold on the one minute candle. I've previously had the price high/low rather the close trigger it, but I've been getting behavior that I don't expect or understand. Sometimes it seems to trigger correctly, and other times it doesn't. I can't figure out why, either. For example, take the INTC trade that triggered today. Even though the price of INTC opened above 30.67, and the 1m candle was actually red with a close lower than the high, the order triggered after the first minute. I do want quick entries on the 1m time scale, but I don't want it to trigger unless my conditions are met.

Questions: does the 1m trigger w the 2:59 candle from the previous trading day? Do i need to adjust the condition wizard in a certain way?

If anybody has en explanatoin or just a simple fix that is not obvious to me, I would greatly appreciate it!

Thanks

it's not clear what you are doing and what time you have as a default.
usually , you use 2nd aggregation to determine levels from other times. sometimes using that data in formulas has strange results. sometimes only the first bar of lower time is evaluated when data from higher times is used in formulas.

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

this is an upper chart study, for experimenting

i made this to not use 2nd aggregation. it uses the chart time to determine highest and lowest from previous day.
this only works with normal trading hours and normal stocks.

it draws horizontal lines at the previous day highest and lowest.
it draws arrows when close crosses above a line

i left in commented out code from previous versions, as i was experimenting

Code:
#cross_prevday_hilo

#https://usethinkscript.com/threads/entry-trigger-close-crosses-above-x-price.18591/
#Entry trigger: close crosses above x price

# trigger when,
#..long (calls) - stock price crosses above the previous trading day's high
#..short (puts) - stock price crosses below the previous trading day's low
#..but not if it gaps past the previous day's high/low.

def na = double.nan;
def bn = barnumber();

def d = GetDay();
def newday = d != d[1];

# using agg , causes formulas to look at 1st bar of day
#def dayagg = AggregationPeriod.DAY;
#def dayopn = open(period = dayagg);
#def dayhi = high(period = dayagg);
#def daylo = low(period = dayagg);
#def daycls = close(period = dayagg);

def dayopn = if newday then open else dayopn[1];
def dayhi = if newday then high else max(high, dayhi[1]);
def daylo = if newday then low else min(low, daylo[1]);
def daycls = if newday[-1] then close else daycls[1];

def prevdayhi = if newday then dayhi[1] else prevdayhi[1];
def prevdaylo = if newday then daylo[1] else prevdaylo[1];
def prevdaycls = if newday then close[1] else prevdaycls[1];


#def xup = close crosses above dayhi[1];
#def xdwn = close crosses below daylo[1];
#def xup = close[1] < dayhi[1] and close[0] > dayhi[1];
#def xdwn = close[1] > daylo[1] and close[0] < daylo[1];
def xup = close[1] < prevdayhi and close[0] > prevdayhi;
def xdwn = close[1] > prevdaylo and close[0] < prevdaylo;


def dayopengapup = dayopn > dayhi[1];
def dayopengapdwn = dayopn < daylo[1];

def up = if dayopengapup then 0
 else if xup then 1
 else 0;

def dwn = if dayopengapdwn then 0
 else if xdwn then 1
 else 0;

plot zup = if up then low else na;
zup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zup.SetDefaultColor(Color.green);
zup.setlineweight(3);
zup.hidebubble();

plot zdwn = if dwn then high else na;
zdwn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
zdwn.SetDefaultColor(Color.red);
zdwn.setlineweight(3);
zdwn.hidebubble();

plot prevhi = if prevdayhi > 0 then prevdayhi else na;
plot prevlo = if prevdaylo > 0 then prevdaylo else na;
prevhi.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
prevlo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
prevhi.SetDefaultColor(Color.gray);
prevlo.SetDefaultColor(Color.gray);


#--------------------------
addchartbubble(0, low*0.99,
 xup + "\n" +
 dayopengapup  + "\n" +
 up + "\n" +
 " "  + "\n" +
 xdwn + "\n" +
 dayopengapdwn + "\n" +
 up + "\n"
, color.yellow, no);
#
 

Attachments

  • img1.JPG
    img1.JPG
    43.8 KB · Views: 38
Hi everyone, first time usethinkscript forum poster here. I've been learning paper trading for options using thinkorswim for a little while, and I'm trying to figure out how to accurately trigger a position entry. The thinkorswim software seems a bit buggy, but it's more probable that I simply don't quite understand it in complete depth yet. I've been getting entry triggers that don't conform to the conditions I want. Some seem to trigger randomly. Basically, I want the order to trigger when the stock price either crosses above (for calls) or below (for puts) the threshold of the previous trading day's high or low stock price, but not if it gaps past the previous day's high/low. I only want the entry to trigger if the direction the stock is going is in a favorable direction for the option trade. As you can see from the screenshots I took in thinkorswim, the configuration I have is set up to trigger when the close crosses above a price threshold on the one minute candle. I've previously had the price high/low rather the close trigger it, but I've been getting behavior that I don't expect or understand. Sometimes it seems to trigger correctly, and other times it doesn't. I can't figure out why, either. For example, take the INTC trade that triggered today. Even though the price of INTC opened above 30.67, and the 1m candle was actually red with a close lower than the high, the order triggered after the first minute. I do want quick entries on the 1m time scale, but I don't want it to trigger unless my conditions are met.

Questions: does the 1m trigger w the 2:59 candle from the previous trading day? Do i need to adjust the condition wizard in a certain way?

If anybody has en explanatoin or just a simple fix that is not obvious to me, I would greatly appreciate it!

Thanks
I used to trade the one minute chart as well. Remember that a candle changes direction every 6-10 bars (historic) regardless of the time frame used. I now use a 5 minute chart for day trading (see my AGAIG-BestTradingChartSetup) which gives a little more time freedom for placing and exiting trades. Since you are paper trading I would encourage you to try my charting setup, or one of the many setups you can find on this site. There is no Holy Grail available and you want to be sure you have more than one indication of a trend direction change taking place. My setup also includes a pdf explanation for the chart.
 
Last edited by a moderator:

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