Add Futures Label to Current Chart


Category:
0
0

Hi there!

I was trying to make a simple label to give me a general feel of where NQ futures are without having to go to that chart. I believe I am close on the code, but the colors/state do not seem to match.

Any thoughts? Thanks!

 

input symbol = “/NQ”;
input showLabel = yes;

def close01 = close(symbol, period = aggregationperiod.TEN_MIN);

def avg1 = movAvgExponential (close01, 9, 0);

addlabel(if ShowLabel == yes then 1 else 0, if close > avg1 then ” NQ – Bullish ” else if close < avg1 then ” NQ – Bearish ” else ” NQ – Flat “,
if close > avg1 then color.green else if close < avg1 then color.red else color.gray);

Marked as spam
Posted by (Questions: 4, Answers: 6)
Asked on July 7, 2021 9:16 am
91 views
0
Private answer

I just tested your code and it appears to be working perfectly. I made no changes. Just copy/paste.

Edit: After getting some feedback from the author of the post I did discover some mistakes in the code. The logic used to set the color of the chart label was referencing the close of the currently charted symbol to the moving average of /NQ. I have corrected those mistakes in the code below:

input symbol = "/NQ";
input showLabel = yes;
def close01 = close(symbol, period = AggregationPeriod.TEN_MIN);
def avg1 = MovAvgExponential (close01, 9, 0);
AddLabel(if showLabel == yes then 1 else 0, if close01 > avg1 then " NQ - Bullish " else if close01 < avg1 then " NQ - Bearish " else " NQ - Flat ", if close01 > avg1 then color.green else if close01 < avg1 then color.red else color.gray);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on July 7, 2021 9:52 am
0
It seems to work when my chart is on /NQ. But it does not seem to work to pull /NQ when I am on any other chart. As an example, when I am on TSLA chart, it is only pulling back where TSLA is in relation to the EMA. I am hoping to get it to always pull /NQ not matter what chart I am on.
( at July 7, 2021 11:01 am)
0
I think I have it, with a little more complexity: input symbol = "/NQ"; input showLabel = yes; def close01 = close(symbol, period = aggregationperiod.TEN_MIN); def avg1 = reference movAvgExponential (close(symbol, period = aggregationperiod.TEN_MIN), 9, 0); addlabel(if ShowLabel == yes then 1 else 0, if close(symbol, period = aggregationperiod.TEN_MIN) > avg1 then symbol + " - Bullish " else if close(symbol, period = aggregationperiod.TEN_MIN) < avg1 then symbol + " - Bearish " else symbol + " - Flat ", if close(symbol, period = aggregationperiod.TEN_MIN) > avg1 then color.green else if close(symbol, period = aggregationperiod.TEN_MIN) < avg1 then color.red else color.gray);
( at July 7, 2021 11:09 am)
0
Thanks for the feedback. I have updated my answer to correct the mistakes in your example code.
( at July 7, 2021 11:23 am)