Hi BenTen: As you know ToS "canned" indicators based on a type of average require a period "length" defined as a number of "bars". Chart bars are specified in "timeframe". As the user changes the chart timeframe, the moving averages change.
I prefer to chart a fixed time duration(s) for all indicators so the average remains a similar "filter bandwidth" and use different timeframes to zoom across various time periods. For example fix exponential moving average "length" with the following statement
expaverage (close (period=aggregationperiod.day), length=XXX) where xxx is specified to be 21, 50, 200.
I would like to modify PPO script to utilize fixed aggregation periods such as PPO(5,21,3) for nfast = 5 days, nslow=21days, and nsmooth=3days. I will also create PPO studies for (21,50,9) and PPO(120,200,50).
Does this make sense?
Thanks!
Try this and let me know if this is what you're looking for.
The timeframe is set to Hourly but you can change it to whatever timeframe you want from the indicator's settings.
Code:
# PPO
# Mobius
# V01.03.2014
declare lower;
input Period = aggregationPeriod.HOUR;
input c = close;
input AvgType = AverageType.Simple;
input nFast = 8;
input nSlow = 13;
input nSmooth = 5;
plot PPO = ((MovingAverage(AverageType = AvgType, close(period = Period), nFast) -
MovingAverage(AverageType = AvgType, close(period = Period), nSlow)) /
MovingAverage(AverageType = AvgType, close(period = Period), nSlow));
PPO.SetPaintingStrategy(PaintingStrategy.Histogram);
PPO.AssignValueColor(if PPO > 0
then color.green
else color.red);
plot smooth = MovingAverage(AverageType = AvgType, PPO, nSmooth);
smooth.SetPaintingStrategy(PaintingStrategy.Line);
smooth.SetDefaultColor(Color.Cyan);
# End Code PPO