Help with this piece of Code - Please


New member
Hi guys,

I am trying to create a Marketwatch where it will have 7 columns: Symbol, Overall Trend, Daily Ichimoku, Hourly Ichimoku, 10-min Ichimoku, Chikou Placement, Chikou Direction.

Trend: Not sure how I want to handle this yet, thinking about just using price above/below a Hull MA

The Daily, 1 hour, 10-min and Chikou Placement relate to whether the price is above/in/below the cloud (with color-coding green/black/red). Also, I would like to could back the number of periods the price has closed above/in/below. So if the price is above the cloud for the last 12 periods then it would print in green color with black text "Above Cloud - Count: 12"

Chikou Direction: Currently Up or down

I do not have all of the code. I am new to coding and thinkscript so I have been trying to teach myself and patching two pieces of code from the ToS site.

I can't get the period count to correctly display the actual amount, and well, to be honest, none of it is working correctly. I am very frustrated with my inability to get something I think should not be particularly difficult to work.

Any help anyone may be able to give would be greatly appreciated.


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 Span_A = (Tenkan[kijun_period] + Kijun[kijun_period]) / 2;
def Span_B = (Highest(high[kijun_period], 2 * kijun_period) + Lowest(low[kijun_period], 2 * kijun_period)) / 2;
def Chikou = close[-kijun_period];

def aboveCloud = close > Span_B AND Span_A > Span_B;
def belowCloud = close < Span_A AND Span_A < Span_B;

def crossUpper = (close crosses above Kijun) OR (Tenkan crosses above Kijun);
def crossLower = (close crosses below Kijun) OR (Tenkan crosses below Kijun);

def isAboveCloud = if aboveCloud == 0 then 1 else 0;
def sumAboveCloud= Sum(isAboveCloud, 10);
def newAboveCloud = if isAboveCloud[1] == 0 and isAboveCloud == 1 then 1 else 0;

def isBelowCloud = if belowCloud == 0 then 1 else 0;
def sumBelowCloud= Sum(isBelowCloud, 10);
def newBelowCloud = if isBelowCloud[1] == 0 and isBelowCloud == 1 then 1 else 0;

AddLabel(newAboveCloud, “Above Cloud“, color.white);
AddLabel(isAboveCloud, “Count: “+sumAboveCloud, color.white);
AssignBackgroundColor(if newAboveCloud then else;

AddLabel(newBelowCloud, “Below Cloud“, color.white);
AddLabel(isBelowCloud, “Count: “+sumBelowCloud, color.white);
AssignBackgroundColor(if newBelowCloud then else;
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
363 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

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?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.