Backtesting and Using MTF indicators

T

Tostechnical

Member
So I am using the CCI_ATR Supertrend MTF indicators. I look for signals on the daily charts with confirmation on the Weekly and Monthly time frame. The issue I encounter with backtesting this in TOS and using it on a day to day basis is that often time the Weekly signal will repaint. Meaning that sometimes I am left with a position in the wrong direction and I have to close with a small loss plus commissions. In TOS backtesting it uses the Weekly close, high and low for ALL daily bars for the week and does not take into account that they change from day to day. I understand this is not a bug. Is there a way to mitigate false signals on the Weekly and Monthly? An example is on 12/3 I got some weekly and daily sell signals for some stocks however the next day the weekly sell signal went away. Anyway to mitigate this?

Thanks this forum has been extremely helpful with a great community :)

here is the code for my indicator, can't seem to find it in forums.

Code:
declare lower;

# GLOBAL DEFINITIONS

DefineGlobalColor("TrendUp", CreateColor(0, 254, 30));
DefineGlobalColor("TrendDown", CreateColor(255, 3, 2));

input agg = AggregationPeriod.DAY;
input agg2 = AggregationPeriod.WEEK;
input agg3 = AggregationPeriod.MONTH;

input lengthCCI = 14;
input lengthATR = 4;
input AtrFactor = 0.7;

input DotSize = 3;
input n = 3;
input Factor = 1.3;
input Pd = 60;
input Lookback = 3;

def n1  = n + 1;

# AGGREGATION 1

def c = close(period = agg);
def h = high(period = agg);
def l = low(period = agg);
def pricedata = HL2(period = agg);
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 MT1_Dot = if IsNaN(close) then Double.NaN else 1;
MT1_Dot.SetPaintingStrategy(PaintingStrategy.Points);
MT1_Dot.SetLineWeight(DotSize);
MT1_Dot.AssignValueColor(if c < MT1 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
#AddChartBubble(!IsNaN(close[n1]) and IsNaN(close[n]), 1, (agg/1000/60) + " min", Color.Yellow, yes);

# AGGREGATION 2

def c2 = close(period = agg2);
def h2 = high(period = agg2);
def l2 = low(period = agg2);
def pricedata2 = HL2(period = agg2);
def ATRcci2 = Average(TrueRange(h2, c2, l2), lengthATR) * AtrFactor;
def price2 = c2 + l2 + h2;
def linDev2 = lindev(price2, lengthCCI);
def CCI2 = if linDev2 == 0 then 0 else (price2 - Average(price2, lengthCCI)) / linDev2 / 0.015;
def MT2 = if CCI2 > 0
          then Max(MT2[1], pricedata2 - ATRcci2)
          else Min(MT2[1], pricedata2 + ATRcci2);
plot MT2_Dot = if IsNaN(close) then Double.NaN else 2;
MT2_Dot.SetPaintingStrategy(PaintingStrategy.Points);
MT2_Dot.SetLineWeight(DotSize);
MT2_Dot.AssignValueColor(if c2 < MT2 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
#AddChartBubble(!IsNaN(close[n1]) and IsNaN(close[n]), 2, (agg2/1000/60) + " min", Color.Yellow, yes);
addlabel(yes, "prev agg2", if c2[1] < MT2[1] then color.red else color.green);
# AGGREGATION 3

def c3 = close(period = agg3);
def h3 = high(period = agg3);
def l3 = low(period = agg3);
def pricedata3 = HL2(period = agg3);

def ATRcci3 = Average(TrueRange(h3, c3, l3), lengthATR) * AtrFactor;
def price3 = c3 + l3 + h3;
def linDev3 = lindev(price3, lengthCCI);
def CCI3 = if linDev3 == 0 then 0 else (price3 - Average(price3, lengthCCI)) / linDev3 / 0.015;
def MT3 = if CCI3 > 0
          then Max(MT3[1], pricedata3 - ATRcci3)
          else Min(MT3[1], pricedata3 + ATRcci3);
plot MT3_Dot = if IsNaN(close) then Double.NaN else 3;
MT3_Dot.SetPaintingStrategy(PaintingStrategy.Points);
MT3_Dot.SetLineWeight(DotSize);
MT3_Dot.AssignValueColor(if c3 < MT3 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
#AddChartBubble(!IsNaN(close[n1]) and IsNaN(close[n]), 3, (agg3/1000/60) + " min", Color.Yellow, yes);
# End Trend Magic MTF
 
BenTen

BenTen

Administrative
Staff
VIP
What you just referred to is not repainting. Think of using this indicator on the 5m chart. Say you see a signal on the current 5m candle; you would want to wait for that candle to close with the signal intact. After that happen, the signal is confirmed. Similar idea to how it should work with the weekly timeframe. You would have to wait for the current weekly candle to close for confirmation. Using the weekly timeframe to day trade would be a bad idea, especially if you rely on this type of indicator.
 
T

Tostechnical

Member
I use this to swing trade. Holding period of around 3-5 days. How would you code that into TOS backtest? I am finding it difficult. Thanks for the quick response, very helpful.
 
markos

markos

Well-known member
VIP
@BenTen for a swing trade of 3-5 days, would you use 15 minute, 4 hour, and Day as your 3 aggs to start with? Also, I believe the chart bubbles would need to be adjusted.
@Tostechnical Read up on CCI if you are not familiar with its nuances. Also use this tab in TOS to learn more: Click Education>Learning Center>Technical Analysis.
 
BenTen

BenTen

Administrative
Staff
VIP
@markos I would start with the hourly and then go to daily.
 
T

tomsk

Well-known member
VIP
I was thinking in terms of @Tostechnical 's question on the study above with three time frames.

If anything at all, the market looks exhausted with not much commitment out there. /ES has been rallying of late with volumes dipping - not much commitment there.
 
T

Tostechnical

Member
@markos I am pretty familiar with the nuances, seems like these dashboards of MTF kinda take them out. Viewing CCI on its own allows me to see them. I pretty much left this indicator because it leaves out a lot of data you cannot see in the dots.

After using it, IMO it seems like a standalone CCI would be better, and just use a flex grid for different time frames. This brings up a bigger issues I have with CSA indicators like the CSA dashboard. Although they do allow you to combine multiple indicators or timeframes into one, a big problem with them is that you cannot see the nuances of the indicators. Such as divergences, whether the indicators is making new highs/lows, how steep is the slope of the indicator, and the distance between indicator and signal lines. I tried adding those data points into a CSA indicator like the one above but it jsut became too cluttered.

Just my two cents.
 

Similar threads

Top