ATRtrailingStop Strategy


Category:
0
0

Hi Pete,

Inspired by your think or swim strategy tutorial, I wrote a simple ATR strategy to backtest the data. (I understand I can’t do conditional orders based on ATR trailing stop.)

 

But when I checked the buy and sell signals on the chart, I found a lot of slippages compared to do orders just based on ATR trailing stop.

As you can see in my screenshot, orders based on ATR should be at white arrow, but the signal won’t pop until red arrow.

Can I know if there is a way to fix it, so I can get correct backtesting report? Also, can I know have you tried to do automated trading on Tradestation based on ATR trailing and how does that work out? (I’m considering switching to TradeStation if TOS doesn’t support ATRtrailing conditional order at all.)

Thank you for your help!!

Best regards,

Daisy

Attachments:
Marked as spam
Posted by (Questions: 1, Answers: 2)
Asked on October 24, 2017 6:40 pm
761 views
0
Private answer

Hi Pete,

Thank you for your help!!! With your help, I found a solution to combine code for ATRtrailing stop together with my strategy and use “trail” to calculate my entry and exit instead of “open”.

Pardon my late reply. Inspired by your answer, I fixed all the alignment problems in my other strategies, so I can get much more accurate data and find the best strategy to use.

Most importantly, you are really a good mentor! Before watching your video and forum, I have really limited knowledge in coding and have zero ideas of how to combine coding with trading. Now I can even experiment and write my own strategy!!

Thank you again!

Marked as spam
Posted by (Questions: 1, Answers: 2)
Answered on October 25, 2017 5:43 pm
0

Goose bumps! Love to get feedback like this. I think this is fantastic. Well done Daisy Liu! Stay tuned for more. For those how like to tinker with code, wait until you see what I share with you on TradeStation and SierraChart. Taking it to the next level.

( at October 25, 2017 6:00 pm)
0
Private answer

I saw that you asked this question on another post. It’s good that you started a new thread though. It helps prevent things from getting cluttered and confusing. Below is the response I gave to your question in that previous post:

First, what you are experiencing here is an alignment problem. The following post may help you understand how to align things correctly. It will also provide you the tools needed to experiment on your own: https://www.hahn-tech.com/ans/parablic-sar-signal-not-firing-in-tos-strategy/

About the alignment issue. The AddOrder() statement is checking the current bar for a signal. If the current bar contains a true condition, the AddOrder executes the order on the NEXT bar. So in order to get the PSAR to execute on the correct bar, we need to check if the condition is true in the next bar to the right. So something like condition2[-1].

However there is another alignment issue, price. Because the PSAR is designed to be traded using a trailing stop, you need to set the trade price to one tick beyond the previous bar’s PSAR value. Confusing? YES! Sorry, but you have picked the very worst indicator upon which to practice building strategies.

TradeStation does indeed support the ATR for both strategies as well as auto-trading. However the development of strategies in TradeStation is far more complex than on Thinkorswim. I have built a strategy on TradeStation that utilizes the PSAR. That was a custom project so I am not at liberty to share any details.

Marked as spam
Posted by (Questions: 37, Answers: 4086)
Answered on October 24, 2017 7:50 pm