# Need help with custom quote formula

#### liminal-rider

##### New member
Hi forum, I need help with the below custom quote formula, particularly the add label function, instead of a word in the label field it produces a digit(i.e.91.62).

What am I missing?

#Combined Script
#TOS MACD
#Hull Concavity by @mashume
input FAST = 9;
input SLOW = 18;
input Length1 = 9;
Input price = close;
input Length2 = 18;
input Lookback = 2;

#Constants
def a = 2 / (1 + FAST);
def b = 1 - a;
def c = 2 / (1 + SLOW);
def d = 1 - c;
def e = 2 / (1 + Length1);
def f = 1 - e;
rec FASTMAQ = (close[1] * a) + (FASTMAQ[1] * b);
rec SLOWMAQ = (close[1] * c) + (SLOWMAQ[1] * d);
def MACD = FastMAQ - SLOWMAQ;
rec Signal = (MACD * e) + (Signal[1] * f);
plot Crossprice = ((Signal * f) + (FASTMAQ * b * e) - (SLOWMAQ * d * e) -
(FASTMAQ * b) + (SLOWMAQ * d)) / (a - c - (a * e) + (c * e));

plot HMA = MovingAverage(AverageType.HULL, price, length2)[-lookback];

def delta = HMA[1] - HMA[lookback + 1];
def delta_per_bar = delta / lookback;
def next_bar = HMA[1] + delta_per_bar;
def concavity = if HMA > next_bar then 1 else -1;
plot MA_Max = if HMA[-1] < HMA and HMA > HMA[1] then HMA else Double.NaN;
plot MA_Min = if HMA[-1] > HMA and HMA < HMA[1] then HMA else Double.Nan;

def trendup = if MA_Min and close > crossprice then 1 else 0;
def trenddown = if MA_Max and close < crossprice then 1 else 0;
def distribution = if !trendup and !trenddown then 1 else 0;

AssignBackgroundColor(if TrendUp then color.ORANGE else if TrendDown then color.BLUE else color.light_gray);

Last edited by a moderator:
@liminal-rider I think your problem may lie here.
Ruby:
``````def trendup = if MA_Min and close > crossprice then 1 else 0;
def trenddown = if MA_Max and close < crossprice then 1 else 0;``````
Since MA_Min and Ma_Max are defined as being HMA or Double.NaN, then you have to check if MA_Min and MA_Max are Double.NaN.
Ruby:
``````def trendup = if IsNaN(MA_Min) and close > crossprice then 1 else 0;
def trenddown = if IsNaN(MA_Max) and close < crossprice then 1 else 0;``````

Last edited:
@liminal-rider Even with @Svanoy's excellent assistance. Results may still have inaccuracies.

If you read through @Mashume's Hull Concavity Thread from where hence the script was derived, you already know that the
calculations for MA_Min and Ma_Max rely on future data:
Rich (BB code):
``````plot MA_Max = if HMA[-1] < HMA and HMA > HMA[1] then HMA else Double.NaN;
plot MA_Min = if HMA[-1] > HMA and HMA < HMA[1] then HMA else Double.Nan;``````
The code is looking if the Hull of the next future bar is greater or lesser than the current bar.
Creating labels and alerts in the present for calculations that rely on future results, tends to be problematic.

Last edited:
Hi MerryDay, now that you mention it I do recall reading that issue...it was problematic. Thanks for pointing this out.

-JP

87k+ Posts
249 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?