Need help in code optimization and extension.

rengagopal

Member
VIP
My goal is to create a kind of 'Dashboard' to display the performance for the last 10 minutes. Ex. Rate of change of HMA 5. I am using a code to get this job done, but the code is very lengthy [may be UN-optimized]. I would like to have this 'Dashboard' done for 6 equities in ONE chart. Please see the following sample code that I use and help me with the code. Thank you!!

Def roc_Hull05 = Round(((HullMovingAvg(vwap, 5) / HullMovingAvg(vwap, 5)[1]) - 1) * 100, 2);

AddLabel(1, "Hull05 " , Color.Blue);

AddLabel(roc_Hull05[9] > 0.00 and roc_Hull05[9] <= 0.02, ".",color.violet);
AddLabel(roc_Hull05[9] > 0.02 and roc_Hull05[9] <= 0.04, "0",color.violet);
AddLabel(roc_Hull05[9] > 0.04 and roc_Hull05[9] <= 0.06, "1",color.violet);
AddLabel(roc_Hull05[9] > 0.06 and roc_Hull05[9] <= 0.10, "2",color.violet);
AddLabel(roc_Hull05[9] > 0.10 and roc_Hull05[9] <= 0.20, "3",color.violet);
AddLabel(roc_Hull05[9] > 0.20 and roc_Hull05[9] <= 0.30, "4",color.violet);
AddLabel(roc_Hull05[9] > 0.30 and roc_Hull05[9] <= 0.40, "5",color.violet);
AddLabel(roc_Hull05[9] > 0.40 and roc_Hull05[9] <= 0.50, "6",color.violet);
AddLabel(roc_Hull05[9] > 0.50, "7",color.violet);
AddLabel(roc_Hull05[9] <= 0.0, "*",color.Red);

AddLabel(roc_Hull05[8] > 0.00 and roc_Hull05[8] <= 0.02, ".",color.violet);
AddLabel(roc_Hull05[8] > 0.02 and roc_Hull05[8] <= 0.04, "0",color.violet);
AddLabel(roc_Hull05[8] > 0.04 and roc_Hull05[8] <= 0.06, "1",color.violet);
AddLabel(roc_Hull05[8] > 0.06 and roc_Hull05[8] <= 0.10, "2",color.violet);
AddLabel(roc_Hull05[8] > 0.10 and roc_Hull05[8] <= 0.20, "3",color.violet);
AddLabel(roc_Hull05[8] > 0.20 and roc_Hull05[8] <= 0.30, "4",color.violet);
AddLabel(roc_Hull05[8] > 0.30 and roc_Hull05[8] <= 0.40, "5",color.violet);
AddLabel(roc_Hull05[8] > 0.40 and roc_Hull05[8] <= 0.50, "6",color.violet);
AddLabel(roc_Hull05[8] > 0.50, "7",color.violet);

Code continous to the current minute.

Thank you Again!!
AddLabel(roc_Hull05[8] <= 0.0, "*",color.Red);
 
My goal is to create a kind of 'Dashboard' to display the performance for the last 10 minutes. Ex. Rate of change of HMA 5. I am using a code to get this job done, but the code is very lengthy [may be UN-optimized]. I would like to have this 'Dashboard' done for 6 equities in ONE chart. Please see the following sample code that I use and help me with the code. Thank you!!

Def roc_Hull05 = Round(((HullMovingAvg(vwap, 5) / HullMovingAvg(vwap, 5)[1]) - 1) * 100, 2);

AddLabel(1, "Hull05 " , Color.Blue);

AddLabel(roc_Hull05[9] > 0.00 and roc_Hull05[9] <= 0.02, ".",color.violet);
AddLabel(roc_Hull05[9] > 0.02 and roc_Hull05[9] <= 0.04, "0",color.violet);
AddLabel(roc_Hull05[9] > 0.04 and roc_Hull05[9] <= 0.06, "1",color.violet);
AddLabel(roc_Hull05[9] > 0.06 and roc_Hull05[9] <= 0.10, "2",color.violet);
AddLabel(roc_Hull05[9] > 0.10 and roc_Hull05[9] <= 0.20, "3",color.violet);
AddLabel(roc_Hull05[9] > 0.20 and roc_Hull05[9] <= 0.30, "4",color.violet);
AddLabel(roc_Hull05[9] > 0.30 and roc_Hull05[9] <= 0.40, "5",color.violet);
AddLabel(roc_Hull05[9] > 0.40 and roc_Hull05[9] <= 0.50, "6",color.violet);
AddLabel(roc_Hull05[9] > 0.50, "7",color.violet);
AddLabel(roc_Hull05[9] <= 0.0, "*",color.Red);

AddLabel(roc_Hull05[8] > 0.00 and roc_Hull05[8] <= 0.02, ".",color.violet);
AddLabel(roc_Hull05[8] > 0.02 and roc_Hull05[8] <= 0.04, "0",color.violet);
AddLabel(roc_Hull05[8] > 0.04 and roc_Hull05[8] <= 0.06, "1",color.violet);
AddLabel(roc_Hull05[8] > 0.06 and roc_Hull05[8] <= 0.10, "2",color.violet);
AddLabel(roc_Hull05[8] > 0.10 and roc_Hull05[8] <= 0.20, "3",color.violet);
AddLabel(roc_Hull05[8] > 0.20 and roc_Hull05[8] <= 0.30, "4",color.violet);
AddLabel(roc_Hull05[8] > 0.30 and roc_Hull05[8] <= 0.40, "5",color.violet);
AddLabel(roc_Hull05[8] > 0.40 and roc_Hull05[8] <= 0.50, "6",color.violet);
AddLabel(roc_Hull05[8] > 0.50, "7",color.violet);

Code continous to the current minute.

Thank you Again!!
AddLabel(roc_Hull05[8] <= 0.0, "*",color.Red);

See if this helps.

Here is a template to copy and paste multiple times and adjust the "last - 3" offset to "last - 4" for example to be the next labels offset, etc, etc
The def of roc has a length and sym input that you can change for each equity.

Code:
AddLabel(1, (last - ) +
(if Between(roc_Hull[last - ], 0.00, 0.02) then "." else
if Between(roc_Hull[last - ], 0.02, 0.04) then "0" else
if Between(roc_Hull[last - ], 0.04, 0.06) then "1" else
if Between(roc_Hull[last - ], 0.06, 0.10) then "2" else
if Between(roc_Hull[last - ], 0.10, 0.20) then "3" else
if Between(roc_Hull[last - ], 0.20, 0.30) then "4" else
if Between(roc_Hull[last - ], 0.30, 0.40) then "5" else
if Between(roc_Hull[last - ], 0.40, 0.50) then "6" else
if roc_Hull[last - ] > 0.50 then "7" else
"*"), Color.VIOLET);

Here is the first 3 labels plus the header code that you can then use the above template to create the remaining minutes. Once finished with the master template with all minutes then you should be able to make additional equite's labels a little easier.

Screenshot-2022-12-01-154724.png
Ruby:
input sym = "SPY";
input len = 5;
def roc_Hull = Round(((HullMovingAvg(vwap(sym), len) / HullMovingAvg(vwap(sym), len)[1]) - 1) * 100, 2);

AddLabel(1, "Hull" + (if len < 10 then "0" + len else "" + len) , Color.BLUE);
input last = 9;
AddLabel(1, last +
(if Between(roc_Hull[last], 0.00, 0.02) then "." else
if Between(roc_Hull[last], 0.02, 0.04) then "0" else
if Between(roc_Hull[last], 0.04, 0.06) then "1" else
if Between(roc_Hull[last], 0.06, 0.10) then "2" else
if Between(roc_Hull[last], 0.10, 0.20) then "3" else
if Between(roc_Hull[last], 0.20, 0.30) then "4" else
if Between(roc_Hull[last], 0.30, 0.40) then "5" else
if Between(roc_Hull[last], 0.40, 0.50) then "6" else
if roc_Hull[last] > 0.50 then "7" else
"*"), Color.VIOLET);

AddLabel(1, (last - 1) +
(if Between(roc_Hull[last - 1], 0.00, 0.02) then "." else
if Between(roc_Hull[last - 1], 0.02, 0.04) then "0" else
if Between(roc_Hull[last - 1], 0.04, 0.06) then "1" else
if Between(roc_Hull[last - 1], 0.06, 0.10) then "2" else
if Between(roc_Hull[last - 1], 0.10, 0.20) then "3" else
if Between(roc_Hull[last - 1], 0.20, 0.30) then "4" else
if Between(roc_Hull[last - 1], 0.30, 0.40) then "5" else
if Between(roc_Hull[last - 1], 0.40, 0.50) then "6" else
if roc_Hull[last - 1] > 0.50 then "7" else
"*"), Color.VIOLET);

AddLabel(1, (last - 2) +
(if Between(roc_Hull[last - 2], 0.00, 0.02) then "." else
if Between(roc_Hull[last - 2], 0.02, 0.04) then "0" else
if Between(roc_Hull[last - 2], 0.04, 0.06) then "1" else
if Between(roc_Hull[last - 2], 0.06, 0.10) then "2" else
if Between(roc_Hull[last - 2], 0.10, 0.20) then "3" else
if Between(roc_Hull[last - 2], 0.20, 0.30) then "4" else
if Between(roc_Hull[last - 2], 0.30, 0.40) then "5" else
if Between(roc_Hull[last - 2], 0.40, 0.50) then "6" else
if roc_Hull[last - 2] > 0.50 then "7" else
"*"), Color.VIOLET);

AddLabel(1, (last - 3) +
(if Between(roc_Hull[last - 3], 0.00, 0.02) then "." else
if Between(roc_Hull[last - 3], 0.02, 0.04) then "0" else
if Between(roc_Hull[last - 3], 0.04, 0.06) then "1" else
if Between(roc_Hull[last - 3], 0.06, 0.10) then "2" else
if Between(roc_Hull[last - 3], 0.10, 0.20) then "3" else
if Between(roc_Hull[last - 3], 0.20, 0.30) then "4" else
if Between(roc_Hull[last - 3], 0.30, 0.40) then "5" else
if Between(roc_Hull[last - 3], 0.40, 0.50) then "6" else
if roc_Hull[last - 3] > 0.50 then "7" else
"*"), Color.VIOLET);
 

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

See if this helps.

Here is a template to copy and paste multiple times and adjust the "last - 3" offset to "last - 4" for example to be the next labels offset, etc, etc
The def of roc has a length and sym input that you can change for each equity.

Code:
AddLabel(1, (last - ) +
(if Between(roc_Hull[last - ], 0.00, 0.02) then "." else
if Between(roc_Hull[last - ], 0.02, 0.04) then "0" else
if Between(roc_Hull[last - ], 0.04, 0.06) then "1" else
if Between(roc_Hull[last - ], 0.06, 0.10) then "2" else
if Between(roc_Hull[last - ], 0.10, 0.20) then "3" else
if Between(roc_Hull[last - ], 0.20, 0.30) then "4" else
if Between(roc_Hull[last - ], 0.30, 0.40) then "5" else
if Between(roc_Hull[last - ], 0.40, 0.50) then "6" else
if roc_Hull[last - ] > 0.50 then "7" else
"*"), Color.VIOLET);

Here is the first 3 labels plus the header code that you can then use the above template to create the remaining minutes. Once finished with the master template with all minutes then you should be able to make additional equite's labels a little easier.
Thank you!!. Is it possible to put the AddLabel code in a loop to change the value of the 'Last'?

Thank you Again!!
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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