Conditional Order using ATR Trailing Stop


Category:
0
0

Hi Pete,

The ATR Trailing Stop code for chart study w/alerts you shared is very helpful.

Is it possible to use ATR Trailing Stop in a conditional order?

I would like to use it only for Stop Loss.  I already have a position entry signal.

Let me know if this is possible.

I am happy to pay for your programming time.

Thanks,

Terry

 

Marked as spam
Posted by (Questions: 1, Answers: 0)
Asked on April 9, 2017 1:33 pm
721 views
0
Private answer

Sorry to say there is no present solution to this. The ATR Trailing Stop uses recursion and this is not supported in the Study Alerts or the Conditional Order functions.

Recursion, in the context of programing, is when a variable requires a previous value of itself in order to derive the current value for itself.

Marked as spam
Posted by (Questions: 37, Answers: 4108)
Answered on April 9, 2017 4:21 pm
0

I had the same problem so I wrote a chandelier exit which gets close.

( at July 22, 2017 4:56 pm)
0

Thanks for that valuable feedback Stephen!

( at July 22, 2017 5:52 pm)
0
So, I may have found a workaround. Create a conditional buy order that triggers on a study that is non-recursive. Copy over the guts of the non-recursive study with the guts of your ATRTrailingStop Study. Go back into the thinkscript of your conditional buy order. The chart will flash and you won’t get the recursive error message and the chart will have your ATRTrailingStop plotted. Unfortunately, this is extremely inconsistent. I’m working on it. Edit: I found something even better. Not sure if you still need to perform the above to make it work. Lets say we have…ATRTrailingStop().”TrailingStop” in the thinkscript of an alert or conditional order. You will get the recursive error. If you just hit return enough times (Making blank lines) eventually the error will go away and it WILL work as long as you see the blue plot on the chart. I’ve been executing forex conditional orders this way all day today. Edit#2: Hitting return makes the alert or conditional order pull the non-recursive study, not the recursive study. The first method works great though if you know to do it right. I may put in a formal answer for this if i have the time for it.
( at February 27, 2020 9:23 pm)
0
Interesting. I would like to try this once the markets chill out and stop freaking out over this virus. But I would suggest using the Study Alert to test this. Functions exactly the same as the Conditional Order with fewer moving pieces. If you can ever get this to work consistently, by all means post this as a new answer to this question and provide some (between 1-3) screenshots showing the basic steps.
( at February 28, 2020 8:37 am)
0
Private answer

Create 3 Studies.

Ex.

Study # 1

Name:

AANonRecursive

Coding:

plot BuyLong = 1;
plot SellLong = 1;

Study # 2

Name:

AARecursive

Coding: This can be whatever study you're trying to push through with the recursive definition(s)

Paste the ATRTrailingStop study

Delete everything from def BuySignal... and down

Add the following...

plot BuyLong = close > trail;
plot SellLong = close < trail;

Study # 3

Name:

AAMoneyMaker

Coding:

plot BuyLong = 1;
plot SellLong = 1;

________________________________________________________________________________

Go to the thinkscript of a new buy order and replace the default coding with...AAMoneyMaker()."BuyLong"

Go to the AAMoneyMaker Study and replace the coding with AARecursive Study

Go back to the buyorder thinkscript. The window will do a flash. There shouldn't be a recursive error and your recursive study should be plotted on the chart. Click ok and you're ready to submit your buy order

You can pair this with a sell order using 1st trgs seq. Just replace AAMoneyMaker()."BuyLong" with AAMoneyMaker()."SellLong" in your sell order thinkscript

Go ahead and save this as a template

________________________________________________________________________________

When you try to reuse the template always check the thinkscript for errors. You MAY find that the recursive error comes back. Here is how you fix it.

Replace AAMoneyMaker Study coding with coding from AANonRecursive Study

Go to the order thinkscript and delete the thinkscript coding, AAMoneyMaker()."BuyLong" or AAMoneyMaker()."SellLong"

In that same window, go to the condition wizard tab and build out what was just deleted, AAMoneyMaker()."BuyLong" or AAMoneyMaker()."SellLong"

Recursive error should be absent and chart should be plotted (Just a straight line at "1" value)

Replace AAMoneyMaker Study coding with coding from AARecursive Study

Go back to your order thinkscript. Recursive error should be absent and chart should be plotted with AARecursive Study conditions

________________________________________________________________________________

After all that you should be back in business. Make sure to always check the order thinkscript before submitting for two reasons

  • Check for recursive errors that need correction
  • Bypass the 155 character thinkscript restriction

This may seem tedious but once you get it down it should take only a few mins. I use this method to setup 4 Long pair and 4 Short pair orders all within 5 mins. This method is 3 days old so there is room for improvement, i'm sure. No screenshots, sorry.

Marked as spam
Posted by (Questions: 0, Answers: 8)
Answered on February 29, 2020 8:34 am
0
Pete, don't use this. It's buggy.
( at March 2, 2020 5:30 am)