Recursion and Secondary Aggregation in Conditional Orders


Category:
0
0

Is there anything wrong with below script that is not working with conditional order?

declare lower;
def delta = close(period = aggregationPeriod.FIVE_MIN) – close(period = aggregationPeriod.FIVE_MIN)[1];

def deltaClose = deltaClose[1] + delta;

def priceAtBuy = close(period = aggregationPeriod.FIVE_MIN) – deltaClose;

def salePrice = close(period = aggregationPeriod.FIVE_MIN) * 1.05;

plot signal = priceAtBuy < salePrice;

RESOLVED
Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on April 26, 2023 5:54 pm
105 views
0
Private answer

I will explain why your code is not supported in the Conditional Order tool on Thinkorswim.

  1. Your code includes references to a secondary aggregation period, which is not supported in the current version of Thinkorswim.
  2. Your code includes a recursive variable, which is also not supported in the current version of Thinkorswim.

Where is this reference to secondary aggregation? Here:

(period = aggregationPeriod.FIVE_MIN)

Each section of code which includes this reference is not supported in the Conditional Order tool. If you paste your code directly into a Conditional Order you will find it generates an error stating "Secondary period cannot be less than primary". And this error persists no matter what time frame is selected for the Conditional Order. However if you tried to save this as a custom study and used only a reference to the study in the Conditional Order the compiler may miss this. Which is why we always recommend that we never reference custom chart studies in this tool. We always want to use the entire code.

Where is the recursive variable?

def deltaClose = deltaClose[1] + delta;

Any variable which refers to a previous value of itself (deltaClose[1]) is a recursive variable. These are not supported in the Conditional Order tool on the current version of Thinkorswim.

For those interested in learning how to avoid these types of mistakes I suggest the following videos:

https://www.hahn-tech.com/thinkorswim-autotrade-almost/

https://www.hahn-tech.com/thinkorswim-automated-round-trip-trades/

 

 

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on April 26, 2023 6:38 pm