a1cturner
Well-known member
I am trying to add a time frame input so that the indicator does not change when I am switching between different charts with different time frames.
My end goal is to see if the MACD crossed on the daily chart while I'm looking at the 10 minute chart or if it crossed on the hourly chart while I'm looking at the daily chart etc. My plan is to add an indicator for the MACD cross using a 10 minute, 1 hour, daily, and weekly time frames. This is an upper study.
I am also trying to keep my doji indicator on a daily time frame when I switch to a 10 minute, hourly chart etc.
I do understand the input Time_Frame = getaggregationperiod.Day code but I don't know where to put the Time_Frame further down in the code.
---------------------------------------------
#MACD Cross
#Justin Turner
Declare Upper;
def lookback = 1;
def fastLength = 12;
def slowLength = 26;
def MACDLength = 9;
def averageType = AverageType.EXPONENTIAL;
def showBreakoutSignals = no;
def Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
def Avg = MovingAverage(averageType, Value, MACDLength);
def bull_cross = value crosses above avg;
def bear_cross = value crosses below avg;
def bull_lookback = highest(bull_cross, lookback);
def bear_lookback = highest(bear_cross, lookback);
AddLabel (yes,
if
bull_lookback then "MACD Bull X"
else if
bear_lookback then "MACD Bear X"
else if
bull_lookback within 2 bars then "MACD Bull XX"
else if bear_lookback within 2 bars then "MACD Bear XX"
else "-",
if bull_lookback then createcolor (0,204, 0)
else if
bear_lookback then createcolor (204, 0, 0)
else if
bull_lookback within 2 bars then createcolor (0, 153, 0)
else if
bear_lookback within 2 bars then createcolor (153, 0, 0)
else color.white);
------------------------------------------------
#Doji
#Justin Turner
Declare upper;
def Doji = reference Doji(bodyFactor = 0.1);
addlabel (yes,
if
Doji within 1 bar then “D1”
else if
Doji within 2 bars then “D2”
else
“-“,
if
Doji within 1 bar then color.dark_green
else if
Doji within 2 bars then createcolor (153, 153, 0)
else
color.white);
My end goal is to see if the MACD crossed on the daily chart while I'm looking at the 10 minute chart or if it crossed on the hourly chart while I'm looking at the daily chart etc. My plan is to add an indicator for the MACD cross using a 10 minute, 1 hour, daily, and weekly time frames. This is an upper study.
I am also trying to keep my doji indicator on a daily time frame when I switch to a 10 minute, hourly chart etc.
I do understand the input Time_Frame = getaggregationperiod.Day code but I don't know where to put the Time_Frame further down in the code.
---------------------------------------------
#MACD Cross
#Justin Turner
Declare Upper;
def lookback = 1;
def fastLength = 12;
def slowLength = 26;
def MACDLength = 9;
def averageType = AverageType.EXPONENTIAL;
def showBreakoutSignals = no;
def Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
def Avg = MovingAverage(averageType, Value, MACDLength);
def bull_cross = value crosses above avg;
def bear_cross = value crosses below avg;
def bull_lookback = highest(bull_cross, lookback);
def bear_lookback = highest(bear_cross, lookback);
AddLabel (yes,
if
bull_lookback then "MACD Bull X"
else if
bear_lookback then "MACD Bear X"
else if
bull_lookback within 2 bars then "MACD Bull XX"
else if bear_lookback within 2 bars then "MACD Bear XX"
else "-",
if bull_lookback then createcolor (0,204, 0)
else if
bear_lookback then createcolor (204, 0, 0)
else if
bull_lookback within 2 bars then createcolor (0, 153, 0)
else if
bear_lookback within 2 bars then createcolor (153, 0, 0)
else color.white);
------------------------------------------------
#Doji
#Justin Turner
Declare upper;
def Doji = reference Doji(bodyFactor = 0.1);
addlabel (yes,
if
Doji within 1 bar then “D1”
else if
Doji within 2 bars then “D2”
else
“-“,
if
Doji within 1 bar then color.dark_green
else if
Doji within 2 bars then createcolor (153, 153, 0)
else
color.white);