Repaints Three Little Pigs MTF Swing Trading For ThinkOrSwim

Repaints

samport

New member
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
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Honestly, I haven't been able to watch the indicator in real time to check for this. As a swing trader, I am not concerned with repainting as much as others. I would be interested to know this for sure though. It is a starting point and I am sure it can be improved upon.
 
@astro_phx @samport When placing a higher timeframe indicator on a lower timeframe chart there will ALWAYS be repainting until the higher timeframe candle closes. If there is a 4hr indicator on a 15min chart, it will continually repaint all the previous 16 bars until the 4hr candle close.

This is built-into the DNA of all multi-timeframe indicators. By definition the bars cannot know what the final close is going to be until the close actually happens.
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
232 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top