Percent change between two candles exit script


Category:
0
0

Hi Pete,
I just came across your videos, and love them and learning a lot from them. However, I do have a question. I was watching your video titled “Thinkorswim AutoTrade Almost”. so I have my buy criteria set and they function just fine, however, for sell i want to put condition as closing price of current candle is below 10% of previous candle. How can I write that in thinkscript. I have tried to research the % change function but my understanding is limited at this point it seems like.

Thank you for helping people like me by creating very informative videos and posts here.

Marked as spam
Posted by (Questions: 1, Answers: 0)
Asked on May 8, 2020 10:34 pm
137 views
0
Private answer

Well you did not provide your source code you are using so I cannot provide a precise solution. Next time, please be sure to include your code, working or not, so I can teach you more. For now, all I can do is provide a single statement that compares the closing price of two candles and computes the percent change between them:

def percentChange = 100 * (close / close[1] -1);

It's just basic math. In English that is "100 times the result of current close divided by previous close minus 1".

The math formula inside the parentheses computes the raw decimal value. We multiply that by 100 to move the decimal place two places to the right so we can express that as an actual percent value. So if the raw percent change from one close to the next is 0.10 then this formula returns a value of 10.0%.

100 * (90 / 100 - 1) = -10%

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on May 9, 2020 8:01 am