# Plot differences between moving averages as lower indicator?

H

#### Hopperious

##### New member
VIP
1 line would be the difference of the 4EMA - 10SMA

the other line would be the difference of the 6EMA - 15SMA

used on any time frame -- T

##### Active member
2019 Donor
VIP
Try this very simple script...

Code:
``````#Plot lines with differences between two moving averages

declare lower;

input price = close;
input ema1 = 4;
input sma1 = 10;
input ema2 = 6;
input sma2 = 15;

plot line1 = ExpAverage(price, ema1) - Average(price, sma1);
plot line2 = ExpAverage(price, ema2) - Average(price, sma2);

line1.SetDefaultColor(Color.GREEN);
line2.SetDefaultColor(Color.RED);``````

• ccurtin
H

#### Hopperious

##### New member
VIP
tyvm - can we make this show an hour time frame but have it on lets say a 15min chart ?

T

##### Active member
2019 Donor
VIP
tyvm - can we make this show an hour time frame but have it on lets say a 15min chart ?

This will only work on a time-based chart that is the same or smaller time-frame than the aggregation period but you can try this.

Code:
``````declare lower;

input Period = aggregationPeriod.HOUR;
input ema1 = 4;
input sma1 = 10;
input ema2 = 6;
input sma2 = 15;

plot line1 = ExpAverage(close(period = Period), ema1) - Average(close(period = Period), sma1);
plot line2 = ExpAverage(close(period = Period), ema2) - Average(close(period = Period), sma2);

line1.SetDefaultColor(Color.GREEN);
line2.SetDefaultColor(Color.RED);``````

F

#### FoofAndFun

##### New member
Thanks for sharing, I realized this is actually close to something I want and that is way to tell how strong the difference is between a MA compared to recent history. This might help remove false-starts on MA (mostly MACD) indicators. I'm not quite sure what I'm looking for though. I can't just grab the median(x, length).

Code:
``````#Plot lines with differences between two moving averages

declare lower;

input price = close;
input sma1 = 9;
input sma2 = 26;

plot line1 = Average(price, sma1) - Average(price, sma2);
plot ZeroLine = 0;

plot Max = Highest(Average(price, sma1) - Average(price, sma2), sma2);

plot StrongUpSignal = if line1 equals Max
and line1 crosses Max
and price is greater than Zeroline
then ZeroLine else Double.NaN;

StrongUpSignal.SetDefaultColor(Color.UPTICK);
StrongUpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);

line1.SetDefaultColor(Color.GREEN);``````

Last edited: