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:

Similar threads