Heiken ashi custom column counter


Category:
0
0

Hello I’m trying to create a Heiken ashi candle counter for stocks on a daily basis. I currently leverage your great solution for flagging a Heiken ashi candle but would like to count it (no formatting just a pure number of green candles in a row or red candles in a row.
ie 3 red ha candles in a row would be -3,  5 green ha candles would be a 5. I do not know how to assign a streak value to count the occurrences. Thanks!

RESOLVED
Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on April 3, 2021 11:00 pm
280 views
0
Thank you mr Hahn ! This was exactly what I wanted!
( at April 5, 2021 3:53 pm)
0
Private answer

I moved your question out of the "Stock Scanners" topic and into the "Watchlist" topic since your request has nothing to do with scanning for stocks.

The following section of code will compute the counts as you have requested:

def haClose = ohlc4;
def haOpen = if haOpen[1] == 0 then haClose[1] else (haOpen[1] + haClose[1]) / 2;
def greenCandle = haClose > haOpen;
def redCandle = haClose < haOpen;
rec countGreen = if greenCandle and redCandle[1] then 1 else if greenCandle and countGreen[1] > 0 then countGreen[1] + 1 else 0;
rec countRed = if redCandle and greenCandle[1] then -1 else if redCandle and countRed[1] < 0 then countRed[1] - 1 else 0;
plot data = if countGreen > AbsValue(countRed) then countGreen else countRed;

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on April 4, 2021 4:20 pm
0
Very nice. Great simple tool. Could this also be turned into a scanner?
( at June 2, 2021 8:28 am)
0
Sure thing. Just remove the last line and add your own scan signal to the bottom of the code that remains. For example you can add the following: plot scan = countGreen > 0; This will find stocks that have at least one green Heikin-Ashi candle.
( at June 2, 2021 9:49 am)
0
Thanks. Sorry, not a coder. :). How would I treat a conditional expression where I wanted countGreen >0 but less than 2 for example?
( at June 3, 2021 6:34 am)
0
plot scan = countGreen > 0 and countGreen < 2;
Which is the same exact thing as saying:
plot scan = countGreen == 1;
( at June 3, 2021 10:34 am)
0
Very nice. Would easy language be able to handle this in a radar screen alert approach?
( at June 6, 2021 2:22 pm)
0
Yes it would be possible to build a version of this for TradeStation.
( at June 6, 2021 2:41 pm)