Can you point me to the right direction?

T

TSnewbie

New member
Hi everyone, I'm new to the thinkscripting world. One day old to be exact.
I have been reading and referencing people's scripts to learn, but I guess I still have some way to go. Hope to get some pointers here.

The challenge:
I am trying to code this candlestick trend change logic that I learnt from a trader.
The logic goes as such:
1. From the start, the current candlestick is made the Reference Candlestick
2. Reference Candlestick is compared to subsequent candlesticks based on some conditions.
3. When certain conditions are met, the Reference Candlestick is "replaced"
4. As the Reference Candlestick is replaced on the way up, the trend is up
5. As the Reference Candlestick is replaced on the way down, the trend is down
6. Along the way up or down, when certain conditions are met, a Trend Change happens.
7. Repeat from Step 4 or 5, until 6.

The objective of this logic is to identify the moments of trend change.

In the following section, I try to describe the logic in "code" format. I'd love any help/feedback that you can provide to make this into Thinkscript.

"Code" starts here.

#Logic for "Uptrend" candlesticks
=======================


Look back 50 candles

Define UpCandle = array(CandleID, BodyHeight, Close) if Close > Open

At start, RefCandle = UpCandle

Loop {
If Close[n] > Open[n] and UpCandle.BodyHeight[n] >= 0.7*RefCandle.BodyHeight, RefCandle = UpCandle[n]

If Open[n] > Close[n], Execute TrendChange
If TrendChange = TRUE,
Change color of UpCandle.CandleID[n] to Yellow
Execute DownTrend
}

#Logic for "Downtrend" candlesticks
=========================


Look back 50 candles

Define DownCandle = array(CandleID, BodyHeight, Open) if Open > Close

At start, RefCandle = DownCandle

Loop {
If Open[n] > Close[n] and DownCandle.BodyHeight[n] >= 0.7*RefCandle.BodyHeight, RefCandle = DownCandle[n]

If Close[n] > Open[n], Execute TrendChange
If TrendChange = TRUE,
Change color of DownCandle.CandleID[n] to Yellow
Execute UpTrend
}

#Logic for "TrendChange"
=================


If Close[n] > Open[n] and UpCandle.BodyHeight[n] >= 0.7*RefCandle.BodyHeight and UpCandle.Open[n] > RefCandle.Close, return TRUE

If Open[n] > Close[n] and DownCandle.BodyHeight[n] >= 0.7*RefCandle.BodyHeight and DownCandle.Open[n] < RefCandle.Close, return TRUE

"Code" ends here.
 
Last edited:

Similar threads

Top