Don't know if I asked the question properly but what I'm trying to do is add variables to the "period" input so that I don't have to add the indicator for each time frame that I'm interested in. Won't let me define "time_frame" in the code.
Here is the original snippet of code in it's entirety that I'm trying to modify.
I mean, I guess it's really not that big of a deal as I can change the 'input period = x' line to give me the time periods but I would rather only have to add the indicator once.
Thank you for any help that you can provide.
Code:
def time_frame = if GetAggregationPeriod() == AggregationPeriod.MONTH then AggregationPeriod.MONTH
else if AggregationPeriod.WEEK then AggregationPeriod.WEEK
else if AggregationPeriod.FOUR_DAYS then AggregationPeriod.FOUR_DAYS
else if AggregationPeriod.THREE_DAYS then AggregationPeriod.THREE_DAYS
else if AggregationPeriod.TWO_DAYS then AggregationPeriod.TWO_DAYS
else if AggregationPeriod.DAY then AggregationPeriod.DAY
else if AggregationPeriod.FOUR_HOURS then AggregationPeriod.FOUR_HOURS
else if AggregationPeriod.TWO_HOURS then AggregationPeriod.TWO_HOURS
else if AggregationPeriod.HOUR then AggregationPeriod.HOUR
else if AggregationPeriod.THIRTY_MIN then AggregationPeriod.THIRTY_MIN
else if AggregationPeriod.TWENTY_MIN then AggregationPeriod.TWENTY_MIN
else if AggregationPeriod.FIFTEEN_MIN then AggregationPeriod.FIFTEEN_MIN
else if AggregationPeriod.TEN_MIN then AggregationPeriod.TEN_MIN
else if AggregationPeriod.FIVE_MIN then AggregationPeriod.FIVE_MIN
else if AggregationPeriod.FOUR_MIN then AggregationPeriod.FOUR_MIN
else if AggregationPeriod.THREE_MIN then AggregationPeriod.THREE_MIN
else if AggregationPeriod.TWO_MIN then AggregationPeriod.TWO_MIN
else if AggregationPeriod.MIN then AggregationPeriod.MIN
else "";
input period = time_frame;
Here is the original snippet of code in it's entirety that I'm trying to modify.
Code:
input period = AggregationPeriod.DAY;
DefineGlobalColor("UpTrend", Color.Green);
DefineGlobalColor("DownTrend", Color.RED);
DefineGlobalColor("NoTrend", Color.GRAY);
script RSM_ {
input aP = AggregationPeriod.DAY;
# RSI
def lengthRSI = 7;
def averageTypeRSI = AverageType.WILDERS;
# Stochastic
def over_boughtSt = 80;
def over_soldSt = 20;
def KPeriod = 14;
def DPeriod = 3;
input averageTypeStoch = AverageType.SIMPLE;
# MACD
def fastLength = 12;
def slowLength = 26;
def MACDLength = 9;
def averageTypeMACD = AverageType.EXPONENTIAL;
###############################################################
########## RSI #########
################################################################
def NetChgAvg = MovingAverage(averageTypeRSI, close(period = aP) - close(period = aP)[1], lengthRSI);
def TotChgAvg = MovingAverage(averageTypeRSI, AbsValue(close(period = aP) - close(period = aP)[1]), lengthRSI);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI_ = 50 * (ChgRatio + 1);
################################################################
########## Stochastic Slow #########
################################################################
def SlowK_ = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, high(period = aP), low(period = aP), close(period = aP), 3, if (averageTypeStoch == 1) then AverageType.SIMPLE else AverageType.EXPONENTIAL).FullK;
def SlowD_ = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, high(period = aP), low(period = aP), close(period = aP), 3, if (averageTypeStoch == 1) then AverageType.SIMPLE else AverageType.EXPONENTIAL).FullD;
################################################################
########## MACD ###########
################################################################
def Value_ = MovingAverage(averageTypeMACD, close(period = aP), fastLength) - MovingAverage(averageTypeMACD, close(period = aP), slowLength);
def Avg_ = MovingAverage(averageTypeMACD, Value_, MACDLength);
def Diff_ = Value_ - Avg_;
#################################################################
########## Trend & Labels #########
#################################################################
def UpTrend_ = if RSI_ >= 50 and SlowD_ >= 50 and Value_ > Avg_ then 1 else 0;
def DownTrend_ = if RSI_ < 50 and SlowD_ < 50 and Value_ < Avg_ then 1 else 0;
plot Trend_ = if UpTrend_ then 1 else if DownTrend_ then 0 else -1;
}
def currentPeriod = GetAggregationPeriod();
def RSM;
if period >= currentPeriod {
RSM = RSM_(aP = period);
} else {
RSM = Double.NaN;
}
AddLabel(!IsNaN(RSM), if period == AggregationPeriod.MONTH then "M"
else if period == AggregationPeriod.WEEK then "W"
else if period == AggregationPeriod.FOUR_DAYS then "4D"
else if period == AggregationPeriod.THREE_DAYS then "3D"
else if period == AggregationPeriod.TWO_DAYS then "2D"
else if period == AggregationPeriod.DAY then "D"
else if period == AggregationPeriod.FOUR_HOURS then "4H"
else if period == AggregationPeriod.TWO_HOURS then "2H"
else if period == AggregationPeriod.HOUR then "60m"
else if period == AggregationPeriod.THIRTY_MIN then "30m"
else if period == AggregationPeriod.TWENTY_MIN then "20m"
else if period == AggregationPeriod.FIFTEEN_MIN then "15m"
else if period == AggregationPeriod.TEN_MIN then "10m"
else if period == AggregationPeriod.FIVE_MIN then "5m"
else if period == AggregationPeriod.FOUR_MIN then "4m"
else if period == AggregationPeriod.THREE_MIN then "3m"
else if period == AggregationPeriod.TWO_MIN then "2m"
else if period == AggregationPeriod.MIN then "1m"
else "", if RSM == 1 then GlobalColor("UpTrend") else if RSM == 0 then GlobalColor("DownTrend") else GlobalColor("NoTrend"));
I mean, I guess it's really not that big of a deal as I can change the 'input period = x' line to give me the time periods but I would rather only have to add the indicator once.
Thank you for any help that you can provide.