NexusFi: Find Your Edge


Home Menu

 





Thinkscript Strategies not executing orders immediately


Discussion in ThinkOrSwim

Updated
      Top Posters
    1. looks_one StockT8er with 10 posts (0 thanks)
    2. looks_two Trader Kevin with 5 posts (2 thanks)
    3. looks_3 esanpi with 4 posts (0 thanks)
    4. looks_4 Cabdoctor with 3 posts (0 thanks)
    1. trending_up 8,945 views
    2. thumb_up 2 thanks given
    3. group 7 followers
    1. forum 23 posts
    2. attach_file 2 attachments




 
Search this Thread

Thinkscript Strategies not executing orders immediately

  #11 (permalink)
 StockT8er 
ROY, Utah
 
Experience: Intermediate
Platform: TradeStation
Posts: 81 since Apr 2020
Thanks Given: 11
Thanks Received: 6

Question, on your strategy you are buying and selling exactly at the point your condition is met, which I have not been able to do. as far as the price are you wanting it to show on the chart?

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Better Renko Gaps
The Elite Circle
Quant vue
Trading Reviews and Vendors
Cheap historycal L1 data for stocks
Stocks and ETFs
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
About a successful futures trader who didn´t know anyth …
Psychology and Money Management
 
  #12 (permalink)
Trader Kevin
Houston, Texas
 
Posts: 13 since Jun 2020
Thanks Given: 3
Thanks Received: 5

I believe you just adapt the trigger for the order as the price for the order as well (in most cases at least). For example, simply put the price in the addorder function as the EMA, pivot point, etc., so it will backtest correctly as if you bought/sold as soon as the price=EMA/pivot point etc (or use EMA+X if you want to wait for it to cross fully by X). You can even use if/then statements if necessary.. you're not limited to close/high/low/hlc3 etc.

Reply With Quote
Thanked by:
  #13 (permalink)
 StockT8er 
ROY, Utah
 
Experience: Intermediate
Platform: TradeStation
Posts: 81 since Apr 2020
Thanks Given: 11
Thanks Received: 6


I hope this is accurate, when I changed to sell on high . it doubled my profits. Just wish we could automate with TOS, so we could really test our strategies

Question how do you set up your strategy to buy on Ask and Sell on Bid. If we could ever automate this is what would be needed to use in trading after hours. Least unless just open or close price worked. When you state open or close, does that make it a Limit Order?

Reply With Quote
  #14 (permalink)
Trader Kevin
Houston, Texas
 
Posts: 13 since Jun 2020
Thanks Given: 3
Thanks Received: 5


StockT8er View Post
I hope this is accurate, when I changed to sell on high . it doubled my profits. Just wish we could automate with TOS, so we could really test our strategies

Question how do you set up your strategy to buy on Ask and Sell on Bid. If we could ever automate this is what would be needed to use in trading after hours. Least unless just open or close price worked. When you state open or close, does that make it a Limit Order?

You wouldn't want to set the price part of the AddOrder function to "high" unless the high of the bar is where you would actually buy/sell if you were actively trading it based on the strategy's signals. If you plan to live trade it by setting a limit order at an EMA or pivot point, for example, and wanted to backtest to see the efficacy, you'd set the "price" part of the addorder function to the EMA or pivot point. You are not making a limit order or market order for the strategy, it doesn't work that way... all you're doing is telling the AddOrder function what price to assume you were able to buy/sell at when it is backtesting for you. If you put "100" in there, it will it will pretend like every time the addorder function activated you were able to buy/sell at $100, regardless of if that's even possible if you were trading it in real life. If you want to see if your strategy is working correctly in your backtest and providing accurate data, you have to go through all the buy/sell orders and verify that they are buying/selling at the correct price that you intended to set, otherwise you'll get garbage and not realize it.

Reply With Quote
Thanked by:
  #15 (permalink)
 StockT8er 
ROY, Utah
 
Experience: Intermediate
Platform: TradeStation
Posts: 81 since Apr 2020
Thanks Given: 11
Thanks Received: 6

Thanks nice to know

Reply With Quote
  #16 (permalink)
Trader Kevin
Houston, Texas
 
Posts: 13 since Jun 2020
Thanks Given: 3
Thanks Received: 5


mtzimmer1 View Post
I'm not sure why it would be waiting a few bars. Thinkscript defaults to filling on the next bar if you don't specify another price to fill at (close,open,high[1],low[1] etc). If you post or PM me your code I can take a closer look and try to find the cause.

Were you able to figure out the reason it was waiting a few bars?

I'm having a very similar issue. I have a pretty simple strategy with addorder functions that don't involve offsets at all. When I backtest it over the last 30 days, before June 26th it delays executing the addorder by 1 extra bar (it buys/sells 2 bars after the condition is met), but after that date it operates normally (buys/sells the bar after the condition is met).

Anyone have any idea why this may be happening?

Reply With Quote
  #17 (permalink)
 StockT8er 
ROY, Utah
 
Experience: Intermediate
Platform: TradeStation
Posts: 81 since Apr 2020
Thanks Given: 11
Thanks Received: 6

I have had similar issues, in it waiting 2 bars
Question how wold I bring the current close Nasdaq into my script. TOS shows how to chart a comparison, I just want to get the close and have it trigger a if/then

Reply With Quote
  #18 (permalink)
esanpi
Buenos Aires Argentina
 
Posts: 4 since Sep 2016
Thanks Given: 0
Thanks Received: 0


Trader Kevin View Post
If you plan to live trade it by setting a limit order at an EMA or pivot point, for example, and wanted to backtest to see the efficacy, you'd set the "price" part of the addorder function to the EMA or pivot point.

Ok, but what happens when your condition is "volume>volume[1]" and you want to buy or sell when the current bar volume crosses above the previous volume bar. In that case you don't have any EMA or Pivot as reference. I want to print that price when that condition is triggered. Is there a way to print that price on the strategy?

Reply With Quote
  #19 (permalink)
 StockT8er 
ROY, Utah
 
Experience: Intermediate
Platform: TradeStation
Posts: 81 since Apr 2020
Thanks Given: 11
Thanks Received: 6

I want to set up a if NASDAQ is positive then to buy on one condition and if it negative to buy under and other

Another question, what does your typical strategy make, like with 100 shares, 1% or better

Reply With Quote
  #20 (permalink)
Trader Kevin
Houston, Texas
 
Posts: 13 since Jun 2020
Thanks Given: 3
Thanks Received: 5



StockT8er View Post
I have had similar issues, in it waiting 2 bars

Were you able to fix it?


StockT8er View Post
Question how wold I bring the current close Nasdaq into my script. TOS shows how to chart a comparison, I just want to get the close and have it trigger a if/then

It's just "close("symbol")". So you could say, for example, "def signal = if close("NDX") > close("NDX")[1] then 1 else 0;", then use signal to trigger a buy if you wanted.


esanpi View Post
Ok, but what happens when your condition is "volume>volume[1]" and you want to buy or sell when the current bar volume crosses above the previous volume bar. In that case you don't have any EMA or Pivot as reference. I want to print that price when that condition is triggered. Is there a way to print that price on the strategy?

That's trickier and I don't know how you could do that exactly (I'm sure there's a way, I am just not experienced enough to know it). In live trading of course it would be easier, and for backtesting you could get closer to the real price you would be buying at by using hlc3 or hl2 instead of just close or open, but it still obviously wouldn't be perfect.

Reply With Quote




Last Updated on July 14, 2020


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts