Create Custom Label Comparing Current Price to a Specific Level

iglesiad

New member
Hi I was looking for a custom script to display a label for daily, 1 hr, and 2 minute trend based on a price level for NQ futures. I was looking for the label to compare the current price to a predetermined price label I input and then label it as uptrend if above or downtrend if below.

I am looking to create a custom label that compares the current instrument price to a predetermine price I input. I want the code to compare them and then label it as an uptrend or downtrend. I have found no success and would like some help. I was able to do it comparing it to an EMA, but not based on a number (price level) that I input. Any help will be greeting appreciated!

So, for example, I want this label to give me the option to input a value for the daily and 1 hr timeframe. I want this value to be compared to the current price of the stock and then output that its an uptrend if above or downtrend if below.

Any help will be appreciated!
 
Last edited by a moderator:
Solution
Hi I was looking for a custom script to display a label for daily, 1 hr, and 2 minute trend based on a price level for NQ futures. I was looking for the label to compare the current price to a predetermined price label I input and then label it as uptrend if above or downtrend if below.

I am looking to create a custom label that compares the current instrument price to a predetermine price I input. I want the code to compare them and then label it as an uptrend or downtrend. I have found no success and would like some help. I was able to do it comparing it to an EMA, but not based on a number (price level) that I input. Any help will be greeting appreciated!

So, for example, I want this label to give me the option to input a value...
Hi I was looking for a custom script to display a label for daily, 1 hr, and 2 minute trend based on a price level for NQ futures. I was looking for the label to compare the current price to a predetermined price label I input and then label it as uptrend if above or downtrend if below.

I am looking to create a custom label that compares the current instrument price to a predetermine price I input. I want the code to compare them and then label it as an uptrend or downtrend. I have found no success and would like some help. I was able to do it comparing it to an EMA, but not based on a number (price level) that I input. Any help will be greeting appreciated!

So, for example, I want this label to give me the option to input a value for the daily and 1 hr timeframe. I want this value to be compared to the current price of the stock and then output that its an uptrend if above or downtrend if below.

Any help will be appreciated!


i'm not exactly sure what you are asking for.
i'm not sure how the different time frames are supposed to fit in. (see below)
here is my guess


pick 3 2nd aggregation times. default 5min, hour, day
pick 3 price levels
compare close price from each agg time to a price level.

show 2 labels for each price,
show some stats and up or down trend.


notes,
it doesn't matter what agg time you pick. all will have the same close price, the current close price.
the current bar will always be part of the last 2nd aggregation period.



Code:
# compare_2nd_agg_price_00

#https://usethinkscript.com/threads/create-custom-label-comparing-current-price-to-a-specific-level.14997/
#Create Custom Label Comparing Current Price to a Specific Level

# get chart agg time
def chartagg = GetAggregationPeriod();
def chartmin = chartagg / (1000 * 60);
#---------------------------------

input agg1 = AggregationPeriod.five_min;
def agg1min = agg1 / 60000;
input price1 = 0;

input agg2 = AggregationPeriod.HOUR;
def agg2min = agg2 / 60000;
input price2 = 0;

input agg3 = AggregationPeriod.day;
def agg3min = agg3 / 60000;
input price3 = 0;


def cls1;
if chartagg > agg1 then {
 cls1 = 0;
} else {
 cls1 = close(period = agg1);
}

def cls2;
if chartagg > agg2 then {
 cls2 = 0;
} else {
 cls2 = close(period = agg2);
}

def cls3;
if chartagg > agg3 then {
 cls3 = 0;
} else {
 cls3 = close(period = agg3);
}

def en1 = (price1 > 0) and (cls1 > 0);
def en2 = (price2 > 0) and (cls2 > 0);
def en3 = (price3 > 0) and (cls3 > 0);

def diff1 = cls1 - price1;
def diff2 = cls2 - price2;
def diff3 = cls3 - price3;

addlabel(1, " ", color.black);
addlabel(1,
 ("price1 | " + agg1min + " min | " + asdollars(price1) + " | ") + (if en1 then diff1 else 0) ,
 (if !en1 then color.gray else if diff1 > 0 then color.green else color.red));
addlabel(1,
 (if !en1 then "--" else if diff1 > 0 then "uptrend" else "downtrend"),
 (if !en1 then color.gray else if diff1 > 0 then color.green else color.red));


addlabel(1, " ", color.black);
addlabel(1,
 ("price2 | " + agg2min + " min | " + asdollars(price2) + " | ") + (if en2 then diff2 else 0) ,
 (if !en2 then color.gray else if diff2 > 0 then color.green else color.red));
addlabel(1,
 (if !en2 then "--" else if diff2 > 0 then "uptrend" else "downtrend"),
 (if !en2 then color.gray else if diff2 > 0 then color.green else color.red));


addlabel(1, " ", color.black);
addlabel(1,
 ("price3 | " + agg3min + " min | " + asdollars(price3) + " | ") + (if en3 then diff3 else 0) ,
 (if !en3 then color.gray else if diff3 > 0 then color.green else color.red));
addlabel(1,
 (if !en3 then "--" else if diff3 > 0 then "uptrend" else "downtrend"),
 (if !en3 then color.gray else if diff3 > 0 then color.green else color.red));

addlabel(1, " ", color.black);
#

7J8HcLK.jpg
 
Solution

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
367 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.
Back
Top