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));
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: