StochasticMomentumIndex higher time frame label


Category:
0
0

Hello Pete,
I was wondering if you can help me modify this code. I want to be able to display the 4Hour, Daily and Weekly SMI labels on my main chart.
Ex: 4H: Buy or Sell. Day: Buy or Sell. Week: Buy or Sell. Thank you so much for your help!

def smi = reference StochasticMomentumIndex().”SMI”;
def smiAvg = StochasticMomentumIndex().”AvgSMI”;
AddLabel(yes, “SMI”, if smi >= smiAvg then Color.GREEN else Color.RED);
input timeFrame = AggregationPeriod.DAY;

Marked as spam
Posted by (Questions: 9, Answers: 4)
Asked on December 12, 2022 6:52 pm
70 views
0
Private answer

This solution plots one label for the selected time frame. User inputs allow you to adjust the time frame and label text as needed. Add the chart study to the chart as many times as you like and set each one to a different time frame:

input timeFrameOne = AggregationPeriod.DAY;
input labelText = "Daily SMI";
input percentDLength = 3;
input percentKLength = 5;
def minLow = lowest(low(period = timeFrameOne), percentKLength);
def maxHigh = highest(high(period = timeFrameOne), percentKLength);
def relDiff = close(period = timeFrameOne) - (maxHigh + minLow)/2;
def diff = maxHigh - minLow;
def avgrel = ExpAverage(ExpAverage(relDiff, percentDLength), percentDLength);
def avgdiff = ExpAverage(ExpAverage(diff, percentDLength), percentDLength);
def smi = if avgdiff != 0 then avgrel / (avgdiff / 2) * 100 else 0;
def avgSMI = ExpAverage(smi, percentDLength);
AddLabel(yes, labelText, if smi >= avgSMI then Color.GREEN else Color.RED);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on December 12, 2022 8:07 pm