Updated Trend Magic indicator to include 3 user selected time frames.
Code:
# Trend Magic MultiTime Frame
#Update to original Trend Magic adding multiTime Frames
#Horserider 8/8/2019
input agg = AggregationPeriod.FIFTEEN_MIN;
def c = close(period = agg);
def h = high(period = agg);
def l = low(period = agg);
def pricedata = hl2(period = agg);
DefineGlobalColor("TrendUp", CreateColor(0, 254, 30));
DefineGlobalColor("TrendDown", CreateColor(255, 3, 2));
input lengthCCI = 50;
input lengthATR = 5;
input AtrFactor = 0.7;
def ATRcci = Average(TrueRange(h, c, l), lengthATR) * AtrFactor;
def price = c + l + h;
def linDev = LinDev(price, lengthCCI);
def CCI = if linDev == 0
then 0
else (price - Average(price, lengthCCI)) / linDev / 0.015;
def MT1 = if CCI > 0
then Max(MT1[1], pricedata - ATRcci)
else Min(MT1[1], pricedata + ATRcci);
plot data = MT1;
data.AssignValueColor(if c < MT1 then Color.RED else Color.GREEN);
# Agg Period 2
input agg2 = AggregationPeriod.DAY;
def c2 = close(period = agg2);
def h2 = high(period = agg2);
def l2 = low(period = agg2);
def pricedata2 = hl2(period = agg2);
DefineGlobalColor("TrendUp", CreateColor(0, 254, 30));
DefineGlobalColor("TrendDown", CreateColor(255, 3, 2));
input lengthCCI2 = 50;
input lengthATR2 = 5;
input AtrFactor2 = 0.7;
def ATRcci2 = Average(TrueRange(h2, c2, l2), lengthATR2) * AtrFactor2;
def price2 = c2 + l2 + h2;
def linDev2 = LinDev(price2, lengthCCI2);
def CCI2 = if linDev2 == 0
then 0
else (price2 - Average(price2, lengthCCI2)) / linDev2 / 0.015;
def MT2 = if CCI2 > 0
then Max(MT2[1], pricedata2 - ATRcci2)
else Min(MT2[1], pricedata2 + ATRcci2);
plot data2 = MT2;
data2.AssignValueColor(if c2 < MT2 then Color.RED else Color.GREEN);
DefineGlobalColor("TrendUp", CreateColor(0, 254, 30));
DefineGlobalColor("TrendDown", CreateColor(255, 3, 2));
# Agg Period 3
input agg3 = AggregationPeriod.DAY;
def c3 = close(period = agg3);
def h3 = high(period = agg3);
def l3 = low(period = agg3);
def pricedata3 = hl2(period = agg3);
DefineGlobalColor("TrendUp", CreateColor(0, 254, 30));
DefineGlobalColor("TrendDown", CreateColor(255, 3, 2));
input lengthCCI3 = 50;
input lengthATR3 = 5;
input AtrFactor3 = 0.7;
def ATRcci3 = Average(TrueRange(h3, c3, l3), lengthATR3) * AtrFactor3;
def price3 = c3 + l3 + h3;
def linDev3 = LinDev(price3, lengthCCI3);
def CCI3 = if linDev3 == 0
then 0
else (price3 - Average(price3, lengthCCI3)) / linDev3 / 0.015;
def MT3 = if CCI3 > 0
then Max(MT3[1], pricedata3 - ATRcci3)
else Min(MT3[1], pricedata3 + ATRcci3);
plot data3 = MT3;
data3.AssignValueColor(if c3 < MT3 then Color.RED else Color.GREEN);
DefineGlobalColor("TrendUp", CreateColor(0, 254, 30));
DefineGlobalColor("TrendDown", CreateColor(255, 3, 2));
Attachments
Last edited: