After Candle Closes

The following thinkScript is executing at the "bid" price for the stock. Is there a way to change this so that the order sells based on the "ask," or is it possible to have the order trigger at the actual price of the stock? I included this script as a part of a conditional order. @halcyonguy was very helpful in helping create this thinkScript. Thank you very much for your time and your help.

Code:
input sell_percent_gain = -20.0;
input price1 = close;
input start = 0930;
def daystart = secondstillTime(start) == 0;
def dayopen = if daystart then open else dayopen[1];
def daydiff = round(price1 - dayopen,2);
def pergain = round(100*daydiff/dayopen,1);

input trigger_on_all_prices_below_stop = yes;
def sell1 = if (daystart or trigger_on_all_prices_below_stop) and pergain <= sell_percent_gain then 1 else
                  if pergain crosses below sell_percent_gain then 1 else 0;

plot z1 = sell1;
 
Last edited:
Solution
The input of 'price1 = close' is only defining what value to use in the calculation of 'daydiff'. The value of close is constantly changing in the duration of 1 bar. To get 'sell1' to only trigger after a bar closes you have to use 'pergain[1]' in its definition as the close of a bar is the only time the 'close' value becomes constant for that bar.
The following thinkScript is executing at the "bid" price for the stock. Is there a way to change this so that the order sells based on the "ask?" I included this script as a part of a conditional order. @halcyonguy was very helpful in helping create this thinkScript. Thank you very much for your time and your help.

Code:
input sell_percent_gain = -20.0;
input price1 = close;
input start = 0930;
def daystart = secondstillTime(start) == 0;
def dayopen = if daystart then open else dayopen[1];
def daydiff = round(price1 - dayopen,2);
def pergain = round(100*daydiff/dayopen,1);

input trigger_on_all_prices_below_stop = yes;
def sell1 = if (daystart or trigger_on_all_prices_below_stop) and pergain <= sell_percent_gain then 1 else
                  if pergain crosses below sell_percent_gain then 1 else 0;

plot z1 = sell1;

You haven't provided enough detail as to WHERE you are using your referenced script.
If you are asking if Bid / Ask can be referenced in a conditional order?
The answer is no.
The ToS platform does not make Ask or Bid price available for use in a Conditional Order.
Therefore, you cannot specify ASK in a conditional order script.

To read more about where bid / ask functions are available and what the appropriate syntax is:
https://usethinkscript.com/threads/...s-watchlists-and-scans-for-thinkorswim.10626/
 
Last edited:

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

You haven't provided enough detail as to WHERE you are using your referenced script.
If you are asking if Bid / Ask can be referenced in a conditional order?
The answer is no.
The ToS platform does not make Ask or Bid price available in the Condition Wizard.
Therefore, you cannot specify ASK in a conditional order script.
The conditional order will execute when the condition is true regardless of bid / ask prices.

To read more about where bid / ask functions are available and what the appropriate syntax is:
https://usethinkscript.com/threads/...s-watchlists-and-scans-for-thinkorswim.10626/
Thank you very much for your response @MerryDay. I am using the referenced script on a 5-minute chart for a conditional order. In regards to the link you are providing, are you saying that we can specify bid/ask to display on a chart, but not when we are trying to have an order trigger through a conditional order? Thank you again for your help @MerryDay.
 
When I apply the following script to a 5-minute chart, the script will trigger during the middle of the formation of a candle. For example, if there is still 2 minutes and 30 seconds remaining until the candle closes, the script will still trigger even though I have written in the script "input price1 = close." I thought that by defining the input as "close" then the script would trigger after the candle closes. Is there anyway to adjust the script below so that the script only triggers after the candle closes? Thank you very much @halcyonguy for your help with this script.

Code:
input sell_percent_gain = 0.0;
input price1 = close;
input start = 0930;
def daystart = secondstillTime(start) == 0;
def dayopen = if daystart then open else dayopen[1];
def daydiff = round(price1 - dayopen,2);
def pergain = round(100*daydiff/dayopen,1);

input trigger_on_all_prices_below_stop = yes;
def sell1 = if (daystart or trigger_on_all_prices_below_stop) and pergain <= sell_percent_gain then 1 else if pergain crosses below sell_percent_gain then 1 else 0;

plot z1 = sell1;
 
The input of 'price1 = close' is only defining what value to use in the calculation of 'daydiff'. The value of close is constantly changing in the duration of 1 bar. To get 'sell1' to only trigger after a bar closes you have to use 'pergain[1]' in its definition as the close of a bar is the only time the 'close' value becomes constant for that bar.
 
Solution
The input of 'price1 = close' is only defining what value to use in the calculation of 'daydiff'. The value of close is constantly changing in the duration of 1 bar. To get 'sell1' to only trigger after a bar closes you have to use 'pergain[1]' in its definition as the close of a bar is the only time the 'close' value becomes constant for that bar.
Hi @Svanoy thank you very much for your help. May you please tell me, did I make the correct change in the code below?

Code:
input sell_percent_gain = 0.0;
input price1 = close;
input start = 0930;
def daystart = secondstillTime(start) == 0;
def dayopen = if daystart then open else dayopen[1];
def daydiff = round(price1 - dayopen,2);
def pergain = round(100*daydiff/dayopen,1);

input trigger_on_all_prices_below_stop = yes;
def sell1 = if (daystart or trigger_on_all_prices_below_stop) and pergain[1] <= sell_percent_gain then 1 else if pergain[1] crosses below sell_percent_gain then 1 else 0;

plot z1 = sell1;
 
Hi @Svanoy thank you very much for your help. May you please tell me, did I make the correct change in the code below?

Code:
input sell_percent_gain = 0.0;
input price1 = close;
input start = 0930;
def daystart = secondstillTime(start) == 0;
def dayopen = if daystart then open else dayopen[1];
def daydiff = round(price1 - dayopen,2);
def pergain = round(100*daydiff/dayopen,1);

input trigger_on_all_prices_below_stop = yes;
def sell1 = if (daystart or trigger_on_all_prices_below_stop) and pergain[1] <= sell_percent_gain then 1 else if pergain[1] crosses below sell_percent_gain then 1 else 0;

plot z1 = sell1;
Thank you again @Svanoy, I just tested this and it appears to work well.
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
473 Online
Create Post

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