I am always seeking for a better method to find MTF alignment to trade with the trend. I discovered the Three Little Pigs strategy on Babypips.com where it has been tweaked and refined extensively for trading FOREX. I see no reason this method/strategy could not be applied for stocks, options, etc. I searched for a thinkscript for TOS but only found scripts for MT4 and other platforms. I constructed this indicator and used some ideas from this forum to attempt to display the plots from higher timeframes. I am posting this here for the community to consider and perhaps improve. Immediate ideas for alerts, arrows, price bar color changes come to mind so feel free to test it out and make corrections where they are needed. Let me know what you think!
Code:
#Three Little Pigs indicator
#inspired/adapted from Three Little Pigs trading system for FOREX
#see this website for more information: https://www.babypips.com/trading/trading-system-test-3-little-pigs
#First Little Pig = 55 SMA on Weekly TF
#Second Little Pig = 21 SMA on Daily TF
#Third Little Pig = 34 SMA on 4H TF
declare lower;
input MA1 = 55;
input MA2 = 21;
input MA3 = 34;
input AvgType = averageType.SIMPLE;
input showdotplot = yes;
input useupper_lower = {default lower, upper};
input Period1 = AggregationPeriod.WEEK;
input Period2 = AggregationPeriod.DAY;
input Period3 = AggregationPeriod.FOUR_HOURS;
def AggPer1 = MovingAverage(AvgType, close(period = Period1), MA1);
def AggPer2 = MovingAverage(AvgType, close(period = Period2), MA2);
def AggPer3 = MovingAverage(AvgType, close(period = Period3), MA3);
plot Agg1lower = if close > AggPer1 then 1.8 else Double.NaN;
Agg1lower.SetPaintingStrategy(PaintingStrategy.POINTS);
Agg1lower.SetLineWeight(3);
Agg1lower.SetDefaultColor(Color.GREEN);
plot Agg2lower = if close < AggPer1 then 1.8 else Double.NaN;
Agg2lower.SetPaintingStrategy(PaintingStrategy.POINTS);
Agg2lower.SetLineWeight(3);
Agg2lower.SetDefaultColor(Color.RED);
plot Agg3Lower = if close > AggPer2 then 1.6 else Double.NaN;
Agg3Lower.SetPaintingStrategy(PaintingStrategy.POINTS);
Agg3Lower.SetLineWeight(3);
Agg3Lower.SetDefaultColor(Color.GREEN);
plot Agg4Lower = if close < AggPer2 then 1.6 else Double.NaN;
Agg4Lower.SetPaintingStrategy(PaintingStrategy.POINTS);
Agg4Lower.SetLineWeight(3);
Agg4Lower.SetDefaultColor(Color.RED);
plot Agg5Lower = if close > AggPer3 then 1.4 else Double.NaN;
Agg5Lower.SetPaintingStrategy(PaintingStrategy.POINTS);
Agg5Lower.SetLineWeight(3);
Agg5Lower.SetDefaultColor(Color.GREEN);
plot Agg6Lower = if close < AggPer3 then 1.4 else Double.NaN;
Agg6Lower.SetPaintingStrategy(PaintingStrategy.POINTS);
Agg6Lower.SetLineWeight(3);
Agg6Lower.SetDefaultColor(Color.RED);
plot lineh = if IsNaN(close) or showdotplot == no
then Double.NaN
else if useupper_lower == useupper_lower.lower then 2 else Double.NaN;
plot linel = if IsNaN(close) or showdotplot == no
then Double.NaN
else if useupper_lower == useupper_lower.lower then 1.2 else Double.NaN;
lineh.SetDefaultColor(Color.DARK_GRAY);
linel.SetDefaultColor(Color.DARK_GRAY);
#Labels with selection to turn them on/off
input showlabels = yes;
AddLabel(showlabels, "Top = Weekly (55 SMA)", Color.GRAY);
AddLabel(showlabels, "Middle = Daily (21 SMA)", Color.GRAY);
AddLabel(showlabels, "Bottom = 4 HOUR (34 SMA)", Color.GRAY);
# End Code - Three Little Pigs