Question: thinkScript entry price

SeattleTrader20

New member
Good morning! Happy labor day! Quick question, has anybody ran into this issue with thinkscript:

I'm trying to AddOrder 1% below the daily open but when I do:

AddOrder(OrderType.BUY_AUTO, (open * 0.99));

It shows that I enter at the open price instead of entering 1% below the open.

However, when I do almost the same thing in studies:

plot line = (open * 0.99); the line gets plotted at the correct price; 1% below the open.

Does anybody know what the issue is? How can I get in 1% below the open?
 
Solution
@rad14733 Thank you for your answer and quick response. Any many hours of research even prior to making this post, I ended up finding a work around this issue. I hope this helps somebody who comes to check on this thread in the future.

Here is the lines of code which allowed me to buy at 1% below the open:

def discount = 0.99;
def buy_price = open * 0.99;
def entry_condition = (open * discount) <= high && (open * discount) >= low;
AddOrder(OrderType.BUY_AUTO, entry_condition, buy_price[-1]);

Yes, the proper logic is to buy at the open of the next candle after the confirmation candle... You can streamline your logic to the following which requires less calculations and thus improves performance...

Ruby:
def discount =...
@SeattleTrader20 What you are seeing is an inherent flaw within the AddOrder() Strategy functionality of Thinkorswim... Orders only fill after the candle closes, not based on price action during the candles formation... This is a limitation for which there is no real remedy, unfortunately... The best we can do is to make adjustments to the conditions, entry price, and which candle that entry takes place on...
 
@rad14733 Thank you for your answer and quick response. Any many hours of research even prior to making this post, I ended up finding a work around this issue. I hope this helps somebody who comes to check on this thread in the future.

Here is the lines of code which allowed me to buy at 1% below the open:

def discount = 0.99;
def buy_price = open * 0.99;
def entry_condition = (open * discount) <= high && (open * discount) >= low;
AddOrder(OrderType.BUY_AUTO, entry_condition, buy_price[-1]);
 
@rad14733 Thank you for your answer and quick response. Any many hours of research even prior to making this post, I ended up finding a work around this issue. I hope this helps somebody who comes to check on this thread in the future.

Here is the lines of code which allowed me to buy at 1% below the open:

def discount = 0.99;
def buy_price = open * 0.99;
def entry_condition = (open * discount) <= high && (open * discount) >= low;
AddOrder(OrderType.BUY_AUTO, entry_condition, buy_price[-1]);

Yes, the proper logic is to buy at the open of the next candle after the confirmation candle... You can streamline your logic to the following which requires less calculations and thus improves performance...

Ruby:
def discount = 0.99;
def buy_price = open * discount;
def entry_condition = buy_price <= high && buy_price >= low;
AddOrder(OrderType.BUY_AUTO, entry_condition, buy_price[-1]);
 
Solution
@rad14733 Thank you, I added that to my code but it looks like there's an issue. The code is trying to buy and sell at a price outside of the body of the candle.. do you have any advice/ resources that can help me fix this. Attached below is my full code and a picture of what I'm talking about. Thank you so much, your help is invaluable!

Photo:
Code:
#Adjustable Variables
    input discount = 0.99;

#Static Variables
    def entry_price = EntryPrice();
    def buy_price = open * 0.99;
    def sell_price = entry_price * 1.01;
    def exit_condition = sell_price <= high && sell_price >= low;
    def entry_condition = buy_price <= high && buy_price >= low;

#Orders
    AddOrder(OrderType.BUY_AUTO, entry_condition, buy_price[-1]);
    AddOrder(OrderType.SELL_TO_CLOSE, exit_condition, sell_price);

Basically what I want it to do is buy when the price goes down 1% in 1 day and sell whenever it goes back up 1%.
 
@SeattleTrader20 Unfortunately, we can't realistically buy at a price that doesn't exist during the candle and that is what is happening... The issue is that AddOrder() won't wait for your desired price, it only trades based on the Condition provided, at the Price you state, on the candle you tell it to enter on... In order to only buy at your desired price you need to add that as part of your Condition... And that means less entry opportunities... Otherwise you need to buy at the open of the next candle... We have to live within the limitations that the platforms backtesting capabilities provide us...
 

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