# Candle Type Watchlist Error

#### Cribbage

##### Member
I just made a watchlist column this morning intended to help my backtesting but I can't seem to get it to work - I used what I thought was a simple range calculation to help me discern when I get a larger than average candle. But it doesn't seem to be triggering. Maybe its because I'm testing it out premarket, but I feel like its something to do with my code. Does anyone have any suggestions?

Code:
``````def up = open > close[1];
def down = open < close[1];
def red = close < open;
def green = close > open;
def doji = close == open;

def upred = up and red;
def dnred = down and red;
def upgreen = up and green;
def dngreen = down and green;

def range = high - low;
def big = range * 2 > ((range[1] + range[2] + range[3] + range[4] + range[5] + range[6] + range[7] + range[8] + range[9] + range[10] + range[11] + range[12] + range[13] + range[14] + range[15] + range[16] + range[17] + range[18] + range[19] + range[20]) / 20);

upred then "UpRed" else if
dnred then "DownRed" else if
upgreen then "UpGreen" else if
dngreen then "DownGreen" else if
doji then "Doji" else if

upred and big then "BigUpRed" else if
dnred and big then "BigDownRed" else if
upgreen and big then "BigUpGreen" else if
dngreen and big then "BigDownGreen" else if
doji and big then "LLDoji" else "");``````

Last edited:
Solution
No, its not the dojis that are the problem but I want it to tell me when there are "big" candles or long-legged dojis. In the code its written as "big" and uses a simple range calculation based on the average of the previous 20 candles high-low. I'm wondering if there's something wrong with my formula because I can't get anything to populate as a "big bar". Or if there's a better way to get what I'm looking for which are unusually wide ranging candles.

For example, PALT would be a ticker I would expect to show "BigUpGreen" today but it just shows as "UpGreen"

I have simplified your range code, and reordered your candletype to put the "big and ..." first. I am getting 'big' one's to appear.

Ruby:
``````def up = open > close[1];
def...``````
I just made a watchlist column this morning intended to help my backtesting but I can't seem to get it to work - I used what I thought was a simple range calculation to help me discern when I get a larger than average candle. But it doesn't seem to be triggering. Maybe its because I'm testing it out premarket, but I feel like its something to do with my code. Does anyone have any suggestions

TOS does not allow 'string' to be used as you have done in a 'plot' statement. You can use your 'string code' in an addlabel or addchartbubble on a chart or a watchlist.

Ruby:
``````def up = open > close[1];
def down = open < close[1];
def red = close < open;
def green = close > open;
def doji = close == open;

def upred = up and red;
def dnred = down and red;
def upgreen = up and green;
def dngreen = down and green;

def range = high - low;
def big = range * 2 > (range[1] + range[2] + range[3] + range[4] + range[5] + range[6] + range[7] + range[8] + range[9] + range[10] + range[11] + range[12] + range[13] + range[14] + range[15] + range[16] + range[17] + range[18] + range[19] + range[20]) / 20;

(if
upred then "UpRed" else if
dnred then "DownRed" else if
upgreen then "UpGreen" else if
dngreen then "DownGreen" else if
doji then "Doji" else if

upred and big then "BigUpRed" else if
dnred and big then "BigDownRed" else if
upgreen and big then "BigUpGreen" else if
dngreen and big then "BigDownGreen" else if
doji and big then "LLDoji" else ""), Color.WHITE);``````

TOS does not allow 'string' to be used as you have done in a 'plot' statement. You can use your 'string code' in an addlabel or addchartbubble on a chart or a watchlist.
Thanks again SleepyZ - I figured that part out. I updated the post with the new code and a different question. Please let me know if you can't see it.

Thanks again SleepyZ - I figured that part out. I updated the post with the new code and a different question. Please let me know if you can't see it.

I tested your revised code in ONDemand in the premarket and it was detecting your code properly. Your label in the following picture detects the doji shown on the 1m chart of AAPL.

Hope this helps or is what you were wanting.

No, its not the dojis that are the problem but I want it to tell me when there are "big" candles or long-legged dojis. In the code its written as "big" and uses a simple range calculation based on the average of the previous 20 candles high-low. I'm wondering if there's something wrong with my formula because I can't get anything to populate as a "big bar". Or if there's a better way to get what I'm looking for which are unusually wide ranging candles.

For example, PALT would be a ticker I would expect to show "BigUpGreen" today but it just shows as "UpGreen"

No, its not the dojis that are the problem but I want it to tell me when there are "big" candles or long-legged dojis. In the code its written as "big" and uses a simple range calculation based on the average of the previous 20 candles high-low. I'm wondering if there's something wrong with my formula because I can't get anything to populate as a "big bar". Or if there's a better way to get what I'm looking for which are unusually wide ranging candles.

For example, PALT would be a ticker I would expect to show "BigUpGreen" today but it just shows as "UpGreen"

I have simplified your range code, and reordered your candletype to put the "big and ..." first. I am getting 'big' one's to appear.

Ruby:
``````def up = open > close[1];
def down = open < close[1];
def red = close < open;
def green = close > open;
def doji = close == open;

def upred = up and red;
def dnred = down and red;
def upgreen = up and green;
def dngreen = down and green;

def range = high - low;
def big = (range * 2) > (Sum(range, 20) / 20);

(if
upred and big then "BigUpRed" else if
dnred and big then "BigDownRed" else if
upgreen and big then "BigUpGreen" else if
dngreen and big then "BigDownGreen" else if
doji and big then "LLDoji" else if
upred then "UpRed" else if
dnred then "DownRed" else if
upgreen then "UpGreen" else if
dngreen then "DownGreen" else if
doji then "Doji"
else ""), Color.WHITE);``````

87k+ Posts
238 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?