MTF Rate of Change

msmmlee

New member
Plus
I am trying to figure out if the Rate of Change indicator can be modified to show three different time frames. I'm hoping for help... I'll be glad to buy a cup of coffee or lunch! I added the "input agg" tag into the ROC code below but it isn't working. I also tried ChatGPT but it is giving me three lengths, not three aggregation periods (below).

declare lower;

input agg = aggregationPeriod.FIVE_MIN;

input length = 14;
input colorNormLength = 14;
input price = close;

assert(length > 0, "'length' must be positive: " + length);

plot ROC = if price[length] != 0 then (price / price[length] - 1) * 100 else 0;
plot ZeroLine = 0;

ROC.DefineColor("Highest", Color.YELLOW);
ROC.DefineColor("Lowest", Color.LIGHT_RED);
ROC.AssignNormGradientColor(colorNormLength, ROC.color("Lowest"), ROC.color("Highest"));
ZeroLine.SetDefaultColor(GetColor(5));

ChatGPT:

# Define Inputsinput length1 = 14;input length2 = 21;input length3 = 28;# Calculate ROC for different aggregation periodsdef roc1 = close / close[length1] - 1;def roc2 = close / close[length2] - 1;def roc3 = close / close[length3] - 1;# Plotting the ROC linesplot ROC_Line1 = roc1;plot ROC_Line2 = roc2;plot ROC_Line3 = roc3;# Plot FormattingROC_Line1.SetDefaultColor(GetColor(1));ROC_Line2.SetDefaultColor(GetColor(2));ROC_Line3.SetDefaultColor(GetColor(3));
 
Last edited by a moderator:
Solution
I am trying to figure out if the Rate of Change indicator can be modified to show three different time frames. I'm hoping for help... I'll be glad to buy a cup of coffee or lunch! I added the "input agg" tag into the ROC code below but it isn't working. I also tried ChatGPT but it is giving me three lengths, not three aggregation periods (below).

declare lower;

input agg = aggregationPeriod.FIVE_MIN;

input length = 14;
input colorNormLength = 14;
input price = close;

assert(length > 0, "'length' must be positive: " + length);

plot ROC = if price[length] != 0 then (price / price[length] - 1) * 100 else 0;
plot ZeroLine = 0;

ROC.DefineColor("Highest", Color.YELLOW);
ROC.DefineColor("Lowest", Color.LIGHT_RED)...
I am trying to figure out if the Rate of Change indicator can be modified to show three different time frames. I'm hoping for help... I'll be glad to buy a cup of coffee or lunch! I added the "input agg" tag into the ROC code below but it isn't working. I also tried ChatGPT but it is giving me three lengths, not three aggregation periods (below).

declare lower;

input agg = aggregationPeriod.FIVE_MIN;

input length = 14;
input colorNormLength = 14;
input price = close;

assert(length > 0, "'length' must be positive: " + length);

plot ROC = if price[length] != 0 then (price / price[length] - 1) * 100 else 0;
plot ZeroLine = 0;

ROC.DefineColor("Highest", Color.YELLOW);
ROC.DefineColor("Lowest", Color.LIGHT_RED);
ROC.AssignNormGradientColor(colorNormLength, ROC.color("Lowest"), ROC.color("Highest"));
ZeroLine.SetDefaultColor(GetColor(5));

ChatGPT:

# Define Inputsinput length1 = 14;input length2 = 21;input length3 = 28;# Calculate ROC for different aggregation periodsdef roc1 = close / close[length1] - 1;def roc2 = close / close[length2] - 1;def roc3 = close / close[length3] - 1;# Plotting the ROC linesplot ROC_Line1 = roc1;plot ROC_Line2 = roc2;plot ROC_Line3 = roc3;# Plot FormattingROC_Line1.SetDefaultColor(GetColor(1));ROC_Line2.SetDefaultColor(GetColor(2));ROC_Line3.SetDefaultColor(GetColor(3));

This uses the script function to create 3 different agg plots of the ROC.

Screenshot 2024-01-11 072520.png

Code:
declare lower;

script rofc {
    input agg = AggregationPeriod.FIVE_MIN;

    input length = 14;
    input colorNormLength = 14;
    input price = FundamentalType.CLOSE;

    Assert(length > 0, "'length' must be positive: " + length);

    plot ROC = if Fundamental(price, period = agg)[length] != 0 then (Fundamental(price, period = agg) / Fundamental(price, period = agg)[length] - 1) * 100 else 0;
}
plot ZeroLine = 0;

input agg1 = AggregationPeriod.MIN;
input agg2 = AggregationPeriod.THREE_MIN;
input agg3 = AggregationPeriod.FIVE_MIN;
input length = 14;
input colorNormLength = 14;
input price = FundamentalType.CLOSE;

def na = Double.NaN;

plot roc1 = if IsNaN(close) then na else rofc(agg1, length = length, "color norm length" = colorNormLength, price = price);
roc1.DefineColor("Highest", Color.YELLOW);
roc1.DefineColor("Lowest", Color.LIGHT_RED);
roc1.AssignNormGradientColor(colorNormLength, roc1.Color("Lowest"), roc1.Color("Highest"));

plot roc2 = if IsNaN(close) then na else rofc(agg2, length = length, "color norm length" = colorNormLength, price = price);
roc2.DefineColor("Highest", Color.YELLOW);
roc2.DefineColor("Lowest", Color.LIGHT_RED);
roc2.AssignNormGradientColor(colorNormLength, roc2.Color("Lowest"), roc2.Color("Highest"));

plot roc3 = if IsNaN(close) then na else rofc(agg3, length = length, "color norm length" = colorNormLength, price = price);
roc3.DefineColor("Highest", Color.YELLOW);
roc3.DefineColor("Lowest", Color.LIGHT_RED);
roc3.AssignNormGradientColor(colorNormLength, roc3.Color("Lowest"), roc3.Color("Highest"));

ZeroLine.SetDefaultColor(GetColor(5));

input show_bubble = yes;
input bubblemover = 1;
def b = bubblemover;
def mover = show_bubble and IsNaN(close[b]) and !IsNaN(close[b + 1]);

AddChartBubble(mover, roc1[b + 1], agg1 / 60000 + "m", roc1.TakeValueColor());
AddChartBubble(mover, roc2[b + 1], agg2 / 60000 + "m", roc2.TakeValueColor());
AddChartBubble(mover, roc3[b + 1], agg3 / 60000 + "m", roc3.TakeValueColor());

#
 
Solution

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

Thread starter Similar threads Forum Replies Date
B MTF Stochastic Questions 1
E MTF Stacked Moving Averages Questions 3
M MTF AMA Questions 2
C MTF EMA cloud Questions 1
V MTF Marubozu signals Questions 0

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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