Watchlist or scan of how many candles are above span A


Category:
0
0

Hi Pete, I’ve been wanting to ask you from a long time. Please how can we make a wachlist or scan that scan on many stocks during last 30days 30minutes candles with TOS ichimoku how many candles are above span A and sort stocks by most numbers that met criteria. thanks a lot

Marked as spam
Posted by (Questions: 3, Answers: 2)
Asked on November 27, 2018 5:57 pm
154 views
0

Do you also want to count candles that inside the cloud then? Because during bearish markets the Span A is below Span B. So any candle above Span A during bearish market might also be below Span B.

( at November 28, 2018 7:52 am)
0

Hi again Pete. I just saw your ichimoku code that you posted long time ago and it works fine. no need to do another time. sorry that i didnt see it before posting. please can i ask you how can i write close[1] or close[2] or close[3] or close[4] or close[5] ….. to [150] without writing 150 times. thanks a lot and sorry for the delay

( at December 2, 2018 7:35 pm)
0
Private answer

Ok now we have some clarification we can proceed. Each post on this Q&A forum is intended to serve the widest possible audience. So while you have reduced your request to something much less complex, the context of the question will lead viewers to expect the full solution.

The first item we must face is the historical data limitation when working with custom watchlists and scans in Thinkorswim. Found at the very bottom of this page: http://tlc.thinkorswim.com/center/howToTos/thinkManual/Scan/Stock-Hacker/studyfilters.html

For the 30 min time frame we have only 15 calendar days of historical data available to us. This includes weekends so we don’t even have all 15 days. So we have to accept this limit before we start using this code.

The request was for counting the number of candles above Span A. But when the cloud is bearish, Span A is below Span B and this could leave you with candles being counted which are actually inside the cloud. So my solution here is for candles above the cloud, period. So we test if the close is above Span A and we test if the close is above Span B. Both must be true in order for a candle to be counted.

Here is the code. Screenshot below shows the result.

input tenkan_period = 9;
input kijun_period = 26;
def tenkan = (Highest(high, tenkan_period) + Lowest(low, tenkan_period)) / 2;
def kijun = (Highest(high, kijun_period) + Lowest(low, kijun_period)) / 2;
def spanA = (tenkan[kijun_period] + kijun[kijun_period]) / 2;
def spanB = (Highest(high[kijun_period], 2 * kijun_period) + Lowest(low[kijun_period], 2 * kijun_period)) / 2;
def aboveCloud = close > spanA and close > spanB;
rec counter = if aboveCloud and !aboveCloud then 1 else if aboveCloud then counter[1] + 1 else 0;
plot data = counter;

 

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on December 3, 2018 12:19 pm