Heiken-Ashi Moving Average (HAMA) for ThinkorSwim

Would someone be able to help code a strategy based on HAMA? I think it could be a useful strategy to buy on the first green candle that closes and then reverse the position on the first red candle that closes. The only challenge i foresee is that since the study is hiding the underlying renko bricks and generating HAMA candles, I'm not sure if TOS can generate buy sell signals based on the candles that the indicator is producing. I am running this indicator on a 2 tick renko and it looks to be producing favorable results.

Here is the indicator. Hope someone can help. Thanks in advance.

https://tos.mx/pLITkME
 

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

Not much to say beyond the title. It is a strategy utilizing 3 HAMAs.

MxcZ1wn.png


Code:
# START
input paintBars = yes;
input length1 = 35;
def HAopen;
def HAhigh;
def HAlow;
def HAclose;
HAopen = CompoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close) / 2);
HAhigh = Max(high, close[1]);
HAlow = Min(low, close[1]);
HAclose = (HAopen + HAclose[1] + HAlow + close) / 4;

plot HAMA = Average(HAclose, length1);

HAMA.DefineColor("Up", GetColor(1));
HAMA.DefineColor("Down", GetColor(0));
HAMA.AssignValueColor(if HAMA > HAMA[1] then HAMA.color("Up") else HAMA.color("Down"));
# END

# START
input length2 = 70;


plot HAMA1 = Average(HAclose, length2);

HAMA1.DefineColor("Up", GetColor(1));
HAMA1.DefineColor("Down", GetColor(0));
HAMA1.AssignValueColor(if HAMA1 > HAMA1[1] then HAMA1.color("Up") else HAMA1.color("Down"));
# END

# START
input length3 = 100;


plot HAMA3 = Average(HAclose, length2);

HAMA3.DefineColor("Up", GetColor(1));
HAMA3.DefineColor("Down", GetColor(0));
HAMA3.AssignValueColor(if HAMA3 > HAMA3[1] then HAMA3.color("Up") else HAMA3.color("Down"));
# END

def GreenPrice = HAMA > HAMA[1] and HAMA1 > HAMA1[1] and HAMA3 > HAMA3[1];
def RedPrice = HAMA < HAMA[1] and HAMA1 < HAMA1[1] and HAMA3 < HAMA3[1];

plot Bullish = GreenPrice;
plot Neutral = !GreenPrice and !RedPrice;
plot Bearish = RedPrice;

Bullish.SetDefaultColor(Color.UPTICK);
Bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
Bullish.SetLineWeight(3);
Bullish.hide();
Neutral.SetDefaultColor(Color.BLUE);
Neutral.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
Neutral.SetLineWeight(3);
Neutral.hide();
Bearish.SetDefaultColor(Color.DOWNTICK);
Bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
Bearish.SetLineWeight(3);
Bearish.hide();

DefineGlobalColor("Bullish", Color.UPTICK);
DefineGlobalColor("Neutral", Color.GRAY);
DefineGlobalColor("Bearish", Color.DOWNTICK);
AssignPriceColor(if !paintBars then Color.CURRENT else if GreenPrice then globalColor("Bullish") else if RedPrice then globalColor("Bearish") else globalColor("Neutral"));


addOrder(OrderType.BUY_AUTO, Bullish);
addOrder(OrderType.SELL_TO_CLOSE, Neutral);
addOrder(OrderType.SELL_AUTO, Bearish);
addOrder(OrderType.BUY_TO_CLOSE, Neutral);
 
@tenacity11 - this chart looks amazing to me as far a potential entry/exit signals. I also like the other indicators you have on there. any chance you have a TOS grid with these studies? Thanks. Joe
 
@Nicholas Correct. All backtesting strategies in ThinkorSwim are for testing only. The platform does not support auto trading.
 
@Nicholas Correct. All backtesting strategies in ThinkorSwim are for testing only. The platform does not support auto trading.
Thank you. Yes I’m using this strategy /MES, 3/3 day green.... today 740am-840 very choppy , 930-934 caught 10 points...
I’m using HAMA weighted 35/111/200
 
Hi Ben, I hate to sound totally stupid all the time but I only ask after I research things that I can't find answers for. On intraday charts say 3 min and 5 min for regular hours trading, 9:30am - 4pm are you supposed to have the "Start Aggregation at Market Open" box checked or unchecked?? Because most of the shared grids have this checked but this guy:

Pete Hahn...https://www.hahn-tech.com/thinkorswim-mtf-macd-indicator/

Says:“Start Aggregation at Market Open”, is a setting that impacts allignment between intraday charts and the rest of the tools on the platform. Uncheck this option to ensure your intraday charts align with the rest of the platform.

So that is why I am confused to what its purpose is and if I should have all my charts checked or unchecked. Thanks as always for your help!

zrOyegc.png

nXDSabF.png
 
@Joseph Patrick 18 Hey, that setting is checked by default in ThinkorSwim. I can see why Pete would say that because the intraday timeframe that ToS uses in their scanner does not include aggregation at the market open. I think it's entirely up to you as to whether you want ToS to "start aggregation at market open" or not. For me, I leave it as is.
 
@Joseph Patrick 18 Hey, that setting is checked by default in ThinkorSwim. I can see why Pete would say that because the intraday timeframe that ToS uses in their scanner does not include aggregation at the market open. I think it's entirely up to you as to whether you want ToS to "start aggregation at market open" or not. For me, I leave it as is.
Ok then I will keep as is just wanted to make sure. Thanks Ben
 
@Joseph Patrick 18 Hey, that setting is checked by default in ThinkorSwim. I can see why Pete would say that because the intraday timeframe that ToS uses in their scanner does not include aggregation at the market open. I think it's entirely up to you as to whether you want ToS to "start aggregation at market open" or not. For me, I leave it as is.
@BenTen Did I get this right? So intraday scanners one would use in TOS are not "programmed" to scan for results when the "Start Aggregation At Market Open" box is checked? This can influence when the scan results appear in the watchlist columns when you're scanning for particular criteria as I have seen a difference in plotting with and without the checked box same with and without extended hours enabled.
 
@HighBredCloud By default, the "Start Aggregation At Market Open" box is checked for your chart. However, that does not apply to your watchlist column or your scanner. I hope that makes sense.
 
I love your code, been using it.

Could I ask for another version where
2 HAMA of same colour, signal an entry.
(35 and 110 , when both hiken Ashi are green, 2nd brick entry. )

Many thanks
When 35 change colour 2nd brick EXIT
(the faster MA, reverse to red , end of trend/trend change)
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
419 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